Skip to content

Commit

Permalink
[8.x] Backport Attempt to get rid of SavedObjectClass (#192265) (#196130
Browse files Browse the repository at this point in the history
)

## Summary

Manual backport of "Attempt to get rid of SavedObjectClass (#192265)"

### Checklist

### 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]>
(cherry picked from commit ac29d0f)

# Conflicts:
#
src/plugins/dashboard/public/services/saved_objects_tagging/saved_objects_tagging.stub.ts
#
src/plugins/dashboard/public/services/saved_objects_tagging/saved_objects_tagging_service.ts
# src/plugins/dashboard/public/services/saved_objects_tagging/types.ts

## Summary

Summarize your PR. If it involves visual changes include a screenshot or
gif.


### Checklist
rudolf authored Oct 15, 2024
1 parent 89f85ab commit 0e205fa
Showing 41 changed files with 10 additions and 2,022 deletions.
3 changes: 0 additions & 3 deletions src/plugins/saved_objects/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -9,9 +9,6 @@
"requiredPlugins": [
"data",
"dataViews"
],
"requiredBundles": [
"kibanaUtils"
]
}
}
6 changes: 0 additions & 6 deletions src/plugins/saved_objects/public/index.ts
Original file line number Diff line number Diff line change
@@ -11,13 +11,7 @@ import { SavedObjectsPublicPlugin } from './plugin';

export type { OnSaveProps, OriginSaveModalProps, SaveModalState, SaveResult } from './save_modal';
export { SavedObjectSaveModal, SavedObjectSaveModalOrigin, showSaveModal } from './save_modal';
export type {
SavedObjectDecorator,
SavedObjectDecoratorFactory,
SavedObjectDecoratorConfig,
} from './saved_object';
export { checkForDuplicateTitle, saveWithConfirmation, isErrorNonFatal } from './saved_object';
export type { SavedObjectSaveOpts, SavedObject, SavedObjectConfig } from './types';
export type { SavedObjectsStart, SavedObjectSetup } from './plugin';

export const plugin = () => new SavedObjectsPublicPlugin();
19 changes: 1 addition & 18 deletions src/plugins/saved_objects/public/mocks.ts
Original file line number Diff line number Diff line change
@@ -7,21 +7,4 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { SavedObjectsStart, SavedObjectSetup } from './plugin';

const createStartContract = (): SavedObjectsStart => {
return {
SavedObjectClass: jest.fn(),
};
};

const createSetupContract = (): jest.Mocked<SavedObjectSetup> => {
return {
registerDecorator: jest.fn(),
};
};

export const savedObjectsPluginMock = {
createStartContract,
createSetupContract,
};
export const savedObjectsPluginMock = {};
44 changes: 4 additions & 40 deletions src/plugins/saved_objects/public/plugin.ts
Original file line number Diff line number Diff line change
@@ -12,55 +12,19 @@ import { CoreStart, Plugin } from '@kbn/core/public';
import './index.scss';
import { DataPublicPluginStart } from '@kbn/data-plugin/public';
import { DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public';
import {
createSavedObjectClass,
SavedObjectDecoratorRegistry,
SavedObjectDecoratorConfig,
} from './saved_object';
import { SavedObject } from './types';
import { setStartServices } from './kibana_services';

export interface SavedObjectSetup {
registerDecorator: (config: SavedObjectDecoratorConfig<any>) => void;
}

export interface SavedObjectsStart {
/**
* @deprecated
* @removeBy 8.8.0
*/
SavedObjectClass: new (raw: Record<string, any>) => SavedObject;
}

export interface SavedObjectsStartDeps {
data: DataPublicPluginStart;
dataViews: DataViewsPublicPluginStart;
}

export class SavedObjectsPublicPlugin
implements Plugin<SavedObjectSetup, SavedObjectsStart, object, SavedObjectsStartDeps>
{
private decoratorRegistry = new SavedObjectDecoratorRegistry();

public setup(): SavedObjectSetup {
return {
registerDecorator: (config) => this.decoratorRegistry.register(config),
};
export class SavedObjectsPublicPlugin implements Plugin<{}, {}, object, SavedObjectsStartDeps> {
public setup() {
return {};
}
public start(core: CoreStart, { data, dataViews }: SavedObjectsStartDeps) {
setStartServices(core);
return {
SavedObjectClass: createSavedObjectClass(
{
dataViews,
savedObjectsClient: core.savedObjects.client,
search: data.search,
chrome: core.chrome,
overlays: core.overlays,
},
core,
this.decoratorRegistry
),
};
return {};
}
}
12 changes: 0 additions & 12 deletions src/plugins/saved_objects/public/saved_object/decorators/index.ts

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

34 changes: 0 additions & 34 deletions src/plugins/saved_objects/public/saved_object/decorators/types.ts

This file was deleted.

This file was deleted.

7 changes: 0 additions & 7 deletions src/plugins/saved_objects/public/saved_object/index.ts
Original file line number Diff line number Diff line change
@@ -7,13 +7,6 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export { createSavedObjectClass } from './saved_object';
export { checkForDuplicateTitle } from './helpers/check_for_duplicate_title';
export { saveWithConfirmation } from './helpers/save_with_confirmation';
export { isErrorNonFatal } from './helpers/save_saved_object';
export type {
SavedObjectDecoratorFactory,
SavedObjectDecorator,
SavedObjectDecoratorConfig,
} from './decorators';
export { SavedObjectDecoratorRegistry } from './decorators';
888 changes: 0 additions & 888 deletions src/plugins/saved_objects/public/saved_object/saved_object.test.ts

This file was deleted.

51 changes: 0 additions & 51 deletions src/plugins/saved_objects/public/saved_object/saved_object.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/plugins/saved_objects/tsconfig.json
Original file line number Diff line number Diff line change
@@ -11,7 +11,6 @@
"@kbn/i18n",
"@kbn/data-views-plugin",
"@kbn/i18n-react",
"@kbn/utility-types",
"@kbn/ui-theme",
"@kbn/react-kibana-mount",
"@kbn/test-jest-helpers",
2 changes: 0 additions & 2 deletions src/plugins/saved_objects_tagging_oss/public/api.mock.ts
Original file line number Diff line number Diff line change
@@ -55,8 +55,6 @@ type SavedObjectsTaggingApiUiMock = Omit<jest.Mocked<SavedObjectsTaggingApiUi>,
const createApiUiMock = () => {
const mock: SavedObjectsTaggingApiUiMock = {
components: createApiUiComponentsMock(),
// TS is very picky with type guards
hasTagDecoration: jest.fn() as any,
getSearchBarFilter: jest.fn(),
getTableColumnDefinition: jest.fn(),
convertNameToReference: jest.fn(),
14 changes: 0 additions & 14 deletions src/plugins/saved_objects_tagging_oss/public/api.ts
Original file line number Diff line number Diff line change
@@ -12,8 +12,6 @@ import { SearchFilterConfig, EuiTableFieldDataColumnType, EuiComboBoxProps } fro
import type { FunctionComponent } from 'react';
import { SavedObject, SavedObjectReference } from '@kbn/core/types';
import { SavedObjectsFindOptionsReference } from '@kbn/core/public';
import { SavedObject as SavedObjectClass } from '@kbn/saved-objects-plugin/public';
import { TagDecoratedSavedObject } from './decorator';
import { ITagsClient, Tag, TagWithOptionalId } from '../common';

/**
@@ -50,11 +48,6 @@ export interface ITagsCache {
getState$(params?: { waitForInitialization?: boolean }): Observable<Tag[]>;
}

/**
* @public
*/
export type SavedObjectTagDecoratorTypeGuard = SavedObjectsTaggingApiUi['hasTagDecoration'];

/**
* React components and utility methods to use the SO tagging feature
*
@@ -72,13 +65,6 @@ export interface SavedObjectsTaggingApiUi {
*/
getTagList(): Tag[];

/**
* Type-guard to safely manipulate tag-enhanced `SavedObject` from the `savedObject` plugin.
*
* @param object
*/
hasTagDecoration(object: SavedObjectClass): object is TagDecoratedSavedObject;

/**
* Return a filter that can be used to filter by tag with `EuiSearchBar` or EUI tables using `EuiSearchBar`.
*

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

25 changes: 0 additions & 25 deletions src/plugins/saved_objects_tagging_oss/public/decorator/factory.ts

This file was deleted.

20 changes: 0 additions & 20 deletions src/plugins/saved_objects_tagging_oss/public/decorator/index.ts

This file was deleted.

This file was deleted.

This file was deleted.

25 changes: 0 additions & 25 deletions src/plugins/saved_objects_tagging_oss/public/decorator/types.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/plugins/saved_objects_tagging_oss/public/index.ts
Original file line number Diff line number Diff line change
@@ -23,11 +23,8 @@ export type {
ParsedSearchQuery,
ParseSearchQueryOptions,
SavedObjectSaveModalTagSelectorComponentProps,
SavedObjectTagDecoratorTypeGuard,
GetTableColumnDefinitionOptions,
} from './api';

export type { TagDecoratedSavedObject } from './decorator';

export const plugin = (initializerContext: PluginInitializerContext) =>
new SavedObjectTaggingOssPlugin(initializerContext);
25 changes: 3 additions & 22 deletions src/plugins/saved_objects_tagging_oss/public/plugin.test.ts
Original file line number Diff line number Diff line change
@@ -8,8 +8,6 @@
*/

import { coreMock } from '@kbn/core/public/mocks';
import { savedObjectsPluginMock } from '@kbn/saved-objects-plugin/public/mocks';
import { tagDecoratorConfig } from './decorator';
import { taggingApiMock } from './api.mock';
import { SavedObjectTaggingOssPlugin } from './plugin';

@@ -22,23 +20,6 @@ describe('SavedObjectTaggingOssPlugin', () => {
plugin = new SavedObjectTaggingOssPlugin(coreMock.createPluginInitializerContext());
});

describe('#setup', () => {
it('registers the tag SO decorator if the `savedObjects` plugin is present', () => {
const savedObjects = savedObjectsPluginMock.createSetupContract();

plugin.setup(coreSetup, { savedObjects });

expect(savedObjects.registerDecorator).toHaveBeenCalledTimes(1);
expect(savedObjects.registerDecorator).toHaveBeenCalledWith(tagDecoratorConfig);
});

it('does not fail if the `savedObjects` plugin is not present', () => {
expect(() => {
plugin.setup(coreSetup, {});
}).not.toThrow();
});
});

describe('#start', () => {
let coreStart: ReturnType<typeof coreMock.createStart>;

@@ -54,7 +35,7 @@ describe('SavedObjectTaggingOssPlugin', () => {

it('returns the tagging API if registered', async () => {
const taggingApi = taggingApiMock.create();
const { registerTaggingApi } = plugin.setup(coreSetup, {});
const { registerTaggingApi } = plugin.setup(coreSetup);

registerTaggingApi(Promise.resolve(taggingApi));

@@ -66,7 +47,7 @@ describe('SavedObjectTaggingOssPlugin', () => {
expect(getTaggingApi()).toStrictEqual(taggingApi);
});
it('does not return the tagging API if not registered', async () => {
plugin.setup(coreSetup, {});
plugin.setup(coreSetup);

await nextTick();

@@ -76,7 +57,7 @@ describe('SavedObjectTaggingOssPlugin', () => {
expect(getTaggingApi()).toBeUndefined();
});
it('does not return the tagging API if resolution promise rejects', async () => {
const { registerTaggingApi } = plugin.setup(coreSetup, {});
const { registerTaggingApi } = plugin.setup(coreSetup);

registerTaggingApi(Promise.reject(new Error('something went bad')));

15 changes: 2 additions & 13 deletions src/plugins/saved_objects_tagging_oss/public/plugin.ts
Original file line number Diff line number Diff line change
@@ -8,29 +8,18 @@
*/

import { CoreSetup, CoreStart, PluginInitializerContext, Plugin } from '@kbn/core/public';
import { SavedObjectSetup } from '@kbn/saved-objects-plugin/public';
import { SavedObjectTaggingOssPluginSetup, SavedObjectTaggingOssPluginStart } from './types';
import { SavedObjectsTaggingApi } from './api';
import { tagDecoratorConfig } from './decorator';

interface SetupDeps {
savedObjects?: SavedObjectSetup;
}

export class SavedObjectTaggingOssPlugin
implements
Plugin<SavedObjectTaggingOssPluginSetup, SavedObjectTaggingOssPluginStart, SetupDeps, {}>
implements Plugin<SavedObjectTaggingOssPluginSetup, SavedObjectTaggingOssPluginStart, {}>
{
private apiRegistered = false;
private api?: SavedObjectsTaggingApi;

constructor(context: PluginInitializerContext) {}

public setup({}: CoreSetup, { savedObjects }: SetupDeps) {
if (savedObjects) {
savedObjects.registerDecorator(tagDecoratorConfig);
}

public setup({}: CoreSetup) {
return {
registerTaggingApi: (provider: Promise<SavedObjectsTaggingApi>) => {
if (this.apiRegistered) {
1 change: 0 additions & 1 deletion src/plugins/saved_objects_tagging_oss/tsconfig.json
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@
],
"kbn_references": [
"@kbn/core",
"@kbn/saved-objects-plugin",
],
"exclude": [
"target/**/*",
2 changes: 0 additions & 2 deletions src/plugins/visualizations/public/mocks.ts
Original file line number Diff line number Diff line change
@@ -17,7 +17,6 @@ import { dataViewPluginMocks } from '@kbn/data-views-plugin/public/mocks';
import { indexPatternEditorPluginMock } from '@kbn/data-view-editor-plugin/public/mocks';
import { uiActionsPluginMock } from '@kbn/ui-actions-plugin/public/mocks';
import { inspectorPluginMock } from '@kbn/inspector-plugin/public/mocks';
import { savedObjectsPluginMock } from '@kbn/saved-objects-plugin/public/mocks';
import { urlForwardingPluginMock } from '@kbn/url-forwarding-plugin/public/mocks';
import { navigationPluginMock } from '@kbn/navigation-plugin/public/mocks';
import { presentationUtilPluginMock } from '@kbn/presentation-util-plugin/public/mocks';
@@ -77,7 +76,6 @@ const createInstance = async () => {
embeddable: embeddablePluginMock.createStartContract(),
spaces: spacesPluginMock.createStartContract(),
savedObjectsClient: coreMock.createStart().savedObjects.client,
savedObjects: savedObjectsPluginMock.createStartContract(),
savedObjectsTaggingOss: savedObjectTaggingOssPluginMock.createStart(),
savedSearch: savedSearchPluginMock.createStartContract(),
navigation: navigationPluginMock.createStartContract(),
2 changes: 0 additions & 2 deletions src/plugins/visualizations/public/plugin.ts
Original file line number Diff line number Diff line change
@@ -38,7 +38,6 @@ import type {
SavedObjectsClientContract,
} from '@kbn/core/public';
import { UiActionsStart, UiActionsSetup, ADD_PANEL_TRIGGER } from '@kbn/ui-actions-plugin/public';
import type { SavedObjectsStart } from '@kbn/saved-objects-plugin/public';
import type { FieldFormatsStart } from '@kbn/field-formats-plugin/public';
import type {
Setup as InspectorSetup,
@@ -166,7 +165,6 @@ export interface VisualizationsStartDeps {
application: ApplicationStart;
navigation: NavigationStart;
presentationUtil: PresentationUtilPluginStart;
savedObjects: SavedObjectsStart;
savedObjectsClient: SavedObjectsClientContract;
savedSearch: SavedSearchPublicPluginStart;
spaces?: SpacesPluginStart;

This file was deleted.

2 changes: 0 additions & 2 deletions x-pack/plugins/saved_objects_tagging/public/ui_api/index.ts
Original file line number Diff line number Diff line change
@@ -21,7 +21,6 @@ import { buildGetSearchBarFilter } from './get_search_bar_filter';
import { buildParseSearchQuery } from './parse_search_query';
import { buildConvertNameToReference } from './convert_name_to_reference';
import { buildGetTagList } from './get_tag_list';
import { hasTagDecoration } from './has_tag_decoration';

interface GetUiApiOptions extends StartServices {
capabilities: TagsCapabilities;
@@ -50,7 +49,6 @@ export const getUiApi = ({
getSearchBarFilter: buildGetSearchBarFilter({ getTagList }),
parseSearchQuery: buildParseSearchQuery({ cache }),
convertNameToReference: buildConvertNameToReference({ cache }),
hasTagDecoration,
getTagIdsFromReferences,
getTagIdFromName: (tagName: string) => convertTagNameToId(tagName, cache.getState()),
updateTagsReferences,
Original file line number Diff line number Diff line change
@@ -15,7 +15,6 @@ import type { ScopedHistory } from '@kbn/core/public';
import { coreMock, themeServiceMock } from '@kbn/core/public/mocks';
import { dataPluginMock } from '@kbn/data-plugin/public/mocks';
import { dataViewPluginMocks } from '@kbn/data-views-plugin/public/mocks';
import { savedObjectsPluginMock } from '@kbn/saved-objects-plugin/public/mocks';
import { chartPluginMock } from '@kbn/charts-plugin/public/mocks';
import { fieldFormatsServiceMock } from '@kbn/field-formats-plugin/public/mocks';
import type { SharePluginStart } from '@kbn/share-plugin/public';
@@ -88,7 +87,6 @@ const appDependencies: AppDependencies = {
theme: themeServiceMock.createStartContract(),
http: coreSetup.http,
history: {} as ScopedHistory,
savedObjectsPlugin: savedObjectsPluginMock.createStartContract(),
share: { urlGenerators: { getUrlGenerator: jest.fn() } } as unknown as SharePluginStart,
triggersActionsUi: {} as jest.Mocked<TriggersAndActionsUIPublicPluginStart>,
unifiedSearch: unifiedSearchPluginMock.createStartContract(),
2 changes: 0 additions & 2 deletions x-pack/plugins/transform/public/app/app_dependencies.tsx
Original file line number Diff line number Diff line change
@@ -19,7 +19,6 @@ import type {
ScopedHistory,
ThemeServiceStart,
} from '@kbn/core/public';
import type { SavedObjectsStart as SavedObjectsPluginStart } from '@kbn/saved-objects-plugin/public';
import type { DataPublicPluginStart } from '@kbn/data-plugin/public';
import type { DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public';
import type { SharePluginStart } from '@kbn/share-plugin/public';
@@ -59,7 +58,6 @@ export interface AppDependencies {
overlays: OverlayStart;
theme: ThemeServiceStart;
history: ScopedHistory;
savedObjectsPlugin: SavedObjectsPluginStart;
share: SharePluginStart;
spaces?: SpacesPluginStart;
triggersActionsUi: TriggersAndActionsUIPublicPluginStart;
Original file line number Diff line number Diff line change
@@ -84,7 +84,6 @@ export async function mountManagementSection(
uiSettings,
settings,
history,
savedObjectsPlugin: plugins.savedObjects,
share,
spaces,
triggersActionsUi,
2 changes: 0 additions & 2 deletions x-pack/plugins/transform/public/plugin.ts
Original file line number Diff line number Diff line change
@@ -11,7 +11,6 @@ import type { CoreSetup } from '@kbn/core/public';
import type { DataPublicPluginStart } from '@kbn/data-plugin/public';
import type { DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public';
import type { HomePublicPluginSetup } from '@kbn/home-plugin/public';
import type { SavedObjectsStart } from '@kbn/saved-objects-plugin/public';
import type { ManagementSetup } from '@kbn/management-plugin/public';
import type { SharePluginStart } from '@kbn/share-plugin/public';
import type { SpacesApi } from '@kbn/spaces-plugin/public';
@@ -37,7 +36,6 @@ export interface PluginsDependencies {
dataViews: DataViewsPublicPluginStart;
management: ManagementSetup;
home: HomePublicPluginSetup;
savedObjects: SavedObjectsStart;
savedSearch: SavedSearchPublicPluginStart;
share: SharePluginStart;
spaces?: SpacesApi;
1 change: 0 additions & 1 deletion x-pack/plugins/transform/tsconfig.json
Original file line number Diff line number Diff line change
@@ -23,7 +23,6 @@
"@kbn/alerting-plugin",
"@kbn/data-views-plugin",
"@kbn/home-plugin",
"@kbn/saved-objects-plugin",
"@kbn/management-plugin",
"@kbn/share-plugin",
"@kbn/spaces-plugin",

0 comments on commit 0e205fa

Please sign in to comment.