Skip to content

Commit

Permalink
fix discover link reload and redirect when missing helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 committed May 12, 2020
1 parent af5b294 commit 6f6a695
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
19 changes: 16 additions & 3 deletions src/plugins/kibana_utils/public/history/redirect_when_missing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
* under the License.
*/

import React from 'react';
import React, { Fragment } from 'react';
import { History } from 'history';
import { i18n } from '@kbn/i18n';
import ReactDOM from 'react-dom';
import ReactMarkdown from 'react-markdown';

import { ApplicationStart, HttpStart, ToastsSetup } from 'kibana/public';
import { MarkdownSimple, toMountPoint } from '../../../kibana_react/public';
import { SavedObjectNotFound } from '../errors';

interface Mapping {
Expand Down Expand Up @@ -94,7 +95,19 @@ export function redirectWhenMissing({
title: i18n.translate('kibana_utils.history.savedObjectIsMissingNotificationMessage', {
defaultMessage: 'Saved object is missing',
}),
text: toMountPoint(<MarkdownSimple>{error.message}</MarkdownSimple>),
text: (element: HTMLElement) => {
ReactDOM.render(
<ReactMarkdown
renderers={{
root: Fragment,
}}
>
{error.message}
</ReactMarkdown>,
element
);
return () => ReactDOM.unmountComponentAtNode(element);
},
});

if (onBeforeRedirect) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { i18n } from '@kbn/i18n';

import { Vis } from 'src/plugins/visualizations/public';
import { SavedSearch } from 'src/plugins/discover/public';
import { useKibana } from '../../../../kibana_react/public';

interface LinkedSearchProps {
savedSearch: SavedSearch;
Expand All @@ -52,12 +53,21 @@ interface SidebarTitleProps {

export function LinkedSearch({ savedSearch, eventEmitter }: LinkedSearchProps) {
const [showPopover, setShowPopover] = useState(false);
const {
services: { application },
} = useKibana();

const closePopover = useCallback(() => setShowPopover(false), []);
const onClickButtonLink = useCallback(() => setShowPopover(v => !v), []);
const onClickUnlikFromSavedSearch = useCallback(() => {
setShowPopover(false);
eventEmitter.emit('unlinkFromSavedSearch');
}, [eventEmitter]);
const onClickViewInDiscover = useCallback(() => {
application.navigateToApp('discover', {
path: `#/${savedSearch.id}`,
});
}, [application, savedSearch.id]);

const linkButtonAriaLabel = i18n.translate(
'visDefaultEditor.sidebar.savedSearch.linkButtonAriaLabel',
Expand Down Expand Up @@ -118,7 +128,7 @@ export function LinkedSearch({ savedSearch, eventEmitter }: LinkedSearchProps) {
<div style={{ width: 260 }}>
<EuiText size="s">
<p>
<EuiButtonEmpty flush="left" href={`discover#/${savedSearch.id}`} size="xs">
<EuiButtonEmpty flush="left" onClick={onClickViewInDiscover} size="xs">
<FormattedMessage
id="visDefaultEditor.sidebar.savedSearch.goToDiscoverButtonText"
defaultMessage="View this search in Discover"
Expand Down

0 comments on commit 6f6a695

Please sign in to comment.