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

feat: Use SPA navigation from datasets list to Explore #20890

Merged
merged 6 commits into from
Aug 1, 2022

Conversation

kgabryje
Copy link
Member

@kgabryje kgabryje commented Jul 27, 2022

SUMMARY

This PR implements SPA navigation in Datasets list. By default, clicking on dataset's name opens Explore, but user can override it with some external URL. Default react-router Link component can't handle external URLs, so I implemented a GenericLink component, which check if URL is external - if it does, use HTML anchor element, else use react-router Link.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Screen.Recording.2022-07-29.at.14.20.16.mov

TESTING INSTRUCTIONS

  1. Open datasets list
  2. Click dataset's name, verify that Explore opens
  3. Go back to datasets list, click "Edit" -> tab "Settings" -> set some external URL in "Default URL" field (like "https://google.com" or whatever) -> Save
  4. Click dataset's name, verify that external URL opens

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 Jul 27, 2022

Codecov Report

Merging #20890 (09db402) into master (77db065) will increase coverage by 0.06%.
The diff coverage is 84.61%.

@@            Coverage Diff             @@
##           master   #20890      +/-   ##
==========================================
+ Coverage   66.25%   66.31%   +0.06%     
==========================================
  Files        1758     1759       +1     
  Lines       67048    67009      -39     
  Branches     7118     7112       -6     
==========================================
+ Hits        44423    44440      +17     
+ Misses      20808    20745      -63     
- Partials     1817     1824       +7     
Flag Coverage Δ
javascript 52.02% <84.61%> (+0.10%) ⬆️

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

Impacted Files Coverage Δ
superset-frontend/src/utils/urlUtils.ts 50.90% <75.00%> (+4.10%) ⬆️
...rontend/src/components/GenericLink/GenericLink.tsx 100.00% <100.00%> (ø)
...ontend/src/views/CRUD/data/dataset/DatasetList.tsx 56.20% <100.00%> (ø)
...rontend/src/components/ListView/Filters/Select.tsx 52.38% <0.00%> (-2.62%) ⬇️
superset-frontend/src/reports/actions/reports.js 39.39% <0.00%> (ø)
...et-frontend/src/components/TableSelector/index.tsx 76.08% <0.00%> (ø)
...et-frontend/src/dashboard/actions/sliceEntities.js 74.28% <0.00%> (ø)
...t-frontend/src/dashboard/components/SliceAdder.jsx 62.66% <0.00%> (ø)
...t-frontend/src/filters/components/GroupBy/types.ts 100.00% <0.00%> (ø)
...frontend/src/components/DatabaseSelector/index.tsx 88.88% <0.00%> (ø)
... and 9 more

Help us with your feedback. Take ten seconds to tell us how you rate us.

@pull-request-size pull-request-size bot added size/L and removed size/M labels Jul 27, 2022
Copy link
Member

@michael-s-molina michael-s-molina left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @kgabryje. I left some first-pass comments.

innerRef,
children,
...rest
}: // css prop type check was failing, override with any
Copy link
Member

Choose a reason for hiding this comment

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

The type of Link properties is not LinkProps but React.PropsWithoutRef<LinkProps<S>> & React.RefAttributes<HTMLAnchorElement>.

To fix the Typescript error, you can define your component like:

export const GenericLink = <S,>({
  to,
  component,
  replace,
  innerRef,
  children,
  ...rest
}: React.PropsWithoutRef<LinkProps<S>> &
  React.RefAttributes<HTMLAnchorElement>) => {
   ...
}

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 nice!

...rest
}: // css prop type check was failing, override with any
LinkProps & { css?: any }) => {
if (typeof to === 'string' && /^https?:\/\//.test(to)) {
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 we need to improve the algorithm to detect internal and external URLs. If we type www.google.com without the https then it breaks. I'm not sure if we already have something similar in the codebase or if we need to find an npm package for this.

Copy link
Member Author

Choose a reason for hiding this comment

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

True. Found some more complex regex, I'll use that one instead + some unit tests

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually that's not really a valid concern in this case. URL passed to <a> must have a protocol prefix, otherwise it's appended to current pathname. In such case it doesn't matter if we use <a> or <Link>.

image

Copy link
Member

Choose a reason for hiding this comment

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

You can design the component with the protocol restriction, but then we need to handle the problem elsewhere because it will be really common to have users type the URL without the protocol. In this case, when they click on the dataset nothing happens.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I see your point. However, I'm wondering if that should be considered a separate bug. Currently, if you type "www.google.com" in default url field, the link would redirect you to http://localhost:9000/tablemodelview/list/www.google.com.
This PR, even with more foolproof external url detection, wouldn't change that behaviour - we'd still get an <a> element linking to http://localhost:9000/tablemodelview/list/www.google.com.
I'd propose adding external URL detection in this PR (even though it wouldn't really do anything) and handling external links without protocol in a separate PR

Copy link
Member

Choose a reason for hiding this comment

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

This PR, even with more foolproof external url detection, wouldn't change that behaviour - we'd still get an element linking to http://localhost:9000/tablemodelview/list/www.google.com.

I was thinking that upon detecting www.google.com as an external link without a protocol, then the component would add the protocol automatically, setting the <a> tag to http://www.google.com. Of course, we can implement this outside of the component but in that case we would need to always call the helper function before using the component.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done :)

Screen.Recording.2022-07-29.at.14.20.16.mov

Copy link
Member

@michael-s-molina michael-s-molina left a comment

Choose a reason for hiding this comment

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

Thank you so much for addressing the comments. The added tests are great!

return (
<a data-test="external-link" href={to} {...rest}>
<a data-test="external-link" href={parseUrl(to)} {...rest}>
Copy link
Member

Choose a reason for hiding this comment

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

Small suggestion for a follow-up: You could return the parsed value when it's valid and undefined or another thing when it's invalid. That way you would only need to apply the regex once by combining isUrlExternal with parseUrl.

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 point! I'll do that in a separate PR

@kgabryje kgabryje merged commit 6ec164e into apache:master Aug 1, 2022
@EugeneTorap
Copy link
Contributor

Hi @kgabryje. Dataset links don't work in SPA in Dataset column on Charts page

Screenshot 2022-08-02 at 09 30 41

@EugeneTorap
Copy link
Contributor

Also in Dashboard

Screenshot 2022-08-02 at 09 53 47

@EugeneTorap
Copy link
Contributor

@michael-s-molina @kgabryje I will create a new PR for this fix

@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 2.1.0 and removed 🚢 2.1.3 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 size/L 🚢 2.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants