@webitel/ui-datalist 26.8.16 → 26.8.17
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 +1 -1
- package/src/modules/filters/components/config/dynamic-view/dynamic-filter-config-form.vue +2 -2
- package/src/modules/filters/composables/useFilterValueChange.ts +2 -11
- package/src/modules/filters/scripts/__tests__/utils.spec.ts +40 -0
- package/src/modules/filters/scripts/utils.ts +12 -1
- package/types/.tsbuildinfo +1 -1
- package/types/modules/filters/scripts/utils.d.ts +2 -1
package/package.json
CHANGED
|
@@ -70,13 +70,13 @@
|
|
|
70
70
|
import { useVuelidate } from '@vuelidate/core';
|
|
71
71
|
import { required } from '@vuelidate/validators';
|
|
72
72
|
import { WtButton, WtSingleSelect } from '@webitel/ui-sdk/components';
|
|
73
|
-
import { isEmpty } from '@webitel/ui-sdk/scripts';
|
|
74
73
|
import deepcopy from 'deep-copy';
|
|
75
74
|
import { computed, ref, watch } from 'vue';
|
|
76
75
|
import { useI18n } from 'vue-i18n';
|
|
77
76
|
|
|
78
77
|
import { FilterInitParams, IFilter } from '../../../classes/Filter';
|
|
79
78
|
import { BaseFilterConfig } from '../../../modules/filterConfig/classes/FilterConfig';
|
|
79
|
+
import { isEmptyFilterValue } from '../../../scripts/utils';
|
|
80
80
|
import DynamicFilterConfigFormLabel from './dynamic-filter-config-form-label.vue';
|
|
81
81
|
import DynamicFilterConfigFormValueInput from './dynamic-filter-config-form-value-input.vue';
|
|
82
82
|
|
|
@@ -142,7 +142,7 @@ v$.value.$touch();
|
|
|
142
142
|
const invalid = ref(false);
|
|
143
143
|
|
|
144
144
|
const isSubmitDisabled = computed(() => {
|
|
145
|
-
if (props.columnMode &&
|
|
145
|
+
if (props.columnMode && isEmptyFilterValue(filterValue.value)) {
|
|
146
146
|
return !editMode || !filterName.value || !!props.filterConfig?.notDeletable;
|
|
147
147
|
}
|
|
148
148
|
|
|
@@ -1,18 +1,9 @@
|
|
|
1
|
-
import { isEmpty } from '@webitel/ui-sdk/scripts';
|
|
2
1
|
import { type MaybeRefOrGetter, toValue } from 'vue';
|
|
3
2
|
|
|
4
3
|
import type { FilterValue, IFilter } from '../classes/Filter';
|
|
5
4
|
import type { StaticFilterEmits } from '../components/types/Filter.types';
|
|
6
5
|
import type { AnyFilterConfig } from '../modules/filterConfig';
|
|
7
|
-
|
|
8
|
-
const isEmptyFilterValue = (value: FilterValue) => {
|
|
9
|
-
if (typeof value === 'boolean') return false;
|
|
10
|
-
if (isEmpty(value)) return true;
|
|
11
|
-
if (typeof value !== 'object' || Array.isArray(value)) return false;
|
|
12
|
-
return Object.values(value).every(
|
|
13
|
-
(field) => field === null || field === undefined || field === '',
|
|
14
|
-
);
|
|
15
|
-
};
|
|
6
|
+
import { isEmptyFilterValue } from '../scripts/utils';
|
|
16
7
|
|
|
17
8
|
type StaticFilterEmit = <K extends keyof StaticFilterEmits>(
|
|
18
9
|
event: K,
|
|
@@ -38,7 +29,7 @@ export const useFilterValueChange = ({
|
|
|
38
29
|
return emit('delete:filter', currentFilter);
|
|
39
30
|
}
|
|
40
31
|
|
|
41
|
-
if (
|
|
32
|
+
if (isEmptyFilterValue(currentFilter?.value)) {
|
|
42
33
|
return emit('add:filter', {
|
|
43
34
|
name: config.name,
|
|
44
35
|
value,
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { isEmptyFilterValue } from '../utils';
|
|
4
|
+
|
|
5
|
+
describe('isEmptyFilterValue', () => {
|
|
6
|
+
it.each([
|
|
7
|
+
true,
|
|
8
|
+
false,
|
|
9
|
+
])('treats boolean %s as a non-empty value', (value) => {
|
|
10
|
+
expect(isEmptyFilterValue(value)).toBe(false);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it.each([
|
|
14
|
+
null,
|
|
15
|
+
undefined,
|
|
16
|
+
'',
|
|
17
|
+
[],
|
|
18
|
+
{},
|
|
19
|
+
{
|
|
20
|
+
from: null,
|
|
21
|
+
to: undefined,
|
|
22
|
+
},
|
|
23
|
+
])('treats %j as an empty value', (value) => {
|
|
24
|
+
expect(isEmptyFilterValue(value)).toBe(true);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it.each([
|
|
28
|
+
'value',
|
|
29
|
+
1,
|
|
30
|
+
[
|
|
31
|
+
1,
|
|
32
|
+
],
|
|
33
|
+
{
|
|
34
|
+
from: 1,
|
|
35
|
+
to: null,
|
|
36
|
+
},
|
|
37
|
+
])('treats %j as a non-empty value', (value) => {
|
|
38
|
+
expect(isEmptyFilterValue(value)).toBe(false);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { isEmpty } from '@webitel/ui-sdk/scripts';
|
|
2
|
+
|
|
3
|
+
import type { FilterData, FilterName, FilterValue } from '../classes/Filter';
|
|
2
4
|
|
|
3
5
|
export const filterLabelToSnapshotKey = (name: FilterName): string =>
|
|
4
6
|
`${name}_lbl`;
|
|
@@ -33,3 +35,12 @@ export const filterValuePropFromSnapshotKey = (
|
|
|
33
35
|
if (isLabelSnapshotKey(snapshotKey)) return 'label';
|
|
34
36
|
if (isValueSnapshotKey(snapshotKey)) return 'value';
|
|
35
37
|
};
|
|
38
|
+
|
|
39
|
+
export const isEmptyFilterValue = (value: FilterValue): boolean => {
|
|
40
|
+
if (typeof value === 'boolean') return false;
|
|
41
|
+
if (isEmpty(value)) return true;
|
|
42
|
+
if (typeof value !== 'object' || Array.isArray(value)) return false;
|
|
43
|
+
return Object.values(value).every(
|
|
44
|
+
(field) => field === null || field === undefined || field === '',
|
|
45
|
+
);
|
|
46
|
+
};
|