@webitel/ui-sdk 3.0.4 → 3.0.6

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.
Files changed (31) hide show
  1. package/dist/ui-sdk.common.js +2 -2
  2. package/dist/ui-sdk.common.js.map +1 -1
  3. package/dist/ui-sdk.umd.js +2 -2
  4. package/dist/ui-sdk.umd.js.map +1 -1
  5. package/dist/ui-sdk.umd.min.js +1 -1
  6. package/dist/ui-sdk.umd.min.js.map +1 -1
  7. package/package.json +4 -1
  8. package/src/locale/en/en.js +13 -0
  9. package/src/locale/es/es.js +282 -0
  10. package/src/locale/i18n.js +2 -0
  11. package/src/locale/ru/ru.js +13 -0
  12. package/src/locale/ua/ua.js +13 -0
  13. package/src/mixins/validationMixin/validationMixin.js +12 -12
  14. package/src/modules/AuditForm/components/__tests__/audit-form-question-read-wrapper.spec.js +14 -0
  15. package/src/modules/AuditForm/components/__tests__/audit-form-question-write-wrapper.spec.js +59 -0
  16. package/src/modules/AuditForm/components/__tests__/audit-form-question.spec.js +14 -0
  17. package/src/modules/AuditForm/components/__tests__/audit-form.spec.js +66 -0
  18. package/src/modules/AuditForm/components/audit-form-question-read-wrapper.vue +100 -0
  19. package/src/modules/AuditForm/components/audit-form-question-write-wrapper.vue +151 -0
  20. package/src/modules/AuditForm/components/audit-form-question.vue +102 -0
  21. package/src/modules/AuditForm/components/audit-form.vue +142 -0
  22. package/src/modules/AuditForm/components/questions/__tests__/audit-form-question-options.spec.js +46 -0
  23. package/src/modules/AuditForm/components/questions/__tests__/audit-form-question-score.spec.js +30 -0
  24. package/src/modules/AuditForm/components/questions/audit-form-question-options.vue +124 -0
  25. package/src/modules/AuditForm/components/questions/audit-form-question-score.vue +89 -0
  26. package/src/modules/AuditForm/composables/useDestroyableSortable.js +66 -0
  27. package/src/modules/AuditForm/schemas/AuditFormQuestionOptionsSchema.js +11 -0
  28. package/src/modules/AuditForm/schemas/AuditFormQuestionSchema.js +8 -0
  29. package/src/modules/AuditForm/schemas/AuditFormQuestionScoreSchema.js +6 -0
  30. package/src/scripts/__tests__/updateObject.spec.js +19 -0
  31. package/src/scripts/updateObject.js +6 -0
@@ -0,0 +1,89 @@
1
+ <template>
2
+ <article class="audit-form-question-score">
3
+ <div
4
+ v-if="mode === 'write'"
5
+ class="audit-form-question-score-write"
6
+ >
7
+ <wt-input
8
+ :value="question.min"
9
+ type="number"
10
+ @input="updateQuestion({ path: 'min', value: $event })"
11
+ ></wt-input>
12
+ <wt-input
13
+ :value="question.max"
14
+ type="number"
15
+ @input="updateQuestion({ path: 'max', value: $event })"
16
+ ></wt-input>
17
+ </div>
18
+ <div
19
+ v-else-if="mode === 'read'"
20
+ class="audit-form-question-score-read"
21
+ >
22
+ <wt-radio
23
+ v-for="(value) of scoreRange"
24
+ :key="value"
25
+ :label="`${value}`"
26
+ :value="value"
27
+ :selected="result ? result.score : result"
28
+ @input="emit('change:result', { score: value })"
29
+ ></wt-radio>
30
+ </div>
31
+ </article>
32
+ </template>
33
+
34
+ <script setup>
35
+ import { computed } from 'vue';
36
+ import updateObject from '../../../../scripts/updateObject';
37
+ import WtRadio from '../../../../components/molecules/wt-radio/wt-radio.vue';
38
+ import WtInput from '../../../../components/molecules/wt-input/wt-input.vue';
39
+
40
+ const props = defineProps({
41
+ question: {
42
+ type: Object,
43
+ required: true,
44
+ },
45
+ result: {
46
+ type: Object,
47
+ },
48
+ mode: {
49
+ // options: ['read', 'write']
50
+ type: String,
51
+ default: 'read',
52
+ },
53
+ });
54
+
55
+ const emit = defineEmits([
56
+ 'change:question',
57
+ 'change:result',
58
+ ]);
59
+
60
+ const scoreRange = computed(() => {
61
+ if (props.question.min > props.question.max) return [];
62
+ const result = [];
63
+ let i = +props.question.min;
64
+ do {
65
+ result.push(i);
66
+ i += 1;
67
+ } while (i <= props.question.max);
68
+ return result;
69
+ });
70
+
71
+ function updateQuestion({ path, value }) {
72
+ emit('change:question', updateObject({ obj: props.question, path, value }));
73
+ }
74
+ </script>
75
+
76
+ <style lang="scss" scoped>
77
+ .audit-form-question-score-write {
78
+ display: grid;
79
+ grid-template-columns: 100px 100px;
80
+ gap: var(--spacing-sm);
81
+ margin-right: calc(var(--spacing-sm) + 24px); // icon offset
82
+ }
83
+
84
+ .audit-form-question-score-read {
85
+ display: flex;
86
+ flex-wrap: nowrap;
87
+ gap: var(--spacing-sm);
88
+ }
89
+ </style>
@@ -0,0 +1,66 @@
1
+ import Sortable from 'sortablejs';
2
+ import {
3
+ ref,
4
+ nextTick,
5
+ onMounted,
6
+ onUnmounted,
7
+ } from 'vue';
8
+
9
+ /**
10
+ * @param elRef
11
+ * @param options
12
+ * @returns {{reloadSortable: Ref<UnwrapRef<boolean>>}}
13
+ *
14
+ * @description initializes Sortable on passed element ref and reinitializes it after each reorder
15
+ *
16
+ * WHY TO REINITIALIZE SORTABLE AFTER EACH ARRAY REORDER?
17
+ * Sortable and Vue both changing DOM so that there are collisions
18
+ * because both Vue and Sortable try to put element to the position. So element is put incorrectly.
19
+ *
20
+ * There are 2 vue packages for sortable (vue 2 and vue 3), but I had encountered issues when tried to use them.
21
+ * Also, it seems to me that they aren't supported now :(
22
+ *
23
+ * So that I decided to reinitialize Sortable each time order changes to represent it correctly.
24
+ * Bad decision, but I haven't come up with a better one
25
+ */
26
+
27
+ // eslint-disable-next-line import/prefer-default-export
28
+ export function useDestroyableSortable(elRef, options) {
29
+ let sortable = null;
30
+
31
+ const reloadSortable = ref(false);
32
+
33
+ function destroySortable() {
34
+ return sortable.destroy();
35
+ }
36
+
37
+ function initSortable() {
38
+ const replaceSortable = async () => {
39
+ if (!sortable) return;
40
+ destroySortable();
41
+ reloadSortable.value = true;
42
+ await nextTick();
43
+ reloadSortable.value = false;
44
+ await nextTick();
45
+ initSortable();
46
+ };
47
+
48
+ sortable = Sortable.create(elRef.value, {
49
+ ...options,
50
+ onEnd: async (e) => {
51
+ if (options.onEnd) options.onEnd(e);
52
+ await replaceSortable();
53
+ },
54
+ });
55
+ }
56
+
57
+ onMounted(() => {
58
+ initSortable();
59
+ });
60
+
61
+ onUnmounted(() => {
62
+ destroySortable();
63
+ });
64
+
65
+ return { reloadSortable };
66
+ }
@@ -0,0 +1,11 @@
1
+ export const generateOption = () => ({
2
+ text: '',
3
+ score: 10,
4
+ });
5
+
6
+ export const generateQuestionOptionsSchema = () => ({
7
+ type: 'options',
8
+ options: [
9
+ generateOption(),
10
+ ],
11
+ });
@@ -0,0 +1,8 @@
1
+ import { generateQuestionScoreSchema } from './AuditFormQuestionScoreSchema';
2
+
3
+ // eslint-disable-next-line import/prefer-default-export
4
+ export const generateQuestionSchema = () => ({
5
+ required: false,
6
+ text: 'Title',
7
+ ...generateQuestionScoreSchema(),
8
+ });
@@ -0,0 +1,6 @@
1
+ // eslint-disable-next-line import/prefer-default-export
2
+ export const generateQuestionScoreSchema = () => ({
3
+ type: 'score',
4
+ min: 1,
5
+ max: 5,
6
+ });
@@ -0,0 +1,19 @@
1
+ import updateObject from '../updateObject';
2
+
3
+ describe('updateObject', () => {
4
+ it('doesn\'t mutate original object', () => {
5
+ const original = { jest: 'jest' };
6
+ updateObject({ obj: original, path: 'jest', value: '123' });
7
+ expect(original.jest).toBe('jest');
8
+ });
9
+ it('changes shallow value', () => {
10
+ const original = { jest: 'jest' };
11
+ const result = { jest: 'huest' };
12
+ expect(updateObject({ obj: original, path: 'jest', value: 'huest' })).toEqual(result);
13
+ });
14
+ it('changes deep value', () => {
15
+ const original = { jest: { deep: 'jest' } };
16
+ const result = { jest: { deep: 'huest' } };
17
+ expect(updateObject({ obj: original, path: 'jest.deep', value: 'huest' })).toEqual(result);
18
+ });
19
+ });
@@ -0,0 +1,6 @@
1
+ import set from 'lodash/set';
2
+ import cloneDeep from 'lodash/cloneDeep';
3
+
4
+ const updateObject = ({ obj, path, value }) => set(cloneDeep(obj), path, value);
5
+
6
+ export default updateObject;