-
Notifications
You must be signed in to change notification settings - Fork 14.1k
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
Conversation
Codecov Report
@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. |
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.
Thanks for the PR @kgabryje. I left some first-pass comments.
innerRef, | ||
children, | ||
...rest | ||
}: // css prop type check was failing, override with 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.
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>) => {
...
}
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.
Oh nice!
...rest | ||
}: // css prop type check was failing, override with any | ||
LinkProps & { css?: any }) => { | ||
if (typeof to === 'string' && /^https?:\/\//.test(to)) { |
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 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.
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.
True. Found some more complex regex, I'll use that one instead + some unit tests
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.
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 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.
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.
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
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 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.
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.
Done :)
Screen.Recording.2022-07-29.at.14.20.16.mov
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.
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}> |
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.
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
.
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.
Good point! I'll do that in a separate PR
Hi @kgabryje. Dataset links don't work in SPA in Dataset column on Charts page |
@michael-s-molina @kgabryje I will create a new PR for this fix |
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
ADDITIONAL INFORMATION