@webitel/ui-sdk 3.2.49 → 3.2.51
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/dist/ui-sdk.common.js +5 -4
- package/dist/ui-sdk.common.js.map +1 -1
- package/dist/ui-sdk.umd.js +5 -4
- package/dist/ui-sdk.umd.js.map +1 -1
- package/dist/ui-sdk.umd.min.js +1 -1
- package/dist/ui-sdk.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/src/modules/Filters/store/FiltersStoreModule.js +33 -18
- package/src/modules/TableStoreModule/composables/useTableStore.js +0 -29
- package/src/modules/TableStoreModule/store/TableStoreModule.js +11 -65
- package/src/scripts/debounce.js +4 -1
package/package.json
CHANGED
|
@@ -5,6 +5,16 @@ import BaseStoreModule from '../../../store/BaseStoreModules/BaseStoreModule';
|
|
|
5
5
|
|
|
6
6
|
export default class FiltersStoreModule extends BaseStoreModule {
|
|
7
7
|
getters = {
|
|
8
|
+
ROUTER: () => console.error('setup ROUTER getter for filters store'),
|
|
9
|
+
TABLE_NAMESPACE: () => console.error('setup TABLE_NAMESPACE getter for filters store'),
|
|
10
|
+
|
|
11
|
+
GET_FILTER: (state) => (filter) => {
|
|
12
|
+
if (!state[filter]) return null;
|
|
13
|
+
const { value, storedProp, multiple } = state[filter];
|
|
14
|
+
if (multiple) return value.map((item) => item[storedProp]); // if arr, map
|
|
15
|
+
if (storedProp) return value[storedProp]; // if object and has specific prop, return this prop
|
|
16
|
+
return value; // else return val
|
|
17
|
+
},
|
|
8
18
|
GET_FILTERS: (state, getters) => Object.keys(state)
|
|
9
19
|
.reduce((filters, filterKey) => {
|
|
10
20
|
const filterValue = getters.GET_FILTER(filterKey);
|
|
@@ -13,13 +23,6 @@ export default class FiltersStoreModule extends BaseStoreModule {
|
|
|
13
23
|
[filterKey]: filterValue,
|
|
14
24
|
};
|
|
15
25
|
}, {}),
|
|
16
|
-
GET_FILTER: (state) => (filter) => {
|
|
17
|
-
if (!state[filter]) return null;
|
|
18
|
-
const { value, storedProp, multiple } = state[filter];
|
|
19
|
-
if (multiple) return value.map((item) => item[storedProp]); // if arr, map
|
|
20
|
-
if (storedProp) return value[storedProp]; // if object and has specific prop, return this prop
|
|
21
|
-
return value; // else return val
|
|
22
|
-
},
|
|
23
26
|
GET_VALUE_FROM_QUERY: (state, getters) => ({ filterQuery }) => (
|
|
24
27
|
getters.ROUTER.currentRoute.value.query[filterQuery]
|
|
25
28
|
),
|
|
@@ -40,7 +43,12 @@ export default class FiltersStoreModule extends BaseStoreModule {
|
|
|
40
43
|
});
|
|
41
44
|
context.commit('SET_FILTER', { filter, value: newValue });
|
|
42
45
|
|
|
43
|
-
if (filter !== 'page')
|
|
46
|
+
if (filter !== 'page') {
|
|
47
|
+
context.dispatch('SET_FILTER', {
|
|
48
|
+
filter: 'page',
|
|
49
|
+
value: 1,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
44
52
|
|
|
45
53
|
return context.dispatch('ON_FILTER_SET', { filter, value });
|
|
46
54
|
},
|
|
@@ -80,10 +88,14 @@ export default class FiltersStoreModule extends BaseStoreModule {
|
|
|
80
88
|
const query = context.getters.GET_VALUE_FROM_QUERY({ filterQuery: filter });
|
|
81
89
|
// note: restore fn may still return value even if there's no query value
|
|
82
90
|
// from localStorage, for instance
|
|
83
|
-
const value = context.state[filter].restore
|
|
91
|
+
const value = context.state[filter].restore
|
|
92
|
+
? context.state[filter].restore({ query })
|
|
93
|
+
: query;
|
|
84
94
|
if (value) {
|
|
85
|
-
if (filter
|
|
86
|
-
|
|
95
|
+
if (filter
|
|
96
|
+
=== 'sort') await context.dispatch('RESTORE_SORT', { value });
|
|
97
|
+
else if (filter
|
|
98
|
+
=== 'fields') await context.dispatch('RESTORE_FIELDS', { value });
|
|
87
99
|
await context.dispatch('SET_FILTER', ({ filter, value }));
|
|
88
100
|
return true;
|
|
89
101
|
}
|
|
@@ -104,9 +116,17 @@ export default class FiltersStoreModule extends BaseStoreModule {
|
|
|
104
116
|
}
|
|
105
117
|
},
|
|
106
118
|
RESET_FILTERS: (context) => {
|
|
107
|
-
context.
|
|
119
|
+
Object.keys(context.state).forEach((filter) => {
|
|
120
|
+
context.dispatch('SET_FILTER', {
|
|
121
|
+
filter,
|
|
122
|
+
value: context.state[filter].defaultValue,
|
|
123
|
+
});
|
|
124
|
+
});
|
|
108
125
|
},
|
|
109
|
-
ON_FILTER_SET: debounce((
|
|
126
|
+
ON_FILTER_SET: debounce((
|
|
127
|
+
context,
|
|
128
|
+
{ filter, value },
|
|
129
|
+
) => context.dispatch('LOAD_DATA_LIST'), 500),
|
|
110
130
|
|
|
111
131
|
LOAD_DATA_LIST: (context) => context.dispatch(
|
|
112
132
|
`${context.getters.TABLE_NAMESPACE}/LOAD_DATA_LIST`,
|
|
@@ -129,10 +149,5 @@ export default class FiltersStoreModule extends BaseStoreModule {
|
|
|
129
149
|
SET_FILTER: (state, { filter, value }) => {
|
|
130
150
|
state[filter].value = value;
|
|
131
151
|
},
|
|
132
|
-
RESET_FILTERS: (state) => {
|
|
133
|
-
Object.keys(state).forEach((filter) => {
|
|
134
|
-
state[filter].value = state[filter].defaultValue;
|
|
135
|
-
});
|
|
136
|
-
},
|
|
137
152
|
};
|
|
138
153
|
}
|
|
@@ -16,29 +16,11 @@ export const useTableStore = (namespace) => {
|
|
|
16
16
|
|
|
17
17
|
const isNext = computed(() => getNamespacedState(store.state, tableNamespace).isNextPage);
|
|
18
18
|
|
|
19
|
-
const page = computed(() => getNamespacedState(store.state, tableNamespace).page);
|
|
20
|
-
|
|
21
|
-
const size = computed(() => getNamespacedState(store.state, tableNamespace).size);
|
|
22
|
-
|
|
23
|
-
const search = computed(() => getNamespacedState(store.state, tableNamespace).search);
|
|
24
|
-
|
|
25
19
|
const error = computed(() => getNamespacedState(store.state, tableNamespace).errors);
|
|
26
20
|
async function loadData(payload) {
|
|
27
21
|
return store.dispatch(`${tableNamespace}/LOAD_DATA_LIST`, payload);
|
|
28
22
|
}
|
|
29
23
|
|
|
30
|
-
async function setSize(payload) {
|
|
31
|
-
return store.dispatch(`${tableNamespace}/SET_SIZE`, payload);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async function nextPage() {
|
|
35
|
-
return store.dispatch(`${tableNamespace}/NEXT_PAGE`);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
async function prevPage() {
|
|
39
|
-
return store.dispatch(`${tableNamespace}/PREV_PAGE`);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
24
|
async function patchProperty(payload) {
|
|
43
25
|
return store.dispatch(`${tableNamespace}/PATCH_ITEM_PROPERTY`, payload);
|
|
44
26
|
}
|
|
@@ -58,10 +40,6 @@ export const useTableStore = (namespace) => {
|
|
|
58
40
|
return store.dispatch(`${tableNamespace}/SET_HEADERS`, payload);
|
|
59
41
|
}
|
|
60
42
|
|
|
61
|
-
async function setSearch(payload) {
|
|
62
|
-
return store.dispatch(`${tableNamespace}/SET_SEARCH`, payload);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
43
|
return {
|
|
66
44
|
namespace: tableNamespace,
|
|
67
45
|
|
|
@@ -69,19 +47,12 @@ export const useTableStore = (namespace) => {
|
|
|
69
47
|
isLoading,
|
|
70
48
|
headers,
|
|
71
49
|
isNext,
|
|
72
|
-
page,
|
|
73
|
-
size,
|
|
74
|
-
search,
|
|
75
50
|
error,
|
|
76
51
|
|
|
77
52
|
loadData,
|
|
78
|
-
setSize,
|
|
79
|
-
nextPage,
|
|
80
|
-
prevPage,
|
|
81
53
|
patchProperty,
|
|
82
54
|
deleteData,
|
|
83
55
|
sort,
|
|
84
56
|
setHeaders,
|
|
85
|
-
setSearch,
|
|
86
57
|
};
|
|
87
58
|
};
|
|
@@ -27,8 +27,8 @@ export default class TableStoreModule extends BaseStoreModule {
|
|
|
27
27
|
.map((header) => header.field);
|
|
28
28
|
|
|
29
29
|
const getFieldsByFieldValues = (values) => {
|
|
30
|
-
values.map((passedValue) => state.headers.find(({ value }) => passedValue
|
|
31
|
-
value).field);
|
|
30
|
+
values.map((passedValue) => state.headers.find(({ value }) => passedValue
|
|
31
|
+
=== value).field);
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
return [
|
|
@@ -52,10 +52,6 @@ export default class TableStoreModule extends BaseStoreModule {
|
|
|
52
52
|
};
|
|
53
53
|
|
|
54
54
|
actions = {
|
|
55
|
-
// HOOKS TO BE OVERRIDEN, IF NEEDED
|
|
56
|
-
BEFORE_SET_DATA_LIST_HOOK: (context, { items, next }) => ({ items, next }),
|
|
57
|
-
AFTER_SET_DATA_LIST_HOOK: (context, { items, next }) => ({ items, next }),
|
|
58
|
-
|
|
59
55
|
LOAD_DATA_LIST: async (context, query) => {
|
|
60
56
|
const params = context.getters.GET_LIST_PARAMS(query);
|
|
61
57
|
try {
|
|
@@ -69,44 +65,15 @@ export default class TableStoreModule extends BaseStoreModule {
|
|
|
69
65
|
* admin-specific were replaced by webitel-sdk consumers and i supposed it will be
|
|
70
66
|
* weird to set this property in each api file through defaultListObject */
|
|
71
67
|
items = items.map((item) => ({ ...item, _isSelected: false }));
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
next,
|
|
75
|
-
});
|
|
76
|
-
context.commit('SET_DATA_LIST', afterHook.items);
|
|
77
|
-
context.commit('SET_IS_NEXT', afterHook.next);
|
|
78
|
-
context.dispatch('AFTER_SET_DATA_LIST_HOOK', afterHook);
|
|
68
|
+
context.commit('SET_DATA_LIST', items);
|
|
69
|
+
context.commit('SET_IS_NEXT', next);
|
|
79
70
|
} catch (err) {
|
|
80
|
-
console.error(err);
|
|
81
71
|
context.commit('SET_ERROR', err);
|
|
82
72
|
} finally {
|
|
83
73
|
context.commit('SET_LOADING', false);
|
|
84
74
|
}
|
|
85
75
|
},
|
|
86
|
-
|
|
87
|
-
context.commit('SET_SIZE', size);
|
|
88
|
-
await context.dispatch('RESET_PAGE');
|
|
89
|
-
},
|
|
90
|
-
SET_SEARCH: async (context, search) => {
|
|
91
|
-
context.commit('SET_SEARCH', search);
|
|
92
|
-
await context.dispatch('RESET_PAGE');
|
|
93
|
-
},
|
|
94
|
-
NEXT_PAGE: (context) => {
|
|
95
|
-
const page = context.state.page + 1;
|
|
96
|
-
context.commit('SET_PAGE', page);
|
|
97
|
-
context.dispatch('LOAD_DATA_LIST');
|
|
98
|
-
},
|
|
99
|
-
PREV_PAGE: (context) => {
|
|
100
|
-
if (context.state.page > 1) {
|
|
101
|
-
const page = context.state.page - 1;
|
|
102
|
-
context.commit('SET_PAGE', page);
|
|
103
|
-
context.dispatch('LOAD_DATA_LIST');
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
|
-
RESET_PAGE: (context) => {
|
|
107
|
-
const page = 1;
|
|
108
|
-
context.commit('SET_PAGE', page);
|
|
109
|
-
},
|
|
76
|
+
SET_HEADERS: (context, headers) => context.commit('SET_HEADERS', headers),
|
|
110
77
|
RESTORE_FIELDS_FROM_FILTER: (context, { value }) => {
|
|
111
78
|
const headers = context.state.headers.map((header) => ({
|
|
112
79
|
...header,
|
|
@@ -114,7 +81,6 @@ export default class TableStoreModule extends BaseStoreModule {
|
|
|
114
81
|
}));
|
|
115
82
|
return context.dispatch('SET_HEADERS', headers);
|
|
116
83
|
},
|
|
117
|
-
SET_HEADERS: (context, headers) => context.commit('SET_HEADERS', headers),
|
|
118
84
|
SORT: async (context, { header, nextSortOrder }) => {
|
|
119
85
|
const sort = nextSortOrder
|
|
120
86
|
? `${sortToQueryAdapter(nextSortOrder)}${header.field}`
|
|
@@ -134,14 +100,12 @@ export default class TableStoreModule extends BaseStoreModule {
|
|
|
134
100
|
});
|
|
135
101
|
},
|
|
136
102
|
UPDATE_HEADER_SORT: (context, { header, nextSortOrder }) => {
|
|
137
|
-
const headers = context.state.headers.map((oldHeader) => {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
};
|
|
144
|
-
});
|
|
103
|
+
const headers = context.state.headers.map((oldHeader) => ({
|
|
104
|
+
...oldHeader,
|
|
105
|
+
sort: oldHeader.field === header.field
|
|
106
|
+
? nextSortOrder
|
|
107
|
+
: SortSymbols.NONE,
|
|
108
|
+
}));
|
|
145
109
|
context.commit('SET_HEADERS', headers);
|
|
146
110
|
},
|
|
147
111
|
PATCH_ITEM_PROPERTY: async (context, {
|
|
@@ -184,30 +148,12 @@ export default class TableStoreModule extends BaseStoreModule {
|
|
|
184
148
|
context,
|
|
185
149
|
deleted,
|
|
186
150
|
) => Promise.allSettled(deleted.map((item) => context.dispatch('DELETE_SINGLE', item))),
|
|
187
|
-
// REMOVE_ITEM: async (context, index) => {
|
|
188
|
-
// const id = context.state.dataList[index].id;
|
|
189
|
-
// context.commit('REMOVE_ITEM', index);
|
|
190
|
-
// try {
|
|
191
|
-
// await context.dispatch('DELETE_ITEM', id);
|
|
192
|
-
// } catch (err) {
|
|
193
|
-
// throw err;
|
|
194
|
-
// }
|
|
195
|
-
// },
|
|
196
151
|
};
|
|
197
152
|
|
|
198
153
|
mutations = {
|
|
199
154
|
SET_DATA_LIST: (state, items) => {
|
|
200
155
|
state.dataList = items;
|
|
201
156
|
},
|
|
202
|
-
SET_SIZE: (state, size) => {
|
|
203
|
-
state.size = size;
|
|
204
|
-
},
|
|
205
|
-
SET_SEARCH: (state, search) => {
|
|
206
|
-
state.search = search;
|
|
207
|
-
},
|
|
208
|
-
SET_PAGE: (state, page) => {
|
|
209
|
-
state.page = page;
|
|
210
|
-
},
|
|
211
157
|
SET_IS_NEXT: (state, next) => {
|
|
212
158
|
state.isNextPage = next;
|
|
213
159
|
},
|
package/src/scripts/debounce.js
CHANGED