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

[WIP] Pull out routing #262

Closed
wants to merge 11 commits into from
Closed

[WIP] Pull out routing #262

wants to merge 11 commits into from

Conversation

annekainicUSDS
Copy link
Contributor

@annekainicUSDS annekainicUSDS commented Sep 12, 2018

Addresses #257.

Types of changes

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • I've reviewed the guidelines for contributing to this repository.
  • I've checked style and lint with npm run lint.
  • I built the production version with npm run build.
  • I added tests to verify a bug fix or new functionality.
  • All tests pass locally with npm test.
  • My change requires a change to the documentation, and I've updated the documentation accordingly.

// * config, pulls out the config for each page, then generates a list of Route components with the
// * config as props
// */
// export function createRoutes(formConfig) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copied this function into the starter app and tested using it there to create the routes to make sure everything still works with this pulled out.

}

goBack = () => {
const { form, route: { pageList }, location } = this.props;
const path = getPreviousPagePath(pageList, form.data, location.pathname);

this.props.router.push(path);
// this.props.router.push(path);
this.props.route.goToRoute(path);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I need a way to pass a function to <FormPage/> from the starter app that will push up the next path we want to go to to the starter app. Once the starter app has the next path, it can determine the routing to get there. The tricky part is how to create this hook from the starter app side. <FormPage/> is rendered as the component for a particular route, not directly rendered in a parent component, so it gets a little tricky to pass props to it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the way to do this is to have the app have a component, say WholePage, that gets withRoutered. That component puts together the parts of the page that the app wants, including the FormPage but also a header, footer, sidebar, or whatever. Any of that can be route specific. When WholePage renders it passes the current route (or page key or whatever lets USFS find the right page) to FormPage. Note that this gives the app flexibility over layout if they want it, although I'd expect our WholePage implementation does what we do today except that we'd put the formConfig.footer in it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes that's what I was thinking, but also including the navigation buttons. This moves us towards a USFS library that is focused on rendering and validating form fields, with basically nothing else. All of the surrounding structure, like header, footer, navigation, etc., exists in the starter app. Just confirming that's the direction we think it makes sense to go in?

@jcmeloni-usds
Copy link
Contributor

jcmeloni-usds commented Sep 12, 2018 via email

@dmethvin-gov
Copy link
Contributor

@jcmeloni-usds Yes, I talked with @annekainicUSDS yesterday and she pointed out that the current nav would also go into the app. The nice thing about that is the app can implement a left nav rather than top, or add route-context-sensitive help text in a sidebar for example, but the forms system doesn't need to be involved in that.

Copy link
Contributor Author

@annekainicUSDS annekainicUSDS left a comment

Choose a reason for hiding this comment

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

In order to pull out routing, I tried keeping the knowledge of the form state within USFS as opposed to trying to pull that out also. That became complicated, as many of the routing decisions need to have a knowledge of the current form data (mainly due to array pages and conditionally hidden pages). Figuring out how to pass information about the form state up to the routing components was complex and messy, and didn't seem like the best design.

@@ -49,36 +49,15 @@ class FormPage extends React.Component {
newData = _.set([this.props.route.pageConfig.arrayPath, this.props.params.index], formData, this.props.form.data);
}
this.props.setData(newData);
}

onSubmit = ({ formData }) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The onChange function in this component provides the same functionality as the onSubmit function except for the router push, which is exactly what we wanted to extract. Therefore, all I had to do was pull out the onChange and goBack functions (all goBack does is the router push), and provide a hook into the onChange function for the high-order component to know when it can push the next path (i.e., after the new data has been set).

@annekainicUSDS
Copy link
Contributor Author

Closing for now.

@dmethvin-gov dmethvin-gov deleted the pull-out-routing branch October 2, 2019 19:37
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.

3 participants