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: Keep Report modal open when there's an error #17988

Conversation

lyndsiWilliams
Copy link
Member

SUMMARY

The report modal was only using toasts for responses - error or success - so the user would have to reopen the modal to fix an errored report. The error is now brought into the modal directly and displayed underneath the name field, and will not close until the error is corrected.

Note: The name field is currently the only field that takes this type of error. The cron scheduler is the only other thing that has an error in this modal, and it has its own separate error handling already set up.

Note II: I also did some code cleanup in the report modal.

ANIMATED MOV

This demonstrates the modal correctly staying open and closing and also keeping correct values in the following events:

  • Create new report
    • With error occurring first
  • Edit existing report
  • Delete existing report
  • Create a new report after deleting
    • A clean un-errored creation
successfulError.mov

TESTING INSTRUCTIONS

  • Create new report
    • With error occurring first
  • Edit existing report
  • Delete existing report
  • Create a new report after deleting
    • A clean un-errored creation
  • Observe that the modal stays open when there's an error and closes when there is not
    • Also observe that the modal keeps all the correct values throughout these events.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@codecov
Copy link

codecov bot commented Jan 10, 2022

Codecov Report

Merging #17988 (5812a79) into master (9e69940) will increase coverage by 0.00%.
The diff coverage is 71.42%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #17988   +/-   ##
=======================================
  Coverage   67.07%   67.08%           
=======================================
  Files        1609     1611    +2     
  Lines       64905    64929   +24     
  Branches     6868     6872    +4     
=======================================
+ Hits        43537    43556   +19     
- Misses      19502    19506    +4     
- Partials     1866     1867    +1     
Flag Coverage Δ
javascript 53.79% <71.42%> (+0.01%) ⬆️

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

Impacted Files Coverage Δ
...rset-frontend/src/components/ReportModal/index.tsx 82.22% <68.42%> (-0.34%) ⬇️
superset-frontend/src/reports/actions/reports.js 39.39% <100.00%> (+5.18%) ⬆️
...et-frontend/src/dashboard/actions/nativeFilters.ts 39.79% <0.00%> (-6.80%) ⬇️
superset-frontend/src/common/components/index.tsx 100.00% <0.00%> (ø)
.../plugins/legacy-preset-chart-nvd3/src/Bar/index.js 66.66% <0.00%> (ø)
...plugins/legacy-preset-chart-nvd3/src/ReactNVD3.jsx 0.00% <0.00%> (ø)
...gins/legacy-preset-chart-nvd3/src/DistBar/index.js 66.66% <0.00%> (ø)
...mponents/nativeFilters/FiltersConfigModal/state.ts 73.33% <0.00%> (ø)
...et-frontend/src/components/Menu/LanguagePicker.tsx
...frontend/src/common/hooks/useChangeEffect/index.ts
... and 40 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9e69940...5812a79. Read the comment docs.

Copy link
Member

@betodealmeida betodealmeida left a comment

Choose a reason for hiding this comment

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

Looks good, I just have a couple questions.

}

onClose();
if (onReportAdd) onReportAdd();
Copy link
Member

Choose a reason for hiding this comment

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

Is this the format preferred by prettier these days? I learned that braceless if clauses should be avoided because they can lead to subtle errors.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not preferred by prettier, I thought it was just a prettier way to do it, haha. I didn't realize there were subtle errors possible with this though, thanks for this catch! I'll change it back.

Copy link
Member

Choose a reason for hiding this comment

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

I think a single line is OK, since it's simple enough. The use that is discouraged is:

if (onReportAdd)
  onReportAdd();

Which I think prettier would remove.

I think it's fine to leave the way you did, I was just curious. :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh okay awesome, I'll keep an eye out for that behavior in the future just in case! Thank you! 😁

Comment on lines +107 to +110
}).then(({ json }) => {
dispatch({ type: ADD_REPORT, json });
dispatch(addSuccessToast(t('The report has been created')));
});
Copy link
Member

Choose a reason for hiding this comment

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

What happens when the endpoint returns an error?

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 moved the catch functionality into the report modal here, this should handle any errors for this endpoint. Should I also put a catch in the action?

Copy link
Member

Choose a reason for hiding this comment

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

Ah, makes sense, because we're no longer showing the error in the toaster, but in the modal. Thanks for clarifying! :)

Copy link
Member Author

Choose a reason for hiding this comment

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

No problem! 😁

@lyndsiWilliams lyndsiWilliams merged commit f7add54 into apache:master Jan 10, 2022
@lyndsiWilliams lyndsiWilliams deleted the lyndsi/keep-report-modal-open-when-errored branch January 10, 2022 23:01
}
label="Description"
placeholder="Include a description that will be sent with your report"
errorMessage=""
Copy link
Member

Choose a reason for hiding this comment

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

where do you display the error message?

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 spoke with Sophie separately and she said that this field doesn't currently have any restrictions so it won't have any errors applicable to its field. I left this blank since errorMessage is a required field, and figured the error handling for this could be set up in the future if the description field ever ends up getting restrictions.

@@ -363,16 +374,16 @@ const ReportModal: FunctionComponent<ReportProps> = ({

<StyledCronPicker
clearButton={false}
value={currentReport?.crontab || '0 12 * * 1'}
value={t(currentReport?.crontab || '0 12 * * 1')}
Copy link
Member

Choose a reason for hiding this comment

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

I don't think a translation is necessary here.

@@ -181,11 +193,10 @@ const ReportModal: FunctionComponent<ReportProps> = ({
const [currentReport, setCurrentReport] = useReducer<
Reducer<Partial<ReportObject> | null, ReportActionType>
>(reportReducer, null);
const onChange = useCallback((type: any, payload: any) => {
const onReducerChange = useCallback((type: any, payload: any) => {
Copy link
Member

Choose a reason for hiding this comment

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

curious why the switch from onChange to onReducerChange. If I'm reading this right, when the reducer changes, you update the reducer?

Copy link
Member Author

Choose a reason for hiding this comment

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

In cases like this one, there was originally an onChange nested into another onChange. I thought that since there were two onChange functions in the component it could get confusing, so I renamed the reducer's onChange to onReducerChange to clarify that onReducerChange is specifically the function that the reducer uses to change state. Is that an unnecessary clarification, or is there maybe a better name I can use here?

Copy link
Member

Choose a reason for hiding this comment

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

Ok, I gotcha. Normally the naming convention will be the element that is changing, rather than the function that is used to do the change, thus the confusion. Maybe something like onInputChange would make sense.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good call, onInputChange sounds a lot better! I'll change the naming once I reopen this to fix it.

errorMessage={
currentReport?.name === 'error' ? t('REPORT NAME ERROR') : ''
}
errorMessage={currentReport?.error || ''}
Copy link
Member

Choose a reason for hiding this comment

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

how/when does this error get cleared out? Does it stay visible until they hit submit again? I'm not sure if we discussed how this should look @yousoph?

Copy link
Member Author

@lyndsiWilliams lyndsiWilliams Jan 12, 2022

Choose a reason for hiding this comment

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

Currently the error stays until the user submits the form again. Once they hit submit it will rerun, if there's still an error it will stay open with that error. If the error is corrected it will close. I think it would be nice to have the error cleared as soon as the user fixes it, but I think that would require front end validation vs. just back end.

shcoderAlex pushed a commit to casual-precision/superset that referenced this pull request Feb 7, 2022
bwang221 pushed a commit to casual-precision/superset that referenced this pull request Feb 10, 2022
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.5.0 labels Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels preset-io size/M 🚢 1.5.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants