Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
f6095c1
Optimize context awareness plugin imports
davismcphee Jan 25, 2025
a877f42
Fix test
davismcphee Jan 25, 2025
b44a21e
Make DiscoverEBTManager import async
davismcphee Jan 25, 2025
ce52049
Optimize plugin service imports
davismcphee Jan 25, 2025
6cf1998
Optimize more plugin imports and services
davismcphee Jan 26, 2025
f600ff1
Fix types
davismcphee Jan 26, 2025
eae8b11
Another optimization
davismcphee Jan 26, 2025
b9d6b1c
Discover analytics registrations on startup
davismcphee Feb 25, 2025
9354e11
Reorganize plugin services
davismcphee Feb 25, 2025
c8bff97
Group plugin dynamic imports
davismcphee Feb 25, 2025
f05f46a
Move search_provider
davismcphee Feb 25, 2025
7663fd9
Don't export appLocatorGetLocationCommon
davismcphee Feb 25, 2025
d6ad865
Split out forwardLegacyUrls
davismcphee Feb 25, 2025
97bb258
Split out onAddSearchEmbeddable
davismcphee Feb 25, 2025
2dd0cd4
Fix utils exports
davismcphee Feb 26, 2025
bc7d308
Fix importing profiles manager and EBT manager
davismcphee Feb 26, 2025
67dcf88
Remove customizations from load bundle
davismcphee Feb 26, 2025
ffd6ba2
Remove embeddable code from page load
davismcphee Feb 26, 2025
2b4ba1c
Fix types
davismcphee Feb 26, 2025
4496ad2
Reduce Discovr page load bundle limit
davismcphee Feb 26, 2025
6669a38
Merge branch 'main' into optimize-plugin-imports
davismcphee Mar 3, 2025
e7ea53c
Merge branch 'main' into optimize-plugin-imports
davismcphee Mar 5, 2025
2fc40f5
Merge branch 'main' into optimize-plugin-imports
davismcphee Mar 6, 2025
b2f6dad
Merge branch 'main' into optimize-plugin-imports
davismcphee Mar 10, 2025
85e126c
Remove EBT manager init flags
davismcphee Mar 10, 2025
c6a17b2
Rename EBT manager registration file and function, and reorder within…
davismcphee Mar 10, 2025
0a3d405
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Mar 10, 2025
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
2 changes: 1 addition & 1 deletion packages/kbn-optimizer/limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pageLoadAssetSize:
dataViews: 65000
dataVisualizer: 30000
devTools: 38637
discover: 99999
discover: 25000
discoverEnhanced: 42730
discoverShared: 17111
embeddable: 24000
Expand Down
17 changes: 11 additions & 6 deletions src/platform/plugins/shared/discover/common/app_locator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ import {
} from '@kbn/kibana-utils-plugin/public';
import { mockStorage } from '@kbn/kibana-utils-plugin/public/storage/hashed_item_store/mock';
import { FilterStateStore } from '@kbn/es-query';
import { DiscoverAppLocatorDefinition } from './app_locator';
import type { DiscoverAppLocatorParams } from './app_locator';
import { DISCOVER_APP_LOCATOR } from './app_locator';
import type { SerializableRecord } from '@kbn/utility-types';
import { createDataViewDataSource, createEsqlDataSource } from './data_sources';
import { appLocatorGetLocationCommon } from './app_locator_get_location';

const dataViewId: string = 'c367b774-a4c2-11ea-bb37-0242ac130002';
const savedSearchId: string = '571aaf70-4c88-11e8-b3d7-01146121b73d';
Expand All @@ -26,11 +28,14 @@ interface SetupParams {
}

const setup = async ({ useHash = false }: SetupParams = {}) => {
const locator = new DiscoverAppLocatorDefinition({ useHash, setStateToKbnUrl });

return {
locator,
const locator = {
id: DISCOVER_APP_LOCATOR,
getLocation: (params: DiscoverAppLocatorParams) => {
return appLocatorGetLocationCommon({ useHash, setStateToKbnUrl }, params);
},
};

return { locator };
};

beforeEach(() => {
Expand Down Expand Up @@ -267,7 +272,7 @@ describe('Discover url generator', () => {
const { locator } = await setup();
const { state } = await locator.getLocation({ dataViewSpec: dataViewSpecMock });

expect(state.dataViewSpec).toEqual(dataViewSpecMock);
expect((state as Record<string, unknown>).dataViewSpec).toEqual(dataViewSpecMock);
});

describe('useHash property', () => {
Expand Down
93 changes: 3 additions & 90 deletions src/platform/plugins/shared/discover/common/app_locator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,11 @@

import type { SerializableRecord } from '@kbn/utility-types';
import type { Filter, TimeRange, Query, AggregateQuery } from '@kbn/es-query';
import { isOfAggregateQueryType } from '@kbn/es-query';
import type { GlobalQueryStateFromUrl, RefreshInterval } from '@kbn/data-plugin/public';
import type { RefreshInterval } from '@kbn/data-plugin/public';
import type { LocatorDefinition, LocatorPublic } from '@kbn/share-plugin/public';
import type { DiscoverGridSettings } from '@kbn/saved-search-plugin/common';
import type { DataViewSpec } from '@kbn/data-views-plugin/common';
import type { setStateToKbnUrl } from '@kbn/kibana-utils-plugin/common';
import type { VIEW_MODE } from './constants';
import type { DiscoverAppState } from '../public';
import { createDataViewDataSource, createEsqlDataSource } from './data_sources';

export const DISCOVER_APP_LOCATOR = 'DISCOVER_APP_LOCATOR';

Expand Down Expand Up @@ -113,11 +109,6 @@ export interface DiscoverAppLocatorParams extends SerializableRecord {

export type DiscoverAppLocator = LocatorPublic<DiscoverAppLocatorParams>;

export interface DiscoverAppLocatorDependencies {
useHash: boolean;
setStateToKbnUrl: typeof setStateToKbnUrl;
}

/**
* Location state of scoped history (history instance of Kibana Platform application service)
*/
Expand All @@ -126,83 +117,5 @@ export interface MainHistoryLocationState {
isAlertResults?: boolean;
}

export class DiscoverAppLocatorDefinition implements LocatorDefinition<DiscoverAppLocatorParams> {
public readonly id = DISCOVER_APP_LOCATOR;

constructor(protected readonly deps: DiscoverAppLocatorDependencies) {}

public readonly getLocation = async (params: DiscoverAppLocatorParams) => {
const {
useHash = this.deps.useHash,
filters,
dataViewId,
indexPatternId,
dataViewSpec,
query,
refreshInterval,
savedSearchId,
timeRange,
searchSessionId,
columns,
grid,
savedQuery,
sort,
interval,
viewMode,
hideAggregatedPreview,
breakdownField,
isAlertResults,
} = params;
const savedSearchPath = savedSearchId ? `view/${encodeURIComponent(savedSearchId)}` : '';
const appState: Partial<DiscoverAppState> = {};
const queryState: GlobalQueryStateFromUrl = {};
const { isFilterPinned } = await import('@kbn/es-query');

if (query) appState.query = query;
if (filters && filters.length) appState.filters = filters?.filter((f) => !isFilterPinned(f));
if (indexPatternId)
appState.dataSource = createDataViewDataSource({ dataViewId: indexPatternId });
if (dataViewId) appState.dataSource = createDataViewDataSource({ dataViewId });
if (isOfAggregateQueryType(query)) appState.dataSource = createEsqlDataSource();
if (columns) appState.columns = columns;
if (grid) appState.grid = grid;
if (savedQuery) appState.savedQuery = savedQuery;
if (sort) appState.sort = sort;
if (interval) appState.interval = interval;
if (timeRange) queryState.time = timeRange;
if (filters && filters.length) queryState.filters = filters?.filter((f) => isFilterPinned(f));
if (refreshInterval) queryState.refreshInterval = refreshInterval;
if (viewMode) appState.viewMode = viewMode;
if (hideAggregatedPreview) appState.hideAggregatedPreview = hideAggregatedPreview;
if (breakdownField) appState.breakdownField = breakdownField;

const state: MainHistoryLocationState = {};
if (dataViewSpec) state.dataViewSpec = dataViewSpec;
if (isAlertResults) state.isAlertResults = isAlertResults;

let path = `#/${savedSearchPath}`;

if (searchSessionId) {
path = `${path}?searchSessionId=${searchSessionId}`;
}

if (Object.keys(queryState).length) {
path = this.deps.setStateToKbnUrl<GlobalQueryStateFromUrl>(
'_g',
queryState,
{ useHash },
path
);
}

if (Object.keys(appState).length) {
path = this.deps.setStateToKbnUrl('_a', appState, { useHash }, path);
}

return {
app: 'discover',
path,
state,
};
};
}
export type DiscoverAppLocatorGetLocation =
LocatorDefinition<DiscoverAppLocatorParams>['getLocation'];
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* 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 { GlobalQueryStateFromUrl } from '@kbn/data-plugin/public';
import { isFilterPinned, isOfAggregateQueryType } from '@kbn/es-query';
import type { setStateToKbnUrl as setStateToKbnUrlCommon } from '@kbn/kibana-utils-plugin/common';
import type { DiscoverAppLocatorGetLocation, MainHistoryLocationState } from './app_locator';
import type { DiscoverAppState } from '../public';
import { createDataViewDataSource, createEsqlDataSource } from './data_sources';

export const appLocatorGetLocationCommon = async (
{
useHash: useHashOriginal,
setStateToKbnUrl,
}: {
useHash: boolean;
setStateToKbnUrl: typeof setStateToKbnUrlCommon;
},
...[params]: Parameters<DiscoverAppLocatorGetLocation>
): ReturnType<DiscoverAppLocatorGetLocation> => {
const {
useHash = useHashOriginal,
filters,
dataViewId,
indexPatternId,
dataViewSpec,
query,
refreshInterval,
savedSearchId,
timeRange,
searchSessionId,
columns,
grid,
savedQuery,
sort,
interval,
viewMode,
hideAggregatedPreview,
breakdownField,
isAlertResults,
} = params;
const savedSearchPath = savedSearchId ? `view/${encodeURIComponent(savedSearchId)}` : '';
const appState: Partial<DiscoverAppState> = {};
const queryState: GlobalQueryStateFromUrl = {};

if (query) appState.query = query;
if (filters && filters.length) appState.filters = filters?.filter((f) => !isFilterPinned(f));
if (indexPatternId)
appState.dataSource = createDataViewDataSource({ dataViewId: indexPatternId });
if (dataViewId) appState.dataSource = createDataViewDataSource({ dataViewId });
if (isOfAggregateQueryType(query)) appState.dataSource = createEsqlDataSource();
if (columns) appState.columns = columns;
if (grid) appState.grid = grid;
if (savedQuery) appState.savedQuery = savedQuery;
if (sort) appState.sort = sort;
if (interval) appState.interval = interval;
if (timeRange) queryState.time = timeRange;
if (filters && filters.length) queryState.filters = filters?.filter((f) => isFilterPinned(f));
if (refreshInterval) queryState.refreshInterval = refreshInterval;
if (viewMode) appState.viewMode = viewMode;
if (hideAggregatedPreview) appState.hideAggregatedPreview = hideAggregatedPreview;
if (breakdownField) appState.breakdownField = breakdownField;

const state: MainHistoryLocationState = {};
if (dataViewSpec) state.dataViewSpec = dataViewSpec;
if (isAlertResults) state.isAlertResults = isAlertResults;

let path = `#/${savedSearchPath}`;

if (searchSessionId) {
path = `${path}?searchSessionId=${searchSessionId}`;
}

if (Object.keys(queryState).length) {
path = setStateToKbnUrl<GlobalQueryStateFromUrl>('_g', queryState, { useHash }, path);
}

if (Object.keys(appState).length) {
path = setStateToKbnUrl('_a', appState, { useHash }, path);
}

return {
app: 'discover',
path,
state,
};
};
28 changes: 2 additions & 26 deletions src/platform/plugins/shared/discover/common/esql_locator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,12 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { DISCOVER_ESQL_LOCATOR } from '@kbn/deeplinks-analytics';
import type { LocatorDefinition, LocatorPublic } from '@kbn/share-plugin/common';
import type { SerializableRecord } from '@kbn/utility-types';
import { getIndexForESQLQuery, getInitialESQLQuery, getESQLAdHocDataview } from '@kbn/esql-utils';
import type { DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public';

export type DiscoverESQLLocatorParams = SerializableRecord;

export interface DiscoverESQLLocatorDependencies {
discoverAppLocator: LocatorPublic<SerializableRecord>;
dataViews: DataViewsPublicPluginStart;
}

export type DiscoverESQLLocator = LocatorPublic<DiscoverESQLLocatorParams>;

export class DiscoverESQLLocatorDefinition implements LocatorDefinition<DiscoverESQLLocatorParams> {
public readonly id = DISCOVER_ESQL_LOCATOR;

constructor(protected readonly deps: DiscoverESQLLocatorDependencies) {}

public readonly getLocation = async () => {
const { discoverAppLocator, dataViews } = this.deps;
const indexName = (await getIndexForESQLQuery({ dataViews })) ?? '*';
const dataView = await getESQLAdHocDataview(`from ${indexName}`, dataViews);
const esql = getInitialESQLQuery(dataView);

const params = {
query: { esql },
};

return await discoverAppLocator.getLocation(params);
};
}
export type DiscoverESQLLocatorGetLocation =
LocatorDefinition<DiscoverESQLLocatorParams>['getLocation'];
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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 { LocatorPublic } from '@kbn/share-plugin/common';
import type { SerializableRecord } from '@kbn/utility-types';
import type { DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public';
import { getESQLAdHocDataview, getIndexForESQLQuery, getInitialESQLQuery } from '@kbn/esql-utils';
import type { DiscoverESQLLocatorGetLocation } from './esql_locator';

export const esqlLocatorGetLocation = async ({
discoverAppLocator,
dataViews,
}: {
discoverAppLocator: LocatorPublic<SerializableRecord>;
dataViews: DataViewsPublicPluginStart;
}): ReturnType<DiscoverESQLLocatorGetLocation> => {
const indexName = (await getIndexForESQLQuery({ dataViews })) ?? '*';
const dataView = await getESQLAdHocDataview(`from ${indexName}`, dataViews);
const esql = getInitialESQLQuery(dataView);

const params = {
query: { esql },
};

return await discoverAppLocator.getLocation(params);
};
3 changes: 1 addition & 2 deletions src/platform/plugins/shared/discover/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@
export const PLUGIN_ID = 'discover';
export const APP_ICON = 'discoverApp';

export { DISCOVER_APP_LOCATOR, DiscoverAppLocatorDefinition } from './app_locator';
export { DISCOVER_APP_LOCATOR } from './app_locator';
export type {
DiscoverAppLocator,
DiscoverAppLocatorParams,
MainHistoryLocationState,
} from './app_locator';

export { DiscoverESQLLocatorDefinition } from './esql_locator';
export type { DiscoverESQLLocator, DiscoverESQLLocatorParams } from './esql_locator';
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import type { SearchSourceDependencies } from '@kbn/data-plugin/common';
import type { SearchResponse } from '@elastic/elasticsearch/lib/api/types';
import { createElement } from 'react';
import { createContextAwarenessMocks } from '../context_awareness/__mocks__';
import { DiscoverEBTManager } from '../services/discover_ebt_manager';
import { DiscoverEBTManager } from '../plugin_imports/discover_ebt_manager';
import { discoverSharedPluginMock } from '@kbn/discover-shared-plugin/public/mocks';
import { createUrlTrackerMock } from './url_tracker.mock';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
*/

import { getStatesFromKbnUrl } from '@kbn/kibana-utils-plugin/public';
import { DiscoverContextAppLocatorDefinition } from './locator';
import type { DiscoverContextAppLocatorParams } from './locator';
import { DISCOVER_CONTEXT_APP_LOCATOR } from './locator';
import { contextAppLocatorGetLocation } from './locator_get_location';

const dataViewId: string = 'c367b774-a4c2-11ea-bb37-0242ac130002';

Expand All @@ -17,7 +19,13 @@ interface SetupParams {
}

const setup = async ({ useHash = false }: SetupParams = {}) => {
const locator = new DiscoverContextAppLocatorDefinition({ useHash });
const locator = {
id: DISCOVER_CONTEXT_APP_LOCATOR,
getLocation: async (params: DiscoverContextAppLocatorParams) => {
return contextAppLocatorGetLocation({ useHash }, params);
},
};

return { locator };
};

Expand Down
Loading