Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions packages/kbn-optimizer/limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ pageLoadAssetSize:
dataViews: 65000
dataVisualizer: 30000
devTools: 38637
discover: 99999
discoverEnhanced: 42730
discover: 42000
discoverEnhanced: 6000
discoverShared: 17111
embeddable: 24000
embeddableEnhanced: 22107
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export const ACTION_VIEW_SAVED_SEARCH = 'ACTION_VIEW_SAVED_SEARCH';
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { discoverServiceMock } from '../../__mocks__/services';
import { createStartContractMock } from '../../__mocks__/start_contract';
import { SearchEmbeddableApi } from '../types';
import { getDiscoverLocatorParams } from '../utils/get_discover_locator_params';
import { ViewSavedSearchAction } from './view_saved_search_action';
import { getViewDiscoverSessionAction } from './view_discover_session_action';

const applicationMock = createStartContractMock();
const services = discoverServiceMock;
Expand All @@ -36,30 +36,30 @@ jest

describe('view saved search action', () => {
it('is compatible when embeddable is of type saved search, in view mode && appropriate permissions are set', async () => {
const action = new ViewSavedSearchAction(applicationMock, services.locator);
expect(await action.isCompatible({ embeddable: compatibleEmbeddableApi })).toBe(true);
const action = getViewDiscoverSessionAction(applicationMock, services.locator);
expect(await action.isCompatible?.({ embeddable: compatibleEmbeddableApi })).toBe(true);
});

it('is not compatible when embeddable not of type saved search', async () => {
const action = new ViewSavedSearchAction(applicationMock, services.locator);
const action = getViewDiscoverSessionAction(applicationMock, services.locator);
expect(
await action.isCompatible({
await action.isCompatible?.({
embeddable: { ...compatibleEmbeddableApi, type: 'CONTACT_CARD_EMBEDDABLE' },
})
).toBe(false);
});

it('is not visible when in edit mode', async () => {
const action = new ViewSavedSearchAction(applicationMock, services.locator);
const action = getViewDiscoverSessionAction(applicationMock, services.locator);
expect(
await action.isCompatible({
await action.isCompatible?.({
embeddable: { ...compatibleEmbeddableApi, viewMode$: new BehaviorSubject('edit') },
})
).toBe(false);
});

it('execute navigates to a saved search', async () => {
const action = new ViewSavedSearchAction(applicationMock, services.locator);
const action = getViewDiscoverSessionAction(applicationMock, services.locator);
await new Promise((resolve) => setTimeout(resolve, 0));
await action.execute({ embeddable: compatibleEmbeddableApi });
expect(discoverServiceMock.locator.navigate).toHaveBeenCalledWith(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import type { ApplicationStart } from '@kbn/core/public';
import { i18n } from '@kbn/i18n';
import {
apiCanAccessViewMode,
getInheritedViewMode,
type EmbeddableApiContext,
apiIsOfType,
CanAccessViewMode,
HasType,
} from '@kbn/presentation-publishing';
import { IncompatibleActionError } from '@kbn/ui-actions-plugin/public';

import { SEARCH_EMBEDDABLE_TYPE } from '@kbn/discover-utils';
import { ActionDefinition } from '@kbn/ui-actions-plugin/public/actions';
import type { DiscoverAppLocator } from '../../../common';
import { getDiscoverLocatorParams } from '../utils/get_discover_locator_params';
import { ACTION_VIEW_SAVED_SEARCH } from './constants';
import { PublishesSavedSearch, apiPublishesSavedSearch } from '../types';

type ViewSavedSearchActionApi = CanAccessViewMode & HasType & PublishesSavedSearch;

export const compatibilityCheck = (
api: EmbeddableApiContext['embeddable']
): api is ViewSavedSearchActionApi => {
return (
apiCanAccessViewMode(api) &&
getInheritedViewMode(api) === 'view' &&
apiIsOfType(api, SEARCH_EMBEDDABLE_TYPE) &&
apiPublishesSavedSearch(api)
);
};

export function getViewDiscoverSessionAction(
application: ApplicationStart,
locator: DiscoverAppLocator
) {
return {
id: ACTION_VIEW_SAVED_SEARCH,
type: ACTION_VIEW_SAVED_SEARCH,
order: 20, // Same order as ACTION_OPEN_IN_DISCOVER
execute: async ({ embeddable }: EmbeddableApiContext) => {
if (!compatibilityCheck(embeddable)) throw new IncompatibleActionError();

const locatorParams = getDiscoverLocatorParams(embeddable);
await locator.navigate(locatorParams);
},
getDisplayName: () =>
i18n.translate('discover.savedSearchEmbeddable.action.viewSavedSearch.displayName', {
defaultMessage: 'Open in Discover',
}),
getIconType: () => 'discoverApp',
isCompatible: async ({ embeddable }: EmbeddableApiContext) => {
const { capabilities } = application;
const hasDiscoverPermissions =
(capabilities.discover_v2.show as boolean) || (capabilities.discover_v2.save as boolean);
return hasDiscoverPermissions && compatibilityCheck(embeddable);
},
} as ActionDefinition<EmbeddableApiContext>;
}

This file was deleted.

This file was deleted.

6 changes: 5 additions & 1 deletion src/platform/plugins/shared/discover/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,9 @@ export {
type SearchEmbeddableApi,
type NonPersistedDisplayOptions,
} from './embeddable';
export { loadSharingDataHelpers } from './utils';

export async function loadSharingDataHelpers() {
return await import('./utils/get_sharing_data');
}

export type { DiscoverServices } from './build_services';
15 changes: 11 additions & 4 deletions src/platform/plugins/shared/discover/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import { i18n } from '@kbn/i18n';
import { PLUGIN_ID } from '../common';
import { registerFeature } from './register_feature';
import { buildServices, UrlTracker } from './build_services';
import { ViewSavedSearchAction } from './embeddable/actions/view_saved_search_action';
import { initializeKbnUrlTracking } from './utils/initialize_kbn_url_tracking';
import {
DiscoverContextAppLocator,
Expand Down Expand Up @@ -59,6 +58,7 @@ import { DataSourceProfileService } from './context_awareness/profiles/data_sour
import { DocumentProfileService } from './context_awareness/profiles/document_profile';
import { ProfilesManager } from './context_awareness/profiles_manager';
import { DiscoverEBTManager } from './services/discover_ebt_manager';
import { ACTION_VIEW_SAVED_SEARCH } from './embeddable/actions/constants';

/**
* Contains Discover, one of the oldest parts of Kibana
Expand Down Expand Up @@ -254,9 +254,16 @@ export class DiscoverPlugin
}

start(core: CoreStart, plugins: DiscoverStartPlugins): DiscoverStart {
const viewSavedSearchAction = new ViewSavedSearchAction(core.application, this.locator!);

plugins.uiActions.addTriggerAction('CONTEXT_MENU_TRIGGER', viewSavedSearchAction);
plugins.uiActions.addTriggerActionAsync(
'CONTEXT_MENU_TRIGGER',
ACTION_VIEW_SAVED_SEARCH,
async () => {
const { getViewDiscoverSessionAction } = await import(
'./embeddable/actions/view_discover_session_action'
);
return getViewDiscoverSessionAction(core.application, this.locator!);
}
);
plugins.uiActions.registerTrigger(SEARCH_EMBEDDABLE_CELL_ACTIONS_TRIGGER);
plugins.uiActions.registerTrigger(DISCOVER_CELL_ACTIONS_TRIGGER);

Expand Down
7 changes: 0 additions & 7 deletions src/platform/plugins/shared/discover/public/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,4 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

/*
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved loadSharingDataHelpers to public/index.ts to avoid loading getSortForEmbeddable in page load bundle.

* Allows the getSharingData function to be lazy loadable
*/
export async function loadSharingDataHelpers() {
return await import('./get_sharing_data');
}

export { getSortForEmbeddable } from './sorting';
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ import { KibanaLocation } from '@kbn/share-plugin/public';

import * as shared from './shared';

export const ACTION_EXPLORE_DATA = 'ACTION_EXPLORE_DATA';

export interface PluginDeps {
discover: Pick<DiscoverStart, 'locator'>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
* 2.0.
*/

export * from './explore_data';
export const ACTION_EXPLORE_DATA_CHART = 'ACTION_EXPLORE_DATA_CHART';
export const ACTION_EXPLORE_DATA = 'ACTION_EXPLORE_DATA';
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import { KibanaLocation } from '@kbn/share-plugin/public';
import { Action } from '@kbn/ui-actions-plugin/public';
import { ApplyGlobalFilterActionContext } from '@kbn/unified-search-plugin/public';
import { AbstractExploreDataAction } from './abstract_explore_data_action';

export const ACTION_EXPLORE_DATA_CHART = 'ACTION_EXPLORE_DATA_CHART';
import { ACTION_EXPLORE_DATA_CHART } from './constants';

export interface ExploreDataChartActionContext extends ApplyGlobalFilterActionContext {
embeddable: Partial<PublishesUnifiedSearch> &
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import { EmbeddableApiContext } from '@kbn/presentation-publishing';
import { Action } from '@kbn/ui-actions-plugin/public';
import { AbstractExploreDataAction } from './abstract_explore_data_action';

export const ACTION_EXPLORE_DATA = 'ACTION_EXPLORE_DATA';
import { ACTION_EXPLORE_DATA } from './constants';

/**
* This is "Explore underlying data" action which appears in the context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
* 2.0.
*/

export * from './explore_data_context_menu_action';
export * from './explore_data_chart_action';
export { ExploreDataChartAction } from './explore_data_chart_action';
export { ExploreDataContextMenuAction } from './explore_data_context_menu_action';
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import type { PluginInitializerContext } from '@kbn/core/public';
import { DiscoverEnhancedPlugin } from './plugin';

export type { ExploreDataContextMenuAction, ExploreDataChartAction } from './actions';

export type {
DiscoverEnhancedPlugin,
DiscoverEnhancedSetupDependencies,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import {
EmbeddableStart,
CONTEXT_MENU_TRIGGER,
} from '@kbn/embeddable-plugin/public';
import { ExploreDataContextMenuAction, ExploreDataChartAction } from './actions';
import { Config } from '../common';
import { ACTION_EXPLORE_DATA, ACTION_EXPLORE_DATA_CHART } from './actions/explore_data/constants';

export interface DiscoverEnhancedSetupDependencies {
discover: DiscoverSetup;
Expand Down Expand Up @@ -55,13 +55,21 @@ export class DiscoverEnhancedPlugin
const params = { start };

if (this.config.actions.exploreDataInContextMenu.enabled) {
const exploreDataAction = new ExploreDataContextMenuAction(params);
uiActions.addTriggerAction(CONTEXT_MENU_TRIGGER, exploreDataAction);
uiActions.addTriggerActionAsync(CONTEXT_MENU_TRIGGER, ACTION_EXPLORE_DATA, async () => {
const { ExploreDataContextMenuAction } = await import('./actions/explore_data/module');
return new ExploreDataContextMenuAction(params);
});
}

if (this.config.actions.exploreDataInChart.enabled) {
const exploreDataChartAction = new ExploreDataChartAction(params);
uiActions.addTriggerAction(APPLY_FILTER_TRIGGER, exploreDataChartAction);
uiActions.addTriggerActionAsync(
APPLY_FILTER_TRIGGER,
ACTION_EXPLORE_DATA_CHART,
async () => {
const { ExploreDataChartAction } = await import('./actions/explore_data/module');
return new ExploreDataChartAction(params);
}
);
}
}
}
Expand Down