@webitel/ui-sdk 3.1.3 → 3.1.5

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.3",
3
+ "version": "3.1.5",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "serve-lib": "vue-cli-service serve",
@@ -293,5 +293,11 @@ export default {
293
293
  score: 'Score',
294
294
  },
295
295
  },
296
+ deleteConfirmationPopup: {
297
+ title: 'Confirm deletion',
298
+ askingAlert: 'Are you sure you want to delete {count} item? | Are you sure you want to delete {count} items?',
299
+ undoneActionAlert: 'This action cannot be undone.',
300
+ deleteAll: 'ALL',
301
+ },
296
302
  },
297
303
  };
@@ -290,5 +290,11 @@ export default {
290
290
  score: 'Бал',
291
291
  },
292
292
  },
293
+ deleteConfirmationPopup: {
294
+ title: 'Подтвердите удаление',
295
+ askingAlert: 'Вы уверенны, что хотите удалить {count} запись? | Вы уверенны, что хотите удалить {count} записей?',
296
+ undoneActionAlert: 'Это действие не может быть отменено.',
297
+ deleteAll: 'ВСЕ',
298
+ },
293
299
  },
294
300
  };
@@ -290,5 +290,11 @@ export default {
290
290
  score: 'Бал',
291
291
  },
292
292
  },
293
+ deleteConfirmationPopup: {
294
+ title: 'Підтвердіть видалення',
295
+ askingAlert: 'Ви впевнені, що хочете видалити {count} запис? | Ви впевнені, що хочете видалити {count} записів?',
296
+ undoneActionAlert: 'Дана дія не може бути скасована.',
297
+ deleteAll: 'ВСІ',
298
+ },
293
299
  },
294
300
  };
@@ -0,0 +1,96 @@
1
+ <template>
2
+ <wt-popup
3
+ class="delete-confirmation-popup"
4
+ min-width="480"
5
+ @close="close"
6
+ >
7
+ <template v-slot:title>{{ $t('webitelUI.deleteConfirmationPopup.title') }}</template>
8
+ <template v-slot:main>
9
+ <p>
10
+ {{ deleteMessage }}
11
+ {{ $t('webitelUI.deleteConfirmationPopup.undoneActionAlert') }}
12
+ </p>
13
+ </template>
14
+ <template v-slot:actions>
15
+ <wt-button
16
+ color="secondary"
17
+ :disabled="isDeleting"
18
+ @click="cancel"
19
+ >{{ $t('reusable.cancel') }}
20
+ </wt-button>
21
+ <wt-button
22
+ color="danger"
23
+ :loading="isDeleting"
24
+ @click="confirm"
25
+ >{{ $t('reusable.delete') }}
26
+ </wt-button>
27
+ </template>
28
+ </wt-popup>
29
+ </template>
30
+
31
+ <script setup>
32
+ import { computed, ref } from 'vue';
33
+ import { useI18n } from 'vue-i18n';
34
+
35
+ const props = defineProps({
36
+ deleteCount: {
37
+ type: Number,
38
+ required: true,
39
+ },
40
+ callback: {
41
+ type: Function,
42
+ required: true,
43
+ },
44
+ });
45
+
46
+ const emit = defineEmits([
47
+ 'confirm',
48
+ 'cancel',
49
+ 'close',
50
+ ]);
51
+
52
+ const { t } = useI18n();
53
+
54
+ const isDeleting = ref(false);
55
+
56
+ const deleteMessage = computed(() => {
57
+ if (props.deleteCount === 0) {
58
+ return t(
59
+ 'webitelUI.deleteConfirmationPopup.askingAlert',
60
+ 2,
61
+ null,
62
+ { count: t('webitelUI.deleteConfirmationPopup.deleteAll') },
63
+ );
64
+ }
65
+ return t(
66
+ 'webitelUI.deleteConfirmationPopup.askingAlert',
67
+ props.deleteCount === 1 ? 1 : 2,
68
+ null,
69
+ { count: props.deleteCount },
70
+ );
71
+ });
72
+
73
+ function close() {
74
+ emit('close');
75
+ }
76
+
77
+ async function confirm() {
78
+ try {
79
+ isDeleting.value = true;
80
+ emit('confirm');
81
+ await props.callback();
82
+ } finally {
83
+ isDeleting.value = false;
84
+ close();
85
+ }
86
+ }
87
+
88
+ function cancel() {
89
+ emit('cancel');
90
+ close();
91
+ }
92
+ </script>
93
+
94
+ <style scoped>
95
+
96
+ </style>
@@ -0,0 +1,33 @@
1
+ import { ref } from 'vue';
2
+
3
+ // eslint-disable-next-line import/prefer-default-export
4
+ export const useDeleteConfirmationPopup = () => {
5
+ const isVisible = ref(false);
6
+ const deleteCount = ref(null);
7
+ const deleteCallback = ref(null);
8
+
9
+ function askDeleteConfirmation({ deleted, callback }) {
10
+ if (Array.isArray(deleted)) deleteCount.value = deleted.length;
11
+ else deleteCount.value = 1;
12
+ isVisible.value = true;
13
+ deleteCallback.value = callback;
14
+ }
15
+
16
+ function confirmDelete() {
17
+ return deleteCallback.value();
18
+ }
19
+
20
+ function closeDelete() {
21
+ isVisible.value = false;
22
+ }
23
+
24
+ return {
25
+ isVisible,
26
+ deleteCount,
27
+ deleteCallback,
28
+
29
+ askDeleteConfirmation,
30
+ confirmDelete,
31
+ closeDelete,
32
+ };
33
+ };
@@ -1,29 +1,37 @@
1
- import BaseStoreModule
2
- from '@webitel/ui-sdk/src/store/BaseStoreModules/BaseStoreModule';
1
+ import BaseStoreModule from './BaseStoreModule';
3
2
 
4
3
  export default class ApiStoreModule extends BaseStoreModule {
5
4
  generateAPIActions(api) {
6
5
  if (!api) throw new ReferenceError('pass API module!');
7
6
  this.actions
8
7
  .GET_LIST = (
9
- context,
10
- params = {},
11
- ) => api.getList({ ...context.state, ...params });
8
+ _,
9
+ { context: callerContext = {}, params = {} },
10
+ ) => api.getList({ ...callerContext.state, ...params });
12
11
  this.actions
13
12
  .GET_ITEM = (
14
- context,
15
- params = {},
16
- ) => api.get({ ...context.state, ...params });
13
+ _,
14
+ { context: callerContext = {}, params = {} } = {},
15
+ ) => api.get({ ...callerContext.state, ...params });
17
16
  this.actions
18
- .POST_ITEM = (context) => api.add(context.state);
17
+ .POST_ITEM = (
18
+ _,
19
+ { context: callerContext = {} } = {},
20
+ ) => api.add(callerContext.state);
19
21
  this.actions
20
- .PATCH_ITEM = (context, { id, changes }) => (
21
- api.patch({ ...context.state, id, changes })
22
+ .PATCH_ITEM = (_, { context: callerContext = {}, id, changes }) => (
23
+ api.patch({ ...callerContext.state, id, changes })
22
24
  );
23
25
  this.actions
24
- .UPD_ITEM = (context) => api.update(context.state);
26
+ .UPD_ITEM = (
27
+ _,
28
+ { context: callerContext = {} } = {},
29
+ ) => api.update(callerContext.state);
25
30
  this.actions
26
- .DELETE_ITEM = (context, id) => api.delete({ ...context.state, id });
31
+ .DELETE_ITEM = (
32
+ _,
33
+ { context: callerContext = {}, id },
34
+ ) => api.delete({ ...callerContext.state, id });
27
35
  return this;
28
36
  }
29
37
  }
@@ -1,6 +1,5 @@
1
- import BaseStoreModule
2
- from '@webitel/ui-sdk/src/store/BaseStoreModules/BaseStoreModule';
3
1
  import deepCopy from 'deep-copy';
2
+ import BaseStoreModule from './BaseStoreModule';
4
3
 
5
4
  export default class CardStoreModule extends BaseStoreModule {
6
5
  state = {
@@ -18,20 +17,20 @@ export default class CardStoreModule extends BaseStoreModule {
18
17
  },
19
18
  LOAD_ITEM: async (context) => {
20
19
  if (context.state.itemId) {
21
- const item = await context.dispatch('api/GET_ITEM');
20
+ const item = await context.dispatch('api/GET_ITEM', { context });
22
21
  context.commit('SET_ITEM', item);
23
22
  }
24
23
  },
25
24
  ADD_ITEM: async (context) => {
26
25
  if (!context.state.itemId) {
27
- const { id } = await context.dispatch('api/POST_ITEM');
26
+ const { id } = await context.dispatch('api/POST_ITEM', { context });
28
27
  await context.dispatch('SET_ITEM_ID', id);
29
28
  context.dispatch('LOAD_ITEM');
30
29
  }
31
30
  },
32
31
  UPDATE_ITEM: async (context) => {
33
32
  if (context.state.itemInstance._dirty) {
34
- await context.dispatch('api/UPD_ITEM');
33
+ await context.dispatch('api/UPD_ITEM', { context });
35
34
  context.dispatch('LOAD_ITEM');
36
35
  }
37
36
  },
@@ -1,9 +1,8 @@
1
1
  import {
2
2
  SortSymbols,
3
3
  sortToQueryAdapter,
4
- } from '@webitel/ui-sdk/src/scripts/sortQueryAdapters';
5
- import BaseStoreModule
6
- from '@webitel/ui-sdk/src/store/BaseStoreModules/BaseStoreModule';
4
+ } from '../../scripts/sortQueryAdapters';
5
+ import BaseStoreModule from './BaseStoreModule';
7
6
 
8
7
  export default class TableStoreModule extends BaseStoreModule {
9
8
  state = {
@@ -27,7 +26,7 @@ export default class TableStoreModule extends BaseStoreModule {
27
26
  let {
28
27
  items = [],
29
28
  next = false,
30
- } = await context.dispatch('api/GET_LIST', query);
29
+ } = await context.dispatch('api/GET_LIST', { context, params: query });
31
30
  /* we should set _isSelected property to all items in tables cause their checkbox selection
32
31
  * is based on this property. Previously, this prop was set it api consumers, but now
33
32
  * admin-specific were replaced by webitel-sdk consumers and i supposed it will be
@@ -100,7 +99,7 @@ export default class TableStoreModule extends BaseStoreModule {
100
99
  const id = item?.id || context.state.dataList[index].id;
101
100
  const changes = { [prop]: value };
102
101
  try {
103
- await context.dispatch('api/PATCH_ITEM', { id, changes });
102
+ await context.dispatch('api/PATCH_ITEM', { context, id, changes });
104
103
  context.commit('PATCH_ITEM_PROPERTY', {
105
104
  item, index, prop, value,
106
105
  });
@@ -124,7 +123,7 @@ export default class TableStoreModule extends BaseStoreModule {
124
123
  },
125
124
  DELETE_SINGLE: async (context, { id }) => {
126
125
  try {
127
- await context.dispatch('api/DELETE_ITEM', id);
126
+ await context.dispatch('api/DELETE_ITEM', { context, id });
128
127
  } catch (err) {
129
128
  throw err;
130
129
  }