Skip to content

Commit

Permalink
correctly specify which fields to query
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkime committed Apr 16, 2023
1 parent a1f0c60 commit 333a8bb
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 25 deletions.
1 change: 1 addition & 0 deletions packages/kbn-content-management-utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 0 additions & 4 deletions src/plugins/data_views/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,6 @@ export interface UiSettingsCommon {
* @public
*/
export interface SavedObjectsClientCommonFindArgs {
/**
* Saved object type
*/
type: string | string[];
/**
* Saved object fields
*/
Expand Down
3 changes: 0 additions & 3 deletions src/plugins/data_views/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

import type { SavedObjectsClientCommon } from './types';

import { DATA_VIEW_SAVED_OBJECT_TYPE } from './constants';

/**
* Returns an object matching a given name
*
Expand All @@ -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'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/data_views/public/saved_objects_client_wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ export class SavedObjectsClientPublicToCommon implements SavedObjectsClientCommo
text: options.search,
limit: options.perPage,
},
options: {
searchFields: options.searchFields,
},
});
return results.hits;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import type {
DataViewUpdateOptions,
DataViewDeleteOut,
DataViewSearchOut,
DataViewSearchOptions,
} from '../../common/content_management';
import { DataViewSOType } from '../../common/content_management/constants';

Expand Down Expand Up @@ -93,7 +94,11 @@ export class DataViewsStorage implements ContentStorage {
return { success: true };
}

async search(ctx: StorageContext, query: SearchQuery): Promise<DataViewSearchOut> {
async search(
ctx: StorageContext,
query: SearchQuery,
options: DataViewSearchOptions
): Promise<DataViewSearchOut> {
const soClient = await savedObjectClientFromRequest(ctx);

const { included, excluded } = query.tags ?? {};
Expand All @@ -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,
Expand Down
12 changes: 0 additions & 12 deletions test/functional/apps/discover/group2/_adhoc_data_views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function createMockDataView(id: string) {
type,
version,
timeFieldName,
fields: JSON.parse(fields),
fields: JSON.parse(fields || '[]'),
title,
runtimeFieldMap: {},
},
Expand Down

0 comments on commit 333a8bb

Please sign in to comment.