Skip to content

Commit ba7c1aa

Browse files
committed
fix filters ui bugs
1 parent cb78560 commit ba7c1aa

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed

biogenome-client/src/components/common/TableFilters.vue

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
<template>
22
<div class="row">
33
<div class="flex">
4-
<VaInput iconColor="primary" v-model="searchForm.filter" clearable
5-
@update:modelValue="(v: string) => emits('onFormChange', [['filter', v.length > 2 ? v : '']])"
4+
<VaInput iconColor="primary" v-model="storeForm.filter" clearable @update:modelValue="handleInputChange"
65
:placeholder="t('buttons.search')">
76
<template #appendInner>
87
<va-icon name="search" />
@@ -63,15 +62,14 @@
6362
</VaBadge>
6463
</div>
6564
<div class="flex">
66-
<VaBadge style="z-index: 1;" overlap color="info"
67-
:text="searchForm.sort_column ? `${searchForm.sort_order} ${searchForm.sort_column}` : null">
65+
<VaBadge style="z-index: 1;" overlap color="info" :text="sortDropdownText">
6866
<VaButtonDropdown preset="primary" :round="true" stickToEdges :closeOnContentClick="false"
6967
:label="t('buttons.sort')" icon="sort">
7068
<div class="w-200">
7169
<div>
7270
<VaSelect @update:modelValue="(v: string) => emits('onFormChange', [['sort_column', v]])"
7371
clearable class="mt-2" :label="t('search.sortColumn')" v-model="searchForm.sort_column"
74-
:options="columns.map(c => c.split('.').length > 0 ? c.split('.')[c.split('.').length - 1] : c)" />
72+
textBy="text" valueBy="value" :options="sortOptions" />
7573
</div>
7674
<div>
7775
<VaSelect @update:modelValue="(v: string) => emits('onFormChange', [['sort_order', v]])"
@@ -89,7 +87,6 @@ import { computed, ref, watchEffect } from 'vue';
8987
import { DateRange, Filter } from '../../data/types'
9088
import { useI18n } from 'vue-i18n';
9189
92-
9390
const { t, locale } = useI18n()
9491
const props = defineProps<{ filters: Filter[], storeForm: Record<string, any>, columns: string[] }>()
9592
@@ -100,16 +97,36 @@ const showFields = ref(props.columns.map(c => {
10097
}
10198
}))
10299
103-
104100
const dateModels = ref({ ...mapDates(props.storeForm) })
105101
106102
const searchForm = ref({ ...props.storeForm })
107103
108104
const activeFilters = computed(() => {
109105
return Object.entries(searchForm.value)
106+
.filter(([k, v]) => k !== 'sort_column' && k !== 'sort_order')
110107
.filter(([k, v]) => v).length
111108
})
112109
110+
const sortOptions = computed(() => {
111+
return props.columns.map(c => {
112+
const splittedField = c.split('.')
113+
if (splittedField.length > 0) {
114+
return { text: splittedField[splittedField.length - 1], value: c }
115+
} else {
116+
return { text: c, value: c }
117+
}
118+
})
119+
})
120+
const sortDropdownText = computed(() => {
121+
if (searchForm.value.sort_column) {
122+
const splittedField = searchForm.value.sort_column.split('.')
123+
if (splittedField.length > 0) {
124+
return `${searchForm.value.sort_order} ${splittedField[splittedField.length - 1]}`
125+
}
126+
return `${searchForm.value.sort_order} ${searchForm.value.sort_column}`
127+
}
128+
return null
129+
})
113130
watchEffect(() => {
114131
emits('onShowFieldChange', showFields.value.filter(f => f.show).map(f => f.value))
115132
})
@@ -172,6 +189,19 @@ function isCheckBoxField(type: string) {
172189
return type === 'checkbox';
173190
};
174191
192+
const handleInputChange = debounce((v: string) => {
193+
emits('onFormChange', [['filter', v.length > 2 ? v : '']]);
194+
}, 300); // Adjust the delay (300ms) as needed
195+
196+
function debounce(fn: any, delay: number) {
197+
let timeoutId: any;
198+
return function (...args: any) {
199+
if (timeoutId) clearTimeout(timeoutId);
200+
timeoutId = setTimeout(() => {
201+
fn(...args);
202+
}, delay);
203+
};
204+
}
175205
</script>
176206
<style scoped>
177207
.w-200 {

server/helpers/data.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from bson.json_util import dumps, JSONOptions, DatetimeRepresentation
44
from helpers import organism, user
55
from mongoengine.queryset.visitor import Q
6-
from extensions.cache import cache
76

87
def dump_json(response_dict):
98
json_options = JSONOptions()

0 commit comments

Comments
 (0)