@webitel/ui-datalist 1.1.66 → 1.1.67

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-datalist",
3
- "version": "1.1.66",
3
+ "version": "1.1.67",
4
4
  "description": "Toolkit for building data lists in webitel ui system",
5
5
  "scripts": {
6
6
  "build:types": "vue-tsc -b tsconfig.build.json",
@@ -3,7 +3,7 @@
3
3
  :label="labelValue"
4
4
  :search-method="props.filterConfig.searchRecords"
5
5
  :v="!disableValidation && vList"
6
- :model-value="model?.list"
6
+ :model-value="value.list"
7
7
  data-key="id"
8
8
  option-value="id"
9
9
  v-bind="$attrs"
@@ -12,9 +12,9 @@
12
12
  <wt-checkbox
13
13
  v-if="!props.filterConfig?.hideUnassigned"
14
14
  :label="t('reusable.showUnassigned')"
15
- :selected="!!model?.unassigned"
15
+ :selected="!!value.unassigned"
16
16
  :v="!disableValidation && vUnassigned"
17
- @update:selected="model.unassigned = !!$event"
17
+ @update:selected="handleInput('unassigned', !!$event)"
18
18
  />
19
19
  </template>
20
20
 
@@ -27,12 +27,6 @@ import { useI18n } from 'vue-i18n';
27
27
 
28
28
  import { IContactGroupFilterConfig } from './index';
29
29
 
30
- const props = defineProps<{
31
- filterConfig: IContactGroupFilterConfig;
32
- disableValidation?: boolean;
33
- hideLabel?: boolean;
34
- }>();
35
-
36
30
  type ModelValue = {
37
31
  list?: string[];
38
32
  unassigned?: boolean | null;
@@ -45,39 +39,62 @@ const model = defineModel<ModelValue>({
45
39
  }),
46
40
  });
47
41
 
42
+ const value = computed<ModelValue>(
43
+ () =>
44
+ model.value ?? {
45
+ list: [],
46
+ unassigned: null,
47
+ },
48
+ );
49
+
50
+ const handleInput = <K extends keyof ModelValue>(
51
+ key: K,
52
+ newFieldValue: ModelValue[K],
53
+ ) => {
54
+ model.value = {
55
+ ...value.value,
56
+ [key]: newFieldValue,
57
+ };
58
+ };
59
+
60
+ const changeListValue = (event: string[]) => {
61
+ if (!event.length && !value.value.unassigned) {
62
+ model.value = {};
63
+ return;
64
+ }
65
+ handleInput('list', event);
66
+ };
67
+
68
+ const props = defineProps<{
69
+ filterConfig: IContactGroupFilterConfig;
70
+ disableValidation?: boolean;
71
+ hideLabel?: boolean;
72
+ }>();
73
+
48
74
  const emit = defineEmits<{
49
75
  'update:invalid': [
50
76
  boolean,
51
77
  ];
52
78
  }>();
79
+
53
80
  const { t } = useI18n();
54
81
 
55
82
  const labelValue = computed(() =>
56
83
  props?.hideLabel ? undefined : t('webitelUI.filters.filterValue'),
57
84
  );
58
85
 
59
- const changeListValue = (event: string[]) => {
60
- if (!event.length && !model.value.unassigned) {
61
- model.value = {};
62
- return;
63
- }
64
- model.value = {
65
- ...model.value,
66
- list: event,
67
- };
68
- };
69
86
  const v$ = useVuelidate<{
70
87
  model: ModelValue;
71
88
  }>(
72
89
  computed(() => ({
73
90
  model: {
74
91
  list: {
75
- required: requiredIf(() => !model.value.unassigned),
92
+ required: requiredIf(() => !value.value.unassigned),
76
93
  },
77
94
  unassigned: {
78
95
  required: requiredIf(
79
96
  () =>
80
- !!props.filterConfig?.hideUnassigned && !model.value.list?.length,
97
+ !!props.filterConfig?.hideUnassigned && !value.value.list?.length,
81
98
  ),
82
99
  },
83
100
  },
@@ -106,11 +123,9 @@ onMounted(() => {
106
123
  });
107
124
 
108
125
  watch(
109
- () => v$?.value?.$invalid,
126
+ () => v$.value.$invalid,
110
127
  (invalid) => {
111
- if (v$?.value) {
112
- emit('update:invalid', invalid);
113
- }
128
+ emit('update:invalid', invalid);
114
129
  },
115
130
  {
116
131
  immediate: true,