diff --git a/striker-ui/components/FormSummary.tsx b/striker-ui/components/FormSummary.tsx index 6fa35c19..8ebd3329 100644 --- a/striker-ui/components/FormSummary.tsx +++ b/striker-ui/components/FormSummary.tsx @@ -42,6 +42,7 @@ const buildEntryList = ({ maxDepth, renderEntry, renderEntryValue, + skip, }: { depth?: number; entries: FormEntries; @@ -52,6 +53,7 @@ const buildEntryList = ({ maxDepth: number; renderEntry: RenderFormEntryFunction; renderEntryValue: RenderFormValueFunction; + skip: Exclude; }): ReactElement => { const result: ReactElement[] = []; @@ -59,24 +61,33 @@ const buildEntryList = ({ const itemId = `form-summary-entry-${itemKey}`; const nest = entry !== null && typeof entry === 'object'; + const value = nest ? null : entry; - result.push( - - {renderEntry({ - depth, - entry: value, - getLabel: getEntryLabel, - key: itemKey, - nest, - renderValue: renderEntryValue, - })} - , - ); + const fnArgs: CommonFormEntryHandlerArgs = { + depth, + entry: value, + key: itemKey, + }; + + if (skip(({ key }) => !/confirm/i.test(key), fnArgs)) { + result.push( + + {renderEntry({ + depth, + entry: value, + getLabel: getEntryLabel, + key: itemKey, + nest, + renderValue: renderEntryValue, + })} + , + ); + } if (nest && depth < maxDepth) { result.push( @@ -88,6 +99,7 @@ const buildEntryList = ({ maxDepth, renderEntry, renderEntryValue, + skip, }), ); } @@ -134,6 +146,7 @@ const FormSummary = ({ ? renderEntryValueWithPassword(args) : renderEntryValueWithMono(args); }, + skip = (base, ...args) => base(...args), }: FormSummaryProps): ReturnType>> => buildEntryList({ entries, @@ -143,6 +156,7 @@ const FormSummary = ({ maxDepth, renderEntry, renderEntryValue, + skip, }); export default FormSummary; diff --git a/striker-ui/types/FormSummary.d.ts b/striker-ui/types/FormSummary.d.ts index 72f44bde..6806060f 100644 --- a/striker-ui/types/FormSummary.d.ts +++ b/striker-ui/types/FormSummary.d.ts @@ -40,6 +40,8 @@ type RenderFormEntryFunction = ( }, ) => import('react').ReactElement; +type SkipFormEntryFunction = (args: CommonFormEntryHandlerArgs) => boolean; + type FormSummaryOptionalProps = { getEntryLabel?: GetFormEntryLabelFunction; getListProps?: GetFormEntriesPropsFunction; @@ -48,6 +50,10 @@ type FormSummaryOptionalProps = { maxDepth?: number; renderEntry?: RenderFormEntryFunction; renderEntryValue?: RenderFormValueFunction; + skip?: ( + base: SkipFormEntryFunction, + ...args: Parameters + ) => ReturnType; }; type FormSummaryProps = FormSummaryOptionalProps & {