From 446683339b4615f35c86da7f8c3872e860557b37 Mon Sep 17 00:00:00 2001 From: Jason Rhodes Date: Mon, 29 Oct 2018 09:58:20 -0400 Subject: [PATCH] [APM] Fixes rare cases where KibanaLink is loaded outside of React context (#24705) * Fixes rare cases where KibanaLink will be loaded outside of React context and requires no redux connect dependency * Fixes tests for updated Kibana link component * Removes obsolete snapshot --- .../Watcher/WatcherFlyOut.js | 8 ++++--- .../components/app/ErrorGroupOverview/view.js | 1 + .../__test__/__snapshots__/url.test.js.snap | 23 +++++++++++-------- .../apm/public/utils/__test__/url.test.js | 8 +++---- x-pack/plugins/apm/public/utils/url.tsx | 17 ++++++++++---- 5 files changed, 36 insertions(+), 21 deletions(-) diff --git a/x-pack/plugins/apm/public/components/app/ErrorGroupOverview/Watcher/WatcherFlyOut.js b/x-pack/plugins/apm/public/components/app/ErrorGroupOverview/Watcher/WatcherFlyOut.js index 75110c5931a0f..d7fb8636baa3c 100644 --- a/x-pack/plugins/apm/public/components/app/ErrorGroupOverview/Watcher/WatcherFlyOut.js +++ b/x-pack/plugins/apm/public/components/app/ErrorGroupOverview/Watcher/WatcherFlyOut.js @@ -33,7 +33,7 @@ import { import { XPACK_DOCS } from '../../../../utils/documentation/xpack'; -import { KibanaLink } from '../../../../utils/url'; +import { UnconnectedKibanaLink } from '../../../../utils/url'; import { createErrorGroupWatch } from './createErrorGroupWatch'; import chrome from 'ui/chrome'; @@ -187,12 +187,13 @@ export default class WatcherFlyout extends Component {

The watch is now ready and will send error reports for{' '} {this.props.serviceName}.{' '} - View watch. - +

) }); @@ -419,6 +420,7 @@ export default class WatcherFlyout extends Component { } WatcherFlyout.propTypes = { + location: PropTypes.object.isRequired, isOpen: PropTypes.bool.isRequired, serviceName: PropTypes.string, onClose: PropTypes.func.isRequired diff --git a/x-pack/plugins/apm/public/components/app/ErrorGroupOverview/view.js b/x-pack/plugins/apm/public/components/app/ErrorGroupOverview/view.js index 9287028347b1d..0348ee5f711f0 100644 --- a/x-pack/plugins/apm/public/components/app/ErrorGroupOverview/view.js +++ b/x-pack/plugins/apm/public/components/app/ErrorGroupOverview/view.js @@ -53,6 +53,7 @@ class ErrorGroupOverview extends Component { /> Go to Discover `; -exports[`RelativeLinkComponent should render correct markup 1`] = ` +exports[`UnconnectedKibanaLink should render correct markup 1`] = ` Go to Discover `; exports[`ViewMLJob should render component 1`] = ` - View Job - + `; diff --git a/x-pack/plugins/apm/public/utils/__test__/url.test.js b/x-pack/plugins/apm/public/utils/__test__/url.test.js index b3617da276379..93daa86281b22 100644 --- a/x-pack/plugins/apm/public/utils/__test__/url.test.js +++ b/x-pack/plugins/apm/public/utils/__test__/url.test.js @@ -11,7 +11,7 @@ import createHistory from 'history/createMemoryHistory'; import { toQuery, fromQuery, - KibanaLinkComponent, + UnconnectedKibanaLink, RelativeLinkComponent, encodeKibanaSearchParams, decodeKibanaSearchParams, @@ -182,7 +182,7 @@ describe('RelativeLinkComponent', () => { }); }); -describe('KibanaLinkComponent', () => { +describe('UnconnectedKibanaLink', () => { let wrapper; beforeEach(() => { @@ -198,14 +198,14 @@ describe('KibanaLinkComponent', () => { }; wrapper = mount( - Go to Discover - + ); }); diff --git a/x-pack/plugins/apm/public/utils/url.tsx b/x-pack/plugins/apm/public/utils/url.tsx index f95c1298f92a0..018b5a270ae10 100644 --- a/x-pack/plugins/apm/public/utils/url.tsx +++ b/x-pack/plugins/apm/public/utils/url.tsx @@ -44,7 +44,8 @@ export function ViewMLJob({ }; return ( - = ({ location, pathname, hash, query = {}, ...props -}: KibanaLinkArgs) { +}) => { // Preserve current _g and _a const currentQuery = toQuery(location.search); const nextQuery = { @@ -186,14 +193,14 @@ export function KibanaLinkComponent({ }); return ; -} +}; const withLocation = connect( ({ location }: { location: any }) => ({ location }), {} ); export const RelativeLink = withLocation(RelativeLinkComponent); -export const KibanaLink = withLocation(KibanaLinkComponent); +export const KibanaLink = withLocation(UnconnectedKibanaLink); // This is downright horrible 😭 💔 // Angular decodes encoded url tokens like "%2F" to "/" which causes the route to change.