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

refactor : Transform SaveModal to typescript #11951

Merged
merged 9 commits into from
Dec 11, 2020

Conversation

maloun96
Copy link
Contributor

@maloun96 maloun96 commented Dec 7, 2020

SUMMARY

Transform SaveModal to Typescript

@maloun96
Copy link
Contributor Author

maloun96 commented Dec 7, 2020

@evans @junlincc

@codecov-io
Copy link

codecov-io commented Dec 7, 2020

Codecov Report

Merging #11951 (2572a3e) into master (a7bba92) will decrease coverage by 0.80%.
The diff coverage is 33.33%.

Impacted file tree graph

@@            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     
Flag Coverage Δ
cypress ?
javascript 62.72% <33.33%> (-0.27%) ⬇️
python 64.19% <ø> (+0.01%) ⬆️

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

Impacted Files Coverage Δ
...uperset-frontend/src/components/Checkbox/index.tsx 100.00% <ø> (ø)
...et-frontend/src/dashboard/components/SaveModal.tsx 19.23% <33.33%> (ø)
superset-frontend/src/dashboard/App.jsx 0.00% <0.00%> (-100.00%) ⬇️
superset-frontend/src/dashboard/index.jsx 0.00% <0.00%> (-100.00%) ⬇️
superset-frontend/src/setup/setupColors.js 0.00% <0.00%> (-100.00%) ⬇️
superset-frontend/src/chart/ChartContainer.jsx 0.00% <0.00%> (-100.00%) ⬇️
...et-frontend/src/dashboard/containers/Dashboard.jsx 0.00% <0.00%> (-100.00%) ⬇️
...-frontend/src/visualizations/presets/MainPreset.js 0.00% <0.00%> (-100.00%) ⬇️
...tend/src/dashboard/containers/DashboardBuilder.jsx 0.00% <0.00%> (-100.00%) ⬇️
superset-frontend/src/setup/setupFormatters.ts 0.00% <0.00%> (-75.00%) ⬇️
... and 102 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 a7bba92...2572a3e. Read the comment docs.

@maloun96 maloun96 changed the title Transform SaveModal to typescript refactor : Transform SaveModal to typescript Dec 7, 2020
type SaveType = typeof SAVE_TYPE_OVERWRITE | typeof SAVE_TYPE_NEWDASHBOARD;

type SaveModalProps = {
addSuccessToast: Function;
Copy link
Member

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;
Copy link
Member

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 {
Copy link
Member

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
Copy link
Member

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) => {
Copy link
Member

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}/`;
Copy link
Member

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?

Copy link
Member

@ktmud ktmud Dec 9, 2020

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 😉

Copy link
Member

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?!? 😆

Copy link
Member

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 {
Copy link
Member

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;
Copy link
Member

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;
Copy link
Member

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!

Comment on lines 28 to 29
onChange: (val?: boolean) => void;
style?: object;
Copy link
Member

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

Copy link
Member

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?

Copy link
Member

@ktmud ktmud Dec 9, 2020

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?

@pull-request-size pull-request-size bot added size/L and removed size/M labels Dec 9, 2020
@maloun96
Copy link
Contributor Author

maloun96 commented Dec 9, 2020

@etr2460 Refactored.

Copy link
Member

@etr2460 etr2460 left a 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}
Copy link
Member

@etr2460 etr2460 Dec 9, 2020

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)

Copy link
Member

@rusackas rusackas left a 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.

Copy link
Member

@etr2460 etr2460 left a 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

@rusackas
Copy link
Member

I think all questions/issues have been resolved! Thanks, everyone!

@rusackas rusackas merged commit 12d9d1e into apache:master Dec 11, 2020
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.0.0 labels Mar 12, 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 size/L 🚢 1.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants