@webitel/ui-datalist 26.8.15 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webitel/ui-datalist",
3
- "version": "26.8.15",
3
+ "version": "26.8.17",
4
4
  "description": "Toolkit for building data lists in webitel ui system",
5
5
  "scripts": {
6
6
  "build:types": "vue-tsc -b tsconfig.build.json",
@@ -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 && isEmpty(filterValue.value)) {
145
+ if (props.columnMode && isEmptyFilterValue(filterValue.value)) {
146
146
  return !editMode || !filterName.value || !!props.filterConfig?.notDeletable;
147
147
  }
148
148
 
@@ -113,6 +113,46 @@ describe('StaticFilterField', () => {
113
113
  expect(wrapper.emitted('delete:filter')).toHaveLength(1);
114
114
  });
115
115
 
116
+ it('deletes an applied range filter when both bounds are cleared', () => {
117
+ filtersManager.addFilter({
118
+ name: FilterOption.Agent,
119
+ value: {
120
+ from: 10,
121
+ to: 20,
122
+ },
123
+ });
124
+
125
+ const wrapper = mountField(deletableConfig, filtersManager);
126
+
127
+ emitValue(wrapper, {
128
+ from: null,
129
+ to: null,
130
+ });
131
+
132
+ expect(wrapper.emitted('delete:filter')).toHaveLength(1);
133
+ expect(wrapper.emitted('update:filter')).toBeUndefined();
134
+ });
135
+
136
+ it('updates an applied range filter when one bound is left', () => {
137
+ filtersManager.addFilter({
138
+ name: FilterOption.Agent,
139
+ value: {
140
+ from: 10,
141
+ to: 20,
142
+ },
143
+ });
144
+
145
+ const wrapper = mountField(deletableConfig, filtersManager);
146
+
147
+ emitValue(wrapper, {
148
+ from: null,
149
+ to: 20,
150
+ });
151
+
152
+ expect(wrapper.emitted('delete:filter')).toBeUndefined();
153
+ expect(wrapper.emitted('update:filter')).toHaveLength(1);
154
+ });
155
+
116
156
  it('keeps a notDeletable filter when its field is cleared', () => {
117
157
  filtersManager.addFilter({
118
158
  name: FilterOption.JoinedAt,
@@ -1,9 +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';
6
+ import { isEmptyFilterValue } from '../scripts/utils';
7
7
 
8
8
  type StaticFilterEmit = <K extends keyof StaticFilterEmits>(
9
9
  event: K,
@@ -23,13 +23,13 @@ export const useFilterValueChange = ({
23
23
  const currentFilter = toValue(filter);
24
24
  const config = toValue(filterConfig);
25
25
 
26
- if (isEmpty(value) && typeof value !== 'boolean') {
26
+ if (isEmptyFilterValue(value)) {
27
27
  if (!currentFilter) return;
28
28
  if (config.notDeletable) return;
29
29
  return emit('delete:filter', currentFilter);
30
30
  }
31
31
 
32
- if (isEmpty(currentFilter?.value)) {
32
+ if (isEmptyFilterValue(currentFilter?.value)) {
33
33
  return emit('add:filter', {
34
34
  name: config.name,
35
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 type { FilterData, FilterName } from '../classes/Filter';
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
+ };
@@ -59,7 +59,8 @@ export const tableHeadersStoreBody = ({
59
59
  }: {
60
60
  column: DatalistTableHeader;
61
61
  order: DatalistTableHeader['sort'];
62
- }) => `${sortToQueryAdapter(order)}${column.field}`;
62
+ }) =>
63
+ `${sortToQueryAdapter(typeof order === 'boolean' ? undefined : order)}${column.field}`;
63
64
 
64
65
  const sortedCol = headers.value.find((header) => header.sort);
65
66