[FEAT] RecordAction destroy many record (#9991)

# Introduction
Added the `RecordAction` destroy multiple record

## Repro
Select multiples `deletedRecords`, you should be able to see the
`Destroy` pinned CTA ( iso short label with the destroy one ), open
control panel and fin new CTA `Permanently delete records`


https://github.com/user-attachments/assets/31ee8738-9d61-4dec-9a1f-41bb6785e018

## TODO
- [ ] Gain granularity within tests to assert the action should be
registered only when filtering by deleted

## Conclusion
Closes https://github.com/twentyhq/core-team-issues/issues/110
This commit is contained in:
Paul Rastoin
2025-02-05 11:33:01 +01:00
committed by GitHub
parent aa003f25d9
commit 28a3f75946
12 changed files with 338 additions and 33 deletions

View File

@ -0,0 +1 @@
export const BACKEND_BATCH_REQUEST_MAX_COUNT = 10000;

View File

@ -1 +0,0 @@
export const DELETE_MAX_COUNT = 10000;

View File

@ -19,7 +19,8 @@ type useDestroyManyRecordProps = {
refetchFindManyQuery?: boolean;
};
type DestroyManyRecordsOptions = {
export type DestroyManyRecordsProps = {
recordIdsToDestroy: string[];
skipOptimisticEffect?: boolean;
delayInMsBetweenRequests?: number;
};
@ -56,16 +57,19 @@ export const useDestroyManyRecords = ({
objectMetadataItem.namePlural,
);
const destroyManyRecords = async (
idsToDestroy: string[],
options?: DestroyManyRecordsOptions,
) => {
const numberOfBatches = Math.ceil(idsToDestroy.length / mutationPageSize);
const destroyManyRecords = async ({
recordIdsToDestroy,
delayInMsBetweenRequests,
skipOptimisticEffect = false,
}: DestroyManyRecordsProps) => {
const numberOfBatches = Math.ceil(
recordIdsToDestroy.length / mutationPageSize,
);
const destroyedRecords = [];
for (let batchIndex = 0; batchIndex < numberOfBatches; batchIndex++) {
const batchedIdToDestroy = idsToDestroy.slice(
const batchedIdToDestroy = recordIdsToDestroy.slice(
batchIndex * mutationPageSize,
(batchIndex + 1) * mutationPageSize,
);
@ -80,7 +84,7 @@ export const useDestroyManyRecords = ({
variables: {
filter: { id: { in: batchedIdToDestroy } },
},
optimisticResponse: options?.skipOptimisticEffect
optimisticResponse: skipOptimisticEffect
? undefined
: {
[mutationResponseField]: batchedIdToDestroy.map(
@ -90,7 +94,7 @@ export const useDestroyManyRecords = ({
}),
),
},
update: options?.skipOptimisticEffect
update: skipOptimisticEffect
? undefined
: (cache, { data }) => {
const records = data?.[mutationResponseField];
@ -126,8 +130,8 @@ export const useDestroyManyRecords = ({
destroyedRecords.push(...destroyedRecordsForThisBatch);
if (isDefined(options?.delayInMsBetweenRequests)) {
await sleep(options.delayInMsBetweenRequests);
if (isDefined(delayInMsBetweenRequests)) {
await sleep(delayInMsBetweenRequests);
}
}