[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:
@ -0,0 +1 @@
|
||||
export const BACKEND_BATCH_REQUEST_MAX_COUNT = 10000;
|
||||
@ -1 +0,0 @@
|
||||
export const DELETE_MAX_COUNT = 10000;
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user