Skip to content

Commit

Permalink
[Saved Object Finder] Move to the component in saved_objects_finder p…
Browse files Browse the repository at this point in the history
…lugin (elastic#151764)

## Summary

This PR replaces the `SavedObjectsFinder` component from `saved_objects`
plugin with the one in `saved_objects_finder` plugin. Code changes are
pretty straightforward; most of the changes are around modifying the
functional tests to work with the selectors from the new component.

### Checklist

Delete any items that are not applicable to this PR.

~- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)~
~- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials~
- [X] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
~- [ ] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard
accessibility](https://webaim.org/techniques/keyboard/))~
~- [ ] Any UI touched in this PR does not create any new axe failures
(run axe in browser:
[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),
[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))~
~- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)~
~- [ ] This renders correctly on smaller devices using a responsive
layout. (You can test this [in your
browser](https://www.browserstack.com/guide/responsive-testing-on-local-server))~
~- [ ] This was checked for [cross-browser
compatibility](https://www.elastic.co/support/matrix#matrix_browsers)~!



### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

---------

Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
2 people authored and bmorelli25 committed Mar 10, 2023
1 parent 77a2b90 commit d93c44e
Show file tree
Hide file tree
Showing 34 changed files with 310 additions and 107 deletions.
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,7 +8,7 @@

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 { pluginServices } from '../../../services/plugin_services';
import { DashboardContainer } from '../dashboard_container';
Expand All @@ -21,12 +21,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
),
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"]
}
}
18 changes: 18 additions & 0 deletions src/plugins/saved_objects_finder/public/finder/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

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';

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

export const getSavedObjectFinder = (
uiSettings: IUiSettingsClient,
http: HttpStart,
savedObjectsManagement: SavedObjectsManagementPluginStart,
savedObjectsTagging?: SavedObjectsTaggingApi
) => {
return (props: SavedObjectFinderProps) => (
<SavedObjectFinder
{...props}
services={{ uiSettings, http, savedObjectsManagement, savedObjectsTagging }}
/>
);
};

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

0 comments on commit d93c44e

Please sign in to comment.