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

[ML] Fix regression with some links not opening in new tab #80785

Merged
merged 10 commits into from
Oct 19, 2020

Conversation

qn895
Copy link
Member

@qn895 qn895 commented Oct 15, 2020

Summary

This PR fixes #80639 where some links not opening in a new tab. Changes include:

  • Anomaly detection View Series and View now open in new tab
    In 7.9, clicking on the link like View Series or View 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

Screen Shot 2020-10-15 at 6 23 42 PM

  • Change the EuiCard to behave as links instead of button in Data Visualizer results 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.

Screen Shot 2020-10-15 at 6 33 24 PM

Checklist

@elasticmachine
Copy link
Contributor

Pinging @elastic/ml-ui (:ml)

await navigateToApp(PLUGIN_ID, {
path: singleMetricViewerLink,
});
window.open(singleMetricViewerLink, '_blank');
Copy link
Contributor

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?

Copy link
Member Author

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 = ({
Copy link
Contributor

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

Comment on lines 36 to 55
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;
}}
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. I think we should call event. preventDefault only once at the beginning of the function with isModifiedEvent 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 the target check in this component because it's not applicable.
  2. There is no need to return true or false. I recall it from old times when preventDefault wasn't a standard.
  3. 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}`)}
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Member Author

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 && (
Copy link
Contributor

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated here 0064254

@pheyos
Copy link
Member

pheyos commented Oct 16, 2020

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.

@peteharverson
Copy link
Contributor

@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.

@pheyos
Copy link
Member

pheyos commented Oct 16, 2020

@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 view series link in the anomaly explorer it's working ok until I close the new opened tab. In that case the old tab freezes and doesn't come back working for me. Is it only me or is anyone else seeing the same?

@qn895
Copy link
Member Author

qn895 commented Oct 16, 2020

@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 view series link in the anomaly explorer it's working ok until I close the new opened tab. In that case the old tab freezes and doesn't come back working for me. Is it only me or is anyone else seeing the same?

I was able to reproduce this but not reliably. How weird! Looking into it some more.

@peteharverson
Copy link
Contributor

@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.

Copy link
Contributor

@peteharverson peteharverson left a 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=()`)}>
Copy link
Member

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?

Copy link
Member Author

@qn895 qn895 Oct 16, 2020

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.

@qn895
Copy link
Member Author

qn895 commented Oct 19, 2020

@elasticmachine merge upstream

1 similar comment
@qn895
Copy link
Member Author

qn895 commented Oct 19, 2020

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

async chunks size

id before after diff
ml 7.2MB 7.2MB +3.2KB

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Copy link
Member

@jgowdyelastic jgowdyelastic left a comment

Choose a reason for hiding this comment

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

LGTM

@qn895 qn895 merged commit f4c596d into elastic:master Oct 19, 2020
@qn895 qn895 deleted the ml-fix-link-regression branch October 19, 2020 13:36
qn895 added a commit to qn895/kibana that referenced this pull request Oct 19, 2020
…0785)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
qn895 added a commit to qn895/kibana that referenced this pull request Oct 19, 2020
…0785)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
qn895 added a commit that referenced this pull request Oct 19, 2020
…0785) (#80981)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
qn895 added a commit that referenced this pull request Oct 19, 2020
) (#80980)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ML] Anomaly explorer - links to single metric viewer don't open in new tab anymore
7 participants