Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Event annotations] Lens design improvements #159057

Merged
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ export interface EventAnnotationGroupSearchQuery {
searchFields?: string[];
}

export type EventAnnotationGroupSearchIn = SearchIn<EventAnnotationGroupContentType, {}>;
export type EventAnnotationGroupSearchIn = SearchIn<
EventAnnotationGroupContentType,
EventAnnotationGroupSearchQuery
>;

export type EventAnnotationGroupSearchOut = SearchResult<EventAnnotationGroupSavedObject>;
Original file line number Diff line number Diff line change
Expand Up @@ -67,35 +67,37 @@ export const EventAnnotationGroupSavedObjectFinder = ({
direction="column"
justifyContent="center"
>
<EuiEmptyPrompt
titleSize="xs"
title={
<h2>
<FormattedMessage
id="eventAnnotation.eventAnnotationGroup.savedObjectFinder.emptyPromptTitle"
defaultMessage="Start by adding an annotation layer"
/>
</h2>
}
body={
<EuiText size="s">
<p>
<EuiFlexItem>
<EuiEmptyPrompt
titleSize="xs"
title={
<h2>
<FormattedMessage
id="eventAnnotation.eventAnnotationGroup.savedObjectFinder.emptyPromptDescription"
defaultMessage="There are currently no annotations available to select from the library. Create a new layer to add annotations."
id="eventAnnotation.eventAnnotationGroup.savedObjectFinder.emptyPromptTitle"
defaultMessage="Start by adding an annotation layer"
/>
</p>
</EuiText>
}
actions={
<EuiButton onClick={() => onCreateNew()} size="s">
<FormattedMessage
id="eventAnnotation.eventAnnotationGroup.savedObjectFinder.emptyCTA"
defaultMessage="Create annotation layer"
/>
</EuiButton>
}
/>
</h2>
}
body={
<EuiText size="s">
<p>
<FormattedMessage
id="eventAnnotation.eventAnnotationGroup.savedObjectFinder.emptyPromptDescription"
defaultMessage="There are currently no annotations available to select from the library. Create a new layer to add annotations."
/>
</p>
</EuiText>
}
actions={
<EuiButton onClick={() => onCreateNew()} size="s">
<FormattedMessage
id="eventAnnotation.eventAnnotationGroup.savedObjectFinder.emptyCTA"
defaultMessage="Create annotation layer"
/>
</EuiButton>
}
/>
</EuiFlexItem>
</EuiFlexGroup>
) : (
<SavedObjectFinder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ import {
isQueryAnnotationConfig,
} from './helpers';
import { EventAnnotationGroupSavedObjectFinder } from '../components/event_annotation_group_saved_object_finder';
import {
import { CONTENT_ID } from '../../common/content_management';
import type {
EventAnnotationGroupCreateIn,
EventAnnotationGroupCreateOut,
EventAnnotationGroupDeleteIn,
Expand Down Expand Up @@ -106,7 +107,7 @@ export function getEventAnnotationService(
savedObjectId: string
): Promise<EventAnnotationGroupConfig> => {
const savedObject = await client.get<EventAnnotationGroupGetIn, EventAnnotationGroupGetOut>({
contentTypeId: EVENT_ANNOTATION_GROUP_TYPE,
contentTypeId: CONTENT_ID,
id: savedObjectId,
});

Expand All @@ -117,6 +118,29 @@ export function getEventAnnotationService(
return mapSavedObjectToGroupConfig(savedObject.item);
};

const groupExistsWithTitle = async (title: string): Promise<boolean> => {
const { hits } = await client.search<
EventAnnotationGroupSearchIn,
EventAnnotationGroupSearchOut
>({
contentTypeId: CONTENT_ID,
query: {
text: title,
},
options: {
searchFields: ['title'],
},
});

for (const hit of hits) {
if (hit.attributes.title.toLowerCase() === title.toLowerCase()) {
return true;
}
}

return false;
};

const findAnnotationGroupContent = async (
searchTerm: string,
pageSize: number,
Expand All @@ -138,7 +162,7 @@ export function getEventAnnotationService(
EventAnnotationGroupSearchIn,
EventAnnotationGroupSearchOut
>({
contentTypeId: EVENT_ANNOTATION_GROUP_TYPE,
contentTypeId: CONTENT_ID,
query: {
text: searchOptions.search,
},
Expand All @@ -153,7 +177,7 @@ export function getEventAnnotationService(
const deleteAnnotationGroups = async (ids: string[]): Promise<void> => {
for (const id of ids) {
await client.delete<EventAnnotationGroupDeleteIn, EventAnnotationGroupDeleteOut>({
contentTypeId: EVENT_ANNOTATION_GROUP_TYPE,
contentTypeId: CONTENT_ID,
id,
});
}
Expand Down Expand Up @@ -223,7 +247,7 @@ export function getEventAnnotationService(

const groupSavedObjectId = (
await client.create<EventAnnotationGroupCreateIn, EventAnnotationGroupCreateOut>({
contentTypeId: EVENT_ANNOTATION_GROUP_TYPE,
contentTypeId: CONTENT_ID,
data: {
...attributes,
},
Expand All @@ -243,7 +267,7 @@ export function getEventAnnotationService(
const { attributes, references } = getAnnotationGroupAttributesAndReferences(group);

await client.update<EventAnnotationGroupUpdateIn, EventAnnotationGroupUpdateOut>({
contentTypeId: EVENT_ANNOTATION_GROUP_TYPE,
contentTypeId: CONTENT_ID,
id: annotationGroupId,
data: {
...attributes,
Expand All @@ -259,7 +283,7 @@ export function getEventAnnotationService(
EventAnnotationGroupSearchIn,
EventAnnotationGroupSearchOut
>({
contentTypeId: EVENT_ANNOTATION_GROUP_TYPE,
contentTypeId: CONTENT_ID,
query: {
text: '*',
},
Expand All @@ -270,6 +294,7 @@ export function getEventAnnotationService(

return {
loadAnnotationGroup,
groupExistsWithTitle,
updateAnnotationGroup,
createAnnotationGroup,
deleteAnnotationGroups,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { EventAnnotationConfig, EventAnnotationGroupConfig } from '../../common'

export interface EventAnnotationServiceType {
loadAnnotationGroup: (savedObjectId: string) => Promise<EventAnnotationGroupConfig>;
groupExistsWithTitle: (title: string) => Promise<boolean>;
findAnnotationGroupContent: (
searchTerm: string,
pageSize: number,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,11 @@ export class EventAnnotationGroupStorage
EventAnnotationGroupSearchQuery,
EventAnnotationGroupSearchQuery
>(options);

if (optionsError) {
throw Boom.badRequest(`Invalid payload. ${optionsError.message}`);
}

const { searchFields = ['title^3', 'description'], types = [SO_TYPE] } = optionsToLatest;

const { included, excluded } = query.tags ?? {};
Expand Down
Loading