@farm-investimentos/front-mfe-components 15.7.2 → 15.7.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farm-investimentos/front-mfe-components",
3
- "version": "15.7.2",
3
+ "version": "15.7.4",
4
4
  "author": "farm investimentos",
5
5
  "private": false,
6
6
  "main": "./dist/front-mfe-components.common.js",
@@ -31,7 +31,7 @@ export const Primary = () => ({
31
31
  formattedDate: '13/06/2022 20:40',
32
32
  status: 'error',
33
33
  },
34
-
34
+
35
35
  {
36
36
  message: 'Aprovado entre as pré elegíveis',
37
37
  userName: 'Cleyton Rasta',
@@ -69,10 +69,10 @@ export const Primary = () => ({
69
69
  status: 'success',
70
70
  },
71
71
  {
72
- message: 'Info',
72
+ message: 'Em validação',
73
73
  userName: 'Cleyton Rasta',
74
74
  formattedDate: '13/06/2022 20:40',
75
- status: 'info',
75
+ status: 'warning',
76
76
  },
77
77
  ],
78
78
  };
@@ -174,7 +174,7 @@ export const Horizontal = () => ({
174
174
  details() {
175
175
  alert('Ver Detalhes');
176
176
  },
177
- }
177
+ },
178
178
  ],
179
179
  };
180
180
  },
@@ -220,7 +220,7 @@ export const HorizontalLeftAligned = () => ({
220
220
  details() {
221
221
  alert('Ver Detalhes');
222
222
  },
223
- }
223
+ },
224
224
  ],
225
225
  };
226
226
  },
@@ -62,6 +62,10 @@
62
62
  @include loggerMessage(var(--farm-info-base));
63
63
  }
64
64
 
65
+ &.logger__item--warning {
66
+ @include loggerMessage(var(--farm-warning-base));
67
+ }
68
+
65
69
  &--horizontal {
66
70
  flex-direction: column;
67
71
  height: auto;
@@ -74,6 +74,20 @@ export const Info = () => ({
74
74
  template: `<farm-logger-item :item="item" />`,
75
75
  });
76
76
 
77
+ export const Warning = () => ({
78
+ data() {
79
+ return {
80
+ item: {
81
+ message: 'Recusado entre as pré elegíveis',
82
+ userName: 'Cleyton Rasta',
83
+ formattedDate: '13/06/2022 20:40',
84
+ status: 'warning',
85
+ },
86
+ };
87
+ },
88
+ template: `<farm-logger-item :item="item" />`,
89
+ });
90
+
77
91
  export const ExtraMessage = () => ({
78
92
  data() {
79
93
  return {
@@ -137,6 +151,17 @@ export const Details = () => ({
137
151
  alert('Ver Detalhes');
138
152
  },
139
153
  },
154
+
155
+ {
156
+ icon: 'book',
157
+ message: 'Warning',
158
+ userName: 'Cleyton Rasta',
159
+ formattedDate: '13/06/2022 20:40',
160
+ status: 'warning',
161
+ details() {
162
+ alert('Ver Detalhes');
163
+ },
164
+ },
140
165
  ],
141
166
  };
142
167
  },
@@ -2,4 +2,5 @@ export default {
2
2
  success: 'check',
3
3
  info: 'timer-sand',
4
4
  error: 'close',
5
+ warning: 'alert-circle-outline',
5
6
  };
@@ -288,6 +288,42 @@ export const Multiple = () => ({
288
288
  </div>`,
289
289
  });
290
290
 
291
+ export const MultipleWithAllOption = () => ({
292
+ data() {
293
+ return {
294
+ v: null,
295
+ items: [
296
+ { value: 0, text: 'value 0' },
297
+ { value: 1, text: 'value 1' },
298
+ { value: 2, text: 'value 2' },
299
+ { value: 3, text: 'value 3' },
300
+ ],
301
+ };
302
+ },
303
+ template: `<div style="width: 400px">
304
+ <farm-select v-model="v" :items="items" multiple has-all-option />
305
+ v-model: {{ v }}
306
+ </div>`,
307
+ });
308
+
309
+ export const MultipleWithAllOptionAndDisabledItems = () => ({
310
+ data() {
311
+ return {
312
+ v: null,
313
+ items: [
314
+ { value: 0, text: 'value 0' },
315
+ { value: 1, text: 'value 1', disabled: true },
316
+ { value: 2, text: 'value 2' },
317
+ { value: 3, text: 'value 3', disabled: true },
318
+ ],
319
+ };
320
+ },
321
+ template: `<div style="width: 400px">
322
+ <farm-select v-model="v" :items="items" multiple has-all-option />
323
+ v-model: {{ v }}
324
+ </div>`,
325
+ });
326
+
291
327
  export const MultipleInitValue = () => ({
292
328
  data() {
293
329
  return {
@@ -1,5 +1,7 @@
1
1
  <template>
2
2
  <div
3
+ v-if="!readonly && !disabled"
4
+ :id="customId"
3
5
  :class="{
4
6
  'farm-textfield': true,
5
7
  'farm-textfield--validatable': rules.length > 0,
@@ -10,8 +12,6 @@
10
12
  'farm-textfield--focused': isFocus || isVisible,
11
13
  'farm-textfield--hiddendetails': hideDetails,
12
14
  }"
13
- v-if="!readonly && !disabled"
14
- :id="customId"
15
15
  >
16
16
  <farm-contextmenu
17
17
  bottom
@@ -20,13 +20,34 @@
20
20
  ref="contextmenu"
21
21
  >
22
22
  <farm-list v-if="!readonly" ref="listRef" @keydown="onKeyDown">
23
+ <farm-listitem
24
+ v-if="hasAllOption"
25
+ tabindex="0"
26
+ clickable
27
+ hover-color-variation="lighten"
28
+ :hover-color="hasAllDisabled ? 'neutral' : 'primary'"
29
+ :class="{
30
+ 'farm-listitem--selected': innerValue === 'all',
31
+ 'farm-listitem--disabled': hasAllDisabled,
32
+ }"
33
+ @click="selectAll"
34
+ >
35
+ <farm-checkbox
36
+ v-model="hasAllSelected"
37
+ class="farm-select__checkbox"
38
+ value="all"
39
+ size="sm"
40
+ :disabled="hasAllDisabled"
41
+ />
42
+ <farm-caption bold tag="span">Todos</farm-caption>
43
+ </farm-listitem>
23
44
  <farm-listitem
24
45
  v-for="(item, index) in items"
25
46
  tabindex="0"
26
47
  clickable
27
48
  hover-color-variation="lighten"
28
- :hover-color="item.disabled ? 'neutral' : 'primary'"
29
49
  :key="'contextmenu_item_' + index"
50
+ :hover-color="item.disabled ? 'neutral' : 'primary'"
30
51
  :class="{
31
52
  'farm-listitem--selected': item[itemValue] === innerValue,
32
53
  'farm-listitem--disabled': item.disabled,
@@ -34,20 +55,20 @@
34
55
  @click="selectItem(item)"
35
56
  >
36
57
  <farm-checkbox
37
- class="farm-select__checkbox"
58
+ v-if="isChecked(item)"
38
59
  v-model="checked"
60
+ class="farm-select__checkbox"
39
61
  value="1"
40
62
  size="sm"
41
63
  :disabled="item.disabled"
42
- v-if="isChecked(item)"
43
64
  />
44
65
  <farm-checkbox
45
- class="farm-select__checkbox"
66
+ v-else-if="multiple"
46
67
  v-model="checked"
68
+ class="farm-select__checkbox"
47
69
  value="2"
48
70
  size="sm"
49
71
  :disabled="item.disabled"
50
- v-else-if="multiple"
51
72
  />
52
73
  <farm-caption bold tag="span">{{ item[itemText] }}</farm-caption>
53
74
  </farm-listitem>
@@ -55,7 +76,7 @@
55
76
  {{ noDataText }}
56
77
  </farm-listitem>
57
78
  </farm-list>
58
- <template v-slot:activator="{}">
79
+ <template #activator="{}">
59
80
  <div
60
81
  class="farm-textfield--input farm-textfield--input--iconed"
61
82
  @keydown="onKeyDown"
@@ -198,6 +219,13 @@ export default defineComponent({
198
219
  type: String,
199
220
  default: '',
200
221
  },
222
+ /**
223
+ * Set "All" as first option to select all other values<br />
224
+ */
225
+ hasAllOption: {
226
+ type: Boolean,
227
+ default: false,
228
+ },
201
229
  /**
202
230
  * The updated bound model<br />
203
231
  * _event_
@@ -262,9 +290,32 @@ export default defineComponent({
262
290
  let fieldValidator = validateFormFieldBuilder(rules.value);
263
291
  let validate = validateFormMethodBuilder(errorBucket, valid, fieldValidator);
264
292
 
293
+ const enabledItems = computed(() => items.value.filter(item => !item.disabled));
294
+ const disabledItems = computed(() => items.value.filter(item => item.disabled));
265
295
  const hasError = computed(() => {
266
296
  return errorBucket.value.length > 0;
267
297
  });
298
+ const hasAllSelected = computed({
299
+ get() {
300
+ if (
301
+ !multiple.value ||
302
+ !Array.isArray(items.value) ||
303
+ !Array.isArray(innerValue.value)
304
+ ) {
305
+ return false;
306
+ }
307
+
308
+ if (innerValue.value.length === enabledItems.value.length) {
309
+ return 'all';
310
+ }
311
+
312
+ return false;
313
+ },
314
+ set() {
315
+ emit('input', innerValue.value);
316
+ },
317
+ });
318
+ const hasAllDisabled = computed(() => items.value.length == disabledItems.value.length);
268
319
 
269
320
  const customId = 'farm-select-' + (props.id || randomId(2));
270
321
 
@@ -282,6 +333,7 @@ export default defineComponent({
282
333
  ) {
283
334
  multipleValues.value = [];
284
335
  }
336
+
285
337
  if (Array.isArray(newValue) && newValue.length > 0) {
286
338
  multipleValues.value = [...newValue];
287
339
  }
@@ -386,6 +438,21 @@ export default defineComponent({
386
438
  emit('change', innerValue.value);
387
439
  }, 100);
388
440
  };
441
+ const selectAll = () => {
442
+ if (hasAllDisabled.value) {
443
+ return;
444
+ }
445
+
446
+ if (multipleValues.value.length === enabledItems.value.length) {
447
+ multipleValues.value = [];
448
+ } else {
449
+ multipleValues.value = enabledItems.value.map(item => item[itemValue.value]);
450
+ }
451
+
452
+ checked.value = '1';
453
+ innerValue.value = [...multipleValues.value];
454
+ validate(innerValue.value);
455
+ };
389
456
 
390
457
  const clickInput = () => {
391
458
  isTouched.value = true;
@@ -474,6 +541,8 @@ export default defineComponent({
474
541
  valid,
475
542
  validatable,
476
543
  hasError,
544
+ hasAllSelected,
545
+ hasAllDisabled,
477
546
  isTouched,
478
547
  isBlured,
479
548
  isFocus,
@@ -485,6 +554,7 @@ export default defineComponent({
485
554
  validate,
486
555
  reset,
487
556
  selectItem,
557
+ selectAll,
488
558
  onBlur,
489
559
  onFocus,
490
560
  clickInput,
@@ -1,17 +1,16 @@
1
1
  import { shallowMount } from '@vue/test-utils';
2
2
  import Select from '../Select';
3
3
 
4
- /* jest.spyOn(global, 'setTimeout').mockImplementation(fn => {
5
- fn();
6
- return setTimeout(() => 1, 0);
7
- }); */
8
-
9
4
  describe('Select component', () => {
10
5
  let wrapper;
11
6
  let component;
12
7
 
13
8
  beforeEach(() => {
14
- wrapper = shallowMount(Select);
9
+ wrapper = shallowMount(Select, {
10
+ propsData: {
11
+ id: 'my-custom-id',
12
+ },
13
+ });
15
14
  component = wrapper.vm;
16
15
  });
17
16
 
@@ -145,21 +144,15 @@ describe('Select component', () => {
145
144
 
146
145
  expect(component.innerValue).toBe(1);
147
146
  expect(component.selectedText).toBe('value 1');
147
+
148
148
  component.selectItem(items[2]);
149
- setTimeout(() => {
150
- expect(component.innerValue).toBe(2);
151
- expect(component.selectedText).toBe('value 2');
152
- }, 150);
149
+ expect(component.innerValue).toBe(2);
150
+
153
151
  component.selectItem(items[0]);
154
- setTimeout(() => {
155
- expect(component.innerValue).toBe(2);
156
- expect(component.selectedText).toBe('value 2');
157
- }, 150);
152
+ expect(component.innerValue).toBe(2);
153
+
158
154
  component.selectItem(items[3]);
159
- setTimeout(() => {
160
- expect(component.innerValue).toBe(3);
161
- expect(component.selectedText).toBe('value 3');
162
- }, 150);
155
+ expect(component.innerValue).toBe(3);
163
156
  });
164
157
  it('should not select a disabled item if is multiple', async () => {
165
158
  const items = [
@@ -177,16 +170,67 @@ describe('Select component', () => {
177
170
 
178
171
  expect(component.innerValue).toEqual([0]);
179
172
  expect(component.selectedText).toBe('value 0');
173
+
180
174
  component.selectItem(items[2]);
181
- setTimeout(() => {
182
- expect(component.innerValue).toEqual([0, 2]);
183
- expect(component.selectedText).toBe('value 0 (+1 outro)');
184
- }, 150);
175
+ expect(component.innerValue).toEqual([0, 2]);
176
+
185
177
  component.selectItem(items[1]);
186
- setTimeout(() => {
187
- expect(component.innerValue).toEqual([0, 2]);
188
- expect(component.selectedText).toBe('value 0 (+1 outro)');
189
- }, 150);
178
+ expect(component.innerValue).toEqual([0, 2]);
179
+
180
+ component.selectItem(items[0]);
181
+ expect(component.innerValue).toEqual([2]);
182
+
183
+ component.selectItem(items[0]);
184
+ expect(component.innerValue).toEqual([2, 0]);
185
+ });
186
+ });
187
+
188
+ describe('multiple with all option', () => {
189
+ it('should check all options', async () => {
190
+ const items = [
191
+ { value: 0, text: 'value 0' },
192
+ { value: 1, text: 'value 1' },
193
+ { value: 2, text: 'value 2' },
194
+ { value: 3, text: 'value 3' },
195
+ ];
196
+
197
+ await wrapper.setProps({
198
+ items,
199
+ value: null,
200
+ multiple: true,
201
+ });
202
+
203
+ expect(component.hasAllSelected).toBe(false);
204
+ expect(component.multipleValues).toEqual([]);
205
+
206
+ component.selectAll();
207
+
208
+ expect(component.hasAllSelected).toBe('all');
209
+ expect(component.multipleValues).toEqual(items.map(item => item.value));
210
+ });
211
+ it('should check all options but disabled', async () => {
212
+ const items = [
213
+ { value: 0, text: 'value 0' },
214
+ { value: 1, text: 'value 1', disabled: true },
215
+ { value: 2, text: 'value 2' },
216
+ { value: 3, text: 'value 3', disabled: true },
217
+ ];
218
+
219
+ await wrapper.setProps({
220
+ items,
221
+ value: null,
222
+ multiple: true,
223
+ });
224
+
225
+ expect(component.hasAllSelected).toBe(false);
226
+ expect(component.multipleValues).toEqual([]);
227
+
228
+ component.selectAll();
229
+
230
+ expect(component.hasAllSelected).toBe('all');
231
+ expect(component.multipleValues).toEqual(
232
+ items.filter(item => !item.disabled).map(item => item.value)
233
+ );
190
234
  });
191
235
  });
192
236