From bd6fa6ff73246a3e1cc588d0ab86b8e20aa5e666 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Sat, 30 Jul 2022 11:22:22 +0530 Subject: [PATCH] feat(gui-v2): integrate search with grid view Signed-off-by: Pranav C --- .../smartsheet-toolbar/ColumnFilter.vue | 11 ++++--- .../smartsheet-toolbar/ColumnFilterMenu.vue | 23 ++++++-------- .../smartsheet-toolbar/SearchData.vue | 31 +++++++------------ .../nc-gui-v2/components/smartsheet/Grid.vue | 4 ++- .../composables/useSmartsheetStore.ts | 23 ++++++++++++++ packages/nc-gui-v2/composables/useViewData.ts | 8 +++-- 6 files changed, 60 insertions(+), 40 deletions(-) diff --git a/packages/nc-gui-v2/components/smartsheet-toolbar/ColumnFilter.vue b/packages/nc-gui-v2/components/smartsheet-toolbar/ColumnFilter.vue index 895fb75c22..6555e12b33 100644 --- a/packages/nc-gui-v2/components/smartsheet-toolbar/ColumnFilter.vue +++ b/packages/nc-gui-v2/components/smartsheet-toolbar/ColumnFilter.vue @@ -97,15 +97,16 @@ const applyChanges = async () => { // sync() // $e('a:filter:apply') - for (const nestedFilter of nestedFilters?.value || []) { - if (nestedFilter.parentId) { - await nestedFilter.applyChanges(true); - } + for (const nestedFilter of nestedFilters?.value || []) { + if (nestedFilter.parentId) { + await nestedFilter.applyChanges(true) } + } } defineExpose({ - applyChanges, parentId + applyChanges, + parentId, }) diff --git a/packages/nc-gui-v2/components/smartsheet-toolbar/ColumnFilterMenu.vue b/packages/nc-gui-v2/components/smartsheet-toolbar/ColumnFilterMenu.vue index a471ffaecf..92b0f5a252 100644 --- a/packages/nc-gui-v2/components/smartsheet-toolbar/ColumnFilterMenu.vue +++ b/packages/nc-gui-v2/components/smartsheet-toolbar/ColumnFilterMenu.vue @@ -1,10 +1,10 @@ diff --git a/packages/nc-gui-v2/components/smartsheet/Grid.vue b/packages/nc-gui-v2/components/smartsheet/Grid.vue index 27dc0478b7..bae3fbbf1e 100644 --- a/packages/nc-gui-v2/components/smartsheet/Grid.vue +++ b/packages/nc-gui-v2/components/smartsheet/Grid.vue @@ -32,9 +32,11 @@ const isPublicView = false const selected = reactive<{ row?: number | null; col?: number | null }>({}) const editEnabled = ref(false) +const { sqlUi } = useProject() +const { xWhere } = useSmartsheetStoreOrThrow() const addColumnDropdown = ref(false) -const { loadData, paginationData, formattedData: data, updateRowProperty, changePage } = useViewData(meta, view as any) +const { loadData, paginationData, formattedData: data, updateRowProperty, changePage } = useViewData(meta, view as any, xWhere) const { loadGridViewColumns, updateWidth, resizingColWidth, resizingCol } = useGridViewColumnWidth(view) onMounted(loadGridViewColumns) diff --git a/packages/nc-gui-v2/composables/useSmartsheetStore.ts b/packages/nc-gui-v2/composables/useSmartsheetStore.ts index 9189a2a122..5e34f72daa 100644 --- a/packages/nc-gui-v2/composables/useSmartsheetStore.ts +++ b/packages/nc-gui-v2/composables/useSmartsheetStore.ts @@ -1,15 +1,36 @@ +import { computed } from '@vue/reactivity' import { createInjectionState } from '@vueuse/core' import type { TableType, ViewType } from 'nocodb-sdk' import type { Ref } from 'vue' import { useNuxtApp } from '#app' +import useProject from '~/composables/useProject' const [useProvideSmartsheetStore, useSmartsheetStore] = createInjectionState((view: Ref, meta: Ref) => { const { $api } = useNuxtApp() + const { sqlUi } = useProject() // state + // todo: move to grid view store + const search = reactive({ + field: '', + value: '', + }) // getters const isLocked = computed(() => view?.value?.lock_type === 'locked') + const xWhere = computed(() => { + let where + const col = meta?.value?.columns?.find(({ id }) => id === search.field) || meta?.value?.columns?.find((v) => v.pv) + if (!col) return + + if (!search.value.trim()) return + if (['text', 'string'].includes(sqlUi.value.getAbstractType(col)) && col.dt !== 'bigint') { + where = `(${col.title},like,%${search.value.trim()}%)` + } else { + where = `(${col.title},eq,${search.value.trim()})` + } + return where + }) // actions @@ -18,6 +39,8 @@ const [useProvideSmartsheetStore, useSmartsheetStore] = createInjectionState((vi meta, isLocked, $api, + search, + xWhere, } }) diff --git a/packages/nc-gui-v2/composables/useViewData.ts b/packages/nc-gui-v2/composables/useViewData.ts index 8446f8d6d8..e60ed0b2eb 100644 --- a/packages/nc-gui-v2/composables/useViewData.ts +++ b/packages/nc-gui-v2/composables/useViewData.ts @@ -17,6 +17,7 @@ export function useViewData( | Ref<(GridType | GalleryType | FormType) & { id: string }> | ComputedRef<(GridType | GalleryType | FormType) & { id: string }> | undefined, + where?: ComputedRef, ) { const data = ref[]>() const formattedData = ref<{ row: Record; oldRow: Record; rowMeta?: any }[]>() @@ -27,7 +28,10 @@ export function useViewData( const loadData = async (params: Parameters['dbViewRow']['list']>[4] = {}) => { if (!project?.value?.id || !meta?.value?.id || !viewMeta?.value?.id) return - const response = await $api.dbViewRow.list('noco', project.value.id, meta.value.id, viewMeta.value.id, params) + const response = await $api.dbViewRow.list('noco', project.value.id, meta.value.id, viewMeta.value.id, { + ...params, + where: where?.value, + }) data.value = response.list formattedData.value = formatData(response.list) paginationData.value = response.pageInfo @@ -97,7 +101,7 @@ export function useViewData( const changePage = async (page: number) => { paginationData.value.page = page - await loadData({ offset: (page - 1) * (paginationData.value.pageSize || 25) } as any) + await loadData({ offset: (page - 1) * (paginationData.value.pageSize || 25), where: where?.value } as any) } return { data, loadData, paginationData, formattedData, insertRow, updateRowProperty, changePage }