Skip to content

Commit 75a37fc

Browse files
authored
Merge pull request #1 from devforth/AdminForth/857
fix: fix filters reset
2 parents 95cdfad + 2edce59 commit 75a37fc

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

custom/UniversalSearchInput.vue

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
v-model="localValue"
66
type="text"
77
:placeholder="props.meta?.placeholder ?? ''"
8-
class="border rounded px-2 py-1 text-sm w-64 dark:bg-gray-800 dark:border-gray-600"
8+
class="border rounded px-2 py-1 text-sm dark:bg-gray-800 dark:border-gray-600"
9+
:class="localValue ? 'w-[222px]' : 'w-64'"
910
@keyup.enter="applyImmediate"
1011
/>
1112
<button
@@ -20,21 +21,40 @@
2021
</div>
2122
</template>
2223
<script setup lang="ts">
23-
import { ref, watch } from 'vue';
24+
import { ref, watch, onMounted } from 'vue';
2425
import adminforth from '@/adminforth';
2526
import { AdminForthFilterOperators } from '@/types/Common';
27+
import { useRoute } from 'vue-router';
28+
29+
const route = useRoute();
2630
2731
const props = defineProps<{ meta?: any; resource?: any; adminUser?: any }>();
2832
const localValue = ref('');
2933
let t: any = null;
34+
let blockFilterUpdate = false;
35+
36+
onMounted(() => {
37+
const filters = Object.keys(route.query).filter(k => k.startsWith('filter__')).map(k => {
38+
const [_, field, operator] = k.split('__');
39+
return {
40+
field,
41+
operator,
42+
value: JSON.parse(decodeURIComponent(route.query[k] as string))
43+
}
44+
});
45+
const isUniversalSearchFilterApplied = filters.find(f => f.field === '_universal_search');
46+
if (isUniversalSearchFilterApplied) {
47+
localValue.value = isUniversalSearchFilterApplied.value;
48+
blockFilterUpdate = true;
49+
};
50+
});
3051
3152
function send(term?: string) {
3253
adminforth?.list?.updateFilter?.({
3354
field: '_universal_search',
3455
operator: AdminForthFilterOperators.EQ,
3556
value: term || '',
3657
});
37-
adminforth?.list?.refresh?.();
3858
}
3959
4060
function apply() {
@@ -49,12 +69,17 @@ function applyImmediate() {
4969
}
5070
5171
watch(localValue, () => {
72+
if (blockFilterUpdate) {
73+
blockFilterUpdate = false;
74+
return;
75+
}
5276
const delay = props.meta?.debounceMs ?? 500;
5377
if (t) clearTimeout(t);
5478
t = setTimeout(apply, delay);
5579
});
5680
5781
function clear() {
82+
blockFilterUpdate = true;
5883
localValue.value = '';
5984
applyImmediate();
6085
}

0 commit comments

Comments
 (0)