-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[ML] Fix regression with some links not opening in new tab #80785
Conversation
This reverts commit 09f8421a0562675fafdada78304417e9e64e656f.
Pinging @elastic/ml-ui (:ml) |
await navigateToApp(PLUGIN_ID, { | ||
path: singleMetricViewerLink, | ||
}); | ||
window.open(singleMetricViewerLink, '_blank'); |
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.
shall we use MlHref
instead of window.open
?
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.
We'll keep this one here for now for 7.10.0.
return !!(event.metaKey || event.altKey || event.ctrlKey || event.shiftKey); | ||
} | ||
|
||
export const MlHref = ({ |
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 component deserves a brief description
onClick={(event) => { | ||
try { | ||
if (onClick) onClick(event); | ||
} catch (ex) { | ||
event.preventDefault(); | ||
throw ex; | ||
} | ||
|
||
if ( | ||
!event.defaultPrevented && // onClick prevented default | ||
event.button === 0 && // ignore everything but left clicks | ||
(!target || target === '_self') && // let browser handle "target=_blank" etc. | ||
!isModifiedEvent(event) // ignore clicks with modifier keys | ||
) { | ||
event.preventDefault(); | ||
navigateToPath(href); | ||
return false; | ||
} | ||
return true; | ||
}} |
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 should call
event. preventDefault
only once at the beginning of the function withisModifiedEvent
check and target="_blank" maybe. But I believe we should not use target=_blank inside of Kibana. There is only one exception - external URLs, hence you can omit thetarget
check in this component because it's not applicable. - There is no need to return
true
orfalse
. I recall it from old times whenpreventDefault
wasn't a standard. - The
onClick
callback that comes with props can cause potential issues, i.e. update state on an unmounted component. Making it Promise based should help.
return ( | ||
<a | ||
target={target} | ||
href={basePath.prepend(`/app/ml/${href}`)} |
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 this component should also support URLs besides the ML plugin.
target, | ||
onClick, | ||
children, | ||
...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.
Not sure if ...rest
should be here because you already destructured all the props.
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 ...rest
is here if the user wants to pass on extra props for the tag like 'className' or style
.
path: `/kibana/indexPatterns${createIndexPattern ? `/patterns/${indexPatternId}` : ''}`, | ||
}); | ||
} | ||
|
||
return ( | ||
<EuiFlexGroup gutterSize="l"> | ||
{createIndexPattern && discoverLink && ( |
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.
do you need to add a check for all the other links as well?
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.
Updated here 0064254
x-pack/plugins/ml/public/application/components/links/ml_href.tsx
Outdated
Show resolved
Hide resolved
I've pulled the changes and tested it locally, but the view series links and data visualizer cards could still not be opened in a new tab. Maybe something is wrong with my test setup - I'll try again later. |
@pheyos I was able to open the file data visualizer card links into new tabs (right click on text on the card worked for me). The 'View series' link will always open in a new tab with this change - I think this is preferable as a quick fix to opening in the same tab, which makes the behavior consistent with 7.9. |
@peteharverson I've set up the branch again and now it's working as you described. But one thing that's not working correctly is: when I follow a |
I was able to reproduce this but not reliably. How weird! Looking into it some more. |
@pheyos the issue you are seeing with the old tab freezing is a known issue that @darnautov has spent some time looking into, and is not related to the changes in this PR. It only occurs when running Kibana in dev mode as far as we know. |
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.
Tested and LGTM
@@ -61,7 +61,9 @@ export function extractJobDetails(job) { | |||
if (job.calendars) { | |||
calendars.items = job.calendars.map((c) => [ | |||
'', | |||
<Link to={`/settings/calendars_list/edit_calendar/${c}?_g=()`}>{c}</Link>, | |||
<EuiLink href={basePath.prepend(`/app/ml/settings/calendars_list/edit_calendar/${c}?_g=()`)}> |
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.
rather than using Link
or EuiLink
here, is there a better way to create this link?
i'm asking because we don't need basePath
anywhere else in this PR, so why here?
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 moving forward we will have to use the url with basePath for all the href. The EuiLink
work here without causing a full page reload because we are wrapping the ml application inside RedirectAppLinks
. Alternatively, we can use it as a button and navigate the user to the new page but that means user will no longer be able to ctrl+click or right click to open in new tab.
RedirectAppLinks
intercepts any tag and override the onClick behavior to use navigatetoUrl
, and therefore requires the href
to have the full base path https://github.com/smith/kibana/blob/765a70f7cc2583d394b96015a6fd7f5ab44662ba/docs/developer/best-practices/navigation.asciidoc#L21
Also, in this particular component the basePath
is needed so the link will work in the management section. If not the href
would be like abc/app/management/insightsAndAlerting/jobsListLink/settings/calendars_list/edit_calendar/nov4?_g=()
which is invalid. So that would mean we have to check if the table is being rendered in the ml
plugin or the management section, and either prepend or not prepend the path for it to work properly.
@elasticmachine merge upstream |
1 similar comment
@elasticmachine merge upstream |
💚 Build SucceededMetrics [docs]async chunks size
History
To update your PR or re-run it, just comment with: |
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.
LGTM
…0785) Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
…0785) Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
) (#80980) Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Summary
This PR fixes #80639 where some links not opening in a new tab. Changes include:
Anomaly detection
View Series
andView
now open in new tabIn 7.9, clicking on the link like
View Series
orView
in the Anomaly Explorer would automatically open the page in another tab. [ML] Migrate internal urls to non-hash paths #76735 later makes it so that it redirect to the new page in the same tab. This PR changes the behavior back to work like how it was in 7.9.Fix an issue with the calendar link not working correctly in management page
Changes from [ML] avoid full page reload for links following CSV import #79539 makes it so that the Data Visualizer won't do a full page reload, but the change makes it cards are no longer linkable. This PR makes it so that these cards act as links, and recent code splitting efforts have made the wait time much less.
Checklist