Skip to content

Commit

Permalink
Added support of saved search (#144095)
Browse files Browse the repository at this point in the history
  • Loading branch information
VladLasitsa authored Oct 27, 2022
1 parent b1fb85b commit cb306df
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export const VisualizeByValueEditor = ({ onAppLeave }: VisualizeAppProps) => {
visEditorRef={visEditorRef}
embeddableId={embeddableId}
onAppLeave={onAppLeave}
eventEmitter={eventEmitter}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export const VisualizeEditor = ({ onAppLeave }: VisualizeAppProps) => {
visEditorRef={visEditorRef}
onAppLeave={onAppLeave}
embeddableId={embeddableIdValue}
eventEmitter={eventEmitter}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import './visualize_editor.scss';
import { EventEmitter } from 'events';
import React, { RefObject, useCallback, useEffect } from 'react';
import { FormattedMessage } from '@kbn/i18n-react';
import { i18n } from '@kbn/i18n';
Expand Down Expand Up @@ -48,6 +49,7 @@ interface VisualizeEditorCommonProps {
originatingPath?: string;
visualizationIdFromUrl?: string;
embeddableId?: string;
eventEmitter?: EventEmitter;
}

export const VisualizeEditorCommon = ({
Expand All @@ -66,6 +68,7 @@ export const VisualizeEditorCommon = ({
visualizationIdFromUrl,
embeddableId,
visEditorRef,
eventEmitter,
}: VisualizeEditorCommonProps) => {
const { services } = useKibana<VisualizeServices>();

Expand Down Expand Up @@ -148,6 +151,7 @@ export const VisualizeEditorCommon = ({
visualizationIdFromUrl={visualizationIdFromUrl}
embeddableId={embeddableId}
onAppLeave={onAppLeave}
eventEmitter={eventEmitter}
/>
)}
{visInstance?.vis?.type?.stage === 'experimental' &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import React, { memo, useCallback, useMemo, useState, useEffect } from 'react';

import { EventEmitter } from 'events';
import { AppMountParameters, OverlayRef } from '@kbn/core/public';
import { i18n } from '@kbn/i18n';
import useLocalStorage from 'react-use/lib/useLocalStorage';
Expand Down Expand Up @@ -40,6 +40,7 @@ interface VisualizeTopNavProps {
visualizationIdFromUrl?: string;
embeddableId?: string;
onAppLeave: AppMountParameters['onAppLeave'];
eventEmitter?: EventEmitter;
}

const TopNav = ({
Expand All @@ -57,6 +58,7 @@ const TopNav = ({
visualizationIdFromUrl,
embeddableId,
onAppLeave,
eventEmitter,
}: VisualizeTopNavProps) => {
const { services } = useKibana<VisualizeServices>();
const { TopNavMenu } = services.navigation.ui;
Expand Down Expand Up @@ -116,6 +118,7 @@ const TopNav = ({
uiStateJSON?.vis,
uiStateJSON?.table,
vis.data.indexPattern,
eventEmitter,
]);

const displayEditInLensItem = Boolean(vis.type.navigateToLens && editInLensConfig);
Expand All @@ -140,6 +143,7 @@ const TopNav = ({
hideLensBadge,
setNavigateToLens,
showBadge: !hideTryInLensBadge && displayEditInLensItem,
eventEmitter,
},
services
);
Expand All @@ -162,6 +166,7 @@ const TopNav = ({
displayEditInLensItem,
hideLensBadge,
hideTryInLensBadge,
eventEmitter,
]);
const [indexPatterns, setIndexPatterns] = useState<DataView[]>([]);
const showDatePicker = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import React from 'react';
import moment from 'moment';
import EventEmitter from 'events';
import { i18n } from '@kbn/i18n';
import { EuiBetaBadgeProps } from '@elastic/eui';
import { parse } from 'query-string';
Expand Down Expand Up @@ -71,6 +72,7 @@ export interface TopNavConfigParams {
hideLensBadge: () => void;
setNavigateToLens: (flag: boolean) => void;
showBadge: boolean;
eventEmitter?: EventEmitter;
}

const SavedObjectSaveModalDashboard = withSuspense(LazySavedObjectSaveModalDashboard);
Expand Down Expand Up @@ -102,6 +104,7 @@ export const getTopNavConfig = (
hideLensBadge,
setNavigateToLens,
showBadge,
eventEmitter,
}: TopNavConfigParams,
{
data,
Expand Down Expand Up @@ -301,6 +304,10 @@ export const getTopNavConfig = (
},
}),
run: async () => {
// lens doesn't support saved searches, should unlink before transition
if (eventEmitter && visInstance.vis.data.savedSearchId) {
eventEmitter.emit('unlinkFromSavedSearch', false);
}
const updatedWithMeta = {
...editInLensConfig,
savedObjectId: visInstance.vis.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const useLinkedSearchUpdates = (
// SearchSource is a promise-based stream of search results that can inherit from other search sources.
const { searchSource } = visInstance.vis.data;

const unlinkFromSavedSearch = () => {
const unlinkFromSavedSearch = (showToast: boolean = true) => {
const searchSourceParent = savedSearch.searchSource;
const searchSourceGrandparent = searchSourceParent?.getParent();
const currentIndex = searchSourceParent?.getField('index');
Expand All @@ -44,14 +44,16 @@ export const useLinkedSearchUpdates = (
parentFilters: (searchSourceParent?.getOwnField('filter') as Filter[]) || [],
});

services.toastNotifications.addSuccess(
i18n.translate('visualizations.linkedToSearch.unlinkSuccessNotificationText', {
defaultMessage: `Unlinked from saved search '{searchTitle}'`,
values: {
searchTitle: savedSearch.title,
},
})
);
if (showToast) {
services.toastNotifications.addSuccess(
i18n.translate('visualizations.linkedToSearch.unlinkSuccessNotificationText', {
defaultMessage: `Unlinked from saved search '{searchTitle}'`,
values: {
searchTitle: savedSearch.title,
},
})
);
}
};

eventEmitter.on('unlinkFromSavedSearch', unlinkFromSavedSearch);
Expand Down

0 comments on commit cb306df

Please sign in to comment.