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

✨ Add upload YAML questionnaire form #1290

Merged
merged 2 commits into from
Aug 25, 2023

Conversation

ibolton336
Copy link
Member

@ibolton336 ibolton336 commented Aug 15, 2023

@codecov
Copy link

codecov bot commented Aug 15, 2023

Codecov Report

Patch and project coverage have no change.

Comparison is base (f8e2b7e) 43.04% compared to head (de8dd04) 43.04%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1290   +/-   ##
=======================================
  Coverage   43.04%   43.04%           
=======================================
  Files         145      145           
  Lines        4330     4330           
  Branches      999      999           
=======================================
  Hits         1864     1864           
  Misses       2454     2454           
  Partials       12       12           
Flag Coverage Δ
client 43.04% <ø> (ø)
server ∅ <ø> (∅)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ibolton336 ibolton336 marked this pull request as ready for review August 16, 2023 16:59
Copy link
Collaborator

@avivtur avivtur left a comment

Choose a reason for hiding this comment

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

Hi there :)
This looks really great!
Added some suggestions

client/src/app/pages/assessment/AssessmentSettings.tsx Outdated Show resolved Hide resolved
<Form onSubmit={handleSubmit(onSubmit)}>
<HookFormPFGroupController
control={control}
name="yamlFile"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I see many "yamlFile" occurences here, maybe extract it to a const?

Copy link
Member Author

Choose a reason for hiding this comment

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

I have moved to using the "name" provided by the controller component on subsequent occurrences. TS helps us here by inferring the types from the react hook form form values initialization.

Screenshot 2023-08-23 at 11 20 21 AM

Copy link
Collaborator

@avivtur avivtur Aug 24, 2023

Choose a reason for hiding this comment

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

I meant maybe to add at the top of the file adding something like: const yamlID = "yamlFile" or similar const name so if the type changes in the future, you can change it in only one place and not multiple places. If it's not possible because of the type inferring than please disregard this.

Copy link
Member Author

Choose a reason for hiding this comment

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

The form values are defined in one place so I think that accomplishes what you are suggesting here. When we define the formValues, the internal TS support for react-hook-form allows us to infer the types from usage so that we will get a TS error if there is a spelling error or another issue.

Screenshot 2023-08-24 at 9 13 41 AM Screenshot 2023-08-24 at 9 13 33 AM

Copy link
Member Author

Choose a reason for hiding this comment

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

Screenshot 2023-08-24 at 9 17 40 AM

Copy link
Collaborator

Choose a reason for hiding this comment

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

gotcha, thanks for the explanation 😄

@ibolton336 ibolton336 force-pushed the export-questionnaires branch 2 times, most recently from 8d98398 to 8176e70 Compare August 23, 2023 15:18
Copy link
Collaborator

@avivtur avivtur left a comment

Choose a reason for hiding this comment

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

Looking real good here! 💯

<Form onSubmit={handleSubmit(onSubmit)}>
<HookFormPFGroupController
control={control}
name="yamlFile"
Copy link
Collaborator

@avivtur avivtur Aug 24, 2023

Choose a reason for hiding this comment

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

I meant maybe to add at the top of the file adding something like: const yamlID = "yamlFile" or similar const name so if the type changes in the future, you can change it in only one place and not multiple places. If it's not possible because of the type inferring than please disregard this.

Copy link
Member

@sjd78 sjd78 left a comment

Choose a reason for hiding this comment

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

Message text typo and async handler suggestion. Only the typo is a blocker.

client/public/locales/en/translation.json Outdated Show resolved Hide resolved
Comment on lines 124 to 135
onFileInputChange={async (_, file) => {
console.log("uploading file", file);
//TODO: handle new api here. This is just a placeholder.
handleFileUpload(file)
.then((res) => {
setFocus(name);
clearErrors(name);
trigger(name);
})
.catch((err) => {
//Handle new api error here
});
}}
Copy link
Member

Choose a reason for hiding this comment

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

With the async handler, probably better to use try/await/catch structure:

            onFileInputChange={async (_, file) => {
              console.log("uploading file", file);
              //TODO: handle new api here. This is just a placeholder.
              try {
                await handleFileUpload(file);
                setFocus(name);
                clearErrors(name);
                trigger(name);            
              } catch (err) {
                //Handle new api error here
              }
            }}

Copy link
Collaborator

@mturley mturley left a comment

Choose a reason for hiding this comment

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

+1 to @sjd78's try/await/catch suggestion, but agreed that it's not a blocker. Otherwise LGTM

Copy link
Member

@sjd78 sjd78 left a comment

Choose a reason for hiding this comment

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

Just the try/await/catch handler, but looks good otherwise.

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.

Import questionnaires
4 participants