@gitlab/ui 38.4.0 → 38.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ # [38.5.0](https://gitlab.com/gitlab-org/gitlab-ui/compare/v38.4.0...v38.5.0) (2022-04-05)
2
+
3
+
4
+ ### Features
5
+
6
+ * **GlFilteredSearch:** Allow to pass token dynamically ([7c85ea1](https://gitlab.com/gitlab-org/gitlab-ui/commit/7c85ea19c3ffb821fdb4f5f6409e4db816de304e))
7
+ * **GlFilteredSearch:** Allow to pass token dynamically ([38f67eb](https://gitlab.com/gitlab-org/gitlab-ui/commit/38f67eb3df2369f39e1323c1a5c90ab2f7b13847))
8
+
1
9
  # [38.4.0](https://gitlab.com/gitlab-org/gitlab-ui/compare/v38.3.0...v38.4.0) (2022-04-04)
2
10
 
3
11
 
@@ -1,3 +1,4 @@
1
+ import _isEqual from 'lodash/isEqual';
1
2
  import _cloneDeep from 'lodash/cloneDeep';
2
3
  import PortalVue from 'portal-vue';
3
4
  import Vue from 'vue';
@@ -184,15 +185,17 @@ var script = {
184
185
 
185
186
  deep: true,
186
187
  immediate: true
187
- }
188
- },
188
+ },
189
+ value: {
190
+ handler(newValue, oldValue) {
191
+ if (newValue.length && !_isEqual(newValue, oldValue)) {
192
+ this.applyNewValue(_cloneDeep(newValue));
193
+ }
194
+ },
189
195
 
190
- mounted() {
191
- if (this.value.length) {
192
- this.applyNewValue(_cloneDeep(this.value));
196
+ immediate: true
193
197
  }
194
198
  },
195
-
196
199
  methods: {
197
200
  applyNewValue(newValue) {
198
201
  this.tokens = needDenormalization(newValue) ? denormalizeTokens(newValue) : newValue;
@@ -166,6 +166,7 @@ var script = {
166
166
  },
167
167
 
168
168
  currentValue(newValue) {
169
+ if (newValue === this.value) return;
169
170
  this.$emit('input', newValue);
170
171
  }
171
172
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gitlab/ui",
3
- "version": "38.4.0",
3
+ "version": "38.5.0",
4
4
  "description": "GitLab UI Components",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -730,4 +730,23 @@ describe('Filtered search integration tests', () => {
730
730
  wrapper.findAllComponents(GlFilteredSearchToken).wrappers.map((cmp) => cmp.props('active'))
731
731
  ).toEqual([false, false]);
732
732
  });
733
+
734
+ it('updates tokens list when value is passed dynamically', async () => {
735
+ mountComponent({ value: ['one'] });
736
+ await nextTick();
737
+
738
+ expect(wrapper.findAllComponents(GlFilteredSearchTerm)).toHaveLength(2);
739
+
740
+ await wrapper.setProps({
741
+ value: ['one two'],
742
+ });
743
+
744
+ const termComponents = wrapper.findAllComponents(GlFilteredSearchTerm).wrappers;
745
+ expect(termComponents).toHaveLength(3);
746
+ expect(termComponents.map((termComponent) => termComponent.props('value'))).toEqual([
747
+ { data: 'one' },
748
+ { data: 'two' },
749
+ { data: '' },
750
+ ]);
751
+ });
733
752
  });
@@ -1,5 +1,5 @@
1
1
  <script>
2
- import { cloneDeep } from 'lodash';
2
+ import { cloneDeep, isEqual } from 'lodash';
3
3
  import PortalVue from 'portal-vue';
4
4
  import Vue from 'vue';
5
5
  import { GlTooltipDirective } from '../../../directives/tooltip';
@@ -174,11 +174,14 @@ export default {
174
174
  deep: true,
175
175
  immediate: true,
176
176
  },
177
- },
178
- mounted() {
179
- if (this.value.length) {
180
- this.applyNewValue(cloneDeep(this.value));
181
- }
177
+ value: {
178
+ handler(newValue, oldValue) {
179
+ if (newValue.length && !isEqual(newValue, oldValue)) {
180
+ this.applyNewValue(cloneDeep(newValue));
181
+ }
182
+ },
183
+ immediate: true,
184
+ },
182
185
  },
183
186
 
184
187
  methods: {
@@ -36,6 +36,14 @@ describe('search box by click component', () => {
36
36
  expect(wrapper.emitted().input).toEqual([['new value']]);
37
37
  });
38
38
 
39
+ it('does not emit an input event when input is updated to the same value', async () => {
40
+ createComponent({ value: 'somevalue' });
41
+
42
+ await wrapper.setProps({ value: 'another value' });
43
+
44
+ expect(wrapper.emitted().input).toBe(undefined);
45
+ });
46
+
39
47
  it('does not displays history dropdown by default', () => {
40
48
  createComponent();
41
49
  expect(wrapper.findComponent({ ref: 'historyDropdown' }).exists()).toBe(false);
@@ -152,6 +152,7 @@ export default {
152
152
  immediate: true,
153
153
  },
154
154
  currentValue(newValue) {
155
+ if (newValue === this.value) return;
155
156
  this.$emit('input', newValue);
156
157
  },
157
158
  },