Skip to content
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

feat: List component - basic model, types & UI #3197

Merged
merged 5 commits into from
May 28, 2024

Conversation

DafyddLlyr
Copy link
Contributor

@DafyddLlyr DafyddLlyr commented May 27, 2024

What does this PR do?

  • Initial setup of List component
  • Mapping of simple example config file ("Zoo") to form fields
  • Basic / rough UI
  • Unit tests covering work in this PR, plus future test.todos()
image

What's not in this PR?

A whole lot! The plan is to split these next steps into smaller, atomic PRs across the course of this week. This PR so already >500 LOC so this seems like a sensible point to stop off.

I'm aware there's a fair number of outstanding TODOs left throughout this PR - I hope you'll forgive this for a WIP feature still behind a feature flag 👍

Upcoming PRs

  • Managing user data in state (responses to form, add/remove items in list)
  • Form validation and error handling (I'd like to be able to generate a Yup schema dynamically based on config file 🤞)
  • Payload generation, adding to passport
  • Building real schemas

Context / Principles

Here's a high-level overview of what I'm hoping to achieve here -

Schemas
Right now, this is a typed object living in the codebase - see the example Zoo.ts. This allows us to write a .ts file, but not worry about a complex Editor form to create this just yet. In future, we can allow greater customisation and control over the generation of these but we're taking a pragmatic approach here for now.

UI / UX
The types used in the Schema type are those already used in out UI components. This means we get a consistent interface and behaviour across our frontend.

Form Validation / Error handling
I'm going to try to generate a dynamic Yup schema / Formik instance based on the schema set up in the Editor. This should mean I can re-use a lot of already tested code validating user inputs. A few options to be explored here if this isn't a viable option.

Payload
When a user submits the form, we can take their responses and map them in the passport based on the fn values supplied in the schema. This will then be referenced in planx-core to create the required payload for a valid ODP schema (e.g. Residential units).

Copy link

github-actions bot commented May 27, 2024

Removed vultr server and associated DNS entries

Comment on lines +25 to +30
type={((type) => {
if (type === "email") return "email";
else if (type === "phone") return "tel";
return "text";
})(data.type)}
multiline={data.type && ["long", "extraLong"].includes(data.type)}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's some repeated code here from existing components.

I'm hoping that once error handling / form values are handled I can DRY this up a little with more generic, shared, input components.

@@ -169,7 +170,7 @@ const Node: React.FC<any> = (props: Props) => {
return <FindProperty {...allProps} />;

case TYPES.List:
return <List {...allProps} />;
return hasFeatureFlag("LIST_COMPONENT") ? <List {...allProps} /> : null;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving this here means I can escape the "don't use conditional hooks" warning.

Docs: https://react.dev/reference/rules/rules-of-hooks#only-call-hooks-at-the-top-level

}) {
return (
<Root htmlFor={props.htmlFor}>
<Root htmlFor={props.htmlFor} id={props.id}>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was necessary due to how MUI handles linking a label to the <Select/> component.

Helpfully, without this fix, the a11y unit test was failing 🧪

As this is our first user facing Select I think there's likely some work in getting this to work as expected with our existing components and styles perfectly - what I have here is a little rough and ready, but will be revisited once it's wired up to a form.

Docs: https://mui.com/material-ui/react-select/#accessibility

@DafyddLlyr DafyddLlyr marked this pull request as ready for review May 27, 2024 13:53
@DafyddLlyr DafyddLlyr requested a review from a team May 27, 2024 13:54
/>
<ListCard>
<Typography component="h2" variant="h3">
{schema.type} index
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

index will be replaced by a number once I've setup user data in state.

Copy link
Member

@jessicamcinchak jessicamcinchak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy for this to move forward, appreciate todo's & feature flag !

// TODO: Track "active" index
// TODO: Validate min / max
// TODO: Validate user input against schema fields, track errors
// TODO: On submit generate a payload
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

],
min: 1,
max: 10,
} as const;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

schema definition files feel like a good MVP route here & editable by someone like August in very near future until more general editor customisation is possible ➕

@DafyddLlyr DafyddLlyr merged commit 0d26b31 into main May 28, 2024
12 checks passed
@DafyddLlyr DafyddLlyr deleted the dp/list-component-basic-types branch May 28, 2024 13:43
@DafyddLlyr
Copy link
Contributor Author

Thanks for the speedy review @jessicamcinchak - appreciate it! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants