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

[Monitoring] Use custom route to ensure global state is preserved #63891

Merged
merged 6 commits into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
} from '@elastic/eui';
import { Status } from './status';
import { formatMetric } from '../../../lib/format_number';
import { getSafeForExternalLink } from '../../../lib/get_safe_for_external_link';
import { formatTimestampToDuration } from '../../../../common';
import { i18n } from '@kbn/i18n';
import { APM_SYSTEM_ID } from '../../../../common/constants';
Expand Down Expand Up @@ -56,7 +57,10 @@ function getColumns(setupMode) {

return (
<Fragment>
<EuiLink href={`#/apm/instances/${apm.uuid}`} data-test-subj={`apmLink-${name}`}>
<EuiLink
href={getSafeForExternalLink(`#/apm/instances/${apm.uuid}`)}
data-test-subj={`apmLink-${name}`}
>
{name}
</EuiLink>
{setupModeStatus}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ import { formatMetric } from 'plugins/monitoring/lib/format_number';
import { EuiMonitoringTable } from 'plugins/monitoring/components/table';
import { i18n } from '@kbn/i18n';
import { BEATS_SYSTEM_ID } from '../../../../common/constants';
import { getSafeForExternalLink } from '../../../lib/get_safe_for_external_link';
import { ListingCallOut } from '../../setup_mode/listing_callout';
import { SetupModeBadge } from '../../setup_mode/badge';
import { FormattedMessage } from '@kbn/i18n/react';

export class Listing extends PureComponent {
getColumns() {
const { kbnUrl, scope } = this.props.angular;
const setupMode = this.props.setupMode;

return [
Expand Down Expand Up @@ -59,11 +59,7 @@ export class Listing extends PureComponent {
return (
<div>
<EuiLink
onClick={() => {
scope.$evalAsync(() => {
kbnUrl.changePath(`/beats/beat/${beat.uuid}`);
});
}}
href={getSafeForExternalLink(`/beats/beat/${beat.uuid}`)}
data-test-subj={`beatLink-${name}`}
>
{name}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { Reason } from '../../logs/reason';
import { SetupModeTooltip } from '../../setup_mode/tooltip';
import { getSafeForExternalLink } from '../../../lib/get_safe_for_external_link';
import { ELASTICSEARCH_SYSTEM_ID } from '../../../../common/constants';

const calculateShards = shards => {
Expand Down Expand Up @@ -168,7 +169,7 @@ export function ElasticsearchPanel(props) {
const showMlJobs = () => {
// if license doesn't support ML, then `ml === null`
if (props.ml) {
const gotoURL = '#/elasticsearch/ml_jobs';
const gotoURL = getSafeForExternalLink('#/elasticsearch/ml_jobs');
return (
<>
<EuiDescriptionListTitle>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import React from 'react';
import moment from 'moment-timezone';
import { getSafeForExternalLink } from '../../../lib/get_safe_for_external_link';
import { capitalize } from 'lodash';
import { EuiLink } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
Expand All @@ -18,7 +19,7 @@ export function LicenseText({ license, showLicenseExpiration }) {
}

return (
<EuiLink href="#/license">
<EuiLink href={getSafeForExternalLink('#/license')}>
<FormattedMessage
id="xpack.monitoring.cluster.overview.licenseText.toLicensePageLinkLabel"
defaultMessage="{licenseType} license {willExpireOn}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
EuiTextColor,
EuiScreenReaderOnly,
} from '@elastic/eui';

import { getSafeForExternalLink } from '../../../lib/get_safe_for_external_link';
import './ccr.css';
import { FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';
Expand Down Expand Up @@ -65,7 +65,9 @@ export class Ccr extends Component {
),
render: shardId => {
return (
<EuiLink href={`#/elasticsearch/ccr/${index}/shard/${shardId}`}>
<EuiLink
href={getSafeForExternalLink(`#/elasticsearch/ccr/${index}/shard/${shardId}`)}
>
{shardId}
</EuiLink>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import React from 'react';
import { capitalize } from 'lodash';
import { LARGE_FLOAT, LARGE_BYTES, LARGE_ABBREVIATED } from '../../../../common/formatting';
import { formatMetric } from '../../../lib/format_number';
import { getSafeForExternalLink } from '../../../lib/get_safe_for_external_link';
import { ElasticsearchStatusIcon } from '../status_icon';
import { ClusterStatus } from '../cluster_status';
import { EuiMonitoringTable } from '../../table';
Expand All @@ -34,7 +35,10 @@ const columns = [
sortable: true,
render: value => (
<div data-test-subj="name">
<EuiLink href={`#/elasticsearch/indices/${value}`} data-test-subj={`indexLink-${value}`}>
<EuiLink
href={getSafeForExternalLink(`#/elasticsearch/indices/${value}`)}
data-test-subj={`indexLink-${value}`}
>
{value}
</EuiLink>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import React, { Fragment } from 'react';
import { NodeStatusIcon } from '../node';
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
import { getSafeForExternalLink } from '../../../lib/get_safe_for_external_link';
import { ClusterStatus } from '../cluster_status';
import { EuiMonitoringSSPTable } from '../../table';
import { MetricCell, OfflineCell } from './cells';
Expand Down Expand Up @@ -75,7 +76,7 @@ const getColumns = (showCgroupMetricsElasticsearch, setupMode, clusterUuid) => {
render: (value, node) => {
let nameLink = (
<EuiLink
href={`#/elasticsearch/nodes/${node.resolver}`}
href={getSafeForExternalLink(`#/elasticsearch/nodes/${node.resolver}`)}
data-test-subj={`nodeLink-${node.resolver}`}
>
{value}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import React from 'react';
import { EuiLink } from '@elastic/eui';
import { Snapshot } from './snapshot';
import { FormattedMessage } from '@kbn/i18n/react';
import { getSafeForExternalLink } from '../../../lib/get_safe_for_external_link';

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

return (
<div>
<EuiLink href={`#/elasticsearch/indices/${name}`}>{name}</EuiLink>
<EuiLink href={getSafeForExternalLink(`#/elasticsearch/indices/${name}`)}>{name}</EuiLink>
<br />
<FormattedMessage
id="xpack.monitoring.elasticsearch.shardActivity.recoveryIndex.shardDescription"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { EuiMonitoringTable } from '../../table';
import { KibanaStatusIcon } from '../status_icon';
import { StatusIcon } from 'plugins/monitoring/components/status_icon';
import { formatMetric, formatNumber } from '../../../lib/format_number';
import { getSafeForExternalLink } from '../../../lib/get_safe_for_external_link';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { SetupModeBadge } from '../../setup_mode/badge';
Expand Down Expand Up @@ -68,7 +69,7 @@ const getColumns = setupMode => {
return (
<div>
<EuiLink
href={`#/kibana/instances/${kibana.kibana.uuid}`}
href={getSafeForExternalLink(`#/kibana/instances/${kibana.kibana.uuid}`)}
data-test-subj={`kibanaLink-${name}`}
>
{name}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

export function getSafeForExternalLink(url: string) {
return `${url.split('?')[0]}?${location.hash.split('?')[1]}`;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
import { PromiseServiceCreator } from './providers/promises';
// @ts-ignore
import { PrivateProvider } from './providers/private';
import { getSafeForExternalLink } from '../../lib/get_safe_for_external_link';

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

Expand Down Expand Up @@ -134,7 +135,8 @@ function createHrefModule(core: AppMountContext['core']) {
pre: (_$scope, _$el, $attr) => {
$attr.$observe(name, val => {
if (val) {
$attr.$set('href', core.http.basePath.prepend(val as string));
const url = getSafeForExternalLink(val as string);
$attr.$set('href', core.http.basePath.prepend(url));
}
});
},
Expand Down