@webitel/ui-sdk 3.1.56 → 3.1.58

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.1.56",
3
+ "version": "3.1.58",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "serve-lib": "vue-cli-service serve",
@@ -0,0 +1,101 @@
1
+ <template>
2
+ <wt-table-column-select
3
+ :headers="headers"
4
+ :static-headers="staticHeaders"
5
+ @change="change"
6
+ ></wt-table-column-select>
7
+ </template>
8
+
9
+ <script>
10
+ import baseFilterMixin from '../mixins/baseFilterMixin/baseFilterMixin';
11
+
12
+ export default {
13
+ name: 'filter-table-fields',
14
+ mixins: [baseFilterMixin],
15
+ props: {
16
+ entity: {
17
+ type: String,
18
+ required: true,
19
+ },
20
+ headers: {
21
+ type: Array,
22
+ required: true,
23
+ },
24
+ staticHeaders: {
25
+ type: Array,
26
+ },
27
+ },
28
+
29
+ data: () => ({
30
+ storedProp: 'value',
31
+ filterQuery: 'fields',
32
+ }),
33
+
34
+ model: {
35
+ prop: 'headers',
36
+ event: 'change',
37
+ },
38
+
39
+ methods: {
40
+ change(headers) {
41
+ this.setValue(headers);
42
+ },
43
+
44
+ // overrides baseFilterMixin method
45
+ restore({ filterQuery }) {
46
+ const queryValue = this.getValueFromQuery({ filterQuery });
47
+ const storageValue = this.getFromLocalStorage({ filterQuery });
48
+ if (!queryValue && storageValue) {
49
+ this.setValueToQuery({
50
+ filterQuery,
51
+ value: storageValue,
52
+ storedProp: this.storedProp,
53
+ });
54
+ }
55
+ if (queryValue || storageValue) {
56
+ this.restoreValue(queryValue || storageValue);
57
+ }
58
+ },
59
+
60
+ restoreValue(value) {
61
+ const headers = this.headers.map((header) => ({
62
+ ...header,
63
+ show: !!value.includes(header.value),
64
+ }));
65
+ this.$emit('change', headers);
66
+ },
67
+
68
+ setValue(headers) {
69
+ const value = headers.filter((item) => item.show);
70
+ const params = {
71
+ filterQuery: this.filterQuery,
72
+ value,
73
+ storedProp: this.storedProp,
74
+ };
75
+ this.setValueToQuery(params);
76
+ this.setToLocalStorage(params);
77
+ this.$emit('change', headers);
78
+ },
79
+
80
+ getFromLocalStorage({ filterQuery }) {
81
+ const value = localStorage.getItem(`${this.entity}-${filterQuery}`);
82
+ return value ? value.split(',') : null;
83
+ },
84
+
85
+ // copy-pasted params from "setValueArrayToQuery method
86
+ // for easier future refactors, if method should be abstract
87
+ setToLocalStorage({
88
+ filterQuery,
89
+ value,
90
+ storedProp = 'id',
91
+ }) {
92
+ const filter = value.map((item) => item[storedProp]);
93
+ localStorage.setItem(`${this.entity}-${filterQuery}`, filter);
94
+ },
95
+ },
96
+ };
97
+ </script>
98
+
99
+ <style scoped>
100
+
101
+ </style>
@@ -17,19 +17,54 @@ export default class TableStoreModule extends BaseStoreModule {
17
17
  isNextPage: false,
18
18
  };
19
19
 
20
+ getters = {
21
+ // required fields to send as "fields" param with GET_LIST
22
+ REQUIRED_FIELDS: () => ['id'],
23
+
24
+ // fields to send with GET_LIST
25
+ FIELDS: (state) => {
26
+ let fields = state.headers
27
+ .filter((header) => header.show)
28
+ .map((header) => header.field);
29
+ fields = [...new Set(fields)];
30
+ return fields;
31
+ },
32
+ // GET_DATA_FIELDS_BY_VALUE: (state) => (headerValues) => state.headers
33
+ // .reduce((fields, header) => {
34
+ // if (headerValues.includes(header.value)) return fields.concat(header.field);
35
+ // return [...new Set(fields)];
36
+ // }, []),
37
+
38
+ // main GET_LIST params collector
39
+ GET_LIST_PARAMS: (state, getters) => (query) => {
40
+ // const fields = (query.fields
41
+ // ? getters.GET_DATA_FIELDS_BY_VALUE(query.fields)
42
+ // : getters.FIELDS).concat(getters.REQUIRED_FIELDS);
43
+ const fields = getters.FIELDS.concat(getters.REQUIRED_FIELDS);
44
+
45
+ const filters = getters.GET_FILTERS || getters['filters/GET_FILTERS'];
46
+
47
+ return {
48
+ ...query,
49
+ ...filters,
50
+ fields,
51
+ };
52
+ },
53
+ };
54
+
20
55
  actions = {
21
56
  // HOOKS TO BE OVERRIDEN, IF NEEDED
22
57
  BEFORE_SET_DATA_LIST_HOOK: (context, { items, next }) => ({ items, next }),
23
58
  AFTER_SET_DATA_LIST_HOOK: (context, { items, next }) => ({ items, next }),
24
59
 
25
- LOAD_DATA_LIST: async (context, _query) => {
26
- const query = { ...context.getters['filters/GET_FILTERS'], ..._query };
60
+ LOAD_DATA_LIST: async (context, query) => {
61
+ const params = context.getters.GET_LIST_PARAMS(query);
27
62
  try {
28
63
  context.commit('SET_LOADING', true);
29
64
  let {
30
65
  items = [],
31
66
  next = false,
32
- } = await context.dispatch('api/GET_LIST', { context, params: query });
67
+ } = await context.dispatch('api/GET_LIST', { context, params });
33
68
  /* we should set _isSelected property to all items in tables cause their checkbox selection
34
69
  * is based on this property. Previously, this prop was set it api consumers, but now
35
70
  * admin-specific were replaced by webitel-sdk consumers and i supposed it will be