Skip to content

Commit 2849095

Browse files
[Monitoring] Use custom route to ensure global state is preserved (elastic#63891) (elastic#64217)
* WIP * PR updates * Fix testing Co-authored-by: Elastic Machine <[email protected]> Co-authored-by: Elastic Machine <[email protected]>
1 parent 72e85cc commit 2849095

File tree

11 files changed

+38
-16
lines changed

11 files changed

+38
-16
lines changed

x-pack/legacy/plugins/monitoring/public/components/apm/instances/instances.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { EuiMonitoringTable } from '../../table';
1111
import { EuiLink, EuiPage, EuiPageBody, EuiPageContent, EuiSpacer } from '@elastic/eui';
1212
import { Status } from './status';
1313
import { formatMetric } from '../../../lib/format_number';
14+
import { getSafeForExternalLink } from '../../../lib/get_safe_for_external_link';
1415
import { formatTimestampToDuration } from '../../../../common';
1516
import { i18n } from '@kbn/i18n';
1617
import { APM_SYSTEM_ID } from '../../../../common/constants';
@@ -48,7 +49,10 @@ function getColumns(setupMode) {
4849

4950
return (
5051
<Fragment>
51-
<EuiLink href={`#/apm/instances/${apm.uuid}`} data-test-subj={`apmLink-${name}`}>
52+
<EuiLink
53+
href={getSafeForExternalLink(`#/apm/instances/${apm.uuid}`)}
54+
data-test-subj={`apmLink-${name}`}
55+
>
5256
{name}
5357
</EuiLink>
5458
{setupModeStatus}

x-pack/legacy/plugins/monitoring/public/components/beats/listing/listing.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ import { formatMetric } from 'plugins/monitoring/lib/format_number';
1212
import { EuiMonitoringTable } from 'plugins/monitoring/components/table';
1313
import { i18n } from '@kbn/i18n';
1414
import { BEATS_SYSTEM_ID } from '../../../../common/constants';
15+
import { getSafeForExternalLink } from '../../../lib/get_safe_for_external_link';
1516
import { ListingCallOut } from '../../setup_mode/listing_callout';
1617
import { SetupModeBadge } from '../../setup_mode/badge';
1718

1819
export class Listing extends PureComponent {
1920
getColumns() {
20-
const { kbnUrl, scope } = this.props.angular;
2121
const setupMode = this.props.setupMode;
2222

2323
return [
@@ -51,11 +51,7 @@ export class Listing extends PureComponent {
5151
return (
5252
<div>
5353
<EuiLink
54-
onClick={() => {
55-
scope.$evalAsync(() => {
56-
kbnUrl.changePath(`/beats/beat/${beat.uuid}`);
57-
});
58-
}}
54+
href={getSafeForExternalLink(`#/beats/beat/${beat.uuid}`)}
5955
data-test-subj={`beatLink-${name}`}
6056
>
6157
{name}

x-pack/legacy/plugins/monitoring/public/components/cluster/overview/elasticsearch_panel.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { i18n } from '@kbn/i18n';
3232
import { FormattedMessage } from '@kbn/i18n/react';
3333
import { Reason } from '../../logs/reason';
3434
import { SetupModeTooltip } from '../../setup_mode/tooltip';
35+
import { getSafeForExternalLink } from '../../../lib/get_safe_for_external_link';
3536
import { ELASTICSEARCH_SYSTEM_ID } from '../../../../common/constants';
3637

3738
const calculateShards = shards => {
@@ -168,7 +169,7 @@ export function ElasticsearchPanel(props) {
168169
const showMlJobs = () => {
169170
// if license doesn't support ML, then `ml === null`
170171
if (props.ml) {
171-
const gotoURL = '#/elasticsearch/ml_jobs';
172+
const gotoURL = getSafeForExternalLink('#/elasticsearch/ml_jobs');
172173
return (
173174
<>
174175
<EuiDescriptionListTitle>

x-pack/legacy/plugins/monitoring/public/components/cluster/overview/license_text.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import React from 'react';
88
import moment from 'moment-timezone';
9+
import { getSafeForExternalLink } from '../../../lib/get_safe_for_external_link';
910
import { capitalize } from 'lodash';
1011
import { EuiLink } from '@elastic/eui';
1112
import { FormattedMessage } from '@kbn/i18n/react';
@@ -18,7 +19,7 @@ export function LicenseText({ license, showLicenseExpiration }) {
1819
}
1920

2021
return (
21-
<EuiLink href="#/license">
22+
<EuiLink href={getSafeForExternalLink('#/license')}>
2223
<FormattedMessage
2324
id="xpack.monitoring.cluster.overview.licenseText.toLicensePageLinkLabel"
2425
defaultMessage="{licenseType} license {willExpireOn}"

x-pack/legacy/plugins/monitoring/public/components/elasticsearch/ccr/ccr.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
EuiIconTip,
1717
EuiTextColor,
1818
} from '@elastic/eui';
19-
19+
import { getSafeForExternalLink } from '../../../lib/get_safe_for_external_link';
2020
import './ccr.css';
2121
import { FormattedMessage } from '@kbn/i18n/react';
2222
import { i18n } from '@kbn/i18n';
@@ -64,7 +64,9 @@ export class Ccr extends Component {
6464
),
6565
render: shardId => {
6666
return (
67-
<EuiLink href={`#/elasticsearch/ccr/${index}/shard/${shardId}`}>
67+
<EuiLink
68+
href={getSafeForExternalLink(`#/elasticsearch/ccr/${index}/shard/${shardId}`)}
69+
>
6870
{shardId}
6971
</EuiLink>
7072
);

x-pack/legacy/plugins/monitoring/public/components/elasticsearch/indices/indices.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import React from 'react';
88
import { capitalize } from 'lodash';
99
import { LARGE_FLOAT, LARGE_BYTES, LARGE_ABBREVIATED } from '../../../../common/formatting';
1010
import { formatMetric } from '../../../lib/format_number';
11+
import { getSafeForExternalLink } from '../../../lib/get_safe_for_external_link';
1112
import { ElasticsearchStatusIcon } from '../status_icon';
1213
import { ClusterStatus } from '../cluster_status';
1314
import { EuiMonitoringTable } from '../../table';
@@ -33,7 +34,10 @@ const columns = [
3334
sortable: true,
3435
render: value => (
3536
<div data-test-subj="name">
36-
<EuiLink href={`#/elasticsearch/indices/${value}`} data-test-subj={`indexLink-${value}`}>
37+
<EuiLink
38+
href={getSafeForExternalLink(`#/elasticsearch/indices/${value}`)}
39+
data-test-subj={`indexLink-${value}`}
40+
>
3741
{value}
3842
</EuiLink>
3943
</div>

x-pack/legacy/plugins/monitoring/public/components/elasticsearch/nodes/nodes.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import React, { Fragment } from 'react';
88
import { NodeStatusIcon } from '../node';
99
import { extractIp } from '../../../lib/extract_ip'; // TODO this is only used for elasticsearch nodes summary / node detail, so it should be moved to components/elasticsearch/nodes/lib
10+
import { getSafeForExternalLink } from '../../../lib/get_safe_for_external_link';
1011
import { ClusterStatus } from '../cluster_status';
1112
import { EuiMonitoringSSPTable } from '../../table';
1213
import { MetricCell, OfflineCell } from './cells';
@@ -73,7 +74,7 @@ const getColumns = (showCgroupMetricsElasticsearch, setupMode, clusterUuid) => {
7374
render: (value, node) => {
7475
let nameLink = (
7576
<EuiLink
76-
href={`#/elasticsearch/nodes/${node.resolver}`}
77+
href={getSafeForExternalLink(`#/elasticsearch/nodes/${node.resolver}`)}
7778
data-test-subj={`nodeLink-${node.resolver}`}
7879
>
7980
{value}

x-pack/legacy/plugins/monitoring/public/components/elasticsearch/shard_activity/recovery_index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ import React from 'react';
88
import { EuiLink } from '@elastic/eui';
99
import { Snapshot } from './snapshot';
1010
import { FormattedMessage } from '@kbn/i18n/react';
11+
import { getSafeForExternalLink } from '../../../lib/get_safe_for_external_link';
1112

1213
export const RecoveryIndex = props => {
1314
const { name, shard, relocationType } = props;
1415

1516
return (
1617
<div>
17-
<EuiLink href={`#/elasticsearch/indices/${name}`}>{name}</EuiLink>
18+
<EuiLink href={getSafeForExternalLink(`#/elasticsearch/indices/${name}`)}>{name}</EuiLink>
1819
<br />
1920
<FormattedMessage
2021
id="xpack.monitoring.elasticsearch.shardActivity.recoveryIndex.shardDescription"

x-pack/legacy/plugins/monitoring/public/components/kibana/instances/instances.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { EuiMonitoringTable } from '../../table';
2020
import { KibanaStatusIcon } from '../status_icon';
2121
import { StatusIcon } from 'plugins/monitoring/components/status_icon';
2222
import { formatMetric, formatNumber } from '../../../lib/format_number';
23+
import { getSafeForExternalLink } from '../../../lib/get_safe_for_external_link';
2324
import { i18n } from '@kbn/i18n';
2425
import { FormattedMessage } from '@kbn/i18n/react';
2526
import { SetupModeBadge } from '../../setup_mode/badge';
@@ -67,7 +68,7 @@ const getColumns = setupMode => {
6768
return (
6869
<div>
6970
<EuiLink
70-
href={`#/kibana/instances/${kibana.kibana.uuid}`}
71+
href={getSafeForExternalLink(`#/kibana/instances/${kibana.kibana.uuid}`)}
7172
data-test-subj={`kibanaLink-${name}`}
7273
>
7374
{name}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
export function getSafeForExternalLink(url: string) {
8+
return `${url.split('?')[0]}?${location.hash.split('?')[1]}`;
9+
}

x-pack/legacy/plugins/monitoring/public/np_imports/angular/modules.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
import { PromiseServiceCreator } from './providers/promises';
2727
// @ts-ignore
2828
import { PrivateProvider } from './providers/private';
29+
import { getSafeForExternalLink } from '../../lib/get_safe_for_external_link';
2930

3031
type IPrivate = <T>(provider: (...injectable: any[]) => T) => T;
3132

@@ -134,7 +135,8 @@ function createHrefModule(core: AppMountContext['core']) {
134135
pre: (_$scope, _$el, $attr) => {
135136
$attr.$observe(name, val => {
136137
if (val) {
137-
$attr.$set('href', core.http.basePath.prepend(val as string));
138+
const url = getSafeForExternalLink(val as string);
139+
$attr.$set('href', core.http.basePath.prepend(url));
138140
}
139141
});
140142
},

0 commit comments

Comments
 (0)