@webitel/ui-sdk 24.10.43 → 24.10.45

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.43",
3
+ "version": "24.10.45",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "dev": "vite",
@@ -14,7 +14,7 @@ import applyTransform, {
14
14
  starToSearch,
15
15
  } from '../../transformers/index.js';
16
16
 
17
- const permissionsUrl = '/acl';
17
+ const permissionsUrl = 'acl';
18
18
 
19
19
  const handlePermissionsList = (items) => {
20
20
  return items.map((item) => ({
@@ -11,7 +11,7 @@ import media from './media/media.js';
11
11
  import queues from './queues/queues.js';
12
12
  import roles from './roles/roles.js';
13
13
  import users from './users/users.js';
14
- import { contacts, contactChatMessagesHistory } from './сontacts/index.js';
14
+ import { contactChatMessagesHistory, contacts } from './сontacts/index.js';
15
15
 
16
16
  export {
17
17
  agents,
@@ -3,15 +3,17 @@
3
3
  class="permissions-role-select"
4
4
  option-label="name"
5
5
  v-bind="attrs"
6
+ :value="model"
7
+ @input="model = $event"
6
8
  >
7
9
  <template #singleLabel="{ option, optionLabel }">
8
- <role-row :role="option.user">
10
+ <role-row :role="option">
9
11
  {{ option[optionLabel] || option }}
10
12
  </role-row>
11
13
  </template>
12
14
 
13
15
  <template #option="{ option, optionLabel }">
14
- <role-row :role="option.user">
16
+ <role-row :role="option">
15
17
  {{ option[optionLabel] || option }}
16
18
  </role-row>
17
19
  </template>
@@ -23,6 +25,8 @@ import { useAttrs } from 'vue';
23
25
  import RoleRow from './permissions-role-row.vue';
24
26
 
25
27
  const attrs = useAttrs();
28
+
29
+ const model = defineModel({ required: true });
26
30
  </script>
27
31
 
28
32
  <style lang="scss" scoped>
@@ -7,8 +7,8 @@
7
7
 
8
8
  <wt-popup
9
9
  :shown="shown"
10
- overflow
11
10
  size="sm"
11
+ overflow
12
12
  @close="close"
13
13
  >
14
14
  <template #title>
@@ -16,14 +16,14 @@
16
16
  </template>
17
17
  <template #main>
18
18
  <permissions-role-select
19
- v-model="grantee"
19
+ v-model:model-value="grantee"
20
20
  :clearable="false"
21
- :placeholder="t('object.role', 1)"
21
+ :placeholder="t('objects.role', 1)"
22
22
  :search-method="getAvailableGrantees"
23
23
  />
24
24
  </template>
25
25
  <template #actions>
26
- <wt-button @click="save">
26
+ <wt-button @click="save(grantee)">
27
27
  {{ t('objects.add') }}
28
28
  </wt-button>
29
29
  <wt-button
@@ -38,7 +38,7 @@
38
38
  </template>
39
39
 
40
40
  <script setup>
41
- import { ref, useAttrs } from 'vue';
41
+ import { computed, ref, useAttrs } from 'vue';
42
42
  import { useI18n } from 'vue-i18n';
43
43
  import { useRoute, useRouter } from 'vue-router';
44
44
  import { useStore } from 'vuex';
@@ -65,16 +65,25 @@ const existingGranteesList = computed(() => getNamespacedState(store.state, prop
65
65
 
66
66
  const shown = computed(() => !!route.params.permissionId);
67
67
 
68
- const add = () => router.push({
69
- ...route,
70
- params: { ...route.params, permissionId: 'new' },
71
- });
68
+ const add = () => {
69
+ const { params, query, hash, name } = route;
70
+
71
+ router.push({
72
+ query,
73
+ hash,
74
+ name,
75
+ params: { ...params, permissionId: 'new' },
76
+ });
77
+ };
72
78
 
73
79
  const close = () => {
80
+ const { query, hash, name } = route;
74
81
  const { permissionId, ...params } = route.params;
75
82
 
76
83
  return router.push({
77
- ...route,
84
+ query,
85
+ hash,
86
+ name,
78
87
  params,
79
88
  });
80
89
  };
@@ -98,8 +107,8 @@ const getAvailableGrantees = async (params) => {
98
107
  };
99
108
  };
100
109
 
101
- const save = async (payload = grantee.value) => {
102
- await store.dispatch(`${props.namespace}/ADD_ROLE_PERMISSIONS`, payload);
110
+ const save = async (grantee) => {
111
+ await store.dispatch(`${props.namespace}/ADD_ROLE_PERMISSIONS`, grantee);
103
112
  return close();
104
113
  };
105
114
 
@@ -19,7 +19,5 @@ export default () => {
19
19
  .addFilter(deepCopy(filtersList))
20
20
  .getModule();
21
21
 
22
- return {
23
- filters,
24
- };
22
+ return filters;
25
23
  };
@@ -1,15 +1,27 @@
1
- import { createBaseStoreModule } from '../../../../../store/new/index.js';
2
- import tableStoreModule
3
- from '../../../../../store/new/modules/tableStoreModule/tableStoreModule.js';
1
+ import {
2
+ createBaseStoreModule,
3
+ createTableStoreModule,
4
+ } from '../../../../../store/new/index.js';
4
5
  import objectPermissionsStoreModule
5
6
  from '../modules/objectPermissionsStoreModule.js';
6
7
 
7
- export const createObjectPermissionsStoreModule = (modules = []) => {
8
+ export const createObjectPermissionsStoreModule = (modules) => {
8
9
  const modulesArr = Array.isArray(modules) ? modules : [modules];
9
10
 
10
- return createBaseStoreModule([
11
- tableStoreModule(),
11
+ const tableSubmodule = createTableStoreModule([
12
12
  objectPermissionsStoreModule(),
13
+ ]);
14
+
15
+ const cardSubmodule = [
16
+ // empty, now permissions don't have standard card functionality
17
+ ];
18
+
19
+ return createBaseStoreModule([
20
+ {
21
+ modules: {
22
+ table: tableSubmodule,
23
+ },
24
+ },
13
25
  ...modulesArr,
14
26
  ]);
15
27
  };
@@ -0,0 +1,28 @@
1
+ import { SortSymbols } from '../../../../../scripts/sortQueryAdapters.js';
2
+
3
+ export default [
4
+ {
5
+ value: 'grantee',
6
+ locale: 'reusable.name',
7
+ field: 'grantee',
8
+ sort: SortSymbols.NONE,
9
+ },
10
+ {
11
+ value: 'read',
12
+ locale: 'reusable.read',
13
+ field: 'granted',
14
+ sort: SortSymbols.NONE,
15
+ },
16
+ {
17
+ value: 'edit',
18
+ locale: 'reusable.edit',
19
+ field: 'granted',
20
+ sort: SortSymbols.NONE,
21
+ },
22
+ {
23
+ value: 'delete',
24
+ locale: 'reusable.delete',
25
+ field: 'granted',
26
+ sort: SortSymbols.NONE,
27
+ },
28
+ ];
@@ -1,5 +1,15 @@
1
+ import deepCopy from 'deep-copy';
1
2
  import { AccessMode } from '../../enums/AccessMode.enum.js';
2
3
  import generateFilters from '../../modules/filters/store/filters.store.js';
4
+ import headers from './headers.js';
5
+
6
+ const state = {
7
+ headers,
8
+ };
9
+
10
+ const getters = {
11
+ REQUIRED_FIELDS: () => [],
12
+ };
3
13
 
4
14
  const actions = {
5
15
  CHANGE_ACCESS_MODE: async (context, { mode, ruleName, item }) => {
@@ -28,38 +38,55 @@ const actions = {
28
38
  default:
29
39
  return;
30
40
  }
31
- const changes = {
41
+ const changes = [
42
+ {
32
43
  grantee: +item.grantee.id,
33
44
  grants: want,
34
- };
45
+ }
46
+ ];
35
47
  try {
36
- await context.dispatch('PATCH_ACCESS_MODE', {
37
- item,
48
+ await context.dispatch('PATCH_ITEM_API', {
38
49
  changes,
50
+ id: context.getters.PARENT_ID,
39
51
  });
40
52
  } finally {
41
53
  await context.dispatch('LOAD_DATA_LIST');
42
54
  }
43
55
  },
44
56
  ADD_ROLE_PERMISSIONS: async (context, role) => {
45
- const changes = {
57
+ console.info(role);
58
+ const changes = [
59
+ {
46
60
  grantee: +role.id,
47
61
  grants: 'r',
48
- };
62
+ }
63
+ ];
49
64
  try {
50
- await context.dispatch('PATCH_ACCESS_MODE', {
65
+ await context.dispatch('PATCH_ITEM_API', {
51
66
  changes,
67
+ id: context.getters.PARENT_ID,
52
68
  });
53
69
  } finally {
54
70
  await context.dispatch('LOAD_DATA_LIST');
55
71
  }
56
72
  },
73
+
74
+ GET_LIST_API: (
75
+ context,
76
+ payload,
77
+ ) => context.dispatch('api/GET_OBJECT_PERMISSIONS_LIST', payload),
78
+ PATCH_ITEM_API: (
79
+ context,
80
+ payload,
81
+ ) => context.dispatch('api/PATCH_OBJECT_PERMISSIONS_ITEM', payload),
57
82
  };
58
83
 
59
84
  export default () => {
60
85
  const filters = generateFilters();
61
86
 
62
87
  return {
88
+ state: deepCopy(state),
89
+ getters,
63
90
  actions,
64
91
  modules: {
65
92
  filters,
@@ -155,7 +155,6 @@ const {
155
155
 
156
156
  const localizedDataList = computed(() => {
157
157
  return dataList.value.map((item) => {
158
-
159
158
  const access = Object.keys(item.access).reduce((access, rule) => {
160
159
  return {
161
160
  ...access,
@@ -1,7 +1,7 @@
1
1
  import apiStoreModule from '../modules/apiStoreModule/apiStoreModule.js';
2
2
  import { createBaseStoreModule } from './createBaseStoreModule.js';
3
3
 
4
- export const createApiStoreModule = (modules = []) => {
4
+ export const createApiStoreModule = (modules) => {
5
5
  const modulesArr = Array.isArray(modules) ? modules : [modules];
6
6
 
7
7
  return createBaseStoreModule([apiStoreModule(), ...modulesArr]);
@@ -1,7 +1,7 @@
1
1
  import baseStoreModule from '../modules/baseStoreModule/baseStoreModule.js';
2
2
  import { createStoreModule } from './createStoreModule.js';
3
3
 
4
- export const createBaseStoreModule = (modules = []) => {
4
+ export const createBaseStoreModule = (modules) => {
5
5
  const modulesArr = Array.isArray(modules) ? modules : [modules];
6
6
 
7
7
  return createStoreModule([baseStoreModule(), ...modulesArr]);
@@ -1,7 +1,7 @@
1
1
  import cardStoreModule from '../modules/cardStoreModule/cardStoreModule.js';
2
2
  import { createBaseStoreModule } from './createBaseStoreModule.js';
3
3
 
4
- export const createCardStoreModule = (modules = []) => {
4
+ export const createCardStoreModule = (modules) => {
5
5
  const modulesArr = Array.isArray(modules) ? modules : [modules];
6
6
 
7
7
  return createBaseStoreModule([cardStoreModule(), ...modulesArr]);
@@ -1,7 +1,7 @@
1
1
  import deepmerge from 'deepmerge';
2
2
  import isPlainObject from 'lodash/isPlainObject.js';
3
3
 
4
- export const createStoreModule = (modules = []) => {
4
+ export const createStoreModule = (modules) => {
5
5
  const modulesArr = Array.isArray(modules) ? modules : [modules];
6
6
 
7
7
  const merged = deepmerge.all(modulesArr, {
@@ -1,7 +1,7 @@
1
1
  import tableStoreModule from '../modules/tableStoreModule/tableStoreModule.js';
2
2
  import { createBaseStoreModule } from './createBaseStoreModule.js';
3
3
 
4
- export const createTableStoreModule = (modules = []) => {
4
+ export const createTableStoreModule = (modules) => {
5
5
  const modulesArr = Array.isArray(modules) ? modules : [modules];
6
6
 
7
7
  return createBaseStoreModule([tableStoreModule(), ...modulesArr]);
@@ -63,6 +63,37 @@ const actions = {
63
63
  id,
64
64
  });
65
65
  },
66
+
67
+ GET_OBJECT_PERMISSIONS_LIST: (
68
+ apiContext,
69
+ { context: callerContext = {}, params = {} },
70
+ ) => {
71
+ if (!apiContext.state.api.getList) throw Error('No API "getPermissionsList" method provided');
72
+ return apiContext.state.api.getPermissionsList({
73
+ ...callerContext.state,
74
+ parentId: getParentIdFromContext(callerContext),
75
+ ...params,
76
+ });
77
+ },
78
+
79
+ PATCH_OBJECT_PERMISSIONS_ITEM: (
80
+ apiContext,
81
+ {
82
+ context: callerContext = {},
83
+ id,
84
+ changes,
85
+ ...rest
86
+ },
87
+ ) => {
88
+ if (!apiContext.state.api.patch) throw Error('No API "patchPermissions" method provided');
89
+ return apiContext.state.api.patchPermissions({
90
+ ...callerContext.state,
91
+ parentId: getParentIdFromContext(callerContext),
92
+ ...rest,
93
+ id,
94
+ changes,
95
+ });
96
+ },
66
97
  };
67
98
 
68
99
  const mutations = {};
@@ -5,7 +5,9 @@ import getNamespacedState from '../../../helpers/getNamespacedState.js';
5
5
  export const useCardStore = (namespace) => {
6
6
  const store = useStore();
7
7
 
8
- const cardNamespace = `${namespace}/card`;
8
+ const cardNamespace = namespace.endsWith('/card')
9
+ ? namespace
10
+ : `${namespace}/card`;
9
11
 
10
12
  const id = computed(() => getNamespacedState(store.state, cardNamespace).itemId);
11
13
  const itemInstance = computed(() => getNamespacedState(store.state, cardNamespace).itemInstance);
@@ -1,9 +1,13 @@
1
1
  import { createRouter, createWebHistory } from 'vue-router';
2
2
  import { createStore } from 'vuex';
3
- import FilterEvent from '../../../../../modules/Filters/enums/FilterEvent.enum.js';
4
- import FiltersStoreModule from '../../../../../modules/Filters/store/FiltersStoreModule.js';
3
+ import FilterEvent
4
+ from '../../../../../modules/Filters/enums/FilterEvent.enum.js';
5
+ import FiltersStoreModule
6
+ from '../../../../../modules/Filters/store/FiltersStoreModule.js';
5
7
  import { SortSymbols } from '../../../../../scripts/sortQueryAdapters.js';
6
- import { createTableStoreModule } from '../../../helpers/createTableStoreModule.js';
8
+ import {
9
+ createTableStoreModule,
10
+ } from '../../../helpers/createTableStoreModule.js';
7
11
 
8
12
  describe('TableStoreModule', () => {
9
13
  it('correctly computes FIELDS getter', () => {
@@ -15,7 +19,11 @@ describe('TableStoreModule', () => {
15
19
 
16
20
  const state = { headers };
17
21
 
18
- expect(createTableStoreModule().getters.FIELDS(state)).toEqual(['id', 'age']);
22
+ const tableStore = createTableStoreModule({ state });
23
+
24
+ const store = createStore(tableStore);
25
+
26
+ expect(store.getters.FIELDS).toEqual(['id', 'age']);
19
27
  });
20
28
  });
21
29
 
@@ -19,13 +19,15 @@ const getters = {
19
19
  // FIXME: maybe move to filters module?
20
20
  FILTERS: (state, getters) => getters['filters/GET_FILTERS'],
21
21
 
22
- FIELDS: (state) => {
22
+ REQUIRED_FIELDS: () => ['id'], // override me
23
+
24
+ FIELDS: (state, getters) => {
23
25
  const fields = state.headers.reduce((fields, { show, field }) => {
24
26
  if (show || show === undefined) return [...fields, field];
25
27
  return fields;
26
28
  }, []);
27
29
 
28
- return [...new Set(['id', ...fields])];
30
+ return [...new Set([...getters.REQUIRED_FIELDS, ...fields])];
29
31
  },
30
32
 
31
33
  // main GET_LIST params collector
@@ -130,7 +132,10 @@ const actions = {
130
132
 
131
133
  const params = context.getters.GET_LIST_PARAMS(query);
132
134
  try {
133
- const { items = [], next = false } = await context.dispatch('api/GET_LIST', {
135
+ const {
136
+ items = [],
137
+ next = false,
138
+ } = await context.dispatch('GET_LIST_API', {
134
139
  context,
135
140
  params,
136
141
  });
@@ -171,7 +176,7 @@ const actions = {
171
176
  const changes = { [prop]: value };
172
177
 
173
178
  try {
174
- await context.dispatch('api/PATCH_ITEM', {
179
+ await context.dispatch('PATCH_ITEM_API', {
175
180
  context,
176
181
  id,
177
182
  etag,
@@ -208,7 +213,7 @@ const actions = {
208
213
 
209
214
  DELETE_SINGLE: async (context, { id, etag }) => {
210
215
  try {
211
- await context.dispatch('api/DELETE_ITEM', { context, id, etag });
216
+ await context.dispatch('DELETE_ITEM_API', { context, id, etag });
212
217
  } catch (err) {
213
218
  throw err;
214
219
  }
@@ -220,6 +225,16 @@ const actions = {
220
225
  SET_SELECTED: (context, selected) => {
221
226
  context.commit('SET', { path: 'selected', value: selected });
222
227
  },
228
+
229
+ GET_LIST_API: (context, payload) => context.dispatch('api/GET_LIST', payload),
230
+ PATCH_ITEM_API: (
231
+ context,
232
+ payload,
233
+ ) => context.dispatch('api/PATCH_ITEM', payload),
234
+ DELETE_ITEM_API: (
235
+ context,
236
+ payload,
237
+ ) => context.dispatch('api/DELETE_ITEM', payload),
223
238
  };
224
239
 
225
240
  export default () => ({