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

[Saved Object Finder] Move to the component in saved_objects_finder plugin #151764

Merged
merged 37 commits into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
1793fb4
[SavedObjectsFinder] Replace savedObjects.client.find
Feb 16, 2023
14041e6
Move server-side logic to saved_objects_finder plugin
Feb 18, 2023
9ddeec1
Fix type
Feb 20, 2023
c286b73
Fix translation
Feb 20, 2023
5480698
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Feb 20, 2023
afc785c
Merge branch 'main' into so-finder-2
kibanamachine Feb 20, 2023
f2191ab
[Saved Object Finder] Standardize the calls
Feb 21, 2023
bc34f07
Change data-test-subj
Feb 22, 2023
ae9fa26
Fix rendering test
Feb 23, 2023
67a8706
Merge main
Feb 23, 2023
39ec7a2
Fix merge conflicts
Feb 23, 2023
2a64434
Fix typescript
Feb 23, 2023
c11b0f7
Add missing types
Feb 23, 2023
0db1f29
Add missing stub
Feb 23, 2023
f123ece
Fix functional tests
Feb 23, 2023
1ce60a4
Merge branch 'main' into so-finder-3
Feb 24, 2023
f74971e
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Feb 24, 2023
ea2c057
Fix rendering test
Feb 24, 2023
c4159e8
Remove sleep
Feb 24, 2023
08c2d9e
Update test
Feb 24, 2023
eecd4bc
Replace SavedObjectsFinder in Canvas
Feb 24, 2023
d61b0c1
Add missing stubs
Feb 24, 2023
7456ef6
Fix failing test
Feb 24, 2023
deab368
Fix types
Feb 25, 2023
9dd9883
Merge main
Feb 25, 2023
e4b5ba3
Fix types
Feb 25, 2023
59741e6
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Feb 25, 2023
d37e628
Merge branch 'main' into so-finder-3
Feb 27, 2023
c7713ef
Change DashboardService > SavedObjectsManagementPluginStart
Feb 27, 2023
882e22a
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Feb 27, 2023
4314b87
Lazy loading components
Feb 28, 2023
a74490f
Extract common logic to service
Feb 28, 2023
4d70c00
Fix test
Feb 28, 2023
aaf7209
Extract common functionality to service
Feb 28, 2023
079f376
Fix missing import
Feb 28, 2023
318d2bc
Fix test
Feb 28, 2023
8565fad
Change selector
Mar 1, 2023
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: 2 additions & 0 deletions src/plugins/dashboard/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
"inspector",
"navigation",
"savedObjects",
"savedObjectsFinder",
"savedObjectsManagement",
"share",
"screenshotMode",
"uiActions",
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/dashboard/public/dashboard_actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import { CONTEXT_MENU_TRIGGER, PANEL_NOTIFICATION_TRIGGER } from '@kbn/embeddable-plugin/public';
import { CoreStart } from '@kbn/core/public';
import { getSavedObjectFinder } from '@kbn/saved-objects-plugin/public';
import { getSavedObjectFinder } from '@kbn/saved-objects-finder-plugin/public';

import { ExportCSVAction } from './export_csv_action';
import { ClonePanelAction } from './clone_panel_action';
Expand All @@ -33,13 +33,13 @@ export const buildAllDashboardActions = async ({
allowByValueEmbeddables,
}: BuildAllDashboardActionsProps) => {
const { uiSettings } = core;
const { uiActions, share, presentationUtil } = plugins;
const { uiActions, share, presentationUtil, savedObjectsManagement } = plugins;

const clonePanelAction = new ClonePanelAction(core.savedObjects);
uiActions.registerAction(clonePanelAction);
uiActions.attachAction(CONTEXT_MENU_TRIGGER, clonePanelAction.id);

const SavedObjectFinder = getSavedObjectFinder(uiSettings, core.http);
const SavedObjectFinder = getSavedObjectFinder(uiSettings, core.http, savedObjectsManagement);
const changeViewAction = new ReplacePanelAction(SavedObjectFinder);
uiActions.registerAction(changeViewAction);
uiActions.attachAction(CONTEXT_MENU_TRIGGER, changeViewAction.id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

import { HttpStart } from '@kbn/core/public';
import { isErrorEmbeddable, openAddPanelFlyout } from '@kbn/embeddable-plugin/public';
import { getSavedObjectFinder } from '@kbn/saved-objects-plugin/public';
import { getSavedObjectFinder } from '@kbn/saved-objects-finder-plugin/public';

import { SavedObjectsManagementPluginStart } from '@kbn/saved-objects-management-plugin/public';
import { pluginServices } from '../../../services/plugin_services';
import { DashboardContainer } from '../dashboard_container';

Expand All @@ -21,12 +22,17 @@ export function addFromLibrary(this: DashboardContainer) {
settings: { uiSettings, theme },
embeddable: { getEmbeddableFactories, getEmbeddableFactory },
http,
savedObjectsManagement,
} = pluginServices.getServices();

if (isErrorEmbeddable(this)) return;
this.openOverlay(
openAddPanelFlyout({
SavedObjectFinder: getSavedObjectFinder(uiSettings, http as HttpStart),
SavedObjectFinder: getSavedObjectFinder(
uiSettings,
http as HttpStart,
savedObjectsManagement as unknown as SavedObjectsManagementPluginStart
),
reportUiCounter: usageCollection.reportUiCounter,
getAllFactories: getEmbeddableFactories,
getFactory: getEmbeddableFactory,
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/dashboard/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import type { UrlForwardingSetup, UrlForwardingStart } from '@kbn/url-forwarding
import type { SavedObjectTaggingOssPluginStart } from '@kbn/saved-objects-tagging-oss-plugin/public';

import { CustomBrandingStart } from '@kbn/core-custom-branding-browser';
import { SavedObjectsManagementPluginStart } from '@kbn/saved-objects-management-plugin/public';
import { DashboardContainerFactoryDefinition } from './dashboard_container/embeddable/dashboard_container_factory';
import {
type DashboardAppLocator,
Expand Down Expand Up @@ -90,6 +91,7 @@ export interface DashboardStartDependencies {
presentationUtil: PresentationUtilPluginStart;
savedObjects: SavedObjectsStart;
savedObjectsClient: SavedObjectsClientContract;
savedObjectsManagement: SavedObjectsManagementPluginStart;
savedObjectsTaggingOss?: SavedObjectTaggingOssPluginStart;
screenshotMode: ScreenshotModePluginStart;
share?: SharePluginStart;
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/dashboard/public/services/plugin_services.stub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { urlForwardingServiceFactory } from './url_forwarding/url_fowarding.stub
import { visualizationsServiceFactory } from './visualizations/visualizations.stub';
import { dashboardSavedObjectServiceFactory } from './dashboard_saved_object/dashboard_saved_object.stub';
import { customBrandingServiceFactory } from './custom_branding/custom_branding.stub';
import { savedObjectsManagementServiceFactory } from './saved_objects_management/saved_objects_management_service.stub';

export const providers: PluginServiceProviders<DashboardServices> = {
dashboardSavedObject: new PluginServiceProvider(dashboardSavedObjectServiceFactory),
Expand Down Expand Up @@ -66,6 +67,7 @@ export const providers: PluginServiceProviders<DashboardServices> = {
usageCollection: new PluginServiceProvider(usageCollectionServiceFactory),
visualizations: new PluginServiceProvider(visualizationsServiceFactory),
customBranding: new PluginServiceProvider(customBrandingServiceFactory),
savedObjectsManagement: new PluginServiceProvider(savedObjectsManagementServiceFactory),
};

export const registry = new PluginServiceRegistry<DashboardServices>(providers);
2 changes: 2 additions & 0 deletions src/plugins/dashboard/public/services/plugin_services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { usageCollectionServiceFactory } from './usage_collection/usage_collecti
import { analyticsServiceFactory } from './analytics/analytics_service';
import { dashboardSavedObjectServiceFactory } from './dashboard_saved_object/dashboard_saved_object_service';
import { customBrandingServiceFactory } from './custom_branding/custom_branding_service';
import { savedObjectsManagementServiceFactory } from './saved_objects_management/saved_objects_management_service';

const providers: PluginServiceProviders<DashboardServices, DashboardPluginServiceParams> = {
dashboardSavedObject: new PluginServiceProvider(dashboardSavedObjectServiceFactory, [
Expand Down Expand Up @@ -80,6 +81,7 @@ const providers: PluginServiceProviders<DashboardServices, DashboardPluginServic
usageCollection: new PluginServiceProvider(usageCollectionServiceFactory),
visualizations: new PluginServiceProvider(visualizationsServiceFactory),
customBranding: new PluginServiceProvider(customBrandingServiceFactory),
savedObjectsManagement: new PluginServiceProvider(savedObjectsManagementServiceFactory),
};

export const pluginServices = new PluginServices<DashboardServices>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* 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 { PluginServiceFactory } from '@kbn/presentation-util-plugin/public';
import { SavedObjectsManagementPluginStart } from '@kbn/saved-objects-management-plugin/public';
import { savedObjectsManagementPluginMock } from '@kbn/saved-objects-management-plugin/public/mocks';

type SavedObjectsManagementServiceFactory = PluginServiceFactory<SavedObjectsManagementPluginStart>;

export const savedObjectsManagementServiceFactory: SavedObjectsManagementServiceFactory = () => {
return savedObjectsManagementPluginMock.createStartContract();
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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 { KibanaPluginServiceFactory } from '@kbn/presentation-util-plugin/public';
import { SavedObjectsManagementPluginStart } from '@kbn/saved-objects-management-plugin/public';
import { DashboardStartDependencies } from '../../plugin';

export type SavedObjectsManagementServiceFactory = KibanaPluginServiceFactory<
SavedObjectsManagementPluginStart,
DashboardStartDependencies
>;

export const savedObjectsManagementServiceFactory: SavedObjectsManagementServiceFactory = ({
startPlugins,
}) => {
const { savedObjectsManagement } = startPlugins;

return savedObjectsManagement;
};
2 changes: 2 additions & 0 deletions src/plugins/dashboard/public/services/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import { PluginInitializerContext } from '@kbn/core/public';
import { KibanaPluginServiceParams } from '@kbn/presentation-util-plugin/public';
import { SavedObjectsManagementPluginStart } from '@kbn/saved-objects-management-plugin/public';

import { DashboardStartDependencies } from '../plugin';
import { DashboardAnalyticsService } from './analytics/types';
Expand Down Expand Up @@ -66,4 +67,5 @@ export interface DashboardServices {
usageCollection: DashboardUsageCollectionService; // TODO: make this optional in follow up
visualizations: DashboardVisualizationsService;
customBranding: DashboardCustomBrandingService;
savedObjectsManagement: SavedObjectsManagementPluginStart;
}
2 changes: 2 additions & 0 deletions src/plugins/dashboard/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
"@kbn/core-execution-context-common",
"@kbn/core-custom-branding-browser",
"@kbn/shared-ux-router",
"@kbn/saved-objects-finder-plugin",
"@kbn/saved-objects-management-plugin",
"@kbn/shared-ux-button-toolbar",
],
"exclude": [
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/embeddable/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"requiredPlugins": [
"data",
"inspector",
"uiActions"
"uiActions",
"savedObjectsFinder",
"savedObjectsManagement"
],
"requiredBundles": [
"savedObjects",
Expand Down
23 changes: 23 additions & 0 deletions src/plugins/embeddable/public/mocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import { type AggregateQuery, type Filter, type Query } from '@kbn/es-query';

import { inspectorPluginMock } from '@kbn/inspector-plugin/public/mocks';
import { uiActionsPluginMock } from '@kbn/ui-actions-plugin/public/mocks';
import {
SavedObjectManagementTypeInfo,
SavedObjectsManagementPluginStart,
} from '@kbn/saved-objects-management-plugin/public';
import { SavedObjectsTaggingApi } from '@kbn/saved-objects-tagging-oss-plugin/public';
import { UiActionsService } from './lib/ui_actions';
import { EmbeddablePublicPlugin } from './plugin';
import {
Expand Down Expand Up @@ -156,10 +161,28 @@ const createInstance = (setupPlugins: Partial<EmbeddableSetupDependencies> = {})
const setup = plugin.setup(coreMock.createSetup(), {
uiActions: setupPlugins.uiActions || uiActionsPluginMock.createSetupContract(),
});
const savedObjectsManagementMock = {
parseQuery: (query: Query, types: SavedObjectManagementTypeInfo[]) => {
return {
queryText: 'some search',
};
},
getTagFindReferences: ({
selectedTags,
taggingApi,
}: {
selectedTags?: string[];
taggingApi?: SavedObjectsTaggingApi;
}) => {
return undefined;
},
};
const doStart = (startPlugins: Partial<EmbeddableStartDependencies> = {}) =>
plugin.start(coreMock.createStart(), {
uiActions: startPlugins.uiActions || uiActionsPluginMock.createStartContract(),
inspector: inspectorPluginMock.createStartContract(),
savedObjectsManagement:
savedObjectsManagementMock as unknown as SavedObjectsManagementPluginStart,
});
return {
plugin,
Expand Down
12 changes: 9 additions & 3 deletions src/plugins/embeddable/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Subscription } from 'rxjs';
import { identity } from 'lodash';
import { UI_SETTINGS } from '@kbn/data-plugin/public';
import type { SerializableRecord } from '@kbn/utility-types';
import { getSavedObjectFinder } from '@kbn/saved-objects-plugin/public';
import { getSavedObjectFinder } from '@kbn/saved-objects-finder-plugin/public';
import { UiActionsSetup, UiActionsStart } from '@kbn/ui-actions-plugin/public';
import { Start as InspectorStart } from '@kbn/inspector-plugin/public';
import {
Expand All @@ -23,6 +23,7 @@ import {
} from '@kbn/core/public';
import { Storage } from '@kbn/kibana-utils-plugin/public';
import { migrateToLatest, PersistableStateService } from '@kbn/kibana-utils-plugin/common';
import { SavedObjectsManagementPluginStart } from '@kbn/saved-objects-management-plugin/public';
import {
EmbeddableFactoryRegistry,
EmbeddableFactoryProvider,
Expand Down Expand Up @@ -64,6 +65,7 @@ export interface EmbeddableSetupDependencies {
export interface EmbeddableStartDependencies {
uiActions: UiActionsStart;
inspector: InspectorStart;
savedObjectsManagement: SavedObjectsManagementPluginStart;
}

export interface EmbeddableSetup {
Expand Down Expand Up @@ -143,7 +145,7 @@ export class EmbeddablePublicPlugin implements Plugin<EmbeddableSetup, Embeddabl

public start(
core: CoreStart,
{ uiActions, inspector }: EmbeddableStartDependencies
{ uiActions, inspector, savedObjectsManagement }: EmbeddableStartDependencies
): EmbeddableStart {
this.embeddableFactoryDefinitions.forEach((def) => {
this.embeddableFactories.set(
Expand Down Expand Up @@ -207,7 +209,11 @@ export class EmbeddablePublicPlugin implements Plugin<EmbeddableSetup, Embeddabl
notifications={core.notifications}
application={core.application}
inspector={inspector}
SavedObjectFinder={getSavedObjectFinder(core.uiSettings, core.http)}
SavedObjectFinder={getSavedObjectFinder(
core.uiSettings,
core.http,
savedObjectsManagement
)}
containerContext={containerContext}
theme={theme}
/>
Expand Down
25 changes: 24 additions & 1 deletion src/plugins/embeddable/public/tests/test_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ import { UiActionsStart } from '@kbn/ui-actions-plugin/public';
import { uiActionsPluginMock } from '@kbn/ui-actions-plugin/public/mocks';
import { inspectorPluginMock } from '@kbn/inspector-plugin/public/mocks';
import { coreMock } from '@kbn/core/public/mocks';
import {
SavedObjectManagementTypeInfo,
SavedObjectsManagementPluginStart,
} from '@kbn/saved-objects-management-plugin/public';
import { Query } from '@kbn/es-query';
import { SavedObjectsTaggingApi } from '@kbn/saved-objects-tagging-oss-plugin/public';
import { EmbeddablePublicPlugin, EmbeddableSetup, EmbeddableStart } from '../plugin';

export interface TestPluginReturn {
plugin: EmbeddablePublicPlugin;
coreSetup: CoreSetup;
Expand All @@ -32,6 +37,22 @@ export const testPlugin = (
const setup = plugin.setup(coreSetup, {
uiActions: uiActions.setup,
});
const savedObjectsManagementMock = {
parseQuery: (query: Query, types: SavedObjectManagementTypeInfo[]) => {
return {
queryText: 'some search',
};
},
getTagFindReferences: ({
selectedTags,
taggingApi,
}: {
selectedTags?: string[];
taggingApi?: SavedObjectsTaggingApi;
}) => {
return undefined;
},
};

return {
plugin,
Expand All @@ -42,6 +63,8 @@ export const testPlugin = (
const start = plugin.start(anotherCoreStart, {
inspector: inspectorPluginMock.createStartContract(),
uiActions: uiActionsPluginMock.createStartContract(),
savedObjectsManagement:
savedObjectsManagementMock as unknown as SavedObjectsManagementPluginStart,
});
return start;
},
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/embeddable/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
"@kbn/data-plugin",
"@kbn/core-overlays-browser-mocks",
"@kbn/core-theme-browser-mocks",
"@kbn/saved-objects-management-plugin",
"@kbn/saved-objects-tagging-oss-plugin",
"@kbn/saved-objects-finder-plugin",
],
"exclude": [
"target/**/*",
Expand Down
4 changes: 1 addition & 3 deletions src/plugins/saved_objects_finder/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
"id": "savedObjectsFinder",
"server": true,
"browser": true,
"requiredBundles": [
"savedObjects"
]
"requiredBundles": ["savedObjects"]
}
}
21 changes: 20 additions & 1 deletion src/plugins/saved_objects_finder/public/finder/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@

import { EuiDelayRender, EuiLoadingContent } from '@elastic/eui';
import React from 'react';
import { IUiSettingsClient } from '@kbn/core-ui-settings-browser';
import { HttpStart } from '@kbn/core-http-browser';
import { SavedObjectsManagementPluginStart } from '@kbn/saved-objects-management-plugin/public';
import { SavedObjectsTaggingApi } from '@kbn/saved-objects-tagging-oss-plugin/public';
import type { SavedObjectFinderProps } from './saved_object_finder';
import SavedObjectFinderUi from './saved_object_finder';
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm making this difficult, sorry 😅. It looks like there's still a 4kb bundle increase and I think it's because of this import which is no longer used since we switched to the lazy one for getSavedObjectFinder. Could we remove this import and its export below and see if that fixes the bundle size increase? If it doesn't fix it, I'll give up and approve anyway -- just want to see if that does it first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it should be fine now


const LazySavedObjectFinder = React.lazy(() => import('./saved_object_finder'));
const SavedObjectFinder = (props: SavedObjectFinderProps) => (
Expand All @@ -23,5 +28,19 @@ const SavedObjectFinder = (props: SavedObjectFinderProps) => (
</React.Suspense>
);

export const getSavedObjectFinder = (
uiSettings: IUiSettingsClient,
http: HttpStart,
savedObjectsManagement: SavedObjectsManagementPluginStart,
savedObjectsTagging?: SavedObjectsTaggingApi
) => {
return (props: SavedObjectFinderProps) => (
<SavedObjectFinderUi
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
<SavedObjectFinderUi
<SavedObjectFinder

Any chance we could use the lazy loaded component here instead to avoid the hit to page load bundles?

{...props}
services={{ uiSettings, http, savedObjectsManagement, savedObjectsTagging }}
/>
);
};

export type { SavedObjectMetaData, SavedObjectFinderProps } from './saved_object_finder';
export { SavedObjectFinder };
export { SavedObjectFinder, SavedObjectFinderUi };
Loading