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

# Backport

This will backport the following commits from `main` to `8.9`:
- [[Event annotations] fix table list tag filtering
(#161048)](https://github.com/elastic/kibana/pull/161048)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Drew
Tate","email":"drew.tate@elastic.co"},"sourceCommit":{"committedDate":"2023-07-06T05:55:53Z","message":"[Event
annotations] fix table list tag filtering
(#161048)","sha":"569e873ffb1456e5c9c814c3d66023061365fd2d","branchLabelMapping":{"^v8.10.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Visualizations","release_note:skip","backport:prev-minor","v8.10.0"],"number":161048,"url":"https://github.com/elastic/kibana/pull/161048","mergeCommit":{"message":"[Event
annotations] fix table list tag filtering
(#161048)","sha":"569e873ffb1456e5c9c814c3d66023061365fd2d"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.10.0","labelRegex":"^v8.10.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/161048","number":161048,"mergeCommit":{"message":"[Event
annotations] fix table list tag filtering
(#161048)","sha":"569e873ffb1456e5c9c814c3d66023061365fd2d"}}]}]
BACKPORT-->

Co-authored-by: Drew Tate <drew.tate@elastic.co>
This commit is contained in:
Kibana Machine 2023-07-06 03:03:51 -04:00 committed by GitHub
parent fc463b9627
commit 7f00cc9e31
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 }>;