Skip to content

refactor: Convert TableElement to TypeScript#14978

Merged
eschutho merged 8 commits into
apache:masterfrom
corbinrobb:corbinrobb/tableelement-to-typescript
Jun 15, 2021
Merged

refactor: Convert TableElement to TypeScript#14978
eschutho merged 8 commits into
apache:masterfrom
corbinrobb:corbinrobb/tableelement-to-typescript

Conversation

@corbinrobb
Copy link
Copy Markdown
Contributor

SUMMARY

Converted TableElement to TypeScript.

Required me to move the expand icon with tooltip off the Collapse.Panel component on to the Collapse parent component where it was supposed to be. Allowed me to remove most of the inline styling in the expand icon because the styles are now being inherited correctly.

Made code more concise and readable wherever I could.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Should look and behave the same

TESTING INSTRUCTIONS

  • To test TableElement navigate to the route superset/sqllab
  • On the left towards the bottom there should be a drop-down saying Select table or type table name
  • Use the drop-down and select some tables and below the drop-down, some TableElement components should appear
  • Check them out

ADDITIONAL INFORMATION

  • Has associated issue:
  • 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

@corbinrobb corbinrobb changed the title [WIP] refactor: Convert TableElement to TypeScript refactor: Convert TableElement to TypeScript Jun 4, 2021
@hughhhh
Copy link
Copy Markdown
Member

hughhhh commented Jun 4, 2021

/testenv up

@hughhhh hughhhh marked this pull request as ready for review June 4, 2021 18:56
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 4, 2021

@hughhhh Container image not yet published for this PR. Please try again when build is complete.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 4, 2021

@hughhhh Ephemeral environment creation failed. Please check the Actions logs for details.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 4, 2021

Codecov Report

Merging #14978 (80ca81a) into master (004a6d9) will decrease coverage by 0.16%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #14978      +/-   ##
==========================================
- Coverage   77.61%   77.45%   -0.17%     
==========================================
  Files         965      969       +4     
  Lines       49503    49944     +441     
  Branches     6259     6423     +164     
==========================================
+ Hits        38422    38682     +260     
- Misses      10881    11057     +176     
- Partials      200      205       +5     
Flag Coverage Δ
javascript 72.23% <100.00%> (-0.26%) ⬇️

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

Impacted Files Coverage Δ
...rontend/src/SqlLab/components/SqlEditorLeftBar.jsx 56.06% <100.00%> (+2.83%) ⬆️
...et-frontend/src/SqlLab/components/TableElement.tsx 92.00% <100.00%> (ø)
...trols/DateFilterControl/components/CommonFrame.tsx 41.66% <0.00%> (-50.00%) ⬇️
...et-frontend/src/dashboard/actions/nativeFilters.ts 50.84% <0.00%> (-30.01%) ⬇️
...nd/src/dashboard/components/nativeFilters/utils.ts 56.25% <0.00%> (-30.00%) ⬇️
...nents/nativeFilters/FilterBar/FilterSets/index.tsx 47.00% <0.00%> (-30.00%) ⬇️
...nd/src/dashboard/components/nativeFilters/state.ts 75.00% <0.00%> (-25.00%) ⬇️
...t-frontend/src/dashboard/reducers/nativeFilters.ts 60.00% <0.00%> (-24.62%) ⬇️
...components/DashboardBuilder/DashboardContainer.tsx 82.97% <0.00%> (-17.03%) ⬇️
...nts/controls/DateFilterControl/DateFilterLabel.tsx 58.47% <0.00%> (-15.26%) ⬇️
... and 87 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 004a6d9...80ca81a. Read the comment docs.

Comment thread superset-frontend/src/SqlLab/components/TableElement.tsx
Copy link
Copy Markdown
Member

@AAfghahi AAfghahi 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! Just some questions.

Comment thread superset-frontend/src/SqlLab/components/TableElement.tsx Outdated
};
isActive: boolean;
key: string | number;
panelKey: string | number;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

oh that's so weird that it can be a string or a number. Wild.

`;

const TableElement = props => {
const TableElement = ({ table, actions, key, ...props }: TableElementProps) => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

it still bothers me that I don't know all of the props being passed in here. But I agree that this is much more elegant.

return (
<Collapse.Panel
{...props}
key={key}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What do you get when console.log key? I am looking at the old component and it looks really weird.
Screen Shot 2021-06-10 at 11 12 23 AM

but key is specifically being put in.
https://github.com/apache/superset/blob/master/superset-frontend/src/SqlLab/components/SqlEditorLeftBar.jsx#L191

Also, where is this panelKey thing coming from!

Copy link
Copy Markdown
Member

@AAfghahi AAfghahi Jun 10, 2021

Choose a reason for hiding this comment

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

I pulled your branch and console logged key:
Screen Shot 2021-06-10 at 11 24 42 AM

removeDataPreview: (table: Table) => void;
removeTable: (table: Table) => void;
};
key: string | number;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks like it might just be a string? Are there places where it is used as a number? (though it is odd that it is a string, since a key should be a number. . .)

Comment thread superset-frontend/src/SqlLab/components/TableElement.tsx Outdated

renderExpandIconWithTooltip = ({ isActive }) => (
<IconTooltip
style={{ transform: 'rotate(90deg)' }}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can we use the css prop here and below instead of style? It's a pattern we've been migrating to.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Certainly!

);
}
let latest = Object.entries(table.partitions?.latest || []).map(
const latest = Object.entries(table.partitions?.latest || []).map(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

small nit, but if we're not going to use latest again, can we just define it once as

const latest = Object.entries(table.partitions?.latest || []).map(
    ([key, value]) => `${key}=${value}`,
).join('/');

// These props are not defined in their TypeScript type for Panel though because
// this logic is happening in the Collapse component itself. We have gotten around the TypeScript
// errors by using the rest and spread operators to pass the necessary extra props to the Panels.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this comment makes sense, but the pattern below doesn't look confusing. I think it's ok to remove the comment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sounds good! I am removing the comment and adding the two other changes. I will push them all up momentarily.

Copy link
Copy Markdown
Member

@eschutho eschutho left a comment

Choose a reason for hiding this comment

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

Looks great @corbinrobb!

@eschutho
Copy link
Copy Markdown
Member

@AAfghahi @corbinrobb would you like me to merge when this passes tests?

@eschutho
Copy link
Copy Markdown
Member

eschutho commented Jun 15, 2021

/testenv up

@corbinrobb
Copy link
Copy Markdown
Contributor Author

Thanks! @eschutho I am happy with merging it if you and @AAfghahi are!

@eschutho
Copy link
Copy Markdown
Member

/testenv up

@eschutho
Copy link
Copy Markdown
Member

Great! I'm going to do a quick visual test when the test environment spins up.

@github-actions
Copy link
Copy Markdown
Contributor

@eschutho Ephemeral environment spinning up at http://52.37.150.225:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

@eschutho
Copy link
Copy Markdown
Member

@corbinrobb this looks great. I wasn't able to sort the columns in the test environment. Can you check and see if that is working for you? It should sort both ascending and descending.
Superset

@corbinrobb
Copy link
Copy Markdown
Contributor Author

@eschutho Hmm, mine is working as expected. The button originally doesn't sort the columns and just displays the way the table is sent and the button toggles between alphabetical and the original. In the picture it looks like that specific table is in alphabetical order already? That is kinda weird though because I also didn't change the logic in the sort function I just shortened it using ternary operators. Does it work on any of the tables?

@eschutho
Copy link
Copy Markdown
Member

You're right, @corbinrobb. That example didn't have anything to sort. I tested on a different list and it's working. I'll go ahead and merge. Thanks for the help on this!

@eschutho eschutho merged commit b179863 into apache:master Jun 15, 2021
@corbinrobb
Copy link
Copy Markdown
Contributor Author

Whew! That's relieving, I got super worried for a moment there lol Thanks for everything! @eschutho

@github-actions
Copy link
Copy Markdown
Contributor

Ephemeral environment shutdown and build artifacts deleted.

@corbinrobb corbinrobb deleted the corbinrobb/tableelement-to-typescript branch December 8, 2021 04:05
cccs-RyanS pushed a commit to CybercentreCanada/superset that referenced this pull request Dec 17, 2021
* Convert TableElement to typescript

* Change type names to better match naming conventions in other files

* Fix import order and update tests on TableElement

* Remove defaultProps

* Destructure the props

* Use Rest and Spread syntax to condense props destructuring

* Fix TypeScript errors and add comment to explain antd props and types weirdness

* Remove comment, add consistency with other files, and use method chaining to make more concise

Co-authored-by: Corbin Robb <corbin@Corbins-MacBook-Pro.local>
QAlexBall pushed a commit to QAlexBall/superset that referenced this pull request Dec 29, 2021
* Convert TableElement to typescript

* Change type names to better match naming conventions in other files

* Fix import order and update tests on TableElement

* Remove defaultProps

* Destructure the props

* Use Rest and Spread syntax to condense props destructuring

* Fix TypeScript errors and add comment to explain antd props and types weirdness

* Remove comment, add consistency with other files, and use method chaining to make more concise

Co-authored-by: Corbin Robb <corbin@Corbins-MacBook-Pro.local>
cccs-rc pushed a commit to CybercentreCanada/superset that referenced this pull request Mar 6, 2024
* Convert TableElement to typescript

* Change type names to better match naming conventions in other files

* Fix import order and update tests on TableElement

* Remove defaultProps

* Destructure the props

* Use Rest and Spread syntax to condense props destructuring

* Fix TypeScript errors and add comment to explain antd props and types weirdness

* Remove comment, add consistency with other files, and use method chaining to make more concise

Co-authored-by: Corbin Robb <corbin@Corbins-MacBook-Pro.local>
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.3.0 First shipped in 1.3.0 labels Mar 12, 2024
qfcwell pushed a commit to qfcwell/superset that referenced this pull request May 12, 2026
* Convert TableElement to typescript

* Change type names to better match naming conventions in other files

* Fix import order and update tests on TableElement

* Remove defaultProps

* Destructure the props

* Use Rest and Spread syntax to condense props destructuring

* Fix TypeScript errors and add comment to explain antd props and types weirdness

* Remove comment, add consistency with other files, and use method chaining to make more concise

Co-authored-by: Corbin Robb <corbin@Corbins-MacBook-Pro.local>
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.3.0 First shipped in 1.3.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants