Skip to content

Commit

Permalink
[SavedObjectFinder] Remove savedObjects.find (elastic#151220)
Browse files Browse the repository at this point in the history
## Summary

This PR replaces deprecated client-side `savedObjects.find` method with
a server-side one and a corresponding API call. As a result, the
dependencies of the `SavedObjectFinder` component have changed slightly:
instead of `coreStart.savedObjects`, the component is now taking
`coreStart.http`.

If you have been tagged as a reviewer, it means your plugin is using
`SavedObjectFinder` somewhere. To test it, ensure it all works as
previously.

### 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
Maja Grubic and kibanamachine authored Feb 16, 2023
1 parent b94c777 commit b4f5fa6
Show file tree
Hide file tree
Showing 37 changed files with 374 additions and 202 deletions.
2 changes: 1 addition & 1 deletion src/plugins/dashboard/public/dashboard_actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const buildAllDashboardActions = async ({
uiActions.registerAction(clonePanelAction);
uiActions.attachAction(CONTEXT_MENU_TRIGGER, clonePanelAction.id);

const SavedObjectFinder = getSavedObjectFinder(core.savedObjects, uiSettings);
const SavedObjectFinder = getSavedObjectFinder(uiSettings, core.http);
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 @@ -6,6 +6,7 @@
* Side Public License, v 1.
*/

import { HttpStart } from '@kbn/core/public';
import { isErrorEmbeddable, openAddPanelFlyout } from '@kbn/embeddable-plugin/public';
import { getSavedObjectFinder } from '@kbn/saved-objects-plugin/public';

Expand All @@ -18,14 +19,14 @@ export function addFromLibrary(this: DashboardContainer) {
notifications,
usageCollection,
settings: { uiSettings, theme },
dashboardSavedObject: { savedObjectsClient },
embeddable: { getEmbeddableFactories, getEmbeddableFactory },
http,
} = pluginServices.getServices();

if (isErrorEmbeddable(this)) return;
this.openOverlay(
openAddPanelFlyout({
SavedObjectFinder: getSavedObjectFinder({ client: savedObjectsClient }, uiSettings),
SavedObjectFinder: getSavedObjectFinder(uiSettings, http as HttpStart),
reportUiCounter: usageCollection.reportUiCounter,
getAllFactories: getEmbeddableFactories,
getFactory: getEmbeddableFactory,
Expand Down
1 change: 1 addition & 0 deletions src/plugins/dashboard/public/services/http/http.stub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ export const httpServiceFactory: HttpServiceFactory = () => {

return {
basePath: serviceMock.http.basePath,
get: serviceMock.http.get,
};
};
3 changes: 2 additions & 1 deletion src/plugins/dashboard/public/services/http/http_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ export type HttpServiceFactory = KibanaPluginServiceFactory<
>;
export const httpServiceFactory: HttpServiceFactory = ({ coreStart }) => {
const {
http: { basePath },
http: { basePath, get },
} = coreStart;

return {
basePath,
get,
};
};
5 changes: 3 additions & 2 deletions src/plugins/dashboard/public/services/http/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
* Side Public License, v 1.
*/

import type { CoreSetup } from '@kbn/core/public';
import type { CoreStart } from '@kbn/core/public';

export interface DashboardHTTPService {
basePath: CoreSetup['http']['basePath'];
basePath: CoreStart['http']['basePath'];
get: CoreStart['http']['get'];
}
2 changes: 1 addition & 1 deletion src/plugins/embeddable/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export class EmbeddablePublicPlugin implements Plugin<EmbeddableSetup, Embeddabl
notifications={core.notifications}
application={core.application}
inspector={inspector}
SavedObjectFinder={getSavedObjectFinder(core.savedObjects, core.uiSettings)}
SavedObjectFinder={getSavedObjectFinder(core.uiSettings, core.http)}
containerContext={containerContext}
theme={theme}
/>
Expand Down
1 change: 1 addition & 0 deletions src/plugins/saved_objects/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@

export const PER_PAGE_SETTING = 'savedObjects:perPage';
export const LISTING_LIMIT_SETTING = 'savedObjects:listingLimit';
export type { SavedObjectCommon, FindQueryHTTP, FindResponseHTTP, FinderAttributes } from './types';
35 changes: 35 additions & 0 deletions src/plugins/saved_objects/common/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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 { SavedObject } from '@kbn/core-saved-objects-server';

export type SavedObjectCommon<T = unknown> = SavedObject<T>;

export interface FindQueryHTTP {
perPage?: number;
page?: number;
type: string | string[];
search?: string;
searchFields?: string[];
defaultSearchOperator?: 'AND' | 'OR';
sortField?: string;
sortOrder?: 'asc' | 'desc';
fields?: string | string[];
}

export interface FinderAttributes {
title?: string;
name?: string;
type: string;
}

export interface FindResponseHTTP<T> {
saved_objects: Array<SavedObjectCommon<T>>;
total: number;
page: number;
per_page: number;
}
6 changes: 1 addition & 5 deletions src/plugins/saved_objects/public/finder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,5 @@
* Side Public License, v 1.
*/

export type {
SavedObjectMetaData,
SavedObjectFinderUiProps,
FinderAttributes,
} from './saved_object_finder';
export type { SavedObjectMetaData, SavedObjectFinderUiProps } from './saved_object_finder';
export { SavedObjectFinderUi, getSavedObjectFinder } from './saved_object_finder';
Loading

0 comments on commit b4f5fa6

Please sign in to comment.