@webitel/ui-sdk 24.10.23 → 24.10.24

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": "24.10.23",
3
+ "version": "24.10.24",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "dev": "vite",
@@ -49,7 +49,10 @@ export default class CSVExport {
49
49
  }
50
50
 
51
51
  save(csv) {
52
- const blob = new Blob([csv], { type: 'data:text/csv;charset=utf-8' });
52
+ // Prepending '\uFEFF' (the BOM) forces these applications to treat the file as UTF-8,
53
+ // ensuring that non-ASCII characters, such as Cyrillic, are displayed correctly.
54
+ const bom = '\uFEFF';
55
+ const blob = new Blob([bom + csv], { type: 'data:text/csv;charset=utf-8' });
53
56
  saveAs(blob, `${this.filename}.csv`);
54
57
  }
55
58
 
@@ -0,0 +1,40 @@
1
+ <template>
2
+ <wt-datepicker
3
+ :label="filterSchema.label"
4
+ :value="value"
5
+ mode="datetime"
6
+ @input="setValue"
7
+ />
8
+ </template>
9
+
10
+ <script setup>
11
+ import { computed } from 'vue';
12
+ import { useStore } from 'vuex';
13
+ import getNamespacedState from '../../../store/helpers/getNamespacedState.js';
14
+
15
+ const props = defineProps({
16
+ namespace: {
17
+ type: String,
18
+ required: true,
19
+ },
20
+ filterQuery: {
21
+ type: String,
22
+ required: true,
23
+ },
24
+ });
25
+
26
+ const store = useStore();
27
+
28
+ const filterSchema = computed(() => getNamespacedState(store.state, props.namespace)[props.filterQuery]);
29
+
30
+ const value = computed(() => store.getters[`${props.namespace}/FILTER_${props.filterQuery}`]);
31
+
32
+ const setValue = (value) => {
33
+ const payload = { value, name: props.filterQuery };
34
+ return store.dispatch(`${props.namespace}/SET_FILTER`, payload);
35
+ };
36
+ </script>
37
+
38
+ <style scoped>
39
+
40
+ </style>
@@ -17,9 +17,15 @@ export const useTableFilters = (namespace) => {
17
17
  return store.dispatch(`${filtersNamespace}/RESTORE_FILTERS`, payload);
18
18
  }
19
19
 
20
+ function resetFilters(payload) {
21
+ return store.dispatch(`${filtersNamespace}/RESET_FILTERS`, payload);
22
+ }
23
+
20
24
  return {
21
25
  namespace: filtersNamespace,
26
+
22
27
  restoreFilters,
28
+ resetFilters,
23
29
 
24
30
  subscribe,
25
31
  flushSubscribers,
@@ -1,6 +1,7 @@
1
1
  const FilterEvent = Object.freeze({
2
2
  FILTER_SET: 'FILTER_SET',
3
3
  RESTORED: 'RESTORED',
4
+ RESET: 'RESET',
4
5
  });
5
6
 
6
7
  export default FilterEvent;
@@ -1,6 +1,7 @@
1
1
  import mitt from 'mitt';
2
2
  import isEmpty from '../../../scripts/isEmpty.js';
3
- import BaseStoreModule from '../../../store/BaseStoreModules/BaseStoreModule.js';
3
+ import BaseStoreModule
4
+ from '../../../store/BaseStoreModules/BaseStoreModule.js';
4
5
  import BaseFilterSchema from '../classes/BaseFilterSchema.js';
5
6
  import FilterEvent from '../enums/FilterEvent.enum.js';
6
7
 
@@ -117,17 +118,43 @@ export default class FiltersStoreModule extends BaseStoreModule {
117
118
  });
118
119
  },
119
120
 
120
- RESET_FILTERS: (context) =>
121
- Promise.allSettled(
122
- context.getters._FILTER_NAMES.map((name) => {
123
- const filter = context.state[name];
121
+ RESET_FILTER: (context, { name }) => {
122
+ const filter = context.state[name];
123
+
124
+ return context.dispatch('SET_FILTER', {
125
+ name,
126
+ value: filter.defaultValue,
127
+ silent: true,
128
+ });
129
+ },
124
130
 
125
- return context.dispatch('SET_FILTER', {
126
- filter,
127
- value: filter.defaultValue,
128
- });
131
+ RESET_FILTERS: async (context) => {
132
+ await Promise.allSettled(
133
+ context.getters._STATE_FILTER_NAMES.map((name) => {
134
+ return context.dispatch('RESET_FILTER', { name });
129
135
  }),
130
- ),
136
+ );
137
+
138
+ // clean up query params
139
+ const router = context.getters.ROUTER;
140
+ const query = Object.entries(router.currentRoute.query)
141
+ .reduce((filteredQuery, [qKey, qValue]) => {
142
+ if (context.state[qKey]) {
143
+ return filteredQuery;
144
+ }
145
+ return { ...filteredQuery, [qKey]: qValue };
146
+ }, {});
147
+
148
+ await router.push({
149
+ ...router.currentRoute,
150
+ query,
151
+ });
152
+
153
+ return context.dispatch('EMIT', {
154
+ event: FilterEvent.RESET,
155
+ payload: context.getters.GET_FILTERS(),
156
+ });
157
+ },
131
158
 
132
159
  SUBSCRIBE: (context, { event, callback }) => {
133
160
  const subscribe = () => context.state._emitter.on(event, callback);
@@ -174,6 +201,12 @@ export default class FiltersStoreModule extends BaseStoreModule {
174
201
  const stateFilter = new BaseFilterSchema(filter);
175
202
  if (stateFilter.requireRouter) this.state._requireRouter = true;
176
203
  this.state[filter.name] = stateFilter;
204
+ this.getters[`FILTER_${filter.name}`] = (state, getters) => {
205
+ // if is used as watcher for getter to recompute,
206
+ // because GET_FILTER is function ==> it's not reactive
207
+ if (state[filter.name].value) {}
208
+ return getters.GET_FILTER(filter.name);
209
+ };
177
210
  };
178
211
 
179
212
  if (Array.isArray(filter)) filter.forEach((f) => setup(f));
@@ -1,5 +1,9 @@
1
- import { queryToSortAdapter, sortToQueryAdapter } from '../../../scripts/sortQueryAdapters.js';
2
- import BaseStoreModule from '../../../store/BaseStoreModules/BaseStoreModule.js';
1
+ import {
2
+ queryToSortAdapter,
3
+ sortToQueryAdapter,
4
+ } from '../../../scripts/sortQueryAdapters.js';
5
+ import BaseStoreModule
6
+ from '../../../store/BaseStoreModules/BaseStoreModule.js';
3
7
  import FilterEvent from '../../Filters/enums/FilterEvent.enum.js';
4
8
 
5
9
  export default class TableStoreModule extends BaseStoreModule {
@@ -53,6 +57,8 @@ export default class TableStoreModule extends BaseStoreModule {
53
57
  return context.dispatch('HANDLE_FILTERS_RESTORE', payload);
54
58
  case FilterEvent.FILTER_SET:
55
59
  return context.dispatch('HANDLE_FILTER_SET', payload);
60
+ case FilterEvent.RESET:
61
+ return context.dispatch('HANDLE_FILTER_RESET', payload);
56
62
  default:
57
63
  throw new Error(`Unknown filter event: ${event}`);
58
64
  }
@@ -65,6 +71,13 @@ export default class TableStoreModule extends BaseStoreModule {
65
71
  return context.dispatch('LOAD_DATA_LIST');
66
72
  },
67
73
 
74
+ // FIXME: maybe move to filters module?
75
+ HANDLE_FILTER_RESET: async (context, { fields, sort }) => {
76
+ if (sort) await context.dispatch('HANDLE_SORT_CHANGE', { value: sort });
77
+ if (fields?.length) await context.dispatch('HANDLE_FIELDS_CHANGE', { value: fields });
78
+ return context.dispatch('LOAD_DATA_LIST');
79
+ },
80
+
68
81
  // FIXME: maybe move to filters module?
69
82
  HANDLE_FILTER_SET: async (context, payload) => {
70
83
  if (payload.name === 'fields') {
@@ -54,6 +54,8 @@ const actions = {
54
54
  return context.dispatch('HANDLE_FILTERS_RESTORE', payload);
55
55
  case FilterEvent.FILTER_SET:
56
56
  return context.dispatch('HANDLE_FILTER_SET', payload);
57
+ case FilterEvent.RESET:
58
+ return context.dispatch('HANDLE_FILTER_RESET', payload);
57
59
  default:
58
60
  throw new Error(`Unknown filter event: ${event}`);
59
61
  }
@@ -66,6 +68,13 @@ const actions = {
66
68
  return context.dispatch('LOAD_DATA_LIST');
67
69
  },
68
70
 
71
+ // FIXME: maybe move to filters module?
72
+ HANDLE_FILTER_RESET: async (context, { fields, sort }) => {
73
+ if (sort) await context.dispatch('HANDLE_SORT_CHANGE', { value: sort });
74
+ if (fields?.length) await context.dispatch('HANDLE_FIELDS_CHANGE', { value: fields });
75
+ return context.dispatch('LOAD_DATA_LIST');
76
+ },
77
+
69
78
  // FIXME: maybe move to filters module?
70
79
  HANDLE_FILTER_SET: async (context, payload) => {
71
80
  if (payload.name === 'fields') {