From b4408e78ceba8fab85539ceeee330ca43907a044 Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Wed, 24 Jan 2024 18:19:26 -0500 Subject: [PATCH] fix(striker-ui): allow customize delete promise chain in CRUD list --- striker-ui/components/CrudList.tsx | 7 ++++++- striker-ui/types/CrudList.d.ts | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/striker-ui/components/CrudList.tsx b/striker-ui/components/CrudList.tsx index f7f0284b..a020521f 100644 --- a/striker-ui/components/CrudList.tsx +++ b/striker-ui/components/CrudList.tsx @@ -28,6 +28,7 @@ const CrudList = < getAddLoading, getDeleteErrorMessage, getDeleteHeader, + getDeletePromiseChain = (base, ...args) => base(...args), getDeleteSuccessMessage, getEditLoading = (previous?: boolean) => previous, listEmpty, @@ -146,7 +147,11 @@ const CrudList = < setConfirmDialogLoading(true); Promise.all( - checks.map((key) => api.delete(`${entriesUrl}/${key}`)), + getDeletePromiseChain( + (cl, up) => cl.map((key) => api.delete(`${up}/${key}`)), + checks, + entriesUrl, + ), ) .then(() => { finishConfirm('Success', getDeleteSuccessMessage()); diff --git a/striker-ui/types/CrudList.d.ts b/striker-ui/types/CrudList.d.ts index 258c81c3..7526bc63 100644 --- a/striker-ui/types/CrudList.d.ts +++ b/striker-ui/types/CrudList.d.ts @@ -12,8 +12,17 @@ type CrudListItemClickHandler = Exclude< undefined >; +type DeletePromiseChainGetter = ( + checks: ArrayChecklist, + urlPrefix: string, +) => Promise[]; + type CrudListOptionalProps = { getAddLoading?: (previous?: boolean) => boolean; + getDeletePromiseChain?: ( + base: DeletePromiseChainGetter, + ...args: Parameters> + ) => ReturnType>; getEditLoading?: (previous?: boolean) => boolean; listProps?: Partial>; onItemClick?: (