Skip to content

Commit

Permalink
24.02.44: custom value restore after refresh in query filters [WTEL-3…
Browse files Browse the repository at this point in the history
…181]
  • Loading branch information
dlohvinov committed Feb 5, 2024
1 parent 4d7c47f commit 9964106
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@webitel/ui-sdk",
"version": "24.2.43",
"version": "24.2.44",
"private": false,
"scripts": {
"dev": "vite",
Expand Down
2 changes: 1 addition & 1 deletion src/assets/icons/sprite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import './call-end.svg';
import './call-end--filled.svg';
import './call-inbound.svg';
import './call-inbound--filled.svg';
import './call-merge-filled.svg';
import './select-custom-value-enter.svg';
import './call-missed.svg';
import './call-missed--filled.svg';
import './call-outbound.svg';
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/components/wt-select/_multiselect.scss
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@
}

.multiselect--active :deep {
.multiselect__select .wt-icon__icon {
.multiselect__select.multiselect__arrow .wt-icon__icon {
fill: var(--icon-active-color);
}

.multiselect__custom-value-arrow {
.multiselect__select.multiselect__custom-value {
transform: none;
}
}
Expand Down
37 changes: 32 additions & 5 deletions src/components/wt-select/wt-select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
:loading="false"
:model-value="selectValue"
:multiple="multiple"
:options="selectOptions"
:options="optionsWithCustomValues"
:placeholder="placeholder || label"
:track-by="trackBy"
class="wt-select__select"
Expand Down Expand Up @@ -88,8 +88,8 @@
<wt-icon-btn
v-if="allowCustomValues && searchParams.search"
:disabled="disabled"
class="multiselect__select multiselect__custom-value-arrow"
icon="call-merge-filled"
class="multiselect__select multiselect__custom-value"
icon="select-custom-value-enter"
@mousedown.prevent
@click="handleCustomValue(toggle)"
/>
Expand All @@ -98,7 +98,7 @@
<wt-icon-btn
v-else
:disabled="disabled"
class="multiselect__select"
class="multiselect__select multiselect__arrow"
icon="arrow-down"
@mousedown.prevent
@click="toggle"
Expand Down Expand Up @@ -165,7 +165,10 @@ export default {
type: Boolean,
default: true,
},
// for taggableMixin functionality
/*
for taggableMixin functionality
for more info, see WTEL-3181
*/
allowCustomValues: {
type: Boolean,
default: false,
Expand Down Expand Up @@ -193,6 +196,30 @@ export default {
taggable() { return this.allowCustomValues; },
// for taggableMixin
manualTagging() { return this.handleCustomValuesAdditionManually; },
optionsWithCustomValues() {
if (!this.allowCustomValues) return this.selectOptions;
/**
custom values could be restored after refresh, so that they could be not included in options prop,
so that we should add them to options manually (but filter duplicates, which are already in options)
i assume it's bad decision and it's better to include custom values to options prop,
but current filters logic restores value at filter component, but options value are pre-defined at store state
*/
const customValuesToOptions = Array.isArray(this.value) ? this.value : [this.value];
const optionsWithoutValues = this.selectOptions.filter((opt) => {
const optKey = this.trackBy ? opt[this.trackBy] : opt;
return !customValuesToOptions.some((customValue) => {
const customValueKey = this.trackBy ? customValue[this.trackBy] : customValue;
return customValueKey === optKey;
});
});
return [
...customValuesToOptions,
...optionsWithoutValues,
];
},
},
methods: {
// for taggableMixin functionality
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
:value="value"
:options="localizedOptions"
:label="label"
:allow-custom-values="allowCustomValues"
:track-by="filterSchema.storedProp"
:multiple="filterSchema.multiple"
@input="setValue({ filter: filterQuery, value: $event })"
Expand Down
29 changes: 29 additions & 0 deletions src/modules/QueryFilters/mixins/enumFilterMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ import baseFilterMixin from './baseFilterMixin/baseFilterMixin';

export default {
mixins: [baseFilterMixin],
props: {
// for more detail, see allowCustomValues wt-select component prop
allowCustomValues: {
type: Boolean,
default: false,
},
},
computed: {
options() {
return this.filterSchema?.options;
Expand Down Expand Up @@ -38,12 +45,34 @@ export default {
restoreValue(value) {
let newValue;
if (Array.isArray(value)) {
/*
restore not just value, but value with all client-side properties like locale
*/
newValue = this.localizedOptions
.filter((option) => value
.some((value) => value === option[this.storedProp]));

/*
but if allowCustomValues is true, we should also restore custom values,
which isn't present in localizedOptions
*/
if (this.allowCustomValues) {
newValue = newValue.concat(
value
.filter((val) => !this.localizedOptions
.some((option) => val === option[this.storedProp]))
.map((val) => ({ [this.storedProp]: val, name: val })),
);
}
} else {
/*
see comments above
*/
newValue = this.localizedOptions
.find((option) => value === option[this.storedProp]);
if (this.allowCustomValues) {
newValue = newValue || { [this.storedProp]: value, name: value };
}
}
this.setValue({ filter: this.filterQuery, value: newValue });
},
Expand Down

0 comments on commit 9964106

Please sign in to comment.