@webitel/ui-sdk 3.2.164 → 3.2.165

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-sdk",
3
- "version": "3.2.164",
3
+ "version": "3.2.165",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "serve-lib": "vue-cli-service serve",
@@ -3,11 +3,17 @@ import debounce from '../../../scripts/debounce';
3
3
  import isEmpty from '../../../scripts/isEmpty';
4
4
  import BaseStoreModule from '../../../store/BaseStoreModules/BaseStoreModule';
5
5
 
6
+ const SET_FILTER_SOURCE = Object.freeze({
7
+ RESTORE: 'restore', // when filter is restored at session start
8
+ DEFAULT: 'default',
9
+ });
10
+
6
11
  export default class FiltersStoreModule extends BaseStoreModule {
7
12
  getters = {
8
13
  ROUTER: () => console.error('setup ROUTER getter for filters store'),
9
14
  TABLE_NAMESPACE: () => console.error('setup TABLE_NAMESPACE getter for filters store'),
10
15
 
16
+ // get value of specific filter
11
17
  GET_FILTER: (state) => (filter) => {
12
18
  if (!state[filter]) return null;
13
19
  const { value, storedProp, multiple } = state[filter];
@@ -15,6 +21,8 @@ export default class FiltersStoreModule extends BaseStoreModule {
15
21
  if (storedProp) return value[storedProp]; // if object and has specific prop, return this prop
16
22
  return value; // else return val
17
23
  },
24
+
25
+ // get all filters values
18
26
  GET_FILTERS: (state, getters) => Object.keys(state)
19
27
  .reduce((filters, filterKey) => {
20
28
  const filterValue = getters.GET_FILTER(filterKey);
@@ -23,6 +31,8 @@ export default class FiltersStoreModule extends BaseStoreModule {
23
31
  [filterKey]: filterValue,
24
32
  };
25
33
  }, {}),
34
+
35
+ // get value of filter from query string by query key
26
36
  GET_VALUE_FROM_QUERY: (state, getters) => ({ filterQuery }) => (
27
37
  getters.ROUTER.currentRoute.value.query[filterQuery]
28
38
  ),
@@ -32,14 +42,19 @@ export default class FiltersStoreModule extends BaseStoreModule {
32
42
  SET_FILTER: async (context, {
33
43
  filter,
34
44
  value,
35
- source, // === restore, if this is filters restore call
45
+ source = SET_FILTER_SOURCE.DEFAULT,
46
+ silent = false, // if true, don't call ON_FILTER_SET event
36
47
  }) => {
37
48
  const { multiple, defaultValue } = context.state[filter];
49
+
38
50
  let newValue = value;
39
- if (newValue) {
40
- if (multiple && !Array.isArray(newValue)) newValue = [newValue];
41
- } else if (newValue === null || newValue
42
- === undefined) newValue = defaultValue;
51
+
52
+ if (value) {
53
+ if (multiple && !Array.isArray(value)) newValue = [value];
54
+ } else if (value === null || value === undefined) {
55
+ newValue = defaultValue;
56
+ }
57
+
43
58
  await context.dispatch('SET_VALUE_TO_QUERY', {
44
59
  filterQuery: filter,
45
60
  value,
@@ -47,14 +62,15 @@ export default class FiltersStoreModule extends BaseStoreModule {
47
62
  });
48
63
  context.commit('SET_FILTER', { filter, value: newValue });
49
64
 
50
- if (source !== 'restore' && filter !== 'page') {
51
- context.dispatch('SET_FILTER', {
65
+ if (source !== SET_FILTER_SOURCE.RESTORE && filter !== 'page') {
66
+ await context.dispatch('SET_FILTER', {
52
67
  filter: 'page',
53
68
  value: 1,
69
+ silent: true,
54
70
  });
55
71
  }
56
72
 
57
- return context.dispatch('ON_FILTER_SET', { filter, value });
73
+ if (!silent) await context.dispatch('ON_FILTER_SET', { filter, value });
58
74
  },
59
75
  SET_VALUE_TO_QUERY: async (
60
76
  context,
@@ -78,6 +94,7 @@ export default class FiltersStoreModule extends BaseStoreModule {
78
94
  filterQuery,
79
95
  }));
80
96
  },
97
+
81
98
  CHANGE_ROUTE_QUERY: (context, { value, filterQuery }) => {
82
99
  if (deepEqual(context.getters.GET_VALUE_FROM_QUERY({ filterQuery }), value)) return;
83
100
  const query = { ...context.getters.ROUTER.currentRoute.value.query };
@@ -88,6 +105,7 @@ export default class FiltersStoreModule extends BaseStoreModule {
88
105
  query,
89
106
  });
90
107
  },
108
+
91
109
  RESTORE_FILTER: async (context, { filter }) => {
92
110
  const query = context.getters.GET_VALUE_FROM_QUERY({ filterQuery: filter });
93
111
  // note: restore fn may still return value even if there's no query value
@@ -100,11 +118,16 @@ export default class FiltersStoreModule extends BaseStoreModule {
100
118
  === 'sort') await context.dispatch('RESTORE_SORT', { value });
101
119
  else if (filter
102
120
  === 'fields') await context.dispatch('RESTORE_FIELDS', { value });
103
- await context.dispatch('SET_FILTER', ({ filter, value, source: 'restore' }));
121
+ await context.dispatch('SET_FILTER', ({
122
+ filter,
123
+ value,
124
+ source: SET_FILTER_SOURCE.RESTORE,
125
+ }));
104
126
  return true;
105
127
  }
106
128
  return false;
107
129
  },
130
+
108
131
  RESTORE_FILTERS: async (context) => {
109
132
  const restores = [];
110
133
  for (const filter of Object.keys(context.state)) {
@@ -119,18 +142,19 @@ export default class FiltersStoreModule extends BaseStoreModule {
119
142
  context.dispatch('LOAD_DATA_LIST');
120
143
  }
121
144
  },
122
- RESET_FILTERS: (context) => {
123
- Object.keys(context.state).forEach((filter) => {
124
- context.dispatch('SET_FILTER', {
125
- filter,
126
- value: context.state[filter].defaultValue,
127
- });
145
+
146
+ RESET_FILTERS: (context) => Promise.allSettled(Object.keys(context.state)
147
+ .map((filter) => {
148
+ return context.dispatch('SET_FILTER', {
149
+ filter,
150
+ value: context.state[filter].defaultValue,
128
151
  });
129
- },
130
- ON_FILTER_SET: debounce((
152
+ })),
153
+
154
+ ON_FILTER_SET: (
131
155
  context,
132
156
  { filter, value },
133
- ) => context.dispatch('LOAD_DATA_LIST'), 500),
157
+ ) => context.dispatch('LOAD_DATA_LIST'),
134
158
 
135
159
  LOAD_DATA_LIST: (context) => context.dispatch(
136
160
  `${context.getters.TABLE_NAMESPACE}/LOAD_DATA_LIST`,