Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolved issue with filter modal closing #1054

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions src/components/Controls/Select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
absolute
z-10
mt-4
w-full
w-60
bg-white
dark:bg-gray-850
border border-gray-300
Expand Down Expand Up @@ -89,10 +89,10 @@
dark:hover:bg-gray-875
flex
"
:class="value !== option.value ? 'pl-6' : 'pl-2'"
:class="selectValue !== option.label ? 'pl-6' : 'pl-2'"
>
<svg
v-if="value === option.value"
v-if="selectValue === option.label"
xmlns="http://www.w3.org/2000/svg"
x="0px"
y="0px"
Expand Down Expand Up @@ -127,9 +127,15 @@ export default defineComponent({
data() {
return {
dropdownVisible: false,
selectValue: '',
selectValue: this.value,
};
},
props: {
closeDropDown: {
type: Boolean,
default: true,
},
},
computed: {
options(): SelectOption[] {
if (this.df.fieldtype !== 'Select') {
Expand All @@ -141,15 +147,19 @@ export default defineComponent({
},
methods: {
toggleDropdown() {
if (!this.isReadOnly) {
if (!this.closeDropDown) {
this.dropdownVisible = true;
} else if (!this.isReadOnly) {
this.dropdownVisible = !this.dropdownVisible;
}
},
selectOption(option: SelectOption) {
this.dropdownVisible = false;
this.selectValue = option.label;
this.triggerChange(option.value);
this.dropdownVisible = !this.dropdownVisible;

if (this.closeDropDown) {
this.dropdownVisible = !this.dropdownVisible;
}
},
},
});
Expand Down
42 changes: 36 additions & 6 deletions src/components/FilterDropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
options: fieldOptions,
}"
:value="filter.fieldname"
@change="(value) => (filter.fieldname = value)"
:close-drop-down="false"
@change="(value) => updateNewFilters(i, 'fieldname', value)"
/>
<Select
:border="true"
Expand All @@ -87,7 +88,8 @@
options: conditions,
}"
:value="filter.condition"
@change="(value) => (filter.condition = value)"
:close-drop-down="false"
@change="(value) => updateNewFilters(i, 'condition', value)"
/>
<Data
:border="true"
Expand All @@ -100,7 +102,8 @@
fieldtype: 'Data',
}"
:value="String(filter.value)"
@change="(value) => (filter.value = value)"
:close-drop-down="false"
@change="(value) => updateNewFilters(i, 'value', value)"
/>
</div>
</div>
Expand Down Expand Up @@ -180,8 +183,9 @@ export default defineComponent({
emits: ['change'],
data() {
return {
filters: [],
} as { filters: Filter[] };
filters: [] as Filter[],
newFilters: [] as Filter[],
};
},
computed: {
fields(): Field[] {
Expand Down Expand Up @@ -250,12 +254,22 @@ export default defineComponent({
implicit?: boolean
): void {
this.filters.push({ fieldname, condition, value, implicit: !!implicit });
this.newFilters.push({
fieldname,
condition,
value,
implicit: !!implicit,
});
},
removeFilter(filter: Filter): void {
this.filters = this.filters.filter((f) => f !== filter);
},
updateNewFilters(index: number, key: keyof Filter, value: Filter['value']) {
this.newFilters![index][key] = value;
},
setFilter(filters: QueryFilter, implicit?: boolean): void {
this.filters = [];
this.newFilters = [];

Object.keys(filters).map((fieldname) => {
let parts = filters[fieldname];
Expand All @@ -277,7 +291,7 @@ export default defineComponent({
},
emitFilterChange(): void {
const filters: Record<string, [Condition, Filter['value']]> = {};
for (const { condition, value, fieldname } of this.filters) {
for (const { condition, value, fieldname } of this.newFilters) {
if (value === '' && condition) {
continue;
}
Expand All @@ -286,6 +300,22 @@ export default defineComponent({
}

this.$emit('change', filters);
if (this.newFilters.length) {
this.filters = this.filters.filter(
(filter) => filter.condition && filter.value && filter.fieldname
);

this.filters.push(this.newFilters[this.newFilters.length - 1]);
}

this.filters = Array.from(
new Map(
this.filters.map((filter) => [
`${filter.condition}-${filter.value}-${filter.fieldname}`,
filter,
])
).values()
);
},
},
});
Expand Down