fix: error thrown when switching between table with/without record group (#9571)

Fix an error when switching between a table with and without record
group.
This commit is contained in:
Jérémy M
2025-01-13 10:48:13 +01:00
committed by GitHub
parent 34ee64a36c
commit 128abb2b85

View File

@ -1,16 +1,10 @@
import { hasRecordGroupsComponentSelector } from '@/object-record/record-group/states/selectors/hasRecordGroupsComponentSelector';
import { recordIndexEntityCountByGroupComponentFamilyState } from '@/object-record/record-index/states/recordIndexEntityCountByGroupComponentFamilyState';
import { recordIndexEntityCountNoGroupComponentFamilyState } from '@/object-record/record-index/states/recordIndexEntityCountNoGroupComponentFamilyState';
import { useRecoilComponentCallbackStateV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentCallbackStateV2';
import { useRecoilComponentValueV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValueV2';
import { useRecoilCallback } from 'recoil';
import { isDefined } from '~/utils/isDefined';
export const useSetRecordIndexEntityCount = (viewBarComponentId?: string) => {
const hasRecordGroup = useRecoilComponentValueV2(
hasRecordGroupsComponentSelector,
);
const recordIndexEntityCountNoGroupFamilyState =
useRecoilComponentCallbackStateV2(
recordIndexEntityCountNoGroupComponentFamilyState,
@ -26,18 +20,13 @@ export const useSetRecordIndexEntityCount = (viewBarComponentId?: string) => {
const setRecordIndexEntityCount = useRecoilCallback(
({ set }) =>
(count: number, recordGroupId?: string) => {
if (hasRecordGroup) {
if (!isDefined(recordGroupId)) {
throw new Error('Record group ID is required');
}
if (isDefined(recordGroupId)) {
set(recordIndexEntityCountByGroupFamilyState(recordGroupId), count);
} else {
set(recordIndexEntityCountNoGroupFamilyState, count);
}
},
[
hasRecordGroup,
recordIndexEntityCountByGroupFamilyState,
recordIndexEntityCountNoGroupFamilyState,
],