-
Notifications
You must be signed in to change notification settings - Fork 14.4k
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 : Transform SaveModal to typescript #11951
Conversation
Codecov Report
@@ Coverage Diff @@
## master #11951 +/- ##
==========================================
- Coverage 64.45% 63.64% -0.81%
==========================================
Files 937 942 +5
Lines 45319 45826 +507
Branches 4317 4400 +83
==========================================
- Hits 29211 29168 -43
- Misses 15948 16482 +534
- Partials 160 176 +16
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
type SaveType = typeof SAVE_TYPE_OVERWRITE | typeof SAVE_TYPE_NEWDASHBOARD; | ||
|
||
type SaveModalProps = { | ||
addSuccessToast: Function; |
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.
Instead of Function
can you define the arguments and return values expected in the function here too?`
addDangerToast: Function; | ||
dashboardId: number; | ||
dashboardTitle: string; | ||
dashboardInfo: object; |
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.
Prefer Record<string, any>
to object
this.modal = ref; | ||
} | ||
|
||
toggleDuplicateSlices() { | ||
toggleDuplicateSlices(): any { |
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.
Why does this return any
? seems like nothing is returned
@@ -116,7 +131,7 @@ class SaveModal extends React.PureComponent { | |||
// check refresh frequency is for current session or persist | |||
const refreshFrequency = shouldPersistRefreshFrequency | |||
? currentRefreshFrequency | |||
: dashboardInfo.metadata.refresh_frequency; // eslint-disable camelcase | |||
: (dashboardInfo as any).metadata.refresh_frequency; // eslint-disable camelcase |
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.
This is a bit worrisome, can we do this without the any
?
@@ -137,17 +152,17 @@ class SaveModal extends React.PureComponent { | |||
t('You must pick a name for the new dashboard'), | |||
); | |||
} else { | |||
this.onSave(data, dashboardId, saveType).then(resp => { | |||
this.onSave(data, dashboardId, saveType).then((resp: any) => { |
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 believe a SupersetResponse
type exists, perhaps in superset-ui/core
? That would be preferable to any
here
if ( | ||
saveType === SAVE_TYPE_NEWDASHBOARD && | ||
resp && | ||
resp.json && | ||
resp.json.id | ||
) { | ||
window.location = `/superset/dashboard/${resp.json.id}/`; | ||
window.location.href = `/superset/dashboard/${resp.json.id}/`; |
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.
oo, was this a bug that typescript caught?
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.
Setting location
is equivalent to setting location.href
. Old JavaScript programmers would know 😉
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.
Wow, you calling me a youngin?!? 😆
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.
Well, back when I started building websites, there wasn't even JavaScript yet! Or CSS! Gather round, let me spin you a yarn about the old days. You see, there was this browser called Mosaic...
... hey, are you kids even listening?
this.modal = ref; | ||
} | ||
|
||
toggleDuplicateSlices() { | ||
toggleDuplicateSlices(val?: boolean | undefined): void { |
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.
you don't need the | undefined
if you already have a ?:
Although, I wonder why you added an argument here since it seems like the function doesn't actually use it? Is that because you pass it into a component that expects a function with this arg?
dashboardId: number; | ||
dashboardTitle: string; | ||
dashboardInfo: Record<string, any>; | ||
expandedSlices: object; |
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.
Could you update all instances of object
?
|
||
modal: ModalTrigger | null; | ||
|
||
onSave: Function; |
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.
and all instances of Function
? Thanks!
onChange: (val?: boolean) => void; | ||
style?: object; |
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.
are these changes intentional? I don't remember them before
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.
If it is intentional (I'm not sure either), it'd be the only remaining instance of object
so maybe we can touch that up too?
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.
Shouldn't it be React.CSSProperties
?
@etr2460 Refactored. |
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.
One more comment from me (and also @rusackas/@ktmud's comment too)
@@ -185,7 +207,7 @@ class SaveModal extends React.PureComponent { | |||
<div className="m-l-25 m-t-5"> | |||
<Checkbox | |||
checked={this.state.duplicateSlices} | |||
onChange={this.toggleDuplicateSlices} | |||
onChange={() => this.toggleDuplicateSlices} |
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.
wondering why this was needed, seems like it might break it (now that toggleDuplicateSlices isn't actually being called I think)
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.
LGTM! Thanks all for the comments, the fixes, and the reminiscing about the olden days.
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.
lgtm with one final question
I think all questions/issues have been resolved! Thanks, everyone! |
SUMMARY
Transform SaveModal to Typescript