diff --git a/packages/twenty-front/src/modules/object-record/record-group/states/selectors/visibleRecordGroupIdsComponentFamilySelector.ts b/packages/twenty-front/src/modules/object-record/record-group/states/selectors/visibleRecordGroupIdsComponentFamilySelector.ts index 90f72745f5..12eccb6f1f 100644 --- a/packages/twenty-front/src/modules/object-record/record-group/states/selectors/visibleRecordGroupIdsComponentFamilySelector.ts +++ b/packages/twenty-front/src/modules/object-record/record-group/states/selectors/visibleRecordGroupIdsComponentFamilySelector.ts @@ -4,6 +4,8 @@ import { type RecordGroupDefinition } from '@/object-record/record-group/types/R import { RecordGroupSort } from '@/object-record/record-group/types/RecordGroupSort'; import { recordGroupSortedInsert } from '@/object-record/record-group/utils/recordGroupSortedInsert'; import { recordIndexRecordGroupSortComponentState } from '@/object-record/record-index/states/recordIndexRecordGroupSortComponentState'; +import { recordIndexRecordIdsByGroupComponentFamilyState } from '@/object-record/record-index/states/recordIndexRecordIdsByGroupComponentFamilyState'; +import { recordIndexShouldHideEmptyRecordGroupsComponentState } from '@/object-record/record-index/states/recordIndexShouldHideEmptyRecordGroupsComponentState'; import { createComponentFamilySelector } from '@/ui/utilities/state/component-state/utils/createComponentFamilySelector'; import { ViewComponentInstanceContext } from '@/views/states/contexts/ViewComponentInstanceContext'; @@ -30,6 +32,12 @@ export const visibleRecordGroupIdsComponentFamilySelector = }), ); + const shouldHideEmptyRecordGroups = get( + recordIndexShouldHideEmptyRecordGroupsComponentState.atomFamily({ + instanceId, + }), + ); + const result: RecordGroupDefinition[] = []; const comparator = ( @@ -60,6 +68,18 @@ export const visibleRecordGroupIdsComponentFamilySelector = continue; } + if (shouldHideEmptyRecordGroups) { + const rowIds = get( + recordIndexRecordIdsByGroupComponentFamilyState.atomFamily({ + instanceId, + familyKey: recordGroupId, + }), + ); + if (rowIds.length === 0) { + continue; + } + } + recordGroupSortedInsert(result, recordGroupDefinition, comparator); }