@webitel/ui-sdk 24.8.11 → 24.8.13
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.js +1 -1
- package/dist/ui-sdk.umd.cjs +1 -1
- package/package.json +15 -1
- package/src/api/history/index.js +5 -0
- package/src/api/history/transcript/callTranscript.js +91 -0
- package/src/store/new/helpers/createApiStoreModule.js +8 -0
- package/src/store/new/helpers/createBaseStoreModule.js +9 -0
- package/src/store/new/helpers/createCardStoreModule.js +8 -0
- package/src/store/new/helpers/createStoreModule.js +10 -0
- package/src/store/new/helpers/createTableStoreModule.js +8 -0
- package/src/store/new/index.js +16 -0
- package/src/store/new/modules/apiStoreModule/apiStoreModule.js +95 -0
- package/src/store/new/modules/baseStoreModule/baseStoreModule.js +21 -0
- package/src/store/new/modules/cardStoreModule/cardStoreModule.js +74 -0
- package/src/store/new/modules/cardStoreModule/useCardStore.js +54 -0
- package/src/store/new/modules/tableStoreModule/__tests__/tableStoreModule.spec.js +250 -0
- package/src/store/new/modules/tableStoreModule/tableStoreModule.js +232 -0
- package/src/store/new/modules/tableStoreModule/useTableStore.js +66 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webitel/ui-sdk",
|
|
3
|
-
"version": "24.8.
|
|
3
|
+
"version": "24.8.13",
|
|
4
4
|
"private": false,
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "vite",
|
|
@@ -16,6 +16,20 @@
|
|
|
16
16
|
},
|
|
17
17
|
"main": "./dist/@webitel/ui-sdk.mjs",
|
|
18
18
|
"type": "module",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"import": "./dist/@webitel/ui-sdk.mjs",
|
|
22
|
+
"require": "./dist/@webitel/ui-sdk.cjs"
|
|
23
|
+
},
|
|
24
|
+
"./store": {
|
|
25
|
+
"import": "./src/store/index.js",
|
|
26
|
+
"require": "./src/store/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./*": {
|
|
29
|
+
"import": "./src",
|
|
30
|
+
"require": "./src"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
19
33
|
"files": [
|
|
20
34
|
"dist/*",
|
|
21
35
|
"src/api/*",
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { FileTranscriptServiceApiFactory } from 'webitel-sdk';
|
|
2
|
+
import {
|
|
3
|
+
getDefaultGetListResponse,
|
|
4
|
+
getDefaultInstance,
|
|
5
|
+
getDefaultOpenAPIConfig,
|
|
6
|
+
} from '../../defaults/index.js';
|
|
7
|
+
import applyTransform, {
|
|
8
|
+
camelToSnake,
|
|
9
|
+
merge,
|
|
10
|
+
notify,
|
|
11
|
+
snakeToCamel,
|
|
12
|
+
} from '../../transformers/index.js';
|
|
13
|
+
|
|
14
|
+
const instance = getDefaultInstance();
|
|
15
|
+
const configuration = getDefaultOpenAPIConfig();
|
|
16
|
+
|
|
17
|
+
const transcriptService = new FileTranscriptServiceApiFactory(configuration, '', instance);
|
|
18
|
+
|
|
19
|
+
const getTranscript = async ({
|
|
20
|
+
id,
|
|
21
|
+
page = 1,
|
|
22
|
+
size = 10000,
|
|
23
|
+
}) => {
|
|
24
|
+
try {
|
|
25
|
+
const response = await transcriptService.getFileTranscriptPhrases(id, page, size);
|
|
26
|
+
const { items } = applyTransform(response.data, [
|
|
27
|
+
snakeToCamel(),
|
|
28
|
+
merge(getDefaultGetListResponse()),
|
|
29
|
+
]);
|
|
30
|
+
return items;
|
|
31
|
+
} catch (err) {
|
|
32
|
+
throw applyTransform(err, [
|
|
33
|
+
notify,
|
|
34
|
+
]);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
const createTranscript = async ({ callId }) => {
|
|
40
|
+
const preRequestHandler = (callId) => {
|
|
41
|
+
return Array.isArray(callId) ? callId : [callId];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const uuid = applyTransform(callId, [
|
|
45
|
+
preRequestHandler,
|
|
46
|
+
camelToSnake(),
|
|
47
|
+
]);
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
const response = await transcriptService.createFileTranscript({ uuid });
|
|
51
|
+
return applyTransform(response.data, [
|
|
52
|
+
snakeToCamel(),
|
|
53
|
+
]);
|
|
54
|
+
} catch (err) {
|
|
55
|
+
throw applyTransform(err, [
|
|
56
|
+
notify,
|
|
57
|
+
]);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const deleteTranscript = async (item) => {
|
|
62
|
+
const preRequestHandler = ({ fileId, callId }) => {
|
|
63
|
+
if (fileId) {
|
|
64
|
+
return { id: Array.isArray(fileId) ? fileId : [fileId] };
|
|
65
|
+
} else {
|
|
66
|
+
return { uuid: Array.isArray(callId) ? callId : [callId] };
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const body = applyTransform(item, [
|
|
71
|
+
preRequestHandler,
|
|
72
|
+
camelToSnake(),
|
|
73
|
+
]);
|
|
74
|
+
|
|
75
|
+
try {
|
|
76
|
+
const response = await transcriptService.deleteFileTranscript(body);
|
|
77
|
+
return applyTransform(response.data, []);
|
|
78
|
+
} catch (err) {
|
|
79
|
+
throw applyTransform(err, [
|
|
80
|
+
notify,
|
|
81
|
+
]);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const CallTranscriptAPI = {
|
|
86
|
+
create: createTranscript,
|
|
87
|
+
get: getTranscript,
|
|
88
|
+
delete: deleteTranscript,
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export default CallTranscriptAPI;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import apiStoreModule from '../modules/apiStoreModule/apiStoreModule.js';
|
|
2
|
+
import { createBaseStoreModule } from './createBaseStoreModule.js';
|
|
3
|
+
|
|
4
|
+
export const createApiStoreModule = (modules = []) => {
|
|
5
|
+
const modulesArr = Array.isArray(modules) ? modules : [modules];
|
|
6
|
+
|
|
7
|
+
return createBaseStoreModule([apiStoreModule, ...modulesArr]);
|
|
8
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import deepmerge from 'deepmerge';
|
|
2
|
+
import { createStoreModule } from './createStoreModule.js';
|
|
3
|
+
import baseStoreModule from '../modules/baseStoreModule/baseStoreModule.js';
|
|
4
|
+
|
|
5
|
+
export const createBaseStoreModule = (modules = []) => {
|
|
6
|
+
const modulesArr = Array.isArray(modules) ? modules : [modules];
|
|
7
|
+
|
|
8
|
+
return createStoreModule([baseStoreModule, ...modulesArr]);
|
|
9
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { createBaseStoreModule } from './createBaseStoreModule.js';
|
|
2
|
+
import cardStoreModule from '../modules/cardStoreModule/cardStoreModule.js';
|
|
3
|
+
|
|
4
|
+
export const createCardStoreModule = (modules = []) => {
|
|
5
|
+
const modulesArr = Array.isArray(modules) ? modules : [modules];
|
|
6
|
+
|
|
7
|
+
return createBaseStoreModule([cardStoreModule, ...modulesArr]);
|
|
8
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import deepcopy from 'deep-copy';
|
|
2
|
+
import deepmerge from 'deepmerge';
|
|
3
|
+
|
|
4
|
+
export const createStoreModule = (modules = []) => {
|
|
5
|
+
const copied = deepcopy(modules);
|
|
6
|
+
|
|
7
|
+
const modulesArr = Array.isArray(copied) ? copied : [copied];
|
|
8
|
+
|
|
9
|
+
return deepmerge.all(modulesArr);
|
|
10
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { createBaseStoreModule } from './createBaseStoreModule';
|
|
2
|
+
import tableStoreModule from '../modules/tableStoreModule/tableStoreModule';
|
|
3
|
+
|
|
4
|
+
export const createTableStoreModule = (modules = []) => {
|
|
5
|
+
const modulesArr = Array.isArray(modules) ? modules : [modules];
|
|
6
|
+
|
|
7
|
+
return createBaseStoreModule([tableStoreModule, ...modulesArr]);
|
|
8
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createBaseStoreModule } from './helpers/createBaseStoreModule.js';
|
|
2
|
+
import { createTableStoreModule } from './helpers/createTableStoreModule.js';
|
|
3
|
+
import { createCardStoreModule } from './helpers/createCardStoreModule.js';
|
|
4
|
+
import { createApiStoreModule } from './helpers/createApiStoreModule.js';
|
|
5
|
+
|
|
6
|
+
import { useCardStore } from './modules/cardStoreModule/useCardStore.js';
|
|
7
|
+
import { useTableStore } from './modules/tableStoreModule/useTableStore.js';
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
createBaseStoreModule,
|
|
11
|
+
createTableStoreModule,
|
|
12
|
+
createCardStoreModule,
|
|
13
|
+
createApiStoreModule,
|
|
14
|
+
useCardStore,
|
|
15
|
+
useTableStore,
|
|
16
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
const getParentIdFromContext = (context) => (
|
|
2
|
+
context?.getters?.PARENT_ID || context?.state?.parentId
|
|
3
|
+
);
|
|
4
|
+
|
|
5
|
+
const state = {
|
|
6
|
+
api: null,
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const getters = {};
|
|
10
|
+
|
|
11
|
+
const actions = {
|
|
12
|
+
GET_LIST: (
|
|
13
|
+
apiContext,
|
|
14
|
+
{ context: callerContext = {}, params = {} },
|
|
15
|
+
) => {
|
|
16
|
+
if (!apiContext.state.api.getList) throw Error('No API "getList" method provided');
|
|
17
|
+
return apiContext.state.api.getList({
|
|
18
|
+
...callerContext.state,
|
|
19
|
+
parentId: getParentIdFromContext(callerContext),
|
|
20
|
+
...params,
|
|
21
|
+
});
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
GET_ITEM: (
|
|
25
|
+
apiContext,
|
|
26
|
+
{ context: callerContext = {}, params = {} } = {},
|
|
27
|
+
) => {
|
|
28
|
+
if (!apiContext.state.api.get) throw Error('No API "get" method provided');
|
|
29
|
+
return apiContext.state.api.get({
|
|
30
|
+
...callerContext.state,
|
|
31
|
+
parentId: getParentIdFromContext(callerContext),
|
|
32
|
+
...params,
|
|
33
|
+
});
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
POST_ITEM: (
|
|
37
|
+
apiContext,
|
|
38
|
+
{ context: callerContext = {}, ...rest } = {},
|
|
39
|
+
) => {
|
|
40
|
+
if (!apiContext.state.api.add) throw Error('No API "add" method provided');
|
|
41
|
+
return apiContext.state.api.add({
|
|
42
|
+
...callerContext.state,
|
|
43
|
+
parentId: getParentIdFromContext(callerContext),
|
|
44
|
+
...rest,
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
UPD_ITEM: (
|
|
49
|
+
apiContext,
|
|
50
|
+
{ context: callerContext = {}, ...rest } = {},
|
|
51
|
+
) => {
|
|
52
|
+
if (!apiContext.state.api.update) throw Error('No API "update" method provided');
|
|
53
|
+
return apiContext.state.api.update({
|
|
54
|
+
...callerContext.state,
|
|
55
|
+
parentId: getParentIdFromContext(callerContext),
|
|
56
|
+
...rest,
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
PATCH_ITEM: (
|
|
61
|
+
apiContext,
|
|
62
|
+
{ context: callerContext = {}, id, changes, ...rest },
|
|
63
|
+
) => {
|
|
64
|
+
if (!apiContext.state.api.patch) throw Error('No API "patch" method provided');
|
|
65
|
+
return apiContext.state.api.patch({
|
|
66
|
+
...callerContext.state,
|
|
67
|
+
parentId: getParentIdFromContext(callerContext),
|
|
68
|
+
...rest,
|
|
69
|
+
id,
|
|
70
|
+
changes,
|
|
71
|
+
});
|
|
72
|
+
},
|
|
73
|
+
|
|
74
|
+
DELETE_ITEM: (
|
|
75
|
+
apiContext,
|
|
76
|
+
{ context: callerContext = {}, id, ...rest },
|
|
77
|
+
) => {
|
|
78
|
+
if (!apiContext.state.api.delete) throw Error('No API "delete" method provided');
|
|
79
|
+
return apiContext.state.api.delete({
|
|
80
|
+
...callerContext.state,
|
|
81
|
+
parentId: getParentIdFromContext(callerContext),
|
|
82
|
+
...rest,
|
|
83
|
+
id,
|
|
84
|
+
});
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const mutations = {};
|
|
89
|
+
|
|
90
|
+
export default {
|
|
91
|
+
state,
|
|
92
|
+
getters,
|
|
93
|
+
actions,
|
|
94
|
+
mutations,
|
|
95
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import set from 'lodash/set';
|
|
2
|
+
|
|
3
|
+
const state = {};
|
|
4
|
+
|
|
5
|
+
const getters = {};
|
|
6
|
+
|
|
7
|
+
const actions = {};
|
|
8
|
+
|
|
9
|
+
const mutations = {
|
|
10
|
+
SET: (state, { path, value }) => {
|
|
11
|
+
return set(state, path, value);
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default {
|
|
16
|
+
state,
|
|
17
|
+
getters,
|
|
18
|
+
actions,
|
|
19
|
+
mutations,
|
|
20
|
+
namespaced: true,
|
|
21
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import deepCopy from 'deep-copy';
|
|
2
|
+
import set from 'lodash/set.js';
|
|
3
|
+
|
|
4
|
+
const state = {
|
|
5
|
+
itemId: 0,
|
|
6
|
+
itemInstance: {},
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const actions = {
|
|
10
|
+
SET_PARENT_ITEM_ID: (context, id) => {
|
|
11
|
+
context.commit('SET_PARENT_ITEM_ID', id);
|
|
12
|
+
},
|
|
13
|
+
SET_ITEM_ID: (context, id) => {
|
|
14
|
+
if (id !== 'new') context.commit('SET_ITEM_ID', id);
|
|
15
|
+
else context.commit('SET_ITEM_ID', 0);
|
|
16
|
+
},
|
|
17
|
+
LOAD_ITEM: async (context) => {
|
|
18
|
+
if (context.state.itemId) {
|
|
19
|
+
const item = await context.dispatch('api/GET_ITEM', { context });
|
|
20
|
+
context.commit('SET_ITEM', item);
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
ADD_ITEM: async (context) => {
|
|
24
|
+
if (!context.state.itemId) {
|
|
25
|
+
const { id } = await context.dispatch('api/POST_ITEM', { context });
|
|
26
|
+
await context.dispatch('SET_ITEM_ID', id);
|
|
27
|
+
context.dispatch('LOAD_ITEM');
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
UPDATE_ITEM: async (context) => {
|
|
31
|
+
await context.dispatch('api/UPD_ITEM', { context });
|
|
32
|
+
context.dispatch('LOAD_ITEM');
|
|
33
|
+
},
|
|
34
|
+
SET_ITEM_PROPERTY: (context, payload) => {
|
|
35
|
+
context.commit('SET_ITEM_PROPERTY', payload);
|
|
36
|
+
context.commit('SET_ITEM_PROPERTY', { path: '_dirty', value: true });
|
|
37
|
+
},
|
|
38
|
+
RESET_ITEM_STATE: async (context) => {
|
|
39
|
+
context.commit('RESET_ITEM_STATE');
|
|
40
|
+
},
|
|
41
|
+
DELETE_ITEM: async (context, { id }) => {
|
|
42
|
+
await context.dispatch('api/DELETE_ITEM', { context, id });
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const mutations = {
|
|
47
|
+
SET_PARENT_ITEM_ID: (state, id) => {
|
|
48
|
+
state.parentId = id;
|
|
49
|
+
},
|
|
50
|
+
SET_ITEM_ID: (state, id) => {
|
|
51
|
+
state.itemId = id;
|
|
52
|
+
},
|
|
53
|
+
SET_ITEM_PROPERTY: (state, { prop, value, path }) => {
|
|
54
|
+
if (path) {
|
|
55
|
+
set(state.itemInstance, path, value);
|
|
56
|
+
} else {
|
|
57
|
+
// DEPRECATED, LEGACY CODE
|
|
58
|
+
state.itemInstance[prop] = value;
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
SET_ITEM: (state, item) => {
|
|
62
|
+
state.itemInstance = item;
|
|
63
|
+
},
|
|
64
|
+
RESET_ITEM_STATE: (state) => {
|
|
65
|
+
Object.assign(state, deepCopy(this.state));
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export default {
|
|
70
|
+
state,
|
|
71
|
+
actions,
|
|
72
|
+
mutations,
|
|
73
|
+
};
|
|
74
|
+
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { computed } from 'vue';
|
|
2
|
+
import { useStore } from 'vuex';
|
|
3
|
+
import getNamespacedState from '../../../store/helpers/getNamespacedState.js';
|
|
4
|
+
|
|
5
|
+
export const useCardStore = (namespace) => {
|
|
6
|
+
const store = useStore();
|
|
7
|
+
|
|
8
|
+
const cardNamespace = `${namespace}/card`;
|
|
9
|
+
|
|
10
|
+
const id = computed(() => getNamespacedState(store.state, cardNamespace).itemId);
|
|
11
|
+
const itemInstance = computed(() => getNamespacedState(store.state, cardNamespace).itemInstance);
|
|
12
|
+
|
|
13
|
+
function loadItem(payload) {
|
|
14
|
+
return store.dispatch(`${cardNamespace}/LOAD_ITEM`, payload);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function addItem(payload) {
|
|
18
|
+
return store.dispatch(`${cardNamespace}/ADD_ITEM`, payload);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function updateItem(payload) {
|
|
22
|
+
return store.dispatch(`${cardNamespace}/UPDATE_ITEM`, payload);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function setId(payload) {
|
|
26
|
+
return store.dispatch(`${cardNamespace}/SET_ITEM_ID`, payload);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function resetState() {
|
|
30
|
+
return store.dispatch(`${cardNamespace}/RESET_ITEM_STATE`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function setItemProp(payload) {
|
|
34
|
+
return store.dispatch(`${cardNamespace}/SET_ITEM_PROPERTY`, payload);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function deleteItem(payload) {
|
|
38
|
+
return store.dispatch(`${cardNamespace}/DELETE_ITEM`, payload);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
namespace: cardNamespace,
|
|
43
|
+
id,
|
|
44
|
+
itemInstance,
|
|
45
|
+
|
|
46
|
+
loadItem,
|
|
47
|
+
addItem,
|
|
48
|
+
updateItem,
|
|
49
|
+
setId,
|
|
50
|
+
resetState,
|
|
51
|
+
setItemProp,
|
|
52
|
+
deleteItem,
|
|
53
|
+
};
|
|
54
|
+
};
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { createRouter, createWebHistory } from 'vue-router';
|
|
2
|
+
import { createStore } from 'vuex';
|
|
3
|
+
import { SortSymbols } from '../../../../../scripts/sortQueryAdapters.js';
|
|
4
|
+
import FilterEvent from '../../../../../modules/Filters/enums/FilterEvent.enum.js';
|
|
5
|
+
import FiltersStoreModule from '../../../../../modules/Filters/store/FiltersStoreModule.js';
|
|
6
|
+
import { createTableStoreModule } from '../../../helpers/createTableStoreModule.js';
|
|
7
|
+
|
|
8
|
+
describe('TableStoreModule', () => {
|
|
9
|
+
it('correctly computes FIELDS getter', () => {
|
|
10
|
+
const headers = [
|
|
11
|
+
{ show: true, field: 'id' },
|
|
12
|
+
{ show: false, field: 'name' },
|
|
13
|
+
{ show: true, field: 'age' },
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
const state = { headers };
|
|
17
|
+
|
|
18
|
+
expect(createTableStoreModule().getters.FIELDS(state))
|
|
19
|
+
.toEqual(['id', 'age']);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe('TableStoreModule integration with FiltersStoreModule', () => {
|
|
24
|
+
const router = createRouter({
|
|
25
|
+
history: createWebHistory(),
|
|
26
|
+
routes: [],
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('filters restore event triggers LOAD_DATA_LIST', async () => {
|
|
30
|
+
const filters = new FiltersStoreModule()
|
|
31
|
+
.addFilter({
|
|
32
|
+
name: 'vi',
|
|
33
|
+
value: 23,
|
|
34
|
+
defaultValue: 23,
|
|
35
|
+
get: ['value'],
|
|
36
|
+
set: ['value'],
|
|
37
|
+
restore: () => 'vivi',
|
|
38
|
+
})
|
|
39
|
+
.getModule();
|
|
40
|
+
|
|
41
|
+
const table = createTableStoreModule({
|
|
42
|
+
modules: { filters },
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const mock = vi.fn();
|
|
46
|
+
vi.spyOn(table.actions, 'LOAD_DATA_LIST')
|
|
47
|
+
.mockImplementationOnce(mock);
|
|
48
|
+
|
|
49
|
+
const store = createStore({
|
|
50
|
+
state: { router },
|
|
51
|
+
modules: { table },
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
await store.dispatch('table/filters/SUBSCRIBE', {
|
|
55
|
+
event: FilterEvent.RESTORED,
|
|
56
|
+
callback: (payload) => store.dispatch('table/ON_FILTER_EVENT', payload),
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
await store.dispatch('table/filters/RESTORE_FILTERS');
|
|
60
|
+
|
|
61
|
+
expect(mock).toHaveBeenCalledTimes(1);
|
|
62
|
+
|
|
63
|
+
await store.dispatch('table/filters/FLUSH_SUBSCRIBERS');
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('FILTER_SET event triggers LOAD_DATA_LIST', async () => {
|
|
67
|
+
const filters = new FiltersStoreModule()
|
|
68
|
+
.addFilter({
|
|
69
|
+
name: 'vi',
|
|
70
|
+
value: 23,
|
|
71
|
+
defaultValue: 23,
|
|
72
|
+
get: ['value'],
|
|
73
|
+
set: ['value'],
|
|
74
|
+
restore: () => {},
|
|
75
|
+
})
|
|
76
|
+
.getModule();
|
|
77
|
+
|
|
78
|
+
const table = createTableStoreModule({
|
|
79
|
+
modules: { filters },
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
const mock = vi.fn();
|
|
83
|
+
vi.spyOn(table.actions, 'LOAD_DATA_LIST')
|
|
84
|
+
.mockImplementationOnce(mock);
|
|
85
|
+
|
|
86
|
+
const store = createStore({
|
|
87
|
+
state: { router },
|
|
88
|
+
modules: { table },
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
await store.dispatch('table/filters/SUBSCRIBE', {
|
|
92
|
+
event: FilterEvent.FILTER_SET,
|
|
93
|
+
callback: (payload) => store.dispatch('table/ON_FILTER_EVENT', payload),
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
await store.dispatch('table/filters/SET_FILTER', {
|
|
97
|
+
name: 'vi',
|
|
98
|
+
value: 24,
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
expect(store.getters['table/filters/GET_FILTER']('vi')).toBe(24);
|
|
102
|
+
|
|
103
|
+
expect(mock).toHaveBeenCalledTimes(1);
|
|
104
|
+
|
|
105
|
+
await store.dispatch('table/filters/FLUSH_SUBSCRIBERS');
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('FILTER_SET with not-page filter name resets page filter', async () => {
|
|
109
|
+
const filters = new FiltersStoreModule()
|
|
110
|
+
.addFilter([
|
|
111
|
+
{
|
|
112
|
+
name: 'vi',
|
|
113
|
+
value: 23,
|
|
114
|
+
defaultValue: 23,
|
|
115
|
+
get: ['value'],
|
|
116
|
+
set: ['value'],
|
|
117
|
+
restore: () => {},
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
name: 'page',
|
|
121
|
+
value: 12,
|
|
122
|
+
defaultValue: 12,
|
|
123
|
+
get: ['value'],
|
|
124
|
+
set: ['value'],
|
|
125
|
+
restore: () => {},
|
|
126
|
+
},
|
|
127
|
+
])
|
|
128
|
+
.getModule();
|
|
129
|
+
|
|
130
|
+
const table = createTableStoreModule({
|
|
131
|
+
modules: { filters },
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
vi.spyOn(table.actions, 'LOAD_DATA_LIST')
|
|
135
|
+
.mockImplementationOnce(vi.fn());
|
|
136
|
+
|
|
137
|
+
const store = createStore({
|
|
138
|
+
state: { router },
|
|
139
|
+
modules: { table },
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
await store.dispatch('table/filters/SUBSCRIBE', {
|
|
143
|
+
event: FilterEvent.FILTER_SET,
|
|
144
|
+
callback: (payload) => store.dispatch('table/ON_FILTER_EVENT', payload),
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
expect(store.getters['table/FILTERS']().page).toBe(12);
|
|
148
|
+
|
|
149
|
+
await store.dispatch('table/filters/SET_FILTER', {
|
|
150
|
+
name: 'vi',
|
|
151
|
+
value: 24,
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
expect(store.getters['table/FILTERS']().page).toBe(1);
|
|
155
|
+
|
|
156
|
+
await store.dispatch('table/filters/FLUSH_SUBSCRIBERS');
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('SORT changes both headers and sort filter', async () => {
|
|
160
|
+
const filters = new FiltersStoreModule()
|
|
161
|
+
.addFilter({
|
|
162
|
+
name: 'sort',
|
|
163
|
+
value: '',
|
|
164
|
+
get: ['value'],
|
|
165
|
+
set: ['value'],
|
|
166
|
+
restore: () => {},
|
|
167
|
+
})
|
|
168
|
+
.getModule();
|
|
169
|
+
|
|
170
|
+
const headers = [
|
|
171
|
+
{ value: 'id', field: 'sort_me', sort: SortSymbols.NONE },
|
|
172
|
+
];
|
|
173
|
+
|
|
174
|
+
const table = createTableStoreModule({
|
|
175
|
+
state: { headers },
|
|
176
|
+
modules: { filters },
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
vi.spyOn(table.actions, 'LOAD_DATA_LIST')
|
|
180
|
+
.mockImplementationOnce(vi.fn());
|
|
181
|
+
|
|
182
|
+
const store = createStore({
|
|
183
|
+
state: { router },
|
|
184
|
+
modules: { table },
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
await store.dispatch('table/filters/SUBSCRIBE', {
|
|
188
|
+
event: FilterEvent.FILTER_SET,
|
|
189
|
+
callback: (payload) => store.dispatch('table/ON_FILTER_EVENT', payload),
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
await store.dispatch('table/SORT', {
|
|
193
|
+
header: headers[0],
|
|
194
|
+
nextSortOrder: SortSymbols.ASC,
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
expect(store.getters['table/filters/GET_FILTER']('sort')).toBe('+sort_me');
|
|
198
|
+
|
|
199
|
+
expect(store.state.table.headers[0].sort).toBe(SortSymbols.ASC);
|
|
200
|
+
|
|
201
|
+
await store.dispatch('table/filters/FLUSH_SUBSCRIBERS');
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it('fields filter change changes headers', async () => {
|
|
205
|
+
const filters = new FiltersStoreModule()
|
|
206
|
+
.addFilter({
|
|
207
|
+
name: 'fields',
|
|
208
|
+
value: [],
|
|
209
|
+
get: ['value'],
|
|
210
|
+
set: ['value'],
|
|
211
|
+
restore: () => {},
|
|
212
|
+
})
|
|
213
|
+
.getModule();
|
|
214
|
+
|
|
215
|
+
const headers = [
|
|
216
|
+
{ value: 'surname', field: 'included', show: false },
|
|
217
|
+
{ value: 'name', field: 'excluded', show: true },
|
|
218
|
+
];
|
|
219
|
+
|
|
220
|
+
const table = createTableStoreModule({
|
|
221
|
+
state: { headers },
|
|
222
|
+
modules: { filters },
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
vi.spyOn(table.actions, 'LOAD_DATA_LIST')
|
|
226
|
+
.mockImplementationOnce(vi.fn());
|
|
227
|
+
|
|
228
|
+
const store = createStore({
|
|
229
|
+
state: { router },
|
|
230
|
+
modules: { table },
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
await store.dispatch('table/filters/SUBSCRIBE', {
|
|
234
|
+
event: FilterEvent.FILTER_SET,
|
|
235
|
+
callback: (payload) => store.dispatch('table/ON_FILTER_EVENT', payload),
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
await store.dispatch('table/filters/SET_FILTER', {
|
|
239
|
+
name: 'fields',
|
|
240
|
+
value: ['surname'],
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
expect(store.getters['table/filters/GET_FILTER']('fields'))
|
|
244
|
+
.toEqual(['surname']);
|
|
245
|
+
|
|
246
|
+
expect(store.getters['table/FIELDS']).toEqual(['id', 'included']);
|
|
247
|
+
|
|
248
|
+
await store.dispatch('table/filters/FLUSH_SUBSCRIBERS');
|
|
249
|
+
});
|
|
250
|
+
});
|