-
Notifications
You must be signed in to change notification settings - Fork 13.9k
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
refactor(ReportModal): simplify state reducer and improve error handling #19942
Conversation
/** | ||
* Types mirroring enums in `superset/reports/models.py`: | ||
*/ | ||
export type ReportScheduleType = 'Alert' | 'Report'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: update views/CURD/alert/types.ts
to use these types
}, | ||
level: 'error', | ||
message: 'Request timed out', | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Early return to reduce indentation.
{ | ||
code: 1000, | ||
message: t('Issue 1000 - The dataset is too large to query.'), | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: timeout can happen in other API endpoints as well. We should probably move these error codes out of this generic helper function.
@@ -133,23 +134,24 @@ def validate_unique_creation_method( | |||
|
|||
@staticmethod | |||
def validate_update_uniqueness( | |||
name: str, report_type: str, report_schedule_id: Optional[int] = None | |||
name: str, report_type: ReportScheduleType, expect_id: Optional[int] = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just rename the variable to make it easier to understand...
Codecov Report
@@ Coverage Diff @@
## master #19942 +/- ##
==========================================
- Coverage 66.27% 66.10% -0.18%
==========================================
Files 1712 1712
Lines 63957 63962 +5
Branches 6720 6726 +6
==========================================
- Hits 42390 42284 -106
- Misses 19859 19966 +107
- Partials 1708 1712 +4
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
06ecb41
to
9354f12
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a couple comments, but this makes sense to me.
/** | ||
* Types mirroring enums in `superset/reports/models.py`: | ||
*/ | ||
export type ReportScheduleType = 'Alert' | 'Report'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is appending Type
to the end of all these types standard? I could see it for ReportScheduleType
(since it's defining what type of report it is), but seems like we could just use ReportCreationMethod
and ReportRecipient
for the other 2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm using the same variables as in the backend but maybe we can change the backend as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'll change ReportCreationMethodType
but keep ReportRecipientType
, as ReportRecipient
sounds like one recipient where both a recipient type and relevant metadata have been configured.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello, I think that I do add these to the backend in this refactor of the report modal.
// of { message: { field1: [msg1, msg2], field2: [msg], } } | ||
if (typeof error.message === 'object' && !error.error) { | ||
error.error = | ||
Object.values(error.message as Record<string, string[]>)[0]?.[0] || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Object.values(error.message as Record<string, string[]>)[0]?.[0] || | |
Object.values(error.message as Record<string, string[]>)?.[0]?.[0] || |
Maybe it'll never happen, but i've found being cautious about parsing errors to be a good idea (since the backend hasn't standardized on it yet)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Object.values()
should always return an array as long as the input object exists. I can add another check in L53 to make sure error.message
is not null
.
874307c
to
00f574f
Compare
SUMMARY
Simplify the state reducer for
ReportModal
and improve error handling:getClientError
to more consistently handle validationmessage
from Marshmallow (set the default"error"
message to be the first error of the first validated field).BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Before
before.mp4
After
after.mp4
TESTING INSTRUCTIONS
Go to dashboard or chart page to create or edit a report
ADDITIONAL INFORMATION