Skip to content

LG-11361: Extract Document Capture Step Code#9433

Closed
charleyf wants to merge 17 commits intomainfrom
charley/reorganize-document-capture-step-code
Closed

LG-11361: Extract Document Capture Step Code#9433
charleyf wants to merge 17 commits intomainfrom
charley/reorganize-document-capture-step-code

Conversation

@charleyf
Copy link
Contributor

@charleyf charleyf commented Oct 23, 2023

🎫 Ticket

https://cm-jira.usa.gov/browse/LG-11361

🛠 Summary of changes

This is a code cleanup ticket. In anticipation that we may need to add/remove steps from the document capture javascript, it extracts and simplifies the code that figures out what those steps should be in various situations.

🥅 Goals 🥅
I'm doing this for two reasons

  1. We (Team Timnit) are expecting to add several steps in the coming months and I want to make that easier.
  2. I think there are plans to move the IPP steps around in the flow. This should make it easier to understand the IPP step dependencies on the FE.

@charleyf charleyf marked this pull request as ready for review October 24, 2023 15:23
@charleyf charleyf marked this pull request as draft October 24, 2023 15:24
@charleyf charleyf marked this pull request as ready for review October 25, 2023 15:30
Comment on lines +39 to +42
// getReviewStep needs to be called even if we're not going to use it because it contains
// a hook (in a context). Conditionally calling a hook causes problems in React, so
// always calling getReviewStep is necessary
const reviewStep: FormStep = useReviewStep(submissionError);
Copy link
Contributor

Choose a reason for hiding this comment

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

Like components, I'd expect a "one hook per file" rule. What's the downside of just assigning the value generated in useReviewStep inline here, aside from noise? Or better yet, we can assign it further down the file past the conditional early return (i.e. alongside locationStep and inPersonProofingSteps).

},
].filter(Boolean) as FormStep[]);

const inPersonProofingStepNames = ['location', 'prepare', 'switch_back'];
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this value never changes, I'd suggest moving it somewhere toward the top of the file to avoid allocating a new array every time the component is rendered.

const IN_PERSON_PROOFING_STEP_NAMES = ['location', 'prepare', 'switch_back'];

Less important (especially since this code already existed), but we could also consider using a Set for this, which is a little more accurate in representing a set of unique values, and has some performance benefit (not that I expect performance to be much an issue here).

const IN_PERSON_PROOFING_STEP_NAMES = new Set(['location', 'prepare', 'switch_back']);

};
};

export const useSteps = (submissionError: Error | undefined) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a return type here? My instinct from the previous code is that this should be returning FormStep[], but looking at the logic of this function I think we may also be returning undefined in some cases. Is that expected?

Suggested change
export const useSteps = (submissionError: Error | undefined) => {
export const useSteps = (submissionError: Error | undefined): FormStep[] => {

@gina-yamada
Copy link
Contributor

gina-yamada commented Nov 3, 2023

Everything you pulled out is working as I'd expect when testing. Doing this work now seems like a good idea rather than when you are trying to add/move steps.

While testing I am seeing behavior that surprised me. I uploaded images to cause a barcode error. When I click Continue I am taken to the upload page with a large error. Add new photos takes me to the same upload page without the error banner. I tested main. This behavior is not isolated to your branch, I just happen to notice it. Bug?

Screenshot 2023-11-03 at 8 11 53 AM Screenshot 2023-11-03 at 8 12 04 AM

@charleyf
Copy link
Contributor Author

Closing for now.

@charleyf charleyf closed this Nov 28, 2023
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