@webitel/ui-sdk 3.2.11 → 3.2.12
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
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<wt-pagination
|
|
3
|
+
:next="isNext"
|
|
4
|
+
:prev="page > 1"
|
|
5
|
+
:size="localSize"
|
|
6
|
+
debounce
|
|
7
|
+
@input="localSize = $event"
|
|
8
|
+
@change="setSize(localSize)"
|
|
9
|
+
@next="setPage(page - 1)"
|
|
10
|
+
@prev="setPage(+page + 1)"
|
|
11
|
+
></wt-pagination>
|
|
12
|
+
</template>
|
|
13
|
+
|
|
14
|
+
<script setup>
|
|
15
|
+
import { computed, ref, watch } from 'vue';
|
|
16
|
+
import { useStore } from 'vuex';
|
|
17
|
+
import getNamespacedState from '../../../store/helpers/getNamespacedState';
|
|
18
|
+
|
|
19
|
+
const props = defineProps({
|
|
20
|
+
namespace: {
|
|
21
|
+
type: String,
|
|
22
|
+
required: true,
|
|
23
|
+
},
|
|
24
|
+
isNext: {
|
|
25
|
+
type: Boolean,
|
|
26
|
+
default: false,
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const pageFilterName = 'page';
|
|
31
|
+
const sizeFilterName = 'size';
|
|
32
|
+
|
|
33
|
+
const store = useStore();
|
|
34
|
+
|
|
35
|
+
const localSize = ref(0);
|
|
36
|
+
|
|
37
|
+
const page = computed(() => getNamespacedState(store.state, props.namespace)[pageFilterName].value);
|
|
38
|
+
const size = computed(() => getNamespacedState(store.state, props.namespace)[sizeFilterName].value);
|
|
39
|
+
|
|
40
|
+
function setFilter(payload) {
|
|
41
|
+
return store.dispatch(`${props.namespace}/SET_FILTER`, payload);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function setPage(value) {
|
|
45
|
+
return setFilter({ value, filter: pageFilterName });
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function setSize(value) {
|
|
49
|
+
if (value === size.value) return;
|
|
50
|
+
// eslint-disable-next-line consistent-return
|
|
51
|
+
return setFilter({ value, filter: sizeFilterName });
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
watch(size, () => {
|
|
55
|
+
localSize.value = size.value;
|
|
56
|
+
}, { immediate: true });
|
|
57
|
+
</script>
|
|
58
|
+
|
|
59
|
+
<style lang="scss" scoped>
|
|
60
|
+
|
|
61
|
+
</style>
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import deepEqual from 'deep-equal';
|
|
2
|
+
import isEmpty from '../../../scripts/isEmpty';
|
|
3
|
+
import BaseStoreModule from '../../../store/BaseStoreModules/BaseStoreModule';
|
|
4
|
+
|
|
5
|
+
export default class FiltersStoreModule extends BaseStoreModule {
|
|
6
|
+
constructor({ router }) {
|
|
7
|
+
super();
|
|
8
|
+
this.router = router;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
getters = {
|
|
12
|
+
GET_FILTERS: (state, getters) => Object.keys(state)
|
|
13
|
+
.reduce((filters, filterKey) => {
|
|
14
|
+
const filterValue = getters.GET_FILTER(filterKey);
|
|
15
|
+
return isEmpty(filterValue) ? filters : {
|
|
16
|
+
...filters,
|
|
17
|
+
[filterKey]: filterValue,
|
|
18
|
+
};
|
|
19
|
+
}, {}),
|
|
20
|
+
GET_FILTER: (state) => (filter) => {
|
|
21
|
+
const { value, storedProp, multiple } = state[filter];
|
|
22
|
+
if (multiple) return value.map((item) => item[storedProp]); // if arr, map
|
|
23
|
+
if (storedProp) return value[storedProp]; // if object and has specific prop, return this prop
|
|
24
|
+
return value; // else return val
|
|
25
|
+
},
|
|
26
|
+
GET_VALUE_FROM_QUERY: () => ({ filterQuery }) => (
|
|
27
|
+
this.router.currentRoute.value.query[filterQuery]
|
|
28
|
+
),
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
actions = {
|
|
32
|
+
SET_FILTER: async (context, { filter, value }) => {
|
|
33
|
+
const { multiple, defaultValue } = context.state[filter];
|
|
34
|
+
let newValue = value;
|
|
35
|
+
if (newValue) {
|
|
36
|
+
if (multiple && !Array.isArray(newValue)) newValue = [newValue];
|
|
37
|
+
} else if (newValue === null || newValue ===
|
|
38
|
+
undefined) newValue = defaultValue;
|
|
39
|
+
await context.dispatch('SET_VALUE_TO_QUERY', {
|
|
40
|
+
filterQuery: filter,
|
|
41
|
+
value,
|
|
42
|
+
storedProp: context.state[filter].storedProp,
|
|
43
|
+
});
|
|
44
|
+
context.commit('SET_FILTER', { filter, value: newValue });
|
|
45
|
+
},
|
|
46
|
+
SET_VALUE_TO_QUERY: async (
|
|
47
|
+
context,
|
|
48
|
+
{ filterQuery, value, storedProp = 'id' },
|
|
49
|
+
) => {
|
|
50
|
+
let newValue = '';
|
|
51
|
+
if (Array.isArray(value)) {
|
|
52
|
+
if (value.length && typeof value[0] !== 'object') {
|
|
53
|
+
newValue = value;
|
|
54
|
+
} else {
|
|
55
|
+
newValue = value.map((item) => item[storedProp]);
|
|
56
|
+
}
|
|
57
|
+
} else if (typeof value === 'object' && value !== null) {
|
|
58
|
+
newValue = value[storedProp];
|
|
59
|
+
} else {
|
|
60
|
+
newValue = value;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return context.dispatch('CHANGE_ROUTE_QUERY', ({
|
|
64
|
+
value: newValue,
|
|
65
|
+
filterQuery,
|
|
66
|
+
}));
|
|
67
|
+
},
|
|
68
|
+
CHANGE_ROUTE_QUERY: (context, { value, filterQuery }) => {
|
|
69
|
+
if (deepEqual(context.getters.GET_VALUE_FROM_QUERY({ filterQuery }), value)) return;
|
|
70
|
+
const query = { ...this.router.currentRoute.value.query };
|
|
71
|
+
query[filterQuery] = value;
|
|
72
|
+
// eslint-disable-next-line consistent-return
|
|
73
|
+
return this.router.replace({
|
|
74
|
+
name: this.router.currentRoute.value.name,
|
|
75
|
+
query,
|
|
76
|
+
});
|
|
77
|
+
},
|
|
78
|
+
// eslint-disable-next-line consistent-return
|
|
79
|
+
RESTORE_FILTER: (context, { filter }) => {
|
|
80
|
+
const value = context.getters.GET_VALUE_FROM_QUERY({ filterQuery: filter });
|
|
81
|
+
if (value) return context.dispatch('SET_FILTER', ({ filter, value }));
|
|
82
|
+
},
|
|
83
|
+
RESTORE_FILTERS: (context) => {
|
|
84
|
+
Object.keys(context.state)
|
|
85
|
+
.forEach((filter) => context.dispatch('RESTORE_FILTER', { filter }));
|
|
86
|
+
},
|
|
87
|
+
RESET_FILTERS: (context) => {
|
|
88
|
+
context.commit('RESET_FILTERS');
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
mutations = {
|
|
93
|
+
SET_FILTER: (state, { filter, value }) => {
|
|
94
|
+
state[filter].value = value;
|
|
95
|
+
},
|
|
96
|
+
RESET_FILTERS: (state) => {
|
|
97
|
+
Object.keys(state).forEach((filter) => {
|
|
98
|
+
state[filter].value = state[filter].defaultValue;
|
|
99
|
+
});
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
}
|
|
@@ -31,15 +31,15 @@ export default class TableStoreModule extends BaseStoreModule {
|
|
|
31
31
|
},
|
|
32
32
|
|
|
33
33
|
// main GET_LIST params collector
|
|
34
|
-
GET_LIST_PARAMS: (state, getters) => (
|
|
34
|
+
GET_LIST_PARAMS: (state, getters) => (overrideFilters) => {
|
|
35
35
|
const fields = getters.FIELDS.concat(getters.REQUIRED_FIELDS);
|
|
36
36
|
|
|
37
37
|
const filters = getters.GET_FILTERS || getters['filters/GET_FILTERS'];
|
|
38
38
|
|
|
39
39
|
return {
|
|
40
|
-
...query,
|
|
41
40
|
...filters,
|
|
42
41
|
fields,
|
|
42
|
+
...overrideFilters,
|
|
43
43
|
};
|
|
44
44
|
},
|
|
45
45
|
};
|
|
@@ -50,13 +50,6 @@ export default class TableStoreModule extends BaseStoreModule {
|
|
|
50
50
|
AFTER_SET_DATA_LIST_HOOK: (context, { items, next }) => ({ items, next }),
|
|
51
51
|
|
|
52
52
|
LOAD_DATA_LIST: async (context, query) => {
|
|
53
|
-
/*
|
|
54
|
-
https://my.webitel.com/browse/WTEL-3560
|
|
55
|
-
preventively disable isNext to handle case when user is clicking
|
|
56
|
-
"next" faster than actual request is made
|
|
57
|
-
*/
|
|
58
|
-
context.commit('SET_IS_NEXT', false);
|
|
59
|
-
|
|
60
53
|
const params = context.getters.GET_LIST_PARAMS(query);
|
|
61
54
|
try {
|
|
62
55
|
context.commit('SET_LOADING', true);
|