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

Fix expand active order in ReviewChapters #267

Merged
merged 9 commits into from
Sep 19, 2018

Conversation

jbalboni
Copy link
Contributor

@jbalboni jbalboni commented Sep 14, 2018

This swaps the order of getActivePages and expandArrayPages to match routing.js.

<Addresses/Closes> #266

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.

@jbalboni
Copy link
Contributor Author

Will push up a test and prod files shortly.

Copy link
Contributor

@dmethvin-gov dmethvin-gov left a comment

Choose a reason for hiding this comment

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

Might there be similar problems with SubmitController, getPageKeys, or getActiveChapters since they use the old order? Should there be a getExpandedActivePages defined to prevent someone calling these in the wrong order?

@@ -125,8 +125,8 @@ function mapStateToProps(state, ownProps) {
const chapters = chapterNames.map(chapterName => {
const pages = pagesByChapter[chapterName];

const activePages = getActivePages(pages, formData);
const expandedPages = expandArrayPages(activePages, formData);
let expandedPages = expandArrayPages(pages, formData);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why let here and not const? You can always nest the expandArrayPages() in the next line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nesting seemed less readable than this, but I'm happy to change it if you'd prefer.

@jbalboni
Copy link
Contributor Author

@dmethvin-gov Yeah, looks like those need changing and also the helper function seems like a good idea.

@@ -106,7 +104,7 @@ class ReviewChapters extends React.Component {
}
}

function mapStateToProps(state, ownProps) {
export function mapStateToProps(state, ownProps) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure how you all feel about this. We made the changes in here to put more code in mapStateToProps because it's more testable, but in order to test it directly, we need to export it.

Copy link
Contributor

Choose a reason for hiding this comment

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

More testing is always good. In this case it's testing a lot of implementation and plumbing details so not ideal, but the test is clearly marked so if it breaks during a refactor it should be clear why.

@jbalboni
Copy link
Contributor Author

@dmethvin-gov Should be ready for another look.

@dmethvin-gov
Copy link
Contributor

This duo of calls seems to be everywhere, here's another one in FormNav. Can you look around and see if I missed any others? Would it be possible to not export one or both of the two individual functions, are they used separately for any reason?

@jbalboni
Copy link
Contributor Author

I found the FormNav one when I took another pass through, but didn't see any others. I did see some uses of the functions on their own, but I didn't look too deeply at if that was valid. I will take another look at that on Monday.

@jbalboni
Copy link
Contributor Author

@dmethvin-gov I looked through for uses of just getActivePages and it looks like the default transformForSubmit was using it without expanding array pages first. So I've updated that, too.

I think all this code was missing because itemFilter instead of depends was initially meant for filtering out items in pagePerItem pages, but then the index was added to depends for one of our forms and wasn't full fleshed out. On vets we don't have any uses of depends and pagePerItem pages outside of one form, which is only now going to beta.

Copy link
Contributor

@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.

One question, otherwise LGTM!

*/
export function transformForSubmit(formConfig, form, replacer = stringifyFormReplacer) {
const expandedPages = expandArrayPages(createFormPageList(formConfig), form.data);
const activePages = getActivePages(expandedPages, form.data);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we not using getActiveExpandedPages here if it's doing these same 2 checks in this order? Because we need to calculate expandedPages separately for the next function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I thought it was useful to used the expandedPage array for both of the following function calls and make it clear that we're using the same base data to get the active and inactive page lists.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, that's what it seemed like. Feel free to merge this when you're ready @jbalboni!

@jbalboni
Copy link
Contributor Author

@annekainicUSDS I think you'll have to merge it, I don't have write access here.

@annekainicUSDS
Copy link
Contributor

@jbalboni Oops sorry! Will merge now.

@annekainicUSDS annekainicUSDS merged commit 45b600a into usds:master Sep 19, 2018
dmethvin-gov pushed a commit to dmethvin-gov/us-forms-system that referenced this pull request Sep 20, 2018
)

Fix expand active order

(cherry picked from commit b667241)

Add build files

(cherry picked from commit 7b8b325)

Add tests and export

(cherry picked from commit 56c8743)

Add helper function

(cherry picked from commit 31fd754)

Fix typo

(cherry picked from commit e999396)

Fix bad change

(cherry picked from commit ccd28fa)

Run prod build

(cherry picked from commit 4fb0362)

Update nav with new helper

Update transform to handle pagePerItem depends functions

(cherry picked from commit 5ece651)

Cleanup usds#267 PR cherry pick (dmethvin-gov)
@dmethvin-gov dmethvin-gov mentioned this pull request Sep 24, 2018
9 tasks
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