From 2b4eff587b9fb387ff62460e31203dbd0e9d9dca Mon Sep 17 00:00:00 2001 From: ethangardner Date: Thu, 24 Oct 2024 09:53:18 -0400 Subject: [PATCH] wip on repeater field --- .../src/Form/components/Repeater/index.tsx | 4 ++- packages/forms/src/patterns/input/prompt.ts | 7 +++++ packages/forms/src/patterns/input/response.ts | 4 +++ packages/forms/src/patterns/radio-group.ts | 4 +++ .../forms/src/patterns/repeater/prompt.ts | 27 ++++++++++++++++++- 5 files changed, 44 insertions(+), 2 deletions(-) diff --git a/packages/design/src/Form/components/Repeater/index.tsx b/packages/design/src/Form/components/Repeater/index.tsx index b02f14a3..f5886787 100644 --- a/packages/design/src/Form/components/Repeater/index.tsx +++ b/packages/design/src/Form/components/Repeater/index.tsx @@ -16,12 +16,14 @@ const Repeater: PatternComponent = props => { const renderWithUniqueIds = (children: React.ReactNode, index: number) => { return React.Children.map(children, child => { if (React.isValidElement(child) && child?.props?.component?.props) { + console.group('renderwithuniqueids'); + console.log(child.props); + console.groupEnd(); return React.cloneElement(child as React.ReactElement, { component: { ...child.props.component, props: { ...child.props.component.props, - idSuffix: `.repeater.${index}`, }, }, }); diff --git a/packages/forms/src/patterns/input/prompt.ts b/packages/forms/src/patterns/input/prompt.ts index a7357dab..e9dd710d 100644 --- a/packages/forms/src/patterns/input/prompt.ts +++ b/packages/forms/src/patterns/input/prompt.ts @@ -19,6 +19,13 @@ export const createPrompt: CreatePrompt = ( extraAttributes['error'] = isValidResult.error; } } + + console.group('input/createprompt'); + console.log(session); + console.log(options); + console.log(pattern); + console.groupEnd(); + return { props: { _patternId: pattern.id, diff --git a/packages/forms/src/patterns/input/response.ts b/packages/forms/src/patterns/input/response.ts index c2ff986e..068bedce 100644 --- a/packages/forms/src/patterns/input/response.ts +++ b/packages/forms/src/patterns/input/response.ts @@ -27,5 +27,9 @@ export const parseUserInput: ParseUserInput< InputPattern, InputPatternOutput > = (pattern, obj) => { + console.group('parseUserInput'); + console.log(pattern); + console.log(obj); + console.groupEnd(); return safeZodParseToFormError(createSchema(pattern['data']), obj); }; diff --git a/packages/forms/src/patterns/radio-group.ts b/packages/forms/src/patterns/radio-group.ts index e66af39f..b47868b1 100644 --- a/packages/forms/src/patterns/radio-group.ts +++ b/packages/forms/src/patterns/radio-group.ts @@ -87,6 +87,10 @@ export const radioGroupConfig: PatternConfig = extraAttributes['error'] = isValidResult.error; } } + console.group('radio/createPrompt'); + console.log(pattern); + console.groupEnd(); + return { props: { _patternId: pattern.id, diff --git a/packages/forms/src/patterns/repeater/prompt.ts b/packages/forms/src/patterns/repeater/prompt.ts index 6a998327..ceff8258 100644 --- a/packages/forms/src/patterns/repeater/prompt.ts +++ b/packages/forms/src/patterns/repeater/prompt.ts @@ -12,10 +12,35 @@ export const createPrompt: CreatePrompt = ( pattern, options ) => { + console.group('repeater/createPrompt'); + console.log(session); + console.log(pattern); + console.groupEnd(); + const children = pattern.data.patterns.map((patternId: string) => { - const childPattern = getPattern(session.form, patternId); + let childPattern = getPattern(session.form, patternId); + childPattern = { + ...childPattern, + id: `${pattern.id}.%%INDEX%%.${childPattern.id}` + } + // { + // "id": "8c8a358d-e977-4d9b-9671-43bf6e847f5d", + // "type": "input", + // "data": { + // "label": "Field label", + // "initial": "", + // "required": true, + // "maxLength": 128 + // } + // } + console.group('repeater/createPrompt/children'); + console.log(childPattern); + console.log(options); + console.groupEnd(); return createPromptForPattern(config, session, childPattern, options); }); + + return { props: { _patternId: pattern.id,