From 4bcbc1ca8e33e6e7595ebdffa8e4412118538c9c Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Wed, 23 Nov 2022 18:17:47 +0800 Subject: [PATCH 1/3] feat(nc-gui): useFieldQuery --- packages/nc-gui/composables/useFieldQuery.ts | 34 ++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 packages/nc-gui/composables/useFieldQuery.ts diff --git a/packages/nc-gui/composables/useFieldQuery.ts b/packages/nc-gui/composables/useFieldQuery.ts new file mode 100644 index 0000000000..b18f488ce5 --- /dev/null +++ b/packages/nc-gui/composables/useFieldQuery.ts @@ -0,0 +1,34 @@ +import type { Ref } from 'vue' +import type { ViewType } from 'nocodb-sdk' +import { useState } from '#imports' + +export function useFieldQuery(view: Ref) { + // initial search object + const emptyFieldQueryObj = { + field: '', + query: '', + } + + // mapping view id (key) to corresponding emptyFieldQueryObj (value) + const searchMap = useState>('field-query-search-map', () => ({})) + + // the fieldQueryObj under the current view + const search = useState<{ field: string; query: string }>('field-query-search', () => emptyFieldQueryObj) + + // map current view id to emptyFieldQueryObj + if (view?.value?.id) { + searchMap.value[view!.value!.id] = search.value + } + + // retrieve the fieldQueryObj of the given view id + // if it is not found in `searchMap`, init with emptyFieldQueryObj + const loadFieldQuery = (view: Ref) => { + if (!view.value?.id) return + if (!(view!.value!.id in searchMap.value)) { + searchMap.value[view!.value!.id!] = emptyFieldQueryObj + } + search.value = searchMap.value[view!.value!.id!] + } + + return { search, loadFieldQuery } +} From ce009649fba5bfa603cc7c33f2d3b8bd9d77693b Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Wed, 23 Nov 2022 18:18:03 +0800 Subject: [PATCH 2/3] feat(nc-gui): load field query when view is changed --- .../smartsheet/toolbar/SearchData.vue | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/packages/nc-gui/components/smartsheet/toolbar/SearchData.vue b/packages/nc-gui/components/smartsheet/toolbar/SearchData.vue index f77f72b7de..7d0440a3e5 100644 --- a/packages/nc-gui/components/smartsheet/toolbar/SearchData.vue +++ b/packages/nc-gui/components/smartsheet/toolbar/SearchData.vue @@ -1,9 +1,22 @@