[8.x] [Dashboards] Replace contentClient with getContentClient on DashboardStart server api (#217586) (#217989)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Dashboards] Replace contentClient with getContentClient on
DashboardStart server api
(#217586)](https://github.com/elastic/kibana/pull/217586)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Nick
Peihl","email":"nick.peihl@elastic.co"},"sourceCommit":{"committedDate":"2025-04-10T18:52:38Z","message":"[Dashboards]
Replace contentClient with getContentClient on DashboardStart server api
(#217586)\n\n## Summary\n\nChanges the DashboardStart server api to
provide a getContentClient\nfunction.\n\nIn
https://github.com/elastic/kibana/pull/214788, we set
the\n`contentClient` returned from the content management register
method\nafter start lifecycle of all plugins. This means the
`contentClient`\nreturned from the `DashboardStart` contract was
undefined. This PR\nchanges the start contract to provide a
getContentClient function\ninstead.\n\nOnly one consumer was using the
contentClient from DashboardStart and\nthis PR also updates that
consumer.","sha":"72d18d8b992c99bb0be42123406453f0379f29d8","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Presentation","release_note:plugin_api_changes","Team:obs-ux-management","backport:version","v9.1.0","v8.19.0"],"title":"[Dashboards]
Replace contentClient with getContentClient on DashboardStart server
api","number":217586,"url":"https://github.com/elastic/kibana/pull/217586","mergeCommit":{"message":"[Dashboards]
Replace contentClient with getContentClient on DashboardStart server api
(#217586)\n\n## Summary\n\nChanges the DashboardStart server api to
provide a getContentClient\nfunction.\n\nIn
https://github.com/elastic/kibana/pull/214788, we set
the\n`contentClient` returned from the content management register
method\nafter start lifecycle of all plugins. This means the
`contentClient`\nreturned from the `DashboardStart` contract was
undefined. This PR\nchanges the start contract to provide a
getContentClient function\ninstead.\n\nOnly one consumer was using the
contentClient from DashboardStart and\nthis PR also updates that
consumer.","sha":"72d18d8b992c99bb0be42123406453f0379f29d8"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/217586","number":217586,"mergeCommit":{"message":"[Dashboards]
Replace contentClient with getContentClient on DashboardStart server api
(#217586)\n\n## Summary\n\nChanges the DashboardStart server api to
provide a getContentClient\nfunction.\n\nIn
https://github.com/elastic/kibana/pull/214788, we set
the\n`contentClient` returned from the content management register
method\nafter start lifecycle of all plugins. This means the
`contentClient`\nreturned from the `DashboardStart` contract was
undefined. This PR\nchanges the start contract to provide a
getContentClient function\ninstead.\n\nOnly one consumer was using the
contentClient from DashboardStart and\nthis PR also updates that
consumer.","sha":"72d18d8b992c99bb0be42123406453f0379f29d8"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->
This commit is contained in:
Nick Peihl 2025-04-15 16:25:15 -04:00 committed by GitHub
parent f94c41e8a8
commit fc686c5527
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 11 deletions

View file

@ -51,7 +51,9 @@ describe('DashboardPlugin', () => {
});
expect(scheduleDashboardTelemetry).toHaveBeenCalledTimes(1);
expect(await mockTaskManager.runSoon).toHaveBeenCalledTimes(1);
expect(response).toEqual({});
expect(response).toEqual({
getContentClient: expect.any(Function),
});
});
});
});

View file

@ -144,7 +144,7 @@ export class DashboardPlugin
}
return {
contentClient: this.contentClient,
getContentClient: () => this.contentClient,
};
}

View file

@ -13,40 +13,40 @@ import { ContentManagementServerSetup } from '@kbn/content-management-plugin/ser
export interface DashboardPluginSetup {}
export interface DashboardPluginStart {
/**
* Use contentClient.getForRequest to get a scoped client to perform CRUD and search operations for dashboards using the methods available in the {@link DashboardStorage} class.
* Use getContentClient().getForRequest to get a scoped client to perform CRUD and search operations for dashboards using the methods available in the {@link DashboardStorage} class.
*
* @example
* Get a dashboard client for the current request
* ```ts
* // dashboardClient is scoped to the current user
* // specifying the version is recommended to return a consistent result
* const dashboardClient = plugins.dashboard.contentClient.getForRequest({ requestHandlerContext, request, version: 3 });
*
* const { search, create, update, delete: deleteDashboard } = dashboardClient;
* const dashboardClient = plugins.dashboard.getContentClient().getForRequest({ requestHandlerContext, request, version: 3 });
* ```
*
* @example
* Search using {@link DashboardStorage#search}
* ```ts
* const dashboardList = await search({ text: 'my dashboard' }, { spaces: ['default'] } });
* const dashboardList = await dashboardClient.search({ text: 'my dashboard' }, { spaces: ['default'] } });
* ```
* @example
* Create a new dashboard using {@link DashboardCreateIn}
* ```ts
* const newDashboard = await create({ attributes: { title: 'My Dashboard' } });
* const newDashboard = await dashboardClient.create({ attributes: { title: 'My Dashboard' } });
* ```
*
* @example
* Update an existing dashboard using {@link DashboardUpdateIn}
* ```ts
* const updatedDashboard = await update({ id: 'dashboard-id', attributes: { title: 'My Updated Dashboard' } });
* const updatedDashboard = await dashboardClient.update({ id: 'dashboard-id', attributes: { title: 'My Updated Dashboard' } });
* ```
*
* @example
* Delete an existing dashboard using {@link DashboardDeleteIn}
* ```ts
* deleteDashboard({ id: 'dashboard-id' });
* dashboardClient.delete({ id: 'dashboard-id' });
* ```
*/
contentClient?: ReturnType<ContentManagementServerSetup['register']>['contentClient'];
getContentClient: () =>
| ReturnType<ContentManagementServerSetup['register']>['contentClient']
| undefined;
}