Skip to content

Commit

Permalink
wip bwc savedobjectfinder
Browse files Browse the repository at this point in the history
  • Loading branch information
Dosant committed Aug 2, 2023
1 parent 4dadcbb commit 8f08e60
Show file tree
Hide file tree
Showing 84 changed files with 475 additions and 816 deletions.
3 changes: 2 additions & 1 deletion examples/content_management_examples/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"developerExamples",
"kibanaReact",
"savedObjectsTaggingOss"
]
],
"requiredBundles": ["savedObjectsFinder"]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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 React from 'react';
import { ContentClientProvider, type ContentClient } from '@kbn/content-management-plugin/public';
import type { CoreStart } from '@kbn/core/public';
import { I18nProvider } from '@kbn/i18n-react';
import { SavedObjectTaggingOssPluginStart } from '@kbn/saved-objects-tagging-oss-plugin/public';
import { SavedObjectFinder } from '@kbn/saved-objects-finder-plugin/public';

export const FinderApp = (props: {
contentClient: ContentClient;
core: CoreStart;
savedObjectsTagging: SavedObjectTaggingOssPluginStart;
}) => {
return (
<ContentClientProvider contentClient={props.contentClient}>
<I18nProvider>
<SavedObjectFinder
showFilter={true}
services={{
savedObjectsTagging: props.savedObjectsTagging.getTaggingApi(),
contentClient: props.contentClient,
}}
onChoose={(...args) => {
alert(JSON.stringify(args));
}}
savedObjectMetaData={[
{
type: `search`,
getIconForSavedObject: () => 'discoverApp',
name: 'Saved search',
},
{
type: 'index-pattern',
getIconForSavedObject: () => 'indexPatternApp',
name: 'Data view',
},
]}
/>
</I18nProvider>
</ContentClientProvider>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,4 @@
* Side Public License, v 1.
*/

export const registerRoutesMock = jest.fn();
jest.doMock('./routes', () => ({
registerRoutes: registerRoutesMock,
}));
export { FinderApp } from './finder_app';
14 changes: 14 additions & 0 deletions examples/content_management_examples/public/examples/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { AppMountParameters, CoreStart } from '@kbn/core/public';
import { StartDeps } from '../types';
import { TodoApp } from './todos';
import { MSearchApp } from './msearch';
import { FinderApp } from './finder';

export const renderApp = (
core: CoreStart,
Expand Down Expand Up @@ -45,6 +46,12 @@ export const renderApp = (
'data-test-subj': 'msearchExample',
href: '/app/contentManagementExamples/msearch',
},
{
id: 'finder',
name: 'Finder',
'data-test-subj': 'finderExample',
href: '/app/contentManagementExamples/finder',
},
],
},
]}
Expand All @@ -64,6 +71,13 @@ export const renderApp = (
savedObjectsTagging={savedObjectsTaggingOss}
/>
</Route>
<Route path="/finder">
<FinderApp
contentClient={contentManagement.client}
core={core}
savedObjectsTagging={savedObjectsTaggingOss}
/>
</Route>
</Routes>
</EuiPageTemplate.Section>
</EuiPageTemplate>
Expand Down
1 change: 1 addition & 0 deletions examples/content_management_examples/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@
"@kbn/content-management-table-list-view-table",
"@kbn/content-management-table-list-view",
"@kbn/shared-ux-router",
"@kbn/saved-objects-finder-plugin",
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export interface SOContentStorageConstrutorParams<Types extends CMCrudTypes> {
updateArgsToSoUpdateOptions?: UpdateArgsToSoUpdateOptions<Types>;
searchArgsToSOFindOptions?: SearchArgsToSOFindOptions<Types>;
enableMSearch?: boolean;
mSearchAdditionalSearchFields?: string[];
}

export abstract class SOContentStorage<Types extends CMCrudTypes>
Expand All @@ -153,6 +154,7 @@ export abstract class SOContentStorage<Types extends CMCrudTypes>
searchArgsToSOFindOptions,
enableMSearch,
allowedSavedObjectAttributes,
mSearchAdditionalSearchFields,
}: SOContentStorageConstrutorParams<Types>) {
this.savedObjectType = savedObjectType;
this.cmServicesDefinition = cmServicesDefinition;
Expand All @@ -166,6 +168,7 @@ export abstract class SOContentStorage<Types extends CMCrudTypes>
if (enableMSearch) {
this.mSearch = {
savedObjectType: this.savedObjectType,
additionalSearchFields: mSearchAdditionalSearchFields,
toItemResult: (ctx: StorageContext, savedObject: SavedObjectsFindResult): Types['Item'] => {
const transforms = ctx.utils.getTransforms(this.cmServicesDefinition);

Expand Down Expand Up @@ -201,6 +204,7 @@ export abstract class SOContentStorage<Types extends CMCrudTypes>
mSearch?: {
savedObjectType: string;
toItemResult: (ctx: StorageContext, savedObject: SavedObjectsFindResult) => Types['Item'];
additionalSearchFields?: string[];
};

async get(ctx: StorageContext, id: string): Promise<Types['GetOut']> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@

import React, { useEffect, useState } from 'react';
import { i18n } from '@kbn/i18n';
import type { CoreStart } from '@kbn/core/public';
import { FormattedMessage } from '@kbn/i18n-react';
import type { IUiSettingsClient } from '@kbn/core-ui-settings-browser';
import type { SavedObjectCommon } from '@kbn/saved-objects-finder-plugin/common';
import { SavedObjectFinder } from '@kbn/saved-objects-finder-plugin/public';
import type { SavedObjectsManagementPluginStart } from '@kbn/saved-objects-management-plugin/public';
import type { ContentClient } from '@kbn/content-management-plugin/public';
import {
EuiButton,
EuiEmptyPrompt,
Expand All @@ -26,17 +24,13 @@ import { css } from '@emotion/react';
import { EVENT_ANNOTATION_GROUP_TYPE } from '@kbn/event-annotation-common';

export const EventAnnotationGroupSavedObjectFinder = ({
uiSettings,
http,
savedObjectsManagement,
fixedPageSize = 10,
checkHasAnnotationGroups,
onChoose,
onCreateNew,
contentClient,
}: {
uiSettings: IUiSettingsClient;
http: CoreStart['http'];
savedObjectsManagement: SavedObjectsManagementPluginStart;
contentClient: ContentClient;
fixedPageSize?: number;
checkHasAnnotationGroups: () => Promise<boolean>;
onChoose: (value: {
Expand Down Expand Up @@ -115,9 +109,7 @@ export const EventAnnotationGroupSavedObjectFinder = ({
}
savedObjectMetaData={savedObjectMetaData}
services={{
uiSettings,
http,
savedObjectsManagement,
contentClient,
}}
/>
);
Expand Down
3 changes: 1 addition & 2 deletions packages/kbn-event-annotation-components/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@
"@kbn/content-management-table-list-view-table",
"@kbn/content-management-tabbed-table-list-view",
"@kbn/event-annotation-common",
"@kbn/core",
"@kbn/i18n-react",
"@kbn/saved-objects-finder-plugin",
"@kbn/saved-objects-management-plugin",
"@kbn/core-notifications-browser-mocks",
"@kbn/core-notifications-browser",
"@kbn/core-saved-objects-api-browser",
"@kbn/expressions-plugin",
"@kbn/content-management-plugin",
]
}
1 change: 1 addition & 0 deletions src/plugins/content_management/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const createStartContract = (): ContentManagementPublicStart => {
update: jest.fn(),
delete: jest.fn(),
search: jest.fn(),
mSearch: jest.fn(),
} as unknown as ContentManagementPublicStart['client'],
registry: {
get: jest.fn(),
Expand Down
8 changes: 2 additions & 6 deletions src/plugins/dashboard/public/dashboard_actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,14 @@ export const buildAllDashboardActions = async ({
plugins,
allowByValueEmbeddables,
}: BuildAllDashboardActionsProps) => {
const { uiSettings } = core;
const { uiActions, share, presentationUtil, savedObjectsManagement, savedObjectsTaggingOss } =
plugins;
const { uiActions, share, presentationUtil, savedObjectsTaggingOss, contentManagement } = plugins;

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

const SavedObjectFinder = getSavedObjectFinder(
uiSettings,
core.http,
savedObjectsManagement,
contentManagement.client,
savedObjectsTaggingOss?.getTaggingApi()
);
const changeViewAction = new ReplacePanelAction(SavedObjectFinder);
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 { ContentManagementPublicStart } from '@kbn/content-management-plugin/public';
import { contentManagementMock } from '@kbn/content-management-plugin/public/mocks';

export type ContentManagementServiceFactory = PluginServiceFactory<ContentManagementPublicStart>;

export const contentManagementServiceFactory: ContentManagementServiceFactory = () => {
return contentManagementMock.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 { ContentManagementPublicStart } from '@kbn/content-management-plugin/public';
import { DashboardStartDependencies } from '../../plugin';

export type ContentManagementServiceFactory = KibanaPluginServiceFactory<
ContentManagementPublicStart,
DashboardStartDependencies
>;

export const contentManagementServiceFactory: ContentManagementServiceFactory = ({
startPlugins,
}) => {
const { contentManagement } = startPlugins;

return contentManagement;
};
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 @@ -40,6 +40,7 @@ import { visualizationsServiceFactory } from './visualizations/visualizations.st
import { dashboardContentManagementServiceFactory } from './dashboard_content_management/dashboard_content_management.stub';
import { customBrandingServiceFactory } from './custom_branding/custom_branding.stub';
import { savedObjectsManagementServiceFactory } from './saved_objects_management/saved_objects_management_service.stub';
import { contentManagementServiceFactory } from './content_management/content_management_service.stub';

export const providers: PluginServiceProviders<DashboardServices> = {
dashboardContentManagement: new PluginServiceProvider(dashboardContentManagementServiceFactory),
Expand Down Expand Up @@ -68,6 +69,7 @@ export const providers: PluginServiceProviders<DashboardServices> = {
visualizations: new PluginServiceProvider(visualizationsServiceFactory),
customBranding: new PluginServiceProvider(customBrandingServiceFactory),
savedObjectsManagement: new PluginServiceProvider(savedObjectsManagementServiceFactory),
contentManagement: new PluginServiceProvider(contentManagementServiceFactory),
};

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 @@ -41,6 +41,7 @@ import { analyticsServiceFactory } from './analytics/analytics_service';
import { customBrandingServiceFactory } from './custom_branding/custom_branding_service';
import { savedObjectsManagementServiceFactory } from './saved_objects_management/saved_objects_management_service';
import { dashboardContentManagementServiceFactory } from './dashboard_content_management/dashboard_content_management_service';
import { contentManagementServiceFactory } from './content_management/content_management_service';

const providers: PluginServiceProviders<DashboardServices, DashboardPluginServiceParams> = {
dashboardContentManagement: new PluginServiceProvider(dashboardContentManagementServiceFactory, [
Expand Down Expand Up @@ -82,6 +83,7 @@ const providers: PluginServiceProviders<DashboardServices, DashboardPluginServic
visualizations: new PluginServiceProvider(visualizationsServiceFactory),
customBranding: new PluginServiceProvider(customBrandingServiceFactory),
savedObjectsManagement: new PluginServiceProvider(savedObjectsManagementServiceFactory),
contentManagement: new PluginServiceProvider(contentManagementServiceFactory),
};

export const pluginServices = new PluginServices<DashboardServices>();
Expand Down
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 @@ -9,6 +9,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 { ContentManagementPublicStart } from '@kbn/content-management-plugin/public';

import { DashboardStartDependencies } from '../plugin';
import { DashboardAnalyticsService } from './analytics/types';
Expand Down Expand Up @@ -68,4 +69,5 @@ export interface DashboardServices {
visualizations: DashboardVisualizationsService;
customBranding: DashboardCustomBrandingService;
savedObjectsManagement: SavedObjectsManagementPluginStart;
contentManagement: ContentManagementPublicStart;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class DataViewsStorage extends SOContentStorage<DataViewCrudTypes> {
'allowNoIndex',
'name',
],
mSearchAdditionalSearchFields: ['name'],
});
}
}
13 changes: 4 additions & 9 deletions src/plugins/discover/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"dataViewEditor",
"expressions",
"unifiedSearch",
"unifiedHistogram"
"unifiedHistogram",
"contentManagement"
],
"optionalPlugins": [
"home",
Expand All @@ -36,13 +37,7 @@
"savedObjectsTaggingOss",
"lens"
],
"requiredBundles": [
"kibanaUtils",
"kibanaReact",
"unifiedSearch"
],
"extraPublicDirs": [
"common"
]
"requiredBundles": ["kibanaUtils", "kibanaReact", "unifiedSearch"],
"extraPublicDirs": ["common"]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,7 @@ interface OpenSearchPanelProps {
}

export function OpenSearchPanel(props: OpenSearchPanelProps) {
const {
addBasePath,
capabilities,
core,
uiSettings,
savedObjectsManagement,
savedObjectsTagging,
} = useDiscoverServices();
const { addBasePath, capabilities, savedObjectsTagging, contentClient } = useDiscoverServices();
const hasSavedObjectPermission =
capabilities.savedObjectsManagement?.edit || capabilities.savedObjectsManagement?.delete;

Expand All @@ -56,10 +49,8 @@ export function OpenSearchPanel(props: OpenSearchPanelProps) {
<EuiFlyoutBody>
<SavedObjectFinder
services={{
http: core.http,
uiSettings,
savedObjectsManagement,
savedObjectsTagging,
contentClient,
}}
noItemsMessage={
<FormattedMessage
Expand Down
Loading

0 comments on commit 8f08e60

Please sign in to comment.