From 7e750a92be26143a8464d6632efd13f09a43f39c Mon Sep 17 00:00:00 2001 From: Anbarasu Date: Thu, 25 Jul 2024 15:45:14 +0530 Subject: [PATCH] feat: groupby bulk apis (#9040) * feat: bulk groupby api * feat: bulk dataList api * feat: bulk dataList api * feat: bulk data load * feat: bulk data load * fix: load Data * feat: custom pagination limit * feat: public bulkapis(wip) * fix: bug fixes * fix: ui bug fixes * fix: issues with strings * fix: case when alias is empty string * fix: cleanup * fix: datetime * fix: mysql group apis failing * fix: sqlite3 groupby fixes * fix: grouoby tests * fix: grouoby tests * fix: invalid page size fix: issue with bulkAggregation fix: aggregation duplicate query * fix: duplicate api call * fix: duplicate aggregation api call * fix: large data-api calls on reload * fix: tests * fix: update bulkapis to use post * fix: page size not updating --- .../components/smartsheet/grid/GroupBy.vue | 29 +- .../smartsheet/grid/GroupByTable.vue | 19 +- .../smartsheet/grid/PaginationV2.vue | 9 +- packages/nc-gui/composables/useSharedView.ts | 69 +- packages/nc-gui/composables/useViewGroupBy.ts | 405 ++++++---- packages/nc-gui/store/views.ts | 3 +- .../src/controllers/data-table.controller.ts | 32 + .../controllers/public-datas.controller.ts | 32 + packages/nocodb/src/db/BaseModelSqlv2.ts | 701 +++++++++++++++++- .../src/db/sql-data-mapper/lib/BaseModel.ts | 1 + .../src/helpers/extractLimitAndOffset.ts | 2 +- packages/nocodb/src/schema/swagger.json | 293 ++++++++ .../nocodb/src/services/data-table.service.ts | 104 +++ .../src/services/public-datas.service.ts | 139 ++++ .../playwright/pages/Dashboard/Grid/Group.ts | 6 +- .../pages/Dashboard/common/Toolbar/Groupby.ts | 4 +- 16 files changed, 1667 insertions(+), 181 deletions(-) diff --git a/packages/nc-gui/components/smartsheet/grid/GroupBy.vue b/packages/nc-gui/components/smartsheet/grid/GroupBy.vue index 4e70ba73bb..d314f47274 100644 --- a/packages/nc-gui/components/smartsheet/grid/GroupBy.vue +++ b/packages/nc-gui/components/smartsheet/grid/GroupBy.vue @@ -10,7 +10,13 @@ import type { Group } from '~/lib/types' const props = defineProps<{ group: Group - loadGroups: (params?: any, group?: Group) => Promise + loadGroups: ( + params?: any, + group?: Group, + options?: { + triggerChildOnly?: boolean + }, + ) => Promise loadGroupData: (group: Group, force?: boolean, params?: any) => Promise loadGroupPage: (group: Group, p: number) => Promise groupWrapperChangePage: (page: number, groupWrapper?: Group) => Promise @@ -42,6 +48,8 @@ const meta = inject(MetaInj, ref()) const fields = inject(FieldsInj, ref()) +const { gridViewPageSize } = useGlobal() + const scrollLeft = toRef(props, 'scrollLeft') const { isViewDataLoading, isPaginationLoading } = storeToRefs(useViewsStore()) @@ -133,9 +141,13 @@ const findAndLoadSubGroup = (key: any) => { const grp = vGroup.value.children.find((g) => `${g.key}` === k) if (grp) { if (grp.nested) { - if (!grp.children?.length) props.loadGroups({}, grp) + if (!grp.children[0].children?.length) { + props.loadGroups({}, grp, { + triggerChildOnly: true, + }) + } } else { - if (!grp.rows?.length || grp.count !== grp.rows?.length) _loadGroupData(grp) + if (!grp.rows?.length) _loadGroupData(grp) } } } @@ -146,7 +158,6 @@ const findAndLoadSubGroup = (key: any) => { const reloadViewDataHandler = (params: void | { shouldShowLoading?: boolean | undefined; offset?: number | undefined }) => { if (vGroup.value.nested) { props.loadGroups({ ...(params?.offset !== undefined ? { offset: params.offset } : {}) }, vGroup.value) - props.loadGroupAggregation(vGroup.value) } else { _loadGroupData(vGroup.value, true, { ...(params?.offset !== undefined ? { offset: params.offset } : {}), @@ -174,8 +185,13 @@ watch([() => vGroup.value.key], async (n, o) => { }) onMounted(async () => { - if (vGroup.value.root === true) { - await props.loadGroups({}, vGroup.value) + if (vGroup.value.root === true && !vGroup.value?.children?.length) { + await props.loadGroups( + { + limit: gridViewPageSize.value, + }, + vGroup.value, + ) } }) @@ -581,6 +597,7 @@ const bgColor = computed(() => { Promise + loadGroups: (params?: any, group?: Group, options?: { triggerChildOnly: boolean }) => Promise loadGroupData: (group: Group, force?: boolean, params?: any) => Promise loadGroupPage: (group: Group, p: number) => Promise groupWrapperChangePage: (page: number, groupWrapper?: Group) => Promise @@ -42,8 +42,6 @@ const isPublic = inject(IsPublicInj, ref(false)) const skipRowRemovalOnCancel = ref(false) -const reloadViewDataHook = inject(ReloadViewDataHookInj, createEventHook()) - const { eventBus } = useSmartsheetStoreOrThrow() const route = router.currentRoute @@ -166,13 +164,6 @@ const reloadTableData = async (params: void | { shouldShowLoading?: boolean | un }) } -onBeforeUnmount(async () => { - // reset hooks - reloadViewDataHook?.off(reloadTableData) -}) - -reloadViewDataHook?.on(reloadTableData) - provide(IsGroupByInj, ref(true)) const pagination = computed(() => { @@ -273,14 +264,8 @@ async function deleteSelectedRowsWrapper() { await deleteSelectedRows() // reload table data - await reloadTableData({ shouldShowLoading: true }) + await reloadTableData({ shouldShowLoading: false }) } - -eventBus.on((event) => { - if (event === SmartsheetStoreEvents.GROUP_BY_RELOAD || event === SmartsheetStoreEvents.DATA_RELOAD) { - reloadViewDataHook?.trigger() - } -})