Skip to content

Commit

Permalink
wip on repeater field
Browse files Browse the repository at this point in the history
  • Loading branch information
ethangardner committed Dec 5, 2024
1 parent 317b750 commit 2b4eff5
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/design/src/Form/components/Repeater/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ const Repeater: PatternComponent<RepeaterProps> = props => {
const renderWithUniqueIds = (children: React.ReactNode, index: number) => {

Check failure on line 16 in packages/design/src/Form/components/Repeater/index.tsx

View workflow job for this annotation

GitHub Actions / run-tests / run-tests

'index' is defined but never used
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}`,
},
},
});
Expand Down
7 changes: 7 additions & 0 deletions packages/forms/src/patterns/input/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ export const createPrompt: CreatePrompt<InputPattern> = (
extraAttributes['error'] = isValidResult.error;
}
}

console.group('input/createprompt');
console.log(session);
console.log(options);
console.log(pattern);
console.groupEnd();

return {
props: {
_patternId: pattern.id,
Expand Down
4 changes: 4 additions & 0 deletions packages/forms/src/patterns/input/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
4 changes: 4 additions & 0 deletions packages/forms/src/patterns/radio-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ export const radioGroupConfig: PatternConfig<RadioGroupPattern, PatternOutput> =
extraAttributes['error'] = isValidResult.error;
}
}
console.group('radio/createPrompt');
console.log(pattern);
console.groupEnd();

return {
props: {
_patternId: pattern.id,
Expand Down
27 changes: 26 additions & 1 deletion packages/forms/src/patterns/repeater/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,35 @@ export const createPrompt: CreatePrompt<RepeaterPattern> = (
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,
Expand Down

0 comments on commit 2b4eff5

Please sign in to comment.