Skip to content

Commit

Permalink
[Event annotations] fix table list tag filtering (#161048)
Browse files Browse the repository at this point in the history
  • Loading branch information
drewdaemon authored Jul 6, 2023
1 parent c5ee8ce commit 569e873
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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']
);
});

Expand Down
4 changes: 2 additions & 2 deletions src/plugins/event_annotation/public/components/table_list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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*",
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
},
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 }>;
Expand Down

0 comments on commit 569e873

Please sign in to comment.