From 21a288a097ea0b5329ea6786295d49e5100bfa89 Mon Sep 17 00:00:00 2001 From: Davis McPhee Date: Mon, 23 Jun 2025 19:51:27 -0300 Subject: [PATCH] [Data Discovery] Remove SO client usages (#224495) ## Summary While checking out our remaining browser SO client usages, I realized it would be _really_ easy to get rid of them. This PR does that. Resolves #224357. ### Checklist - [ ] 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/src/platform/packages/shared/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 - [ ] [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 - [ ] 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 was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The `release_note:breaking` label should be applied in these situations. - [ ] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [ ] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> --- .../kibana.jsonc | 3 ++- .../public/plugin.tsx | 16 +++++++----- .../tsconfig.json | 2 ++ .../state_management/discover_state.test.ts | 26 ------------------- .../public/services/saved_searches/types.ts | 8 +++--- .../plugins/shared/saved_search/tsconfig.json | 1 + 6 files changed, 18 insertions(+), 38 deletions(-) diff --git a/examples/discover_customization_examples/kibana.jsonc b/examples/discover_customization_examples/kibana.jsonc index 42f488293568..a7849e481b94 100644 --- a/examples/discover_customization_examples/kibana.jsonc +++ b/examples/discover_customization_examples/kibana.jsonc @@ -12,7 +12,8 @@ "discover", "embeddable", "kibanaUtils", - "data" + "data", + "savedSearch" ] } } diff --git a/examples/discover_customization_examples/public/plugin.tsx b/examples/discover_customization_examples/public/plugin.tsx index 982689c91f4f..fb1f6cab1251 100644 --- a/examples/discover_customization_examples/public/plugin.tsx +++ b/examples/discover_customization_examples/public/plugin.tsx @@ -25,6 +25,9 @@ import { Route, Router, Routes } from '@kbn/shared-ux-router'; import { I18nProvider } from '@kbn/i18n-react'; import { KibanaThemeProvider } from '@kbn/react-kibana-context-theme'; import { DataPublicPluginStart } from '@kbn/data-plugin/public'; +import { SavedSearchPublicPluginStart } from '@kbn/saved-search-plugin/public'; +import type { SOWithMetadata } from '@kbn/content-management-utils'; +import type { SavedSearchAttributes } from '@kbn/saved-search-plugin/common'; import image from './discover_customization_examples.png'; export interface DiscoverCustomizationExamplesSetupPlugins { @@ -35,6 +38,7 @@ export interface DiscoverCustomizationExamplesSetupPlugins { export interface DiscoverCustomizationExamplesStartPlugins { discover: DiscoverStart; data: DataPublicPluginStart; + savedSearch: SavedSearchPublicPluginStart; } const PLUGIN_ID = 'discoverCustomizationExamples'; @@ -112,15 +116,13 @@ export class DiscoverCustomizationExamplesPlugin implements Plugin { const togglePopover = () => setIsPopoverOpen((open) => !open); const closePopover = () => setIsPopoverOpen(false); const [savedSearches, setSavedSearches] = useState< - Array> + Array> >([]); useEffect(() => { - core.savedObjects.client - .find<{ title: string }>({ type: 'search' }) - .then((response) => { - setSavedSearches(response.savedObjects); - }); + plugins.savedSearch.getAll().then((response) => { + setSavedSearches(response); + }); }, []); const currentSavedSearch = useObservable( @@ -154,7 +156,7 @@ export class DiscoverCustomizationExamplesPlugin implements Plugin { id: 0, title: 'Saved logs views', items: savedSearches.map((savedSearch) => ({ - name: savedSearch.get('title'), + name: savedSearch.attributes.title, onClick: () => stateContainer.actions.onOpenSavedSearch(savedSearch.id), icon: savedSearch.id === currentSavedSearch.id ? 'check' : 'empty', 'data-test-subj': `logsViewSelectorOption-${savedSearch.attributes.title.replace( diff --git a/examples/discover_customization_examples/tsconfig.json b/examples/discover_customization_examples/tsconfig.json index 30ff666575f1..b31e79f8493f 100644 --- a/examples/discover_customization_examples/tsconfig.json +++ b/examples/discover_customization_examples/tsconfig.json @@ -13,6 +13,8 @@ "@kbn/i18n-react", "@kbn/react-kibana-context-theme", "@kbn/data-plugin", + "@kbn/saved-search-plugin", + "@kbn/content-management-utils", ], "exclude": ["target/**/*"] } diff --git a/src/platform/plugins/shared/discover/public/application/main/state_management/discover_state.test.ts b/src/platform/plugins/shared/discover/public/application/main/state_management/discover_state.test.ts index 0cb2220acc7c..7d668a4d3f99 100644 --- a/src/platform/plugins/shared/discover/public/application/main/state_management/discover_state.test.ts +++ b/src/platform/plugins/shared/discover/public/application/main/state_management/discover_state.test.ts @@ -409,32 +409,6 @@ describe('Discover state', () => { mockServices.data.search.searchSource.create = jest .fn() .mockReturnValue(savedSearchMock.searchSource); - mockServices.core.savedObjects.client.resolve = jest.fn().mockReturnValue({ - saved_object: { - attributes: { - kibanaSavedObjectMeta: { - searchSourceJSON: - '{"query":{"query":"","language":"kuery"},"filter":[],"indexRefName":"kibanaSavedObjectMeta.searchSourceJSON.index"}', - }, - title: 'The saved search that will save the world', - sort: [], - columns: ['test123'], - description: 'description', - hideChart: false, - }, - id: 'the-saved-search-id', - type: 'search', - references: [ - { - name: 'kibanaSavedObjectMeta.searchSourceJSON.index', - id: 'the-data-view-id', - type: 'index-pattern', - }, - ], - namespaces: ['default'], - }, - outcome: 'exactMatch', - }); }); afterEach(() => { diff --git a/src/platform/plugins/shared/saved_search/public/services/saved_searches/types.ts b/src/platform/plugins/shared/saved_search/public/services/saved_searches/types.ts index 9141d96ed743..0d3f748d02b5 100644 --- a/src/platform/plugins/shared/saved_search/public/services/saved_searches/types.ts +++ b/src/platform/plugins/shared/saved_search/public/services/saved_searches/types.ts @@ -8,15 +8,15 @@ */ import type { Reference } from '@kbn/content-management-utils'; -import type { ResolvedSimpleSavedObject } from '@kbn/core/public'; +import type { SavedObjectsResolveResponse } from '@kbn/core-saved-objects-api-server'; import type { SavedSearch as SavedSearchCommon, SavedSearchAttributes } from '../../../common'; /** @public **/ export interface SavedSearch extends SavedSearchCommon { sharingSavedObjectProps?: { - outcome?: ResolvedSimpleSavedObject['outcome']; - aliasTargetId?: ResolvedSimpleSavedObject['alias_target_id']; - aliasPurpose?: ResolvedSimpleSavedObject['alias_purpose']; + outcome?: SavedObjectsResolveResponse['outcome']; + aliasTargetId?: SavedObjectsResolveResponse['alias_target_id']; + aliasPurpose?: SavedObjectsResolveResponse['alias_purpose']; errorJSON?: string; }; } diff --git a/src/platform/plugins/shared/saved_search/tsconfig.json b/src/platform/plugins/shared/saved_search/tsconfig.json index bcea4f5a8784..2305bdef2b83 100644 --- a/src/platform/plugins/shared/saved_search/tsconfig.json +++ b/src/platform/plugins/shared/saved_search/tsconfig.json @@ -28,6 +28,7 @@ "@kbn/utility-types", "@kbn/search-types", "@kbn/unified-data-table", + "@kbn/core-saved-objects-api-server", ], "exclude": ["target/**/*"] }