From 333a8bb6401dd46d8c821c2ff598da3a4a238cfe Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Sun, 16 Apr 2023 00:22:58 -0500 Subject: [PATCH] correctly specify which fields to query --- packages/kbn-content-management-utils/types.ts | 1 + src/plugins/data_views/common/types.ts | 4 ---- src/plugins/data_views/common/utils.ts | 3 --- .../public/saved_objects_client_wrapper.test.ts | 6 +++--- .../public/saved_objects_client_wrapper.ts | 3 +++ .../server/content_management/data_views_storage.ts | 9 +++++++-- .../apps/discover/group2/_adhoc_data_views.ts | 12 ------------ .../utils/saved_search_utils.test.ts | 2 +- 8 files changed, 15 insertions(+), 25 deletions(-) diff --git a/packages/kbn-content-management-utils/types.ts b/packages/kbn-content-management-utils/types.ts index 3291b8f5ed106..a08a2a6ac6a32 100644 --- a/packages/kbn-content-management-utils/types.ts +++ b/packages/kbn-content-management-utils/types.ts @@ -35,6 +35,7 @@ export interface CreateOptions { export interface SearchOptions { /** Flag to indicate to only search the text on the "title" field */ onlyTitle?: boolean; + searchFields?: string[]; } export interface UpdateOptions { diff --git a/src/plugins/data_views/common/types.ts b/src/plugins/data_views/common/types.ts index 721c6d6630cf8..978128f350bd7 100644 --- a/src/plugins/data_views/common/types.ts +++ b/src/plugins/data_views/common/types.ts @@ -232,10 +232,6 @@ export interface UiSettingsCommon { * @public */ export interface SavedObjectsClientCommonFindArgs { - /** - * Saved object type - */ - type: string | string[]; /** * Saved object fields */ diff --git a/src/plugins/data_views/common/utils.ts b/src/plugins/data_views/common/utils.ts index 2c097b550f2af..05822ed363e9f 100644 --- a/src/plugins/data_views/common/utils.ts +++ b/src/plugins/data_views/common/utils.ts @@ -8,8 +8,6 @@ import type { SavedObjectsClientCommon } from './types'; -import { DATA_VIEW_SAVED_OBJECT_TYPE } from './constants'; - /** * Returns an object matching a given name * @@ -20,7 +18,6 @@ import { DATA_VIEW_SAVED_OBJECT_TYPE } from './constants'; export async function findByName(client: SavedObjectsClientCommon, name: string) { if (name) { const savedObjects = await client.find({ - type: DATA_VIEW_SAVED_OBJECT_TYPE, perPage: 10, search: `"${name}"`, searchFields: ['name.keyword'], diff --git a/src/plugins/data_views/public/saved_objects_client_wrapper.test.ts b/src/plugins/data_views/public/saved_objects_client_wrapper.test.ts index c62c11c498e7e..898d22b7d3637 100644 --- a/src/plugins/data_views/public/saved_objects_client_wrapper.test.ts +++ b/src/plugins/data_views/public/saved_objects_client_wrapper.test.ts @@ -19,7 +19,7 @@ describe('SavedObjectsClientPublicToCommon', () => { const mockedSavedObject = { version: 'abc', }; - soClient.get = jest + cmClient.get = jest .fn() .mockResolvedValue({ meta: { outcome: 'exactMatch' }, item: mockedSavedObject }); const service = new SavedObjectsClientPublicToCommon(cmClient, soClient); @@ -31,7 +31,7 @@ describe('SavedObjectsClientPublicToCommon', () => { const mockedSavedObject = { version: 'def', }; - soClient.get = jest + cmClient.get = jest .fn() .mockResolvedValue({ meta: { outcome: 'aliasMatch' }, item: mockedSavedObject }); const service = new SavedObjectsClientPublicToCommon(cmClient, soClient); @@ -44,7 +44,7 @@ describe('SavedObjectsClientPublicToCommon', () => { version: 'ghi', }; - soClient.get = jest + cmClient.get = jest .fn() .mockResolvedValue({ meta: { outcome: 'conflict' }, item: mockedSavedObject }); const service = new SavedObjectsClientPublicToCommon(cmClient, soClient); diff --git a/src/plugins/data_views/public/saved_objects_client_wrapper.ts b/src/plugins/data_views/public/saved_objects_client_wrapper.ts index c9614e34ca182..3db65bb7f3879 100644 --- a/src/plugins/data_views/public/saved_objects_client_wrapper.ts +++ b/src/plugins/data_views/public/saved_objects_client_wrapper.ts @@ -52,6 +52,9 @@ export class SavedObjectsClientPublicToCommon implements SavedObjectsClientCommo text: options.search, limit: options.perPage, }, + options: { + searchFields: options.searchFields, + }, }); return results.hits; } diff --git a/src/plugins/data_views/server/content_management/data_views_storage.ts b/src/plugins/data_views/server/content_management/data_views_storage.ts index 1e3a1bd3fdca5..b8e551397509f 100644 --- a/src/plugins/data_views/server/content_management/data_views_storage.ts +++ b/src/plugins/data_views/server/content_management/data_views_storage.ts @@ -21,6 +21,7 @@ import type { DataViewUpdateOptions, DataViewDeleteOut, DataViewSearchOut, + DataViewSearchOptions, } from '../../common/content_management'; import { DataViewSOType } from '../../common/content_management/constants'; @@ -93,7 +94,11 @@ export class DataViewsStorage implements ContentStorage { return { success: true }; } - async search(ctx: StorageContext, query: SearchQuery): Promise { + async search( + ctx: StorageContext, + query: SearchQuery, + options: DataViewSearchOptions + ): Promise { const soClient = await savedObjectClientFromRequest(ctx); const { included, excluded } = query.tags ?? {}; @@ -117,7 +122,7 @@ export class DataViewsStorage implements ContentStorage { perPage: query.limit, page: query.cursor ? +query.cursor : undefined, defaultSearchOperator: 'AND', - searchFields: ['title', 'name'], + searchFields: options.searchFields || ['title', 'name'], fields: ['title', 'name', 'type', 'typeMeta'], hasReference, hasNoReference, diff --git a/test/functional/apps/discover/group2/_adhoc_data_views.ts b/test/functional/apps/discover/group2/_adhoc_data_views.ts index 9699dc36dd81c..bb1b292ceb2f0 100644 --- a/test/functional/apps/discover/group2/_adhoc_data_views.ts +++ b/test/functional/apps/discover/group2/_adhoc_data_views.ts @@ -134,18 +134,6 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { expect(prevDataViewId).not.to.equal(newDataViewId); }); - it('should update data view id when saving data view from hoc one', async () => { - const prevDataViewId = await PageObjects.discover.getCurrentDataViewId(); - - await testSubjects.click('shareTopNavButton'); - await testSubjects.click('confirmModalConfirmButton'); - await PageObjects.header.waitUntilLoadingHasFinished(); - - const newDataViewId = await PageObjects.discover.getCurrentDataViewId(); - - expect(prevDataViewId).not.to.equal(newDataViewId); - }); - it('search results should be different after data view update', async () => { await PageObjects.discover.createAdHocDataView('logst', true); await PageObjects.header.waitUntilLoadingHasFinished(); diff --git a/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/utils/saved_search_utils.test.ts b/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/utils/saved_search_utils.test.ts index b872dfb91b00d..4fb0d40bb5d83 100644 --- a/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/utils/saved_search_utils.test.ts +++ b/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/utils/saved_search_utils.test.ts @@ -35,7 +35,7 @@ function createMockDataView(id: string) { type, version, timeFieldName, - fields: JSON.parse(fields), + fields: JSON.parse(fields || '[]'), title, runtimeFieldMap: {}, },