From d4b8a1957b99fce5da7fc86769600e51dcf59498 Mon Sep 17 00:00:00 2001 From: Ramesh Mane <101566080+rameshmane7218@users.noreply.github.com> Date: Mon, 22 Apr 2024 05:37:59 +0000 Subject: [PATCH] fix(nc-gui): add validations for field context group by --- .../components/smartsheet/header/Menu.vue | 54 +++++++++++++------ .../smartsheet/toolbar/GroupByMenu.vue | 4 +- packages/nc-gui/composables/useViewGroupBy.ts | 3 ++ 3 files changed, 42 insertions(+), 19 deletions(-) diff --git a/packages/nc-gui/components/smartsheet/header/Menu.vue b/packages/nc-gui/components/smartsheet/header/Menu.vue index aa0b9fee26..94b67ba106 100644 --- a/packages/nc-gui/components/smartsheet/header/Menu.vue +++ b/packages/nc-gui/components/smartsheet/header/Menu.vue @@ -54,6 +54,8 @@ const showDeleteColumnModal = ref(false) const { gridViewCols } = useViewColumnsOrThrow() +const { fieldsToGroupBy, groupByLimit } = useViewGroupBy(view) + const setAsDisplayValue = async () => { try { const currentDisplayValue = meta?.value?.columns?.find((f) => f.pv) @@ -298,8 +300,13 @@ const isDuplicateAllowed = computed(() => { return column?.value && !column.value.system }) -const isGroupedByThisField = computed(() => { - return !!gridViewCols.value[column?.value?.id]?.group_by +const isGroupedByThisField = computed(() => !!gridViewCols.value[column?.value?.id]?.group_by) + +const isGroupBySupported = computed(() => !!(fieldsToGroupBy.value || []).find((f) => f.id === column?.value?.id)) + +const isGroupByLimitExceeded = computed(() => { + const groupBy = Object.values(gridViewCols.value).filter((c) => c.group_by) + return !(fieldsToGroupBy.value.length && fieldsToGroupBy.value.length > groupBy.length && groupBy.length < groupByLimit) }) const filterOrGroupByThisField = (event: SmartsheetStoreEvents) => { @@ -381,24 +388,34 @@ const filterOrGroupByThisField = (event: SmartsheetStoreEvents) => {
- + Filter by this field
- -
- - - {{ isGroupedByThisField ? "Don't group by this field" : 'Group by this field' }} -
-
+ + + +
+ + + {{ isGroupedByThisField ? "Don't group by this field" : 'Group by this field' }} +
+
+
@@ -457,7 +474,10 @@ const filterOrGroupByThisField = (event: SmartsheetStoreEvents) => { } } -:deep(.ant-dropdown-menu-item) { +:deep(.ant-dropdown-menu-item:not(.ant-dropdown-menu-item-disabled)) { @apply !hover:text-black text-gray-700; } +:deep(.ant-dropdown-menu-item.ant-dropdown-menu-item-disabled .nc-icon) { + @apply text-current; +} diff --git a/packages/nc-gui/components/smartsheet/toolbar/GroupByMenu.vue b/packages/nc-gui/components/smartsheet/toolbar/GroupByMenu.vue index ab5e5f828a..324b7fa36f 100644 --- a/packages/nc-gui/components/smartsheet/toolbar/GroupByMenu.vue +++ b/packages/nc-gui/components/smartsheet/toolbar/GroupByMenu.vue @@ -22,7 +22,7 @@ const isLocked = inject(IsLockedInj, ref(false)) const { gridViewCols, updateGridViewColumn, metaColumnById, showSystemFields } = useViewColumnsOrThrow() -const { fieldsToGroupBy } = useViewGroupBy(view) +const { fieldsToGroupBy, groupByLimit } = useViewGroupBy(view) const { $e } = useNuxtApp() @@ -254,7 +254,7 @@ eventBus.on(async (event, column) => { , where?: ComputedRef) => { + const groupByLimit: number = 3 + const { api } = useApi() const { appInfo } = useGlobal() @@ -533,6 +535,7 @@ export const useViewGroupBy = (view: Ref, where?: Computed groupBy, isGroupBy, fieldsToGroupBy, + groupByLimit, loadGroups, loadGroupData, loadGroupPage,