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, getAddLoading,
getDeleteErrorMessage, getDeleteErrorMessage,
getDeleteHeader, getDeleteHeader,
getDeletePromiseChain = (base, ...args) => base(...args),
getDeleteSuccessMessage, getDeleteSuccessMessage,
getEditLoading = (previous?: boolean) => previous, getEditLoading = (previous?: boolean) => previous,
listEmpty, listEmpty,
@ -146,7 +147,11 @@ const CrudList = <
setConfirmDialogLoading(true); setConfirmDialogLoading(true);
Promise.all( Promise.all(
checks.map((key) => api.delete(`${entriesUrl}/${key}`)), getDeletePromiseChain(
(cl, up) => cl.map((key) => api.delete(`${up}/${key}`)),
checks,
entriesUrl,
),
) )
.then(() => { .then(() => {
finishConfirm('Success', getDeleteSuccessMessage()); finishConfirm('Success', getDeleteSuccessMessage());

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

Loading…
Cancel
Save