[Event annotations] fix table list tag filtering (#161048)

This commit is contained in:
Drew Tate 2023-07-06 00:55:53 -05:00 committed by GitHub
parent c5ee8ce47b
commit 569e873ffb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 33 deletions

View file

@ -108,8 +108,8 @@ describe('annotation list view', () => {
expect(mockEventAnnotationService.findAnnotationGroupContent).toHaveBeenCalledWith(
'My Search Query',
30,
[{ id: 'first_id', type: 'sometype' }],
[{ id: 'second_id', type: 'sometype' }]
['first_id'],
['second_id']
);
});

View file

@ -95,8 +95,8 @@ export const EventAnnotationGroupTableList = ({
return eventAnnotationService.findAnnotationGroupContent(
searchTerm,
listingLimit, // TODO is this right?
references,
referencesToExclude
references?.map(({ id }) => id),
referencesToExclude?.map(({ id }) => id)
);
},
[eventAnnotationService, listingLimit]

View file

@ -514,7 +514,7 @@ describe('Event Annotation Service', () => {
const searchTerm = 'my search';
const content = await eventAnnotationService.findAnnotationGroupContent(searchTerm, 20, [
{ type: 'mytype', id: '1234' },
'1234',
]);
expect(content).toMatchSnapshot();
@ -525,6 +525,13 @@ describe('Event Annotation Service', () => {
Object {
"contentTypeId": "event-annotation-group",
"query": Object {
"limit": 20,
"tags": Object {
"excluded": undefined,
"included": Array [
"1234",
],
},
"text": "my search*",
},
},

View file

@ -10,22 +10,13 @@ import React from 'react';
import { partition } from 'lodash';
import { queryToAst } from '@kbn/data-plugin/common';
import { ExpressionAstExpression } from '@kbn/expressions-plugin/common';
import {
CoreStart,
SavedObjectReference,
SavedObjectsFindOptions,
SavedObjectsFindOptionsReference,
} from '@kbn/core/public';
import type { CoreStart, SavedObjectReference } from '@kbn/core/public';
import { SavedObjectsManagementPluginStart } from '@kbn/saved-objects-management-plugin/public';
import { DataViewPersistableStateService } from '@kbn/data-views-plugin/common';
import { ContentManagementPublicStart } from '@kbn/content-management-plugin/public';
import { defaultAnnotationLabel } from '../../common/manual_event_annotation';
import { EventAnnotationGroupContent } from '../../common/types';
import {
EventAnnotationConfig,
EventAnnotationGroupConfig,
EVENT_ANNOTATION_GROUP_TYPE,
} from '../../common';
import { EventAnnotationConfig, EventAnnotationGroupConfig } from '../../common';
import { EventAnnotationServiceType } from './types';
import {
defaultAnnotationColor,
@ -144,27 +135,21 @@ export function getEventAnnotationService(
const findAnnotationGroupContent = async (
searchTerm: string,
pageSize: number,
references?: SavedObjectsFindOptionsReference[],
referencesToExclude?: SavedObjectsFindOptionsReference[]
tagsToInclude?: string[],
tagsToExclude?: string[]
): Promise<{ total: number; hits: EventAnnotationGroupContent[] }> => {
const searchOptions: SavedObjectsFindOptions = {
type: [EVENT_ANNOTATION_GROUP_TYPE],
searchFields: ['title^3', 'description'],
search: searchTerm ? `${searchTerm}*` : undefined,
perPage: pageSize,
page: 1,
defaultSearchOperator: 'AND' as const,
hasReference: references,
hasNoReference: referencesToExclude,
};
const { pagination, hits } = await client.search<
EventAnnotationGroupSearchIn,
EventAnnotationGroupSearchOut
>({
contentTypeId: CONTENT_ID,
query: {
text: searchOptions.search,
text: searchTerm ? `${searchTerm}*` : undefined,
limit: pageSize,
tags: {
included: tagsToInclude,
excluded: tagsToExclude,
},
},
});

View file

@ -7,7 +7,6 @@
*/
import { ExpressionAstExpression } from '@kbn/expressions-plugin/common/ast';
import { SavedObjectsFindOptionsReference } from '@kbn/core-saved-objects-api-browser';
import type { SavedObjectCommon } from '@kbn/saved-objects-finder-plugin/common';
import { EventAnnotationGroupContent } from '../../common/types';
import { EventAnnotationConfig, EventAnnotationGroupConfig } from '../../common';
@ -18,8 +17,8 @@ export interface EventAnnotationServiceType {
findAnnotationGroupContent: (
searchTerm: string,
pageSize: number,
references?: SavedObjectsFindOptionsReference[],
referencesToExclude?: SavedObjectsFindOptionsReference[]
tagsToInclude?: string[],
tagsToExclude?: string[]
) => Promise<{ total: number; hits: EventAnnotationGroupContent[] }>;
deleteAnnotationGroups: (ids: string[]) => Promise<void>;
createAnnotationGroup: (group: EventAnnotationGroupConfig) => Promise<{ id: string }>;