@webitel/ui-sdk 3.0.11 → 3.1.0-1
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 +106 -1
- package/dist/ui-sdk.common.js.map +1 -1
- package/dist/ui-sdk.umd.js +109 -4
- package/dist/ui-sdk.umd.js.map +1 -1
- package/dist/ui-sdk.umd.min.js +3 -3
- package/dist/ui-sdk.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/src/components/index.js +2 -0
- package/src/components/organisms/wt-icon-action/__tests__/WtIconAction.spec.js +9 -0
- package/src/components/organisms/wt-icon-action/_internals/__tests__/WtDeleteIconAction.spec.js +9 -0
- package/src/components/organisms/wt-icon-action/_internals/__tests__/WtEditIconAction.spec.js +9 -0
- package/src/components/organisms/{wt-table/table-cells/wt-table-delete-action.vue → wt-icon-action/_internals/wt-delete-icon-action.vue} +2 -2
- package/src/components/organisms/{wt-table/table-cells/wt-table-edit-action.vue → wt-icon-action/_internals/wt-edit-icon-action.vue} +2 -2
- package/src/components/organisms/wt-icon-action/wt-icon-action.vue +31 -0
- package/src/locale/en/en.js +7 -7
- package/src/locale/es/es.js +265 -265
- package/src/locale/ru/ru.js +9 -8
- package/src/locale/ua/ua.js +9 -8
- package/src/store/BaseStoreModules/ApiStoreModule.js +29 -0
- package/src/store/BaseStoreModules/CardStoreModule.js +78 -0
- package/src/store/BaseStoreModules/ObjectStoreModule.js +4 -0
- package/src/store/BaseStoreModules/TableStoreModule.js +181 -0
- package/src/components/organisms/wt-table/__tests__/WtTableDeleteAction.spec.js +0 -9
- package/src/components/organisms/wt-table/__tests__/WtTableEditAction.spec.js +0 -9
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import BaseStoreModule
|
|
2
|
+
from '@webitel/ui-sdk/src/store/BaseStoreModules/BaseStoreModule';
|
|
3
|
+
import deepCopy from 'deep-copy';
|
|
4
|
+
|
|
5
|
+
export default class CardStoreModule extends BaseStoreModule {
|
|
6
|
+
state = {
|
|
7
|
+
itemId: 0,
|
|
8
|
+
itemInstance: {},
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
actions = {
|
|
12
|
+
SET_PARENT_ITEM_ID: (context, id) => {
|
|
13
|
+
context.commit('SET_PARENT_ITEM_ID', id);
|
|
14
|
+
},
|
|
15
|
+
SET_ITEM_ID: (context, id) => {
|
|
16
|
+
if (id !== 'new') context.commit('SET_ITEM_ID', id);
|
|
17
|
+
else context.commit('SET_ITEM_ID', 0);
|
|
18
|
+
},
|
|
19
|
+
LOAD_ITEM: async (context) => {
|
|
20
|
+
if (context.state.itemId) {
|
|
21
|
+
const item = await context.dispatch('GET_ITEM');
|
|
22
|
+
context.commit('SET_ITEM', item);
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
ADD_ITEM: async (context) => {
|
|
26
|
+
if (!context.state.itemId) {
|
|
27
|
+
const { id } = await context.dispatch('POST_ITEM');
|
|
28
|
+
await context.dispatch('SET_ITEM_ID', id);
|
|
29
|
+
context.dispatch('LOAD_ITEM');
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
UPDATE_ITEM: async (context) => {
|
|
33
|
+
if (context.state.itemInstance._dirty) {
|
|
34
|
+
await context.dispatch('UPD_ITEM');
|
|
35
|
+
context.dispatch('LOAD_ITEM');
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
SET_ITEM_PROPERTY: (context, payload) => {
|
|
39
|
+
context.commit('SET_ITEM_PROPERTY', payload);
|
|
40
|
+
context.commit('SET_ITEM_PROPERTY', { prop: '_dirty', value: true });
|
|
41
|
+
},
|
|
42
|
+
RESET_ITEM_STATE: async (context) => {
|
|
43
|
+
context.commit('RESET_ITEM_STATE');
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
mutations = {
|
|
48
|
+
SET_PARENT_ITEM_ID: (state, id) => {
|
|
49
|
+
state.parentId = id;
|
|
50
|
+
},
|
|
51
|
+
SET_ITEM_ID: (state, id) => {
|
|
52
|
+
state.itemId = id;
|
|
53
|
+
},
|
|
54
|
+
SET_ITEM_PROPERTY: (state, { prop, value }) => {
|
|
55
|
+
state.itemInstance[prop] = value;
|
|
56
|
+
},
|
|
57
|
+
SET_ITEM: (state, item) => {
|
|
58
|
+
state.itemInstance = item;
|
|
59
|
+
},
|
|
60
|
+
RESET_ITEM_STATE: (state) => {
|
|
61
|
+
Object.assign(state, deepCopy(this.state));
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
getModule({
|
|
66
|
+
state = {},
|
|
67
|
+
...rest
|
|
68
|
+
} = {}) {
|
|
69
|
+
this.state = {
|
|
70
|
+
...this.state,
|
|
71
|
+
state,
|
|
72
|
+
};
|
|
73
|
+
return super.getModule({
|
|
74
|
+
state: deepCopy(this.state),
|
|
75
|
+
...rest,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SortSymbols,
|
|
3
|
+
sortToQueryAdapter,
|
|
4
|
+
} from '@webitel/ui-sdk/src/scripts/sortQueryAdapters';
|
|
5
|
+
import BaseStoreModule
|
|
6
|
+
from '@webitel/ui-sdk/src/store/BaseStoreModules/BaseStoreModule';
|
|
7
|
+
|
|
8
|
+
export default class TableStoreModule extends BaseStoreModule {
|
|
9
|
+
state = {
|
|
10
|
+
headers: [],
|
|
11
|
+
dataList: [],
|
|
12
|
+
size: 10,
|
|
13
|
+
search: '',
|
|
14
|
+
page: 1,
|
|
15
|
+
sort: '',
|
|
16
|
+
isNextPage: false,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
actions = {
|
|
20
|
+
// HOOKS TO BE OVERRIDEN, IF NEEDED
|
|
21
|
+
BEFORE_SET_DATA_LIST_HOOK: (context, { items, next }) => ({ items, next }),
|
|
22
|
+
AFTER_SET_DATA_LIST_HOOK: (context, { items, next }) => ({ items, next }),
|
|
23
|
+
|
|
24
|
+
LOAD_DATA_LIST: async (context, _query) => {
|
|
25
|
+
const query = { ...context.getters['filters/GET_FILTERS'], ..._query };
|
|
26
|
+
try {
|
|
27
|
+
let {
|
|
28
|
+
items = [],
|
|
29
|
+
next = false,
|
|
30
|
+
} = await context.dispatch('api/GET_LIST', query);
|
|
31
|
+
/* we should set _isSelected property to all items in tables cause their checkbox selection
|
|
32
|
+
* is based on this property. Previously, this prop was set it api consumers, but now
|
|
33
|
+
* admin-specific were replaced by webitel-sdk consumers and i supposed it will be
|
|
34
|
+
* weird to set this property in each api file through defaultListObject */
|
|
35
|
+
items = items.map((item) => ({ ...item, _isSelected: false }));
|
|
36
|
+
const afterHook = await context.dispatch('BEFORE_SET_DATA_LIST_HOOK', {
|
|
37
|
+
items,
|
|
38
|
+
next,
|
|
39
|
+
});
|
|
40
|
+
context.commit('SET_DATA_LIST', afterHook.items);
|
|
41
|
+
context.commit('SET_IS_NEXT', afterHook.next);
|
|
42
|
+
context.dispatch('AFTER_SET_DATA_LIST_HOOK', afterHook);
|
|
43
|
+
} catch (err) {
|
|
44
|
+
console.error(err);
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
SET_SIZE: async (context, size) => {
|
|
48
|
+
context.commit('SET_SIZE', size);
|
|
49
|
+
await context.dispatch('RESET_PAGE');
|
|
50
|
+
},
|
|
51
|
+
SET_SEARCH: async (context, search) => {
|
|
52
|
+
context.commit('SET_SEARCH', search);
|
|
53
|
+
await context.dispatch('RESET_PAGE');
|
|
54
|
+
},
|
|
55
|
+
NEXT_PAGE: (context) => {
|
|
56
|
+
const page = context.state.page + 1;
|
|
57
|
+
context.commit('SET_PAGE', page);
|
|
58
|
+
context.dispatch('LOAD_DATA_LIST');
|
|
59
|
+
},
|
|
60
|
+
PREV_PAGE: (context) => {
|
|
61
|
+
if (context.state.page > 1) {
|
|
62
|
+
const page = context.state.page - 1;
|
|
63
|
+
context.commit('SET_PAGE', page);
|
|
64
|
+
context.dispatch('LOAD_DATA_LIST');
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
RESET_PAGE: (context) => {
|
|
68
|
+
const page = 1;
|
|
69
|
+
context.commit('SET_PAGE', page);
|
|
70
|
+
},
|
|
71
|
+
SET_HEADERS: (context, headers) => context.commit('SET_HEADERS', headers),
|
|
72
|
+
SORT: async (context, { header, nextSortOrder }) => {
|
|
73
|
+
const sort = nextSortOrder
|
|
74
|
+
? `${sortToQueryAdapter(nextSortOrder)}${header.field}`
|
|
75
|
+
: nextSortOrder;
|
|
76
|
+
context.commit('SET_SORT', sort);
|
|
77
|
+
context.dispatch('UPDATE_HEADER_SORT', { header, nextSortOrder });
|
|
78
|
+
await context.dispatch('RESET_PAGE');
|
|
79
|
+
return context.dispatch('LOAD_DATA_LIST');
|
|
80
|
+
},
|
|
81
|
+
UPDATE_HEADER_SORT: (context, { header, nextSortOrder }) => {
|
|
82
|
+
const headers = context.state.headers.map((oldHeader) => {
|
|
83
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
84
|
+
if (oldHeader.sort !== undefined) {
|
|
85
|
+
return {
|
|
86
|
+
...oldHeader,
|
|
87
|
+
sort: oldHeader.field === header.field
|
|
88
|
+
? nextSortOrder
|
|
89
|
+
: SortSymbols.NONE,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
return oldHeader;
|
|
93
|
+
});
|
|
94
|
+
context.commit('SET_HEADERS', headers);
|
|
95
|
+
},
|
|
96
|
+
PATCH_ITEM_PROPERTY: async (context, {
|
|
97
|
+
item, index, prop, value,
|
|
98
|
+
}) => {
|
|
99
|
+
await context.commit('PATCH_ITEM_PROPERTY', { index, prop, value });
|
|
100
|
+
const id = item?.id || context.state.dataList[index].id;
|
|
101
|
+
const changes = { [prop]: value };
|
|
102
|
+
try {
|
|
103
|
+
await context.dispatch('api/PATCH_ITEM', { id, changes });
|
|
104
|
+
context.commit('PATCH_ITEM_PROPERTY', {
|
|
105
|
+
item, index, prop, value,
|
|
106
|
+
});
|
|
107
|
+
} catch {
|
|
108
|
+
context.dispatch('LOAD_DATA_LIST');
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
DELETE: async (context, deleted) => {
|
|
112
|
+
let action = 'DELETE_SINGLE';
|
|
113
|
+
if (Array.isArray(deleted)) {
|
|
114
|
+
if (deleted.length) action = 'DELETE_BULK';
|
|
115
|
+
else action = 'DELETE_ALL';
|
|
116
|
+
}
|
|
117
|
+
try {
|
|
118
|
+
await context.dispatch(action, deleted);
|
|
119
|
+
} catch (err) {
|
|
120
|
+
throw err;
|
|
121
|
+
} finally {
|
|
122
|
+
await context.dispatch('LOAD_DATA_LIST');
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
DELETE_SINGLE: async (context, { id }) => {
|
|
126
|
+
try {
|
|
127
|
+
await context.dispatch('api/DELETE_ITEM', id);
|
|
128
|
+
} catch (err) {
|
|
129
|
+
throw err;
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
DELETE_BULK: async (
|
|
133
|
+
context,
|
|
134
|
+
deleted,
|
|
135
|
+
) => Promise.allSettled(deleted.map((item) => context.dispatch('DELETE_SINGLE', item))),
|
|
136
|
+
// REMOVE_ITEM: async (context, index) => {
|
|
137
|
+
// const id = context.state.dataList[index].id;
|
|
138
|
+
// context.commit('REMOVE_ITEM', index);
|
|
139
|
+
// try {
|
|
140
|
+
// await context.dispatch('DELETE_ITEM', id);
|
|
141
|
+
// } catch (err) {
|
|
142
|
+
// throw err;
|
|
143
|
+
// }
|
|
144
|
+
// },
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
mutations = {
|
|
148
|
+
SET_DATA_LIST: (state, items) => {
|
|
149
|
+
state.dataList = items;
|
|
150
|
+
},
|
|
151
|
+
SET_SIZE: (state, size) => {
|
|
152
|
+
state.size = size;
|
|
153
|
+
},
|
|
154
|
+
SET_SEARCH: (state, search) => {
|
|
155
|
+
state.search = search;
|
|
156
|
+
},
|
|
157
|
+
SET_PAGE: (state, page) => {
|
|
158
|
+
state.page = page;
|
|
159
|
+
},
|
|
160
|
+
SET_SORT: (state, sort) => {
|
|
161
|
+
state.sort = sort;
|
|
162
|
+
},
|
|
163
|
+
SET_IS_NEXT: (state, next) => {
|
|
164
|
+
state.isNextPage = next;
|
|
165
|
+
},
|
|
166
|
+
SET_HEADERS: (state, headers) => {
|
|
167
|
+
state.headers = headers;
|
|
168
|
+
},
|
|
169
|
+
PATCH_ITEM_PROPERTY: (state, { index, prop, value }) => {
|
|
170
|
+
state.dataList[index][prop] = value;
|
|
171
|
+
},
|
|
172
|
+
// REMOVE_ITEM: (state, index) => {
|
|
173
|
+
// state.dataList.splice(index, 1);
|
|
174
|
+
// },
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
constructor({ headers = [] }) {
|
|
178
|
+
super();
|
|
179
|
+
this.state.headers = headers;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { shallowMount } from '@vue/test-utils';
|
|
2
|
-
import WtTableDeleteAction from '../table-cells/wt-table-delete-action.vue';
|
|
3
|
-
|
|
4
|
-
describe('WtTableDeleteAction', () => {
|
|
5
|
-
it('renders a component', () => {
|
|
6
|
-
const wrapper = shallowMount(WtTableDeleteAction);
|
|
7
|
-
expect(wrapper.exists()).toBe(true);
|
|
8
|
-
});
|
|
9
|
-
});
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { shallowMount } from '@vue/test-utils';
|
|
2
|
-
import WtTableEditAction from '../table-cells/wt-table-edit-action.vue';
|
|
3
|
-
|
|
4
|
-
describe('WtTableEditAction', () => {
|
|
5
|
-
it('renders a component', () => {
|
|
6
|
-
const wrapper = shallowMount(WtTableEditAction);
|
|
7
|
-
expect(wrapper.exists()).toBe(true);
|
|
8
|
-
});
|
|
9
|
-
});
|