Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Embeddable Rebuild] [Discover] Fix bundle size #189206

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,15 @@
*/

import type { ApplicationStart } from '@kbn/core/public';
import { SEARCH_EMBEDDABLE_TYPE } from '@kbn/discover-utils';
import { ViewMode } from '@kbn/embeddable-plugin/public';
import { i18n } from '@kbn/i18n';
import {
apiCanAccessViewMode,
apiHasType,
apiIsOfType,
CanAccessViewMode,
EmbeddableApiContext,
getInheritedViewMode,
HasType,
} from '@kbn/presentation-publishing';
import type { EmbeddableApiContext } from '@kbn/presentation-publishing';
import type { Action } from '@kbn/ui-actions-plugin/public';

import type { DiscoverAppLocator } from '../../../common';
import { PublishesSavedSearch, apiPublishesSavedSearch } from '../types';
import { getDiscoverLocatorParams } from '../utils/get_discover_locator_params';

export const ACTION_VIEW_SAVED_SEARCH = 'ACTION_VIEW_SAVED_SEARCH';

type ViewSavedSearchActionApi = CanAccessViewMode & HasType & PublishesSavedSearch;

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

export class ViewSavedSearchAction implements Action<EmbeddableApiContext> {
public id = ACTION_VIEW_SAVED_SEARCH;
public readonly type = ACTION_VIEW_SAVED_SEARCH;
Expand All @@ -51,6 +26,7 @@ export class ViewSavedSearchAction implements Action<EmbeddableApiContext> {
) {}

async execute({ embeddable }: EmbeddableApiContext): Promise<void> {
const { compatibilityCheck } = await import('./view_saved_search_compatibility_check');
if (!compatibilityCheck(embeddable)) {
return;
}
Expand All @@ -73,6 +49,9 @@ export class ViewSavedSearchAction implements Action<EmbeddableApiContext> {
const { capabilities } = this.application;
const hasDiscoverPermissions =
(capabilities.discover.show as boolean) || (capabilities.discover.save as boolean);
return compatibilityCheck(embeddable) && hasDiscoverPermissions;

if (!hasDiscoverPermissions) return false; // early return to delay async import until absolutely necessary
const { compatibilityCheck } = await import('./view_saved_search_compatibility_check');
return compatibilityCheck(embeddable);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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 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 or the Server
* Side Public License, v 1.
*/

import { SEARCH_EMBEDDABLE_TYPE } from '@kbn/discover-utils';
import { ViewMode } from '@kbn/embeddable-plugin/public';
import {
apiCanAccessViewMode,
apiHasType,
apiIsOfType,
CanAccessViewMode,
EmbeddableApiContext,
getInheritedViewMode,
HasType,
} from '@kbn/presentation-publishing';

import { apiPublishesSavedSearch, PublishesSavedSearch } from '../types';

type ViewSavedSearchActionApi = CanAccessViewMode & HasType & PublishesSavedSearch;

export const compatibilityCheck = (
api: EmbeddableApiContext['embeddable']
): api is ViewSavedSearchActionApi => {
return (
apiCanAccessViewMode(api) &&
getInheritedViewMode(api) === ViewMode.VIEW &&
apiHasType(api) &&
apiIsOfType(api, SEARCH_EMBEDDABLE_TYPE) &&
apiPublishesSavedSearch(api)
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import type { Filter } from '@kbn/es-query';
import { PublishesSavedObjectId, PublishesUnifiedSearch } from '@kbn/presentation-publishing';
import type { PublishesSavedObjectId, PublishesUnifiedSearch } from '@kbn/presentation-publishing';
import { DiscoverAppLocatorParams } from '../../../common';
import { PublishesSavedSearch } from '../types';

Expand Down