2
0
mirror of https://github.com/frappe/books.git synced 2024-12-22 10:58:59 +00:00

Merge pull request #1054 from AbleKSaju/fix-filter-modal

fix: resolved issue with filter modal closing
This commit is contained in:
Akshay 2024-12-13 15:54:22 +05:30 committed by GitHub
commit c2d7a1831f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 53 additions and 13 deletions

View File

@ -60,7 +60,7 @@
absolute absolute
z-10 z-10
mt-4 mt-4
w-full w-60
bg-white bg-white
dark:bg-gray-850 dark:bg-gray-850
border border-gray-300 border border-gray-300
@ -89,10 +89,10 @@
dark:hover:bg-gray-875 dark:hover:bg-gray-875
flex flex
" "
:class="value !== option.value ? 'pl-6' : 'pl-2'" :class="selectValue !== option.label ? 'pl-6' : 'pl-2'"
> >
<svg <svg
v-if="value === option.value" v-if="selectValue === option.label"
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
x="0px" x="0px"
y="0px" y="0px"
@ -127,9 +127,15 @@ export default defineComponent({
data() { data() {
return { return {
dropdownVisible: false, dropdownVisible: false,
selectValue: '', selectValue: this.value,
}; };
}, },
props: {
closeDropDown: {
type: Boolean,
default: true,
},
},
computed: { computed: {
options(): SelectOption[] { options(): SelectOption[] {
if (this.df.fieldtype !== 'Select') { if (this.df.fieldtype !== 'Select') {
@ -141,15 +147,19 @@ export default defineComponent({
}, },
methods: { methods: {
toggleDropdown() { toggleDropdown() {
if (!this.isReadOnly) { if (!this.closeDropDown) {
this.dropdownVisible = true;
} else if (!this.isReadOnly) {
this.dropdownVisible = !this.dropdownVisible; this.dropdownVisible = !this.dropdownVisible;
} }
}, },
selectOption(option: SelectOption) { selectOption(option: SelectOption) {
this.dropdownVisible = false;
this.selectValue = option.label; this.selectValue = option.label;
this.triggerChange(option.value); this.triggerChange(option.value);
this.dropdownVisible = !this.dropdownVisible;
if (this.closeDropDown) {
this.dropdownVisible = !this.dropdownVisible;
}
}, },
}, },
}); });

View File

@ -73,7 +73,8 @@
options: fieldOptions, options: fieldOptions,
}" }"
:value="filter.fieldname" :value="filter.fieldname"
@change="(value) => (filter.fieldname = value)" :close-drop-down="false"
@change="(value) => updateNewFilters(i, 'fieldname', value)"
/> />
<Select <Select
:border="true" :border="true"
@ -87,7 +88,8 @@
options: conditions, options: conditions,
}" }"
:value="filter.condition" :value="filter.condition"
@change="(value) => (filter.condition = value)" :close-drop-down="false"
@change="(value) => updateNewFilters(i, 'condition', value)"
/> />
<Data <Data
:border="true" :border="true"
@ -100,7 +102,8 @@
fieldtype: 'Data', fieldtype: 'Data',
}" }"
:value="String(filter.value)" :value="String(filter.value)"
@change="(value) => (filter.value = value)" :close-drop-down="false"
@change="(value) => updateNewFilters(i, 'value', value)"
/> />
</div> </div>
</div> </div>
@ -180,8 +183,9 @@ export default defineComponent({
emits: ['change'], emits: ['change'],
data() { data() {
return { return {
filters: [], filters: [] as Filter[],
} as { filters: Filter[] }; newFilters: [] as Filter[],
};
}, },
computed: { computed: {
fields(): Field[] { fields(): Field[] {
@ -250,12 +254,22 @@ export default defineComponent({
implicit?: boolean implicit?: boolean
): void { ): void {
this.filters.push({ fieldname, condition, value, implicit: !!implicit }); this.filters.push({ fieldname, condition, value, implicit: !!implicit });
this.newFilters.push({
fieldname,
condition,
value,
implicit: !!implicit,
});
}, },
removeFilter(filter: Filter): void { removeFilter(filter: Filter): void {
this.filters = this.filters.filter((f) => f !== filter); 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 { setFilter(filters: QueryFilter, implicit?: boolean): void {
this.filters = []; this.filters = [];
this.newFilters = [];
Object.keys(filters).map((fieldname) => { Object.keys(filters).map((fieldname) => {
let parts = filters[fieldname]; let parts = filters[fieldname];
@ -277,7 +291,7 @@ export default defineComponent({
}, },
emitFilterChange(): void { emitFilterChange(): void {
const filters: Record<string, [Condition, Filter['value']]> = {}; 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) { if (value === '' && condition) {
continue; continue;
} }
@ -286,6 +300,22 @@ export default defineComponent({
} }
this.$emit('change', filters); 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()
);
}, },
}, },
}); });