fix(striker-ui): allow skip entry in form summary

main
Tsu-ba-me 11 months ago
parent e8ac1a9c4f
commit 1cfd588448
  1. 46
      striker-ui/components/FormSummary.tsx
  2. 6
      striker-ui/types/FormSummary.d.ts

@ -42,6 +42,7 @@ const buildEntryList = ({
maxDepth, maxDepth,
renderEntry, renderEntry,
renderEntryValue, renderEntryValue,
skip,
}: { }: {
depth?: number; depth?: number;
entries: FormEntries; entries: FormEntries;
@ -52,6 +53,7 @@ const buildEntryList = ({
maxDepth: number; maxDepth: number;
renderEntry: RenderFormEntryFunction; renderEntry: RenderFormEntryFunction;
renderEntryValue: RenderFormValueFunction; renderEntryValue: RenderFormValueFunction;
skip: Exclude<FormSummaryOptionalProps['skip'], undefined>;
}): ReactElement => { }): ReactElement => {
const result: ReactElement[] = []; const result: ReactElement[] = [];
@ -59,24 +61,33 @@ const buildEntryList = ({
const itemId = `form-summary-entry-${itemKey}`; const itemId = `form-summary-entry-${itemKey}`;
const nest = entry !== null && typeof entry === 'object'; const nest = entry !== null && typeof entry === 'object';
const value = nest ? null : entry; const value = nest ? null : entry;
result.push( const fnArgs: CommonFormEntryHandlerArgs = {
<MUIListItem depth,
key={itemId} entry: value,
sx={{ paddingLeft: `${depth}em` }} key: itemKey,
{...getListItemProps?.call(null, { depth, entry: value, key: itemKey })} };
>
{renderEntry({ if (skip(({ key }) => !/confirm/i.test(key), fnArgs)) {
depth, result.push(
entry: value, <MUIListItem
getLabel: getEntryLabel, key={itemId}
key: itemKey, sx={{ paddingLeft: `${depth}em` }}
nest, {...getListItemProps?.call(null, fnArgs)}
renderValue: renderEntryValue, >
})} {renderEntry({
</MUIListItem>, depth,
); entry: value,
getLabel: getEntryLabel,
key: itemKey,
nest,
renderValue: renderEntryValue,
})}
</MUIListItem>,
);
}
if (nest && depth < maxDepth) { if (nest && depth < maxDepth) {
result.push( result.push(
@ -88,6 +99,7 @@ const buildEntryList = ({
maxDepth, maxDepth,
renderEntry, renderEntry,
renderEntryValue, renderEntryValue,
skip,
}), }),
); );
} }
@ -134,6 +146,7 @@ const FormSummary = <T extends FormEntries>({
? renderEntryValueWithPassword(args) ? renderEntryValueWithPassword(args)
: renderEntryValueWithMono(args); : renderEntryValueWithMono(args);
}, },
skip = (base, ...args) => base(...args),
}: FormSummaryProps<T>): ReturnType<FC<FormSummaryProps<T>>> => }: FormSummaryProps<T>): ReturnType<FC<FormSummaryProps<T>>> =>
buildEntryList({ buildEntryList({
entries, entries,
@ -143,6 +156,7 @@ const FormSummary = <T extends FormEntries>({
maxDepth, maxDepth,
renderEntry, renderEntry,
renderEntryValue, renderEntryValue,
skip,
}); });
export default FormSummary; export default FormSummary;

@ -40,6 +40,8 @@ type RenderFormEntryFunction = (
}, },
) => import('react').ReactElement; ) => import('react').ReactElement;
type SkipFormEntryFunction = (args: CommonFormEntryHandlerArgs) => boolean;
type FormSummaryOptionalProps = { type FormSummaryOptionalProps = {
getEntryLabel?: GetFormEntryLabelFunction; getEntryLabel?: GetFormEntryLabelFunction;
getListProps?: GetFormEntriesPropsFunction; getListProps?: GetFormEntriesPropsFunction;
@ -48,6 +50,10 @@ type FormSummaryOptionalProps = {
maxDepth?: number; maxDepth?: number;
renderEntry?: RenderFormEntryFunction; renderEntry?: RenderFormEntryFunction;
renderEntryValue?: RenderFormValueFunction; renderEntryValue?: RenderFormValueFunction;
skip?: (
base: SkipFormEntryFunction,
...args: Parameters<SkipFormEntryFunction>
) => ReturnType<SkipFormEntryFunction>;
}; };
type FormSummaryProps<T extends FormEntries> = FormSummaryOptionalProps & { type FormSummaryProps<T extends FormEntries> = FormSummaryOptionalProps & {

Loading…
Cancel
Save