Fix re render view groups (#9098)
Co-authored-by: Jérémy Magrin <jeremy.magrin@gmail.com> Co-authored-by: Marie Stoppa <marie.stoppa@essec.edu>
This commit is contained in:
@ -24,7 +24,7 @@ export const useSetRecordGroup = (viewId?: string) => {
|
||||
return useRecoilCallback(
|
||||
({ snapshot, set }) =>
|
||||
(recordGroups: RecordGroupDefinition[]) => {
|
||||
const currentRecordGroupId = getSnapshotValue(
|
||||
const currentRecordGroupIds = getSnapshotValue(
|
||||
snapshot,
|
||||
recordIndexRecordGroupIdsState,
|
||||
);
|
||||
@ -61,7 +61,7 @@ export const useSetRecordGroup = (viewId?: string) => {
|
||||
const recordGroupIds = recordGroups.map(({ id }) => id);
|
||||
|
||||
// Get ids that has been removed between the current and new record groups
|
||||
const removedRecordGroupIds = currentRecordGroupId.filter(
|
||||
const removedRecordGroupIds = currentRecordGroupIds.filter(
|
||||
(id) => !recordGroupIds.includes(id),
|
||||
);
|
||||
|
||||
@ -70,7 +70,7 @@ export const useSetRecordGroup = (viewId?: string) => {
|
||||
set(recordGroupDefinitionFamilyState(id), undefined);
|
||||
});
|
||||
|
||||
if (isDeeplyEqual(currentRecordGroupId, recordGroupIds)) {
|
||||
if (isDeeplyEqual(currentRecordGroupIds, recordGroupIds)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@ -6,12 +6,12 @@ import { useUpdateOneRecord } from '@/object-record/hooks/useUpdateOneRecord';
|
||||
import { getDraggedRecordPosition } from '@/object-record/record-board/utils/getDraggedRecordPosition';
|
||||
import { recordGroupDefinitionFamilyState } from '@/object-record/record-group/states/recordGroupDefinitionFamilyState';
|
||||
import { recordIndexRecordIdsByGroupComponentFamilyState } from '@/object-record/record-index/states/recordIndexRecordIdsByGroupComponentFamilyState';
|
||||
import { recordIndexSortsState } from '@/object-record/record-index/states/recordIndexSortsState';
|
||||
import { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState';
|
||||
import { useRecordTableContextOrThrow } from '@/object-record/record-table/contexts/RecordTableContext';
|
||||
import { isRemoveSortingModalOpenState } from '@/object-record/record-table/states/isRemoveSortingModalOpenState';
|
||||
import { useRecoilComponentCallbackStateV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentCallbackStateV2';
|
||||
import { getSnapshotValue } from '@/ui/utilities/state/utils/getSnapshotValue';
|
||||
import { useGetCurrentView } from '@/views/hooks/useGetCurrentView';
|
||||
import { isDefined } from '~/utils/isDefined';
|
||||
|
||||
export const RecordTableBodyRecordGroupDragDropContextProvider = ({
|
||||
@ -19,18 +19,13 @@ export const RecordTableBodyRecordGroupDragDropContextProvider = ({
|
||||
}: {
|
||||
children: ReactNode;
|
||||
}) => {
|
||||
const { objectNameSingular, recordTableId, objectMetadataItem } =
|
||||
const { objectNameSingular, objectMetadataItem } =
|
||||
useRecordTableContextOrThrow();
|
||||
|
||||
const { updateOneRecord: updateOneRow } = useUpdateOneRecord({
|
||||
objectNameSingular,
|
||||
});
|
||||
|
||||
const { currentViewWithCombinedFiltersAndSorts } =
|
||||
useGetCurrentView(recordTableId);
|
||||
|
||||
const viewSorts = currentViewWithCombinedFiltersAndSorts?.viewSorts || [];
|
||||
|
||||
const setIsRemoveSortingModalOpenState = useSetRecoilState(
|
||||
isRemoveSortingModalOpenState,
|
||||
);
|
||||
@ -57,6 +52,10 @@ export const RecordTableBodyRecordGroupDragDropContextProvider = ({
|
||||
recordGroupDefinitionFamilyState(destinationRecordGroupId),
|
||||
);
|
||||
|
||||
const indexSorts = snapshot
|
||||
.getLoadable(recordIndexSortsState)
|
||||
.getValue();
|
||||
|
||||
if (!isDefined(destinationRecordGroup)) {
|
||||
throw new Error('Record group is not defined');
|
||||
}
|
||||
@ -69,7 +68,7 @@ export const RecordTableBodyRecordGroupDragDropContextProvider = ({
|
||||
throw new Error('Field metadata is not defined');
|
||||
}
|
||||
|
||||
if (viewSorts.length > 0) {
|
||||
if (indexSorts.length > 0) {
|
||||
setIsRemoveSortingModalOpenState(true);
|
||||
return;
|
||||
}
|
||||
@ -128,7 +127,6 @@ export const RecordTableBodyRecordGroupDragDropContextProvider = ({
|
||||
},
|
||||
[
|
||||
objectMetadataItem.fields,
|
||||
viewSorts.length,
|
||||
recordIdsByGroupFamilyState,
|
||||
updateOneRow,
|
||||
setIsRemoveSortingModalOpenState,
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
import { v4 } from 'uuid';
|
||||
import { isDefined } from '~/utils/isDefined';
|
||||
|
||||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
@ -65,7 +64,7 @@ export const mapViewGroupsToRecordGroupDefinitions = ({
|
||||
);
|
||||
|
||||
const noValueColumn = {
|
||||
id: viewGroup?.id ?? v4(),
|
||||
id: viewGroup?.id ?? '20202020-c05f-46c9-ae1e-2b3c5c702049',
|
||||
title: 'No Value',
|
||||
type: RecordGroupDefinitionType.NoValue,
|
||||
value: null,
|
||||
|
||||
Reference in New Issue
Block a user