-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: refactor public component wrappers for auto-answering into preview Node
#4108
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for spotting this - this looks like just a weird artifact of somebody calling |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,10 +75,18 @@ interface Props { | |
} | ||
|
||
const Node: React.FC<Props> = (props) => { | ||
const [childNodesOf, resetPreview, cachedBreadcrumbs] = useStore((state) => [ | ||
const [ | ||
childNodesOf, | ||
resetPreview, | ||
cachedBreadcrumbs, | ||
autoAnswerableFlag, | ||
autoAnswerableOptions, | ||
] = useStore((state) => [ | ||
state.childNodesOf, | ||
state.resetPreview, | ||
state.cachedBreadcrumbs, | ||
state.autoAnswerableFlag, | ||
state.autoAnswerableOptions, | ||
]); | ||
|
||
const handleSubmit = props.handleSubmit; | ||
|
@@ -96,13 +104,16 @@ const Node: React.FC<Props> = (props) => { | |
}); | ||
|
||
switch (props.node.type) { | ||
case TYPES.AddressInput: | ||
return <AddressInputComponent {...getComponentProps<AddressInput>()} />; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file is a bit extra noisy because I've alphabetized our component types within the |
||
case TYPES.Calculate: | ||
return <CalculateComponent {...getComponentProps<Calculate>()} />; | ||
|
||
case TYPES.Checklist: { | ||
const checklistProps = getComponentProps<Checklist>(); | ||
const childNodes = childNodesOf( | ||
props.node.id, | ||
nodeId, | ||
) as (typeof checklistProps)["options"]; | ||
|
||
return ( | ||
|
@@ -135,6 +146,9 @@ const Node: React.FC<Props> = (props) => { | |
case TYPES.Confirmation: | ||
return <ConfirmationComponent {...getComponentProps<Confirmation>()} />; | ||
|
||
case TYPES.ContactInput: | ||
return <ContactInputComponent {...getComponentProps<ContactInput>()} />; | ||
|
||
case TYPES.Content: | ||
return <ContentComponent {...getComponentProps<Content>()} />; | ||
|
||
|
@@ -143,8 +157,10 @@ const Node: React.FC<Props> = (props) => { | |
|
||
case TYPES.DrawBoundary: | ||
return <DrawBoundaryComponent {...getComponentProps<DrawBoundary>()} />; | ||
|
||
case TYPES.Feedback: | ||
return <FeedbackComponent {...getComponentProps<Feedback>()} />; | ||
|
||
case TYPES.FileUpload: | ||
return <FileUploadComponent {...getComponentProps<FileUpload>()} />; | ||
|
||
|
@@ -155,6 +171,13 @@ const Node: React.FC<Props> = (props) => { | |
/> | ||
); | ||
|
||
case TYPES.Filter: { | ||
const filterProps = getComponentProps<Filter>(); | ||
const autoAnswer = nodeId ? autoAnswerableFlag(nodeId) : undefined; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: We could calculate this at the top of the file and add it to both Slightly cleaner / more consistent, and we could put a check for component type within |
||
|
||
return <FilterComponent {...filterProps} autoAnswer={autoAnswer} />; | ||
} | ||
|
||
case TYPES.FindProperty: | ||
return <FindPropertyComponent {...getComponentProps<FindProperty>()} />; | ||
|
||
|
@@ -179,6 +202,38 @@ const Node: React.FC<Props> = (props) => { | |
case TYPES.Pay: | ||
return <PayComponent {...getComponentProps<Pay>()} />; | ||
|
||
case TYPES.PlanningConstraints: | ||
return ( | ||
<PlanningConstraintsComponent | ||
{...getComponentProps<PlanningConstraints>()} | ||
/> | ||
); | ||
|
||
case TYPES.PropertyInformation: | ||
return ( | ||
<PropertyInformationComponent | ||
{...getComponentProps<PropertyInformation>()} | ||
/> | ||
); | ||
|
||
case TYPES.Question: { | ||
const questionProps = getComponentProps<Question>(); | ||
const autoAnswers = nodeId ? autoAnswerableOptions(nodeId) : undefined; | ||
|
||
return ( | ||
<QuestionComponent | ||
{...questionProps} | ||
responses={childNodesOf(nodeId).map((n, i) => ({ | ||
id: n.id, | ||
responseKey: i + 1, | ||
title: n.data?.text, | ||
...n.data, | ||
}))} | ||
autoAnswers={autoAnswers} | ||
/> | ||
); | ||
} | ||
|
||
case TYPES.Result: | ||
return <ResultComponent {...getComponentProps<Result>()} />; | ||
|
||
|
@@ -194,19 +249,6 @@ const Node: React.FC<Props> = (props) => { | |
case TYPES.SetValue: | ||
return <SetValueComponent {...getComponentProps<SetValue>()} />; | ||
|
||
case TYPES.Question: | ||
return ( | ||
<QuestionComponent | ||
{...getComponentProps<Question>()} | ||
responses={childNodesOf(props.node.id).map((n, i) => ({ | ||
id: n.id, | ||
responseKey: i + 1, | ||
title: n.data?.text, | ||
...n.data, | ||
}))} | ||
/> | ||
); | ||
|
||
case TYPES.TaskList: { | ||
const taskListProps = getComponentProps<TaskList>(); | ||
|
||
|
@@ -221,34 +263,11 @@ const Node: React.FC<Props> = (props) => { | |
case TYPES.TextInput: | ||
return <TextInputComponent {...getComponentProps<TextInput>()} />; | ||
|
||
case TYPES.AddressInput: | ||
return <AddressInputComponent {...getComponentProps<AddressInput>()} />; | ||
|
||
case TYPES.ContactInput: | ||
return <ContactInputComponent {...getComponentProps<ContactInput>()} />; | ||
|
||
case TYPES.PlanningConstraints: | ||
return ( | ||
<PlanningConstraintsComponent | ||
{...getComponentProps<PlanningConstraints>()} | ||
/> | ||
); | ||
|
||
case TYPES.PropertyInformation: | ||
return ( | ||
<PropertyInformationComponent | ||
{...getComponentProps<PropertyInformation>()} | ||
/> | ||
); | ||
|
||
case TYPES.Filter: | ||
return <FilterComponent {...getComponentProps<Filter>()} />; | ||
|
||
// These types are never seen by users, nor do they leave their own breadcrumbs entry | ||
case TYPES.Answer: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Always appreciate seeing some alphabetising! |
||
case TYPES.ExternalPortal: | ||
case TYPES.Flow: | ||
case TYPES.InternalPortal: | ||
case TYPES.Answer: | ||
case undefined: | ||
return null; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! 💪