From a7b11de17e19e175261c72b8ca67cb60d572f09f Mon Sep 17 00:00:00 2001 From: Nick Peihl Date: Tue, 4 Feb 2025 16:15:56 -0500 Subject: [PATCH 1/4] Expose content management request method on Dashboard server contract --- src/platform/plugins/shared/dashboard/server/plugin.ts | 8 ++++++-- src/platform/plugins/shared/dashboard/server/types.ts | 7 +++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/platform/plugins/shared/dashboard/server/plugin.ts b/src/platform/plugins/shared/dashboard/server/plugin.ts index a102fb39eaf34..37183897c0a1c 100644 --- a/src/platform/plugins/shared/dashboard/server/plugin.ts +++ b/src/platform/plugins/shared/dashboard/server/plugin.ts @@ -47,6 +47,7 @@ interface StartDeps { export class DashboardPlugin implements Plugin { + private contentClient?: ReturnType['contentClient']; private readonly logger: Logger; constructor(private initializerContext: PluginInitializerContext) { @@ -64,7 +65,7 @@ export class DashboardPlugin }) ); - plugins.contentManagement.register({ + const { contentClient } = plugins.contentManagement.register({ id: CONTENT_ID, storage: new DashboardStorage({ throwOnResultValidationError: this.initializerContext.env.mode.dev, @@ -74,6 +75,7 @@ export class DashboardPlugin latest: LATEST_VERSION, }, }); + this.contentClient = contentClient; plugins.contentManagement.favorites.registerFavoriteType('dashboard'); @@ -136,7 +138,9 @@ export class DashboardPlugin }); } - return {}; + return { + contentClient: this.contentClient, + }; } public stop() {} diff --git a/src/platform/plugins/shared/dashboard/server/types.ts b/src/platform/plugins/shared/dashboard/server/types.ts index 389f5d3c6227c..3302f82f1ae63 100644 --- a/src/platform/plugins/shared/dashboard/server/types.ts +++ b/src/platform/plugins/shared/dashboard/server/types.ts @@ -7,7 +7,10 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ +import { ContentManagementServerSetup } from '@kbn/content-management-plugin/server'; + // eslint-disable-next-line @typescript-eslint/no-empty-interface export interface DashboardPluginSetup {} -// eslint-disable-next-line @typescript-eslint/no-empty-interface -export interface DashboardPluginStart {} +export interface DashboardPluginStart { + contentClient?: ReturnType['contentClient']; +} From d85c3d5504f3bd62cae7e37f0319d8858adcbaf7 Mon Sep 17 00:00:00 2001 From: Nick Peihl Date: Tue, 11 Feb 2025 17:00:59 -0500 Subject: [PATCH 2/4] Dashboard should stop using mSearch --- .../public/examples/msearch/msearch_table.tsx | 1 - .../content_management/dashboard_storage.ts | 51 +------------------ .../dashboard_picker/dashboard_picker.tsx | 8 ++- 3 files changed, 7 insertions(+), 53 deletions(-) diff --git a/examples/content_management_examples/public/examples/msearch/msearch_table.tsx b/examples/content_management_examples/public/examples/msearch/msearch_table.tsx index 7176f94992034..22e36c77a3647 100644 --- a/examples/content_management_examples/public/examples/msearch/msearch_table.tsx +++ b/examples/content_management_examples/public/examples/msearch/msearch_table.tsx @@ -35,7 +35,6 @@ export const MSearchTable = () => { }, contentTypes: [ { contentTypeId: 'map' }, - { contentTypeId: 'dashboard' }, { contentTypeId: 'visualization' }, { contentTypeId: 'lens' }, { contentTypeId: 'search' }, diff --git a/src/platform/plugins/shared/dashboard/server/content_management/dashboard_storage.ts b/src/platform/plugins/shared/dashboard/server/content_management/dashboard_storage.ts index d113d509f5e89..db716a6d739fa 100644 --- a/src/platform/plugins/shared/dashboard/server/content_management/dashboard_storage.ts +++ b/src/platform/plugins/shared/dashboard/server/content_management/dashboard_storage.ts @@ -9,10 +9,7 @@ import Boom from '@hapi/boom'; import { tagsToFindOptions } from '@kbn/content-management-utils'; -import { - SavedObjectsFindOptions, - SavedObjectsFindResult, -} from '@kbn/core-saved-objects-api-server'; +import { SavedObjectsFindOptions } from '@kbn/core-saved-objects-api-server'; import type { Logger } from '@kbn/logging'; import { CreateResult, DeleteResult, SearchQuery } from '@kbn/content-management-plugin/common'; @@ -68,57 +65,11 @@ export class DashboardStorage { }) { this.logger = logger; this.throwOnResultValidationError = throwOnResultValidationError ?? false; - this.mSearch = { - savedObjectType: DASHBOARD_SAVED_OBJECT_TYPE, - additionalSearchFields: [], - toItemResult: (ctx: StorageContext, savedObject: SavedObjectsFindResult): DashboardItem => { - const transforms = ctx.utils.getTransforms(cmServicesDefinition); - - const { item, error: itemError } = savedObjectToItem( - savedObject as SavedObjectsFindResult, - false - ); - if (itemError) { - throw Boom.badRequest(`Invalid response. ${itemError.message}`); - } - - const validationError = transforms.mSearch.out.result.validate(item); - if (validationError) { - if (this.throwOnResultValidationError) { - throw Boom.badRequest(`Invalid response. ${validationError.message}`); - } else { - this.logger.warn(`Invalid response. ${validationError.message}`); - } - } - - // Validate DB response and DOWN transform to the request version - const { value, error: resultError } = transforms.mSearch.out.result.down< - DashboardItem, - DashboardItem - >( - item, - undefined, // do not override version - { validate: false } // validation is done above - ); - - if (resultError) { - throw Boom.badRequest(`Invalid response. ${resultError.message}`); - } - - return value; - }, - }; } private logger: Logger; private throwOnResultValidationError: boolean; - mSearch: { - savedObjectType: string; - toItemResult: (ctx: StorageContext, savedObject: SavedObjectsFindResult) => DashboardItem; - additionalSearchFields?: string[]; - }; - async get(ctx: StorageContext, id: string): Promise { const transforms = ctx.utils.getTransforms(cmServicesDefinition); const soClient = await savedObjectClientFromRequest(ctx); diff --git a/src/platform/plugins/shared/presentation_util/public/components/dashboard_picker/dashboard_picker.tsx b/src/platform/plugins/shared/presentation_util/public/components/dashboard_picker/dashboard_picker.tsx index 416071732b45a..9f372094677d7 100644 --- a/src/platform/plugins/shared/presentation_util/public/components/dashboard_picker/dashboard_picker.tsx +++ b/src/platform/plugins/shared/presentation_util/public/components/dashboard_picker/dashboard_picker.tsx @@ -23,6 +23,7 @@ import { import { i18n } from '@kbn/i18n'; import { ToolbarButton } from '@kbn/shared-ux-button-toolbar'; import { SavedObjectCommon } from '@kbn/saved-objects-finder-plugin/common'; +import type { SearchIn, SearchResult } from '@kbn/content-management-plugin/common'; import { contentManagementService } from '../../services/kibana_services'; @@ -73,8 +74,11 @@ export function DashboardPicker({ isDisabled, onChange, idsToOmit }: DashboardPi (async () => { setIsLoading(true); - const response = await contentManagementService.client.mSearch({ - contentTypes: [{ contentTypeId: 'dashboard' }], + const response = await contentManagementService.client.search< + SearchIn<'dashboard'>, + SearchResult + >({ + contentTypeId: 'dashboard', query: { text: debouncedQuery ? `${debouncedQuery}*` : undefined, limit: 30, From cd47284acac58565597119b8379d01f3ff9afe4a Mon Sep 17 00:00:00 2001 From: Nick Peihl Date: Tue, 11 Feb 2025 18:04:00 -0500 Subject: [PATCH 3/4] Remove changes from a different PR. --- src/platform/plugins/shared/dashboard/server/plugin.ts | 8 ++------ src/platform/plugins/shared/dashboard/server/types.ts | 7 ++----- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/platform/plugins/shared/dashboard/server/plugin.ts b/src/platform/plugins/shared/dashboard/server/plugin.ts index 37183897c0a1c..a102fb39eaf34 100644 --- a/src/platform/plugins/shared/dashboard/server/plugin.ts +++ b/src/platform/plugins/shared/dashboard/server/plugin.ts @@ -47,7 +47,6 @@ interface StartDeps { export class DashboardPlugin implements Plugin { - private contentClient?: ReturnType['contentClient']; private readonly logger: Logger; constructor(private initializerContext: PluginInitializerContext) { @@ -65,7 +64,7 @@ export class DashboardPlugin }) ); - const { contentClient } = plugins.contentManagement.register({ + plugins.contentManagement.register({ id: CONTENT_ID, storage: new DashboardStorage({ throwOnResultValidationError: this.initializerContext.env.mode.dev, @@ -75,7 +74,6 @@ export class DashboardPlugin latest: LATEST_VERSION, }, }); - this.contentClient = contentClient; plugins.contentManagement.favorites.registerFavoriteType('dashboard'); @@ -138,9 +136,7 @@ export class DashboardPlugin }); } - return { - contentClient: this.contentClient, - }; + return {}; } public stop() {} diff --git a/src/platform/plugins/shared/dashboard/server/types.ts b/src/platform/plugins/shared/dashboard/server/types.ts index 3302f82f1ae63..389f5d3c6227c 100644 --- a/src/platform/plugins/shared/dashboard/server/types.ts +++ b/src/platform/plugins/shared/dashboard/server/types.ts @@ -7,10 +7,7 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import { ContentManagementServerSetup } from '@kbn/content-management-plugin/server'; - // eslint-disable-next-line @typescript-eslint/no-empty-interface export interface DashboardPluginSetup {} -export interface DashboardPluginStart { - contentClient?: ReturnType['contentClient']; -} +// eslint-disable-next-line @typescript-eslint/no-empty-interface +export interface DashboardPluginStart {} From 964a2c96e9242b26862a73d2988529d1d6b2ec9a Mon Sep 17 00:00:00 2001 From: Nick Peihl Date: Thu, 13 Feb 2025 08:58:43 -0500 Subject: [PATCH 4/4] Fix test --- test/examples/content_management/msearch.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/test/examples/content_management/msearch.ts b/test/examples/content_management/msearch.ts index c02b92ab8eb39..7a4867f6d9f93 100644 --- a/test/examples/content_management/msearch.ts +++ b/test/examples/content_management/msearch.ts @@ -43,7 +43,6 @@ export default function ({ getService, getPageObjects }: PluginFunctionalProvide `kibana_sample_data_flights`, `[Flights] Airport Connections (Hover Over Airport)`, `[Flights] Departures Count Map`, - `[Flights] Global Flight Dashboard`, `[Flights] Origin Time Delayed`, `[Flights] Flight Log`, ];