Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Charles Bochet
2026-02-23 12:01:37 +01:00
committed by GitHub
parent 22bc3004b9
commit b51eb6471f
538 changed files with 4664 additions and 4127 deletions
@@ -4,11 +4,12 @@ import { useLoadRecordIndexStates } from '@/object-record/record-index/hooks/use
import { type ExtendedAggregateOperations } from '@/object-record/record-table/types/ExtendedAggregateOperations';
import { convertExtendedAggregateOperationToAggregateOperation } from '@/object-record/utils/convertExtendedAggregateOperationToAggregateOperation';
import { useRecoilComponentValue } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValue';
import { jotaiStore } from '@/ui/utilities/state/jotai/jotaiStore';
import { usePerformViewAPIUpdate } from '@/views/hooks/internal/usePerformViewAPIUpdate';
import { useCanPersistViewChanges } from '@/views/hooks/useCanPersistViewChanges';
import { coreViewsState } from '@/views/states/coreViewState';
import { convertCoreViewToView } from '@/views/utils/convertCoreViewToView';
import { useRecoilCallback } from 'recoil';
import { useCallback } from 'react';
import {
isDefined,
upsertIntoArrayOfObjectsComparingId,
@@ -23,61 +24,60 @@ export const useUpdateViewAggregate = () => {
const { performViewAPIUpdate } = usePerformViewAPIUpdate();
const { loadRecordIndexStates } = useLoadRecordIndexStates();
const updateViewAggregate = useRecoilCallback(
({ set }) =>
async ({
kanbanAggregateOperationFieldMetadataId,
const updateViewAggregate = useCallback(
async ({
kanbanAggregateOperationFieldMetadataId,
kanbanAggregateOperation,
objectMetadataItem,
}: {
kanbanAggregateOperationFieldMetadataId: string | null;
kanbanAggregateOperation: ExtendedAggregateOperations | null;
objectMetadataItem: ObjectMetadataItem;
}) => {
if (!canPersistChanges) {
return;
}
const convertedKanbanAggregateOperation = isDefined(
kanbanAggregateOperation,
objectMetadataItem,
}: {
kanbanAggregateOperationFieldMetadataId: string | null;
kanbanAggregateOperation: ExtendedAggregateOperations | null;
objectMetadataItem: ObjectMetadataItem;
}) => {
if (!canPersistChanges) {
)
? convertExtendedAggregateOperationToAggregateOperation(
kanbanAggregateOperation,
)
: null;
if (!isDefined(currentViewId)) {
return;
}
const updatedViewResult = await performViewAPIUpdate({
id: currentViewId,
input: {
kanbanAggregateOperationFieldMetadataId,
kanbanAggregateOperation: convertedKanbanAggregateOperation,
},
});
if (updatedViewResult.status === 'successful') {
const updatedCoreView = updatedViewResult.response.data
?.updateCoreView as CoreView;
if (!isDefined(updatedCoreView)) {
return;
}
const convertedKanbanAggregateOperation = isDefined(
kanbanAggregateOperation,
)
? convertExtendedAggregateOperationToAggregateOperation(
kanbanAggregateOperation,
)
: null;
jotaiStore.set(coreViewsState.atom, (currentCoreViews) =>
upsertIntoArrayOfObjectsComparingId(
currentCoreViews,
updatedCoreView,
),
);
if (!isDefined(currentViewId)) {
return;
}
const updatedView = convertCoreViewToView(updatedCoreView);
const updatedViewResult = await performViewAPIUpdate({
id: currentViewId,
input: {
kanbanAggregateOperationFieldMetadataId,
kanbanAggregateOperation: convertedKanbanAggregateOperation,
},
});
if (updatedViewResult.status === 'successful') {
const updatedCoreView = updatedViewResult.response.data
?.updateCoreView as CoreView;
if (!isDefined(updatedCoreView)) {
return;
}
set(coreViewsState, (currentCoreViews) =>
upsertIntoArrayOfObjectsComparingId(
currentCoreViews,
updatedCoreView,
),
);
const updatedView = convertCoreViewToView(updatedCoreView);
loadRecordIndexStates(updatedView, objectMetadataItem);
}
},
loadRecordIndexStates(updatedView, objectMetadataItem);
}
},
[
canPersistChanges,
currentViewId,