Browse Source

fix(nc-gui): add validations for field context group by

pull/8309/head
Ramesh Mane 3 months ago
parent
commit
d4b8a1957b
  1. 28
      packages/nc-gui/components/smartsheet/header/Menu.vue
  2. 4
      packages/nc-gui/components/smartsheet/toolbar/GroupByMenu.vue
  3. 3
      packages/nc-gui/composables/useViewGroupBy.ts

28
packages/nc-gui/components/smartsheet/header/Menu.vue

@ -54,6 +54,8 @@ const showDeleteColumnModal = ref(false)
const { gridViewCols } = useViewColumnsOrThrow() const { gridViewCols } = useViewColumnsOrThrow()
const { fieldsToGroupBy, groupByLimit } = useViewGroupBy(view)
const setAsDisplayValue = async () => { const setAsDisplayValue = async () => {
try { try {
const currentDisplayValue = meta?.value?.columns?.find((f) => f.pv) const currentDisplayValue = meta?.value?.columns?.find((f) => f.pv)
@ -298,8 +300,13 @@ const isDuplicateAllowed = computed(() => {
return column?.value && !column.value.system return column?.value && !column.value.system
}) })
const isGroupedByThisField = computed(() => { const isGroupedByThisField = computed(() => !!gridViewCols.value[column?.value?.id]?.group_by)
return !!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) => { const filterOrGroupByThisField = (event: SmartsheetStoreEvents) => {
@ -381,12 +388,21 @@ const filterOrGroupByThisField = (event: SmartsheetStoreEvents) => {
<NcMenuItem @click="filterOrGroupByThisField(SmartsheetStoreEvents.FILTER_ADD)"> <NcMenuItem @click="filterOrGroupByThisField(SmartsheetStoreEvents.FILTER_ADD)">
<div v-e="['a:field:add:filter']" class="nc-column-filter nc-header-menu-item"> <div v-e="['a:field:add:filter']" class="nc-column-filter nc-header-menu-item">
<component :is="iconMap.filter" class="text-gray-700" /> <component :is="iconMap.filter" class="text-gray-700" />
<!-- Group by this field --> <!-- Filter by this field -->
Filter by this field Filter by this field
</div> </div>
</NcMenuItem> </NcMenuItem>
<NcTooltip :disabled="(isGroupBySupported && !isGroupByLimitExceeded) || isGroupedByThisField">
<template #title>{{
!isGroupBySupported
? "This field type doesn't support grouping"
: isGroupByLimitExceeded
? 'Group by limit exceeded'
: 'ds'
}}</template>
<NcMenuItem <NcMenuItem
:disabled="(!isGroupBySupported || isGroupByLimitExceeded) && !isGroupedByThisField"
@click=" @click="
filterOrGroupByThisField( filterOrGroupByThisField(
isGroupedByThisField ? SmartsheetStoreEvents.GROUP_BY_REMOVE : SmartsheetStoreEvents.GROUP_BY_ADD, isGroupedByThisField ? SmartsheetStoreEvents.GROUP_BY_REMOVE : SmartsheetStoreEvents.GROUP_BY_ADD,
@ -399,6 +415,7 @@ const filterOrGroupByThisField = (event: SmartsheetStoreEvents) => {
{{ isGroupedByThisField ? "Don't group by this field" : 'Group by this field' }} {{ isGroupedByThisField ? "Don't group by this field" : 'Group by this field' }}
</div> </div>
</NcMenuItem> </NcMenuItem>
</NcTooltip>
<a-divider class="!my-0" /> <a-divider class="!my-0" />
</template> </template>
@ -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; @apply !hover:text-black text-gray-700;
} }
:deep(.ant-dropdown-menu-item.ant-dropdown-menu-item-disabled .nc-icon) {
@apply text-current;
}
</style> </style>

4
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 { gridViewCols, updateGridViewColumn, metaColumnById, showSystemFields } = useViewColumnsOrThrow()
const { fieldsToGroupBy } = useViewGroupBy(view) const { fieldsToGroupBy, groupByLimit } = useViewGroupBy(view)
const { $e } = useNuxtApp() const { $e } = useNuxtApp()
@ -254,7 +254,7 @@ eventBus.on(async (event, column) => {
</template> </template>
</div> </div>
<NcDropdown <NcDropdown
v-if="availableColumns.length && fieldsToGroupBy.length > _groupBy.length && _groupBy.length < 3" v-if="availableColumns.length && fieldsToGroupBy.length > _groupBy.length && _groupBy.length < groupByLimit"
v-model:visible="showCreateGroupBy" v-model:visible="showCreateGroupBy"
:trigger="['click']" :trigger="['click']"
overlay-class-name="nc-toolbar-dropdown" overlay-class-name="nc-toolbar-dropdown"

3
packages/nc-gui/composables/useViewGroupBy.ts

@ -9,6 +9,8 @@ import type { Group, GroupNestedIn, Row } from '#imports'
const excludedGroupingUidt = [UITypes.Attachment, UITypes.QrCode, UITypes.Barcode] const excludedGroupingUidt = [UITypes.Attachment, UITypes.QrCode, UITypes.Barcode]
export const useViewGroupBy = (view: Ref<ViewType | undefined>, where?: ComputedRef<string | undefined>) => { export const useViewGroupBy = (view: Ref<ViewType | undefined>, where?: ComputedRef<string | undefined>) => {
const groupByLimit: number = 3
const { api } = useApi() const { api } = useApi()
const { appInfo } = useGlobal() const { appInfo } = useGlobal()
@ -533,6 +535,7 @@ export const useViewGroupBy = (view: Ref<ViewType | undefined>, where?: Computed
groupBy, groupBy,
isGroupBy, isGroupBy,
fieldsToGroupBy, fieldsToGroupBy,
groupByLimit,
loadGroups, loadGroups,
loadGroupData, loadGroupData,
loadGroupPage, loadGroupPage,

Loading…
Cancel
Save