fix(striker-ui): allow customize delete promise chain in CRUD list

main
Tsu-ba-me 11 months ago
parent 0192fb7bf6
commit b4408e78ce
  1. 7
      striker-ui/components/CrudList.tsx
  2. 9
      striker-ui/types/CrudList.d.ts

@ -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());

@ -12,8 +12,17 @@ type CrudListItemClickHandler = Exclude<
undefined
>;
type DeletePromiseChainGetter<T> = (
checks: ArrayChecklist,
urlPrefix: string,
) => Promise<T>[];
type CrudListOptionalProps<Overview> = {
getAddLoading?: (previous?: boolean) => boolean;
getDeletePromiseChain?: <T>(
base: DeletePromiseChainGetter<T>,
...args: Parameters<DeletePromiseChainGetter<T>>
) => ReturnType<DeletePromiseChainGetter<T>>;
getEditLoading?: (previous?: boolean) => boolean;
listProps?: Partial<ListProps<Overview>>;
onItemClick?: (

Loading…
Cancel
Save