-
Notifications
You must be signed in to change notification settings - Fork 13.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
Changes from 3 commits
779f7db
cbabb4f
15051b1
8581f26
ab26012
09db402
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { render, screen } from 'spec/helpers/testing-library'; | ||
import { GenericLink } from './GenericLink'; | ||
|
||
test('renders', () => { | ||
render(<GenericLink to="/explore">Link to Explore</GenericLink>, { | ||
useRouter: true, | ||
}); | ||
expect(screen.getByText('Link to Explore')).toBeVisible(); | ||
}); | ||
|
||
test('navigates to internal URL', () => { | ||
render(<GenericLink to="/explore">Link to Explore</GenericLink>, { | ||
useRouter: true, | ||
}); | ||
const internalLink = screen.getByTestId('internal-link'); | ||
expect(internalLink).toHaveAttribute('href', '/explore'); | ||
}); | ||
|
||
test('navigates to external URL', () => { | ||
render( | ||
<GenericLink to="https://superset.apache.org/"> | ||
Link to external website | ||
</GenericLink>, | ||
{ useRouter: true }, | ||
); | ||
const externalLink = screen.getByTestId('external-link'); | ||
expect(externalLink).toHaveAttribute('href', 'https://superset.apache.org/'); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { Link, LinkProps } from 'react-router-dom'; | ||
|
||
export const GenericLink = ({ | ||
to, | ||
component, | ||
replace, | ||
innerRef, | ||
children, | ||
...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 commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe 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 commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done :) Screen.Recording.2022-07-29.at.14.20.16.mov |
||
return ( | ||
<a data-test="external-link" href={to} {...rest}> | ||
{children} | ||
</a> | ||
); | ||
} | ||
return ( | ||
<Link | ||
data-test="internal-link" | ||
to={to} | ||
component={component} | ||
replace={replace} | ||
innerRef={innerRef} | ||
{...rest} | ||
> | ||
{children} | ||
</Link> | ||
); | ||
}; |
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 notLinkProps
butReact.PropsWithoutRef<LinkProps<S>> & React.RefAttributes<HTMLAnchorElement>
.To fix the Typescript error, you can define your component like:
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!