Skip to content

Commit

Permalink
[Monitoring] Use custom route to ensure global state is preserved (el…
Browse files Browse the repository at this point in the history
…astic#63891) (elastic#64217)

* WIP

* PR  updates

* Fix testing

Co-authored-by: Elastic Machine <[email protected]>

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
chrisronline and elasticmachine authored Apr 27, 2020
1 parent 72e85cc commit 2849095
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { EuiMonitoringTable } from '../../table';
import { EuiLink, EuiPage, EuiPageBody, EuiPageContent, EuiSpacer } 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 @@ -48,7 +49,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 @@ -12,12 +12,12 @@ 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';

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

return [
Expand Down Expand Up @@ -51,11 +51,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 @@ -16,7 +16,7 @@ import {
EuiIconTip,
EuiTextColor,
} 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 @@ -64,7 +64,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 @@ -33,7 +34,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 @@ -73,7 +74,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 @@ -20,6 +20,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 @@ -67,7 +68,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

0 comments on commit 2849095

Please sign in to comment.