[Cases] Version user_action domain and apis (#161783)

## Summary

This PR versions the `user_action` domain object and its corresponding
APIs

### Checklist

Delete any items that are not applicable to this PR.

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

### For maintainers

- [x] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

---------

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Christos Nasikas 2023-07-17 15:42:01 +03:00 committed by GitHub
parent 02de7c83db
commit f9adf3bbf7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
160 changed files with 1404 additions and 1395 deletions

View file

@ -8,7 +8,6 @@
export * from './case';
export * from './comment';
export * from './status';
export * from './user_actions';
export * from './constants';
export * from './alerts';
export * from './user_profiles';

View file

@ -1,95 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import {
UserActionCommonAttributesRt,
CaseUserActionInjectedIdsRt,
CaseUserActionInjectedDeprecatedIdsRt,
} from './common';
describe('Common', () => {
describe('UserActionCommonAttributesRt', () => {
const defaultRequest = {
created_at: '2020-02-19T23:06:33.798Z',
created_by: {
full_name: 'Leslie Knope',
username: 'lknope',
email: 'leslie.knope@elastic.co',
},
owner: 'cases',
action: 'add',
};
it('has expected attributes in request', () => {
const query = UserActionCommonAttributesRt.decode(defaultRequest);
expect(query).toStrictEqual({
_tag: 'Right',
right: defaultRequest,
});
});
it('removes foo:bar attributes from request', () => {
const query = UserActionCommonAttributesRt.decode({ ...defaultRequest, foo: 'bar' });
expect(query).toStrictEqual({
_tag: 'Right',
right: defaultRequest,
});
});
});
describe('CaseUserActionInjectedIdsRt', () => {
const defaultRequest = {
comment_id: 'comment-id',
};
it('has expected attributes in request', () => {
const query = CaseUserActionInjectedIdsRt.decode(defaultRequest);
expect(query).toStrictEqual({
_tag: 'Right',
right: defaultRequest,
});
});
it('removes foo:bar attributes from request', () => {
const query = CaseUserActionInjectedIdsRt.decode({ ...defaultRequest, foo: 'bar' });
expect(query).toStrictEqual({
_tag: 'Right',
right: defaultRequest,
});
});
});
describe('CaseUserActionInjectedDeprecatedIdsRt', () => {
const defaultRequest = {
action_id: 'basic-action-id',
case_id: 'basic-case-id',
comment_id: 'basic-comment-id',
};
it('has expected attributes in request', () => {
const query = CaseUserActionInjectedDeprecatedIdsRt.decode(defaultRequest);
expect(query).toStrictEqual({
_tag: 'Right',
right: defaultRequest,
});
});
it('removes foo:bar attributes from request', () => {
const query = CaseUserActionInjectedDeprecatedIdsRt.decode({ ...defaultRequest, foo: 'bar' });
expect(query).toStrictEqual({
_tag: 'Right',
right: defaultRequest,
});
});
});
});

View file

@ -1,70 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import * as rt from 'io-ts';
import { UserRt } from '../../user';
/**
* These values are used in a number of places including to define the accepted values in the
* user_actions/_find api. These values should not be removed only new values can be added.
*/
export const ActionTypes = {
assignees: 'assignees',
comment: 'comment',
connector: 'connector',
description: 'description',
pushed: 'pushed',
tags: 'tags',
title: 'title',
status: 'status',
settings: 'settings',
severity: 'severity',
create_case: 'create_case',
delete_case: 'delete_case',
category: 'category',
} as const;
type ActionTypeKeys = keyof typeof ActionTypes;
export type ActionTypeValues = typeof ActionTypes[ActionTypeKeys];
export const Actions = {
add: 'add',
create: 'create',
delete: 'delete',
update: 'update',
push_to_service: 'push_to_service',
} as const;
export const ActionsRt = rt.keyof(Actions);
export const UserActionCommonAttributesRt = rt.strict({
created_at: rt.string,
created_by: UserRt,
owner: rt.string,
action: ActionsRt,
});
/**
* This should only be used for the getAll route and it should be removed when the route is removed
* @deprecated use CaseUserActionInjectedIdsRt instead
*/
export const CaseUserActionInjectedDeprecatedIdsRt = rt.strict({
action_id: rt.string,
case_id: rt.string,
comment_id: rt.union([rt.string, rt.null]),
});
export const CaseUserActionInjectedIdsRt = rt.strict({
comment_id: rt.union([rt.string, rt.null]),
});
export type UserActionWithAttributes<T> = T & rt.TypeOf<typeof UserActionCommonAttributesRt>;
export type UserActionWithResponse<T> = T & { id: string; version: string } & rt.TypeOf<
typeof CaseUserActionInjectedIdsRt
>;
export type UserActionWithDeprecatedResponse<T> = T &
rt.TypeOf<typeof CaseUserActionInjectedDeprecatedIdsRt>;

View file

@ -1,22 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
export * from './common';
export * from './comment';
export * from './connector';
export * from './create_case';
export * from './delete_case';
export * from './description';
export * from './pushed';
export * from './settings';
export * from './status';
export * from './tags';
export * from './title';
export * from './assignees';
export * from './operations';
export * from './response';
export * from './category';

View file

@ -1,108 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { UserActionFindResponseRt, UserActionFindRequestRt } from './find';
import { ActionTypes } from '../common';
import { CommentType } from '../../comment';
describe('Find UserActions', () => {
describe('UserActionFindRequestRt', () => {
const defaultRequest = {
types: [ActionTypes.comment],
sortOrder: 'desc',
page: '1',
perPage: '10',
};
it('has expected attributes in request', () => {
const query = UserActionFindRequestRt.decode(defaultRequest);
expect(query).toStrictEqual({
_tag: 'Right',
right: {
...defaultRequest,
page: 1,
perPage: 10,
},
});
});
it('removes foo:bar attributes from request', () => {
const query = UserActionFindRequestRt.decode({ ...defaultRequest, foo: 'bar' });
expect(query).toStrictEqual({
_tag: 'Right',
right: {
...defaultRequest,
page: 1,
perPage: 10,
},
});
});
});
describe('UserActionFindResponseRt', () => {
const defaultRequest = {
userActions: [
{
type: ActionTypes.comment,
payload: {
comment: {
comment: 'this is a sample comment',
type: CommentType.user,
owner: 'cases',
},
},
created_at: '2020-02-19T23:06:33.798Z',
created_by: {
full_name: 'Leslie Knope',
username: 'lknope',
email: 'leslie.knope@elastic.co',
},
owner: 'cases',
action: 'create',
id: 'basic-comment-id',
version: 'WzQ3LDFc',
comment_id: 'basic-comment-id',
},
],
page: 1,
perPage: 10,
total: 20,
};
it('has expected attributes in request', () => {
const query = UserActionFindResponseRt.decode(defaultRequest);
expect(query).toStrictEqual({
_tag: 'Right',
right: defaultRequest,
});
});
it('removes foo:bar attributes from request', () => {
const query = UserActionFindResponseRt.decode({ ...defaultRequest, foo: 'bar' });
expect(query).toStrictEqual({
_tag: 'Right',
right: defaultRequest,
});
});
it('removes foo:bar attributes from userActions', () => {
const query = UserActionFindResponseRt.decode({
...defaultRequest,
userActions: [{ ...defaultRequest.userActions[0], foo: 'bar' }],
});
expect(query).toStrictEqual({
_tag: 'Right',
right: defaultRequest,
});
});
});
});

View file

@ -1,49 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import * as rt from 'io-ts';
import { MAX_USER_ACTIONS_PER_PAGE } from '../../../../constants';
import { UserActionsRt } from '../response';
import { ActionTypes } from '../common';
import { paginationSchema } from '../../../../schema';
const AdditionalFilterTypes = {
action: 'action',
alert: 'alert',
user: 'user',
attachment: 'attachment',
} as const;
export const FindTypes = {
...ActionTypes,
...AdditionalFilterTypes,
} as const;
const FindTypeFieldRt = rt.keyof(FindTypes);
export type FindTypeField = rt.TypeOf<typeof FindTypeFieldRt>;
export const UserActionFindRequestRt = rt.intersection([
rt.exact(
rt.partial({
types: rt.array(FindTypeFieldRt),
sortOrder: rt.union([rt.literal('desc'), rt.literal('asc')]),
})
),
paginationSchema({ maxPerPage: MAX_USER_ACTIONS_PER_PAGE }),
]);
export type UserActionFindRequest = rt.TypeOf<typeof UserActionFindRequestRt>;
export const UserActionFindResponseRt = rt.strict({
userActions: UserActionsRt,
page: rt.number,
perPage: rt.number,
total: rt.number,
});
export type UserActionFindResponse = rt.TypeOf<typeof UserActionFindResponseRt>;

View file

@ -1,114 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import * as rt from 'io-ts';
import type { ActionsRt, ActionTypeValues } from './common';
import {
CaseUserActionInjectedIdsRt,
CaseUserActionInjectedDeprecatedIdsRt,
UserActionCommonAttributesRt,
} from './common';
import { CreateCaseUserActionRt, CreateCaseUserActionWithoutConnectorIdRt } from './create_case';
import { DescriptionUserActionRt } from './description';
import { CommentUserActionRt, CommentUserActionWithoutIdsRt } from './comment';
import { ConnectorUserActionRt, ConnectorUserActionWithoutConnectorIdRt } from './connector';
import { PushedUserActionRt, PushedUserActionWithoutConnectorIdRt } from './pushed';
import { TagsUserActionRt } from './tags';
import { TitleUserActionRt } from './title';
import { SettingsUserActionRt } from './settings';
import { StatusUserActionRt } from './status';
import { DeleteCaseUserActionRt } from './delete_case';
import { SeverityUserActionRt } from './severity';
import { AssigneesUserActionRt } from './assignees';
import { CaseUserActionStatsRt } from './stats';
import { CategoryUserActionRt } from './category';
const BasicUserActionsRt = rt.union([
DescriptionUserActionRt,
TagsUserActionRt,
TitleUserActionRt,
SettingsUserActionRt,
StatusUserActionRt,
SeverityUserActionRt,
AssigneesUserActionRt,
DeleteCaseUserActionRt,
CategoryUserActionRt,
]);
const CommonUserActionsWithIdsRt = rt.union([BasicUserActionsRt, CommentUserActionRt]);
const CommonUserActionsWithoutIdsRt = rt.union([BasicUserActionsRt, CommentUserActionWithoutIdsRt]);
const UserActionPayloadRt = rt.union([
CommonUserActionsWithIdsRt,
CreateCaseUserActionRt,
ConnectorUserActionRt,
PushedUserActionRt,
]);
const UserActionsWithoutIdsRt = rt.union([
CommonUserActionsWithoutIdsRt,
CreateCaseUserActionWithoutConnectorIdRt,
ConnectorUserActionWithoutConnectorIdRt,
PushedUserActionWithoutConnectorIdRt,
]);
const CaseUserActionBasicRt = rt.intersection([UserActionPayloadRt, UserActionCommonAttributesRt]);
export const CaseUserActionWithoutReferenceIdsRt = rt.intersection([
UserActionsWithoutIdsRt,
UserActionCommonAttributesRt,
]);
export const CaseUserActionDeprecatedResponseRt = rt.intersection([
CaseUserActionBasicRt,
CaseUserActionInjectedDeprecatedIdsRt,
]);
/**
* This includes the comment_id but not the action_id or case_id
*/
export const UserActionAttributesRt = rt.intersection([
CaseUserActionBasicRt,
CaseUserActionInjectedIdsRt,
]);
const UserActionRt = rt.intersection([
UserActionAttributesRt,
rt.strict({
id: rt.string,
version: rt.string,
}),
]);
export const UserActionsRt = rt.array(UserActionRt);
export const CaseUserActionsDeprecatedResponseRt = rt.array(CaseUserActionDeprecatedResponseRt);
export const CaseUserActionStatsResponseRt = CaseUserActionStatsRt;
export type CaseUserActionWithoutReferenceIds = rt.TypeOf<
typeof CaseUserActionWithoutReferenceIdsRt
>;
export type CaseUserActionStatsResponse = rt.TypeOf<typeof CaseUserActionStatsRt>;
export type UserActions = rt.TypeOf<typeof UserActionsRt>;
export type UserAction = rt.TypeOf<typeof UserActionRt>;
export type CaseUserActionsDeprecatedResponse = rt.TypeOf<
typeof CaseUserActionsDeprecatedResponseRt
>;
export type CaseUserActionDeprecatedResponse = rt.TypeOf<typeof CaseUserActionDeprecatedResponseRt>;
export type UserActionAttributes = rt.TypeOf<typeof UserActionAttributesRt>;
/**
* This defines the high level category for the user action. Whether the user add, removed, updated something
*/
export type ActionCategory = rt.TypeOf<typeof ActionsRt>;
/**
* This defines the type of the user action, meaning what individual action was taken, for example changing the status,
* adding an assignee etc.
*/
export type UserActionTypes = ActionTypeValues;

View file

@ -1,36 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { CaseUserActionStatsRt } from './stats';
describe('Stats', () => {
describe('CaseUserActionStatsRt', () => {
const defaultRequest = {
total: 100,
total_comments: 60,
total_other_actions: 40,
};
it('has expected attributes in request', () => {
const query = CaseUserActionStatsRt.decode(defaultRequest);
expect(query).toStrictEqual({
_tag: 'Right',
right: defaultRequest,
});
});
it('removes foo:bar attributes from request', () => {
const query = CaseUserActionStatsRt.decode({ ...defaultRequest, foo: 'bar' });
expect(query).toStrictEqual({
_tag: 'Right',
right: defaultRequest,
});
});
});
});

View file

@ -7,6 +7,8 @@
// Latest
export * from './configure/latest';
export * from './user_action/latest';
// V1
export * as configureApiV1 from './configure/v1';
export * as userActionApiV1 from './user_action/v1';

View file

@ -0,0 +1,169 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { CommentType } from '../../../api';
import { UserActionTypes } from '../../domain/user_action/action/v1';
import {
CaseUserActionStatsResponseRt,
CaseUserActionStatsRt,
UserActionFindRequestRt,
UserActionFindResponseRt,
} from './v1';
describe('User actions APIs', () => {
describe('Find API', () => {
describe('UserActionFindRequestRt', () => {
const defaultRequest = {
types: [UserActionTypes.comment],
sortOrder: 'desc',
page: '1',
perPage: '10',
};
it('has expected attributes in request', () => {
const query = UserActionFindRequestRt.decode(defaultRequest);
expect(query).toStrictEqual({
_tag: 'Right',
right: {
...defaultRequest,
page: 1,
perPage: 10,
},
});
});
it('removes foo:bar attributes from request', () => {
const query = UserActionFindRequestRt.decode({ ...defaultRequest, foo: 'bar' });
expect(query).toStrictEqual({
_tag: 'Right',
right: {
...defaultRequest,
page: 1,
perPage: 10,
},
});
});
});
describe('UserActionFindResponseRt', () => {
const defaultRequest = {
userActions: [
{
type: UserActionTypes.comment,
payload: {
comment: {
comment: 'this is a sample comment',
type: CommentType.user,
owner: 'cases',
},
},
created_at: '2020-02-19T23:06:33.798Z',
created_by: {
full_name: 'Leslie Knope',
username: 'lknope',
email: 'leslie.knope@elastic.co',
},
owner: 'cases',
action: 'create',
id: 'basic-comment-id',
version: 'WzQ3LDFc',
comment_id: 'basic-comment-id',
},
],
page: 1,
perPage: 10,
total: 20,
};
it('has expected attributes in request', () => {
const query = UserActionFindResponseRt.decode(defaultRequest);
expect(query).toStrictEqual({
_tag: 'Right',
right: defaultRequest,
});
});
it('removes foo:bar attributes from request', () => {
const query = UserActionFindResponseRt.decode({ ...defaultRequest, foo: 'bar' });
expect(query).toStrictEqual({
_tag: 'Right',
right: defaultRequest,
});
});
it('removes foo:bar attributes from userActions', () => {
const query = UserActionFindResponseRt.decode({
...defaultRequest,
userActions: [{ ...defaultRequest.userActions[0], foo: 'bar' }],
});
expect(query).toStrictEqual({
_tag: 'Right',
right: defaultRequest,
});
});
});
});
describe('User actions stats API', () => {
describe('CaseUserActionStatsResponseRt', () => {
const defaultRequest = {
total: 15,
total_comments: 10,
total_other_actions: 5,
};
it('has expected attributes in request', () => {
const query = CaseUserActionStatsResponseRt.decode(defaultRequest);
expect(query).toStrictEqual({
_tag: 'Right',
right: defaultRequest,
});
});
it('removes foo:bar attributes from request', () => {
const query = CaseUserActionStatsResponseRt.decode({ ...defaultRequest, foo: 'bar' });
expect(query).toStrictEqual({
_tag: 'Right',
right: defaultRequest,
});
});
});
describe('CaseUserActionStatsRt', () => {
const defaultRequest = {
total: 100,
total_comments: 60,
total_other_actions: 40,
};
it('has expected attributes in request', () => {
const query = CaseUserActionStatsRt.decode(defaultRequest);
expect(query).toStrictEqual({
_tag: 'Right',
right: defaultRequest,
});
});
it('removes foo:bar attributes from request', () => {
const query = CaseUserActionStatsRt.decode({ ...defaultRequest, foo: 'bar' });
expect(query).toStrictEqual({
_tag: 'Right',
right: defaultRequest,
});
});
});
});
});

View file

@ -0,0 +1,87 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import * as rt from 'io-ts';
import { paginationSchema } from '../../../schema';
import { MAX_USER_ACTIONS_PER_PAGE } from '../../../constants';
import { UserActionTypes } from '../../domain/user_action/action/v1';
import type { CaseUserActionInjectedIdsRt } from '../../domain/user_action/v1';
import {
CaseUserActionInjectedDeprecatedIdsRt,
CaseUserActionBasicRt,
UserActionsRt,
} from '../../domain/user_action/v1';
export type UserActionWithResponse<T> = T & { id: string; version: string } & rt.TypeOf<
typeof CaseUserActionInjectedIdsRt
>;
/**
* User actions stats API
*/
export const CaseUserActionStatsRt = rt.strict({
total: rt.number,
total_comments: rt.number,
total_other_actions: rt.number,
});
export type CaseUserActionStatsResponse = rt.TypeOf<typeof CaseUserActionStatsRt>;
export const CaseUserActionStatsResponseRt = CaseUserActionStatsRt;
/**
* Deprecated APIs
*/
export const CaseUserActionDeprecatedResponseRt = rt.intersection([
CaseUserActionBasicRt,
CaseUserActionInjectedDeprecatedIdsRt,
]);
export const CaseUserActionsDeprecatedResponseRt = rt.array(CaseUserActionDeprecatedResponseRt);
export type CaseUserActionsDeprecatedResponse = rt.TypeOf<
typeof CaseUserActionsDeprecatedResponseRt
>;
export type CaseUserActionDeprecatedResponse = rt.TypeOf<typeof CaseUserActionDeprecatedResponseRt>;
/**
* Find User Actions API
*/
const UserActionAdditionalFindRequestFilterTypes = {
action: 'action',
alert: 'alert',
user: 'user',
attachment: 'attachment',
} as const;
const UserActionFindRequestTypes = {
...UserActionTypes,
...UserActionAdditionalFindRequestFilterTypes,
} as const;
const UserActionFindRequestTypesRt = rt.keyof(UserActionFindRequestTypes);
export type UserActionFindRequestTypes = rt.TypeOf<typeof UserActionFindRequestTypesRt>;
export const UserActionFindRequestRt = rt.intersection([
rt.exact(
rt.partial({
types: rt.array(UserActionFindRequestTypesRt),
sortOrder: rt.union([rt.literal('desc'), rt.literal('asc')]),
})
),
paginationSchema({ maxPerPage: MAX_USER_ACTIONS_PER_PAGE }),
]);
export type UserActionFindRequest = rt.TypeOf<typeof UserActionFindRequestRt>;
export const UserActionFindResponseRt = rt.strict({
userActions: UserActionsRt,
page: rt.number,
perPage: rt.number,
total: rt.number,
});
export type UserActionFindResponse = rt.TypeOf<typeof UserActionFindResponseRt>;

View file

@ -7,6 +7,8 @@
// Latest
export * from './configure/latest';
export * from './user_action/latest';
// V1
export * as configureDomainV1 from './configure/v1';
export * as userActionDomainV1 from './user_action/v1';

View file

@ -5,12 +5,4 @@
* 2.0.
*/
import * as rt from 'io-ts';
export const CaseUserActionStatsRt = rt.strict({
total: rt.number,
total_comments: rt.number,
total_other_actions: rt.number,
});
export type CaseUserActionStats = rt.TypeOf<typeof CaseUserActionStatsRt>;
export * from './v1';

View file

@ -0,0 +1,50 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import * as rt from 'io-ts';
/**
* These values are used in a number of places including to define the accepted values in the
* user_actions/_find api. These values should not be removed only new values can be added.
*/
export const UserActionTypes = {
assignees: 'assignees',
comment: 'comment',
connector: 'connector',
description: 'description',
pushed: 'pushed',
tags: 'tags',
title: 'title',
status: 'status',
settings: 'settings',
severity: 'severity',
create_case: 'create_case',
delete_case: 'delete_case',
category: 'category',
} as const;
type UserActionActionTypeKeys = keyof typeof UserActionTypes;
/**
* This defines the type of the user action, meaning what individual action was taken, for example changing the status,
* adding an assignee etc.
*/
export type UserActionType = typeof UserActionTypes[UserActionActionTypeKeys];
export const UserActionActions = {
add: 'add',
create: 'create',
delete: 'delete',
update: 'update',
push_to_service: 'push_to_service',
} as const;
export const UserActionActionsRt = rt.keyof(UserActionActions);
/**
* This defines the high level category for the user action. Whether the user add, removed, updated something
*/
export type UserActionAction = rt.TypeOf<typeof UserActionActionsRt>;

View file

@ -0,0 +1,8 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
export * from './v1';

View file

@ -5,8 +5,8 @@
* 2.0.
*/
import { AssigneesUserActionPayloadRt, AssigneesUserActionRt } from './assignees';
import { ActionTypes } from './common';
import { UserActionTypes } from '../action/v1';
import { AssigneesUserActionPayloadRt, AssigneesUserActionRt } from './v1';
describe('Assignees', () => {
describe('AssigneesUserActionPayloadRt', () => {
@ -34,7 +34,7 @@ describe('Assignees', () => {
});
describe('AssigneesUserActionRt', () => {
const defaultRequest = {
type: ActionTypes.assignees,
type: UserActionTypes.assignees,
payload: {
assignees: [{ uid: '1' }, { uid: '2' }, { uid: '3' }],
},
@ -60,7 +60,7 @@ describe('Assignees', () => {
it('removes foo:bar attributes from assignees', () => {
const query = AssigneesUserActionRt.decode({
type: ActionTypes.assignees,
type: UserActionTypes.assignees,
payload: {
assignees: [{ uid: '1', foo: 'bar' }, { uid: '2' }, { uid: '3' }],
},
@ -69,7 +69,7 @@ describe('Assignees', () => {
expect(query).toStrictEqual({
_tag: 'Right',
right: {
type: ActionTypes.assignees,
type: UserActionTypes.assignees,
payload: {
assignees: [{ uid: '1' }, { uid: '2' }, { uid: '3' }],
},

View file

@ -6,15 +6,12 @@
*/
import * as rt from 'io-ts';
import { CaseAssigneesRt } from '../assignee';
import type { UserActionWithAttributes } from './common';
import { ActionTypes } from './common';
import { CaseAssigneesRt } from '../../../../api';
import { UserActionTypes } from '../action/v1';
export const AssigneesUserActionPayloadRt = rt.strict({ assignees: CaseAssigneesRt });
export const AssigneesUserActionRt = rt.strict({
type: rt.literal(ActionTypes.assignees),
type: rt.literal(UserActionTypes.assignees),
payload: AssigneesUserActionPayloadRt,
});
export type AssigneesUserAction = UserActionWithAttributes<rt.TypeOf<typeof AssigneesUserActionRt>>;

View file

@ -0,0 +1,8 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
export * from './v1';

View file

@ -5,8 +5,8 @@
* 2.0.
*/
import { ActionTypes } from './common';
import { CategoryUserActionPayloadRt, CategoryUserActionRt } from './category';
import { UserActionTypes } from '../action/v1';
import { CategoryUserActionPayloadRt, CategoryUserActionRt } from './v1';
describe('Category', () => {
describe('CategoryUserActionPayloadRt', () => {
@ -35,7 +35,7 @@ describe('Category', () => {
describe('CategoryUserActionRt', () => {
const defaultRequest = {
type: ActionTypes.category,
type: UserActionTypes.category,
payload: {
category: 'foobar',
},

View file

@ -6,14 +6,11 @@
*/
import * as rt from 'io-ts';
import type { UserActionWithAttributes } from './common';
import { ActionTypes } from './common';
import { UserActionTypes } from '../action/v1';
export const CategoryUserActionPayloadRt = rt.strict({ category: rt.union([rt.string, rt.null]) });
export const CategoryUserActionRt = rt.strict({
type: rt.literal(ActionTypes.category),
type: rt.literal(UserActionTypes.category),
payload: CategoryUserActionPayloadRt,
});
export type CategoryUserAction = UserActionWithAttributes<rt.TypeOf<typeof CategoryUserActionRt>>;

View file

@ -0,0 +1,8 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
export * from './v1';

View file

@ -5,9 +5,9 @@
* 2.0.
*/
import { CommentType } from '../comment';
import { CommentUserActionPayloadRt, CommentUserActionRt } from './comment';
import { ActionTypes } from './common';
import { CommentType } from '../../../../api';
import { UserActionTypes } from '../action/v1';
import { CommentUserActionPayloadRt, CommentUserActionRt } from './v1';
describe('Comment', () => {
describe('CommentUserActionPayloadRt', () => {
@ -50,7 +50,7 @@ describe('Comment', () => {
});
describe('CommentUserActionRt', () => {
const defaultRequest = {
type: ActionTypes.comment,
type: UserActionTypes.comment,
payload: {
comment: {
comment: 'this is a sample comment',

View file

@ -6,9 +6,8 @@
*/
import * as rt from 'io-ts';
import { CommentRequestRt, CommentRequestWithoutRefsRt } from '../comment';
import type { UserActionWithAttributes } from './common';
import { ActionTypes } from './common';
import { CommentRequestRt, CommentRequestWithoutRefsRt } from '../../../../api';
import { UserActionTypes } from '../action/v1';
export const CommentUserActionPayloadRt = rt.strict({ comment: CommentRequestRt });
export const CommentUserActionPayloadWithoutIdsRt = rt.strict({
@ -16,16 +15,11 @@ export const CommentUserActionPayloadWithoutIdsRt = rt.strict({
});
export const CommentUserActionRt = rt.strict({
type: rt.literal(ActionTypes.comment),
type: rt.literal(UserActionTypes.comment),
payload: CommentUserActionPayloadRt,
});
export const CommentUserActionWithoutIdsRt = rt.strict({
type: rt.literal(ActionTypes.comment),
type: rt.literal(UserActionTypes.comment),
payload: CommentUserActionPayloadWithoutIdsRt,
});
export type CommentUserAction = UserActionWithAttributes<rt.TypeOf<typeof CommentUserActionRt>>;
export type CommentUserActionPayloadWithoutIds = UserActionWithAttributes<
rt.TypeOf<typeof CommentUserActionPayloadWithoutIdsRt>
>;

View file

@ -0,0 +1,8 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
export * from './v1';

View file

@ -5,8 +5,8 @@
* 2.0.
*/
import { ConnectorTypes } from '../../connectors';
import { ConnectorUserActionPayloadWithoutConnectorIdRt } from './connector';
import { ConnectorTypes } from '../../../../api';
import { ConnectorUserActionPayloadWithoutConnectorIdRt } from './v1';
describe('Connector', () => {
describe('ConnectorUserActionPayloadWithoutConnectorIdRt', () => {

View file

@ -6,9 +6,8 @@
*/
import * as rt from 'io-ts';
import { CaseUserActionConnectorRt, CaseConnectorRt } from '../../connectors/connector';
import type { UserActionWithAttributes } from './common';
import { ActionTypes } from './common';
import { CaseConnectorRt, CaseUserActionConnectorRt } from '../../../../api';
import { UserActionTypes } from '../action/v1';
export const ConnectorUserActionPayloadWithoutConnectorIdRt = rt.strict({
connector: CaseUserActionConnectorRt,
@ -19,16 +18,11 @@ export const ConnectorUserActionPayloadRt = rt.strict({
});
export const ConnectorUserActionWithoutConnectorIdRt = rt.strict({
type: rt.literal(ActionTypes.connector),
type: rt.literal(UserActionTypes.connector),
payload: ConnectorUserActionPayloadWithoutConnectorIdRt,
});
export const ConnectorUserActionRt = rt.strict({
type: rt.literal(ActionTypes.connector),
type: rt.literal(UserActionTypes.connector),
payload: ConnectorUserActionPayloadRt,
});
export type ConnectorUserAction = UserActionWithAttributes<rt.TypeOf<typeof ConnectorUserActionRt>>;
export type ConnectorUserActionWithoutConnectorId = UserActionWithAttributes<
rt.TypeOf<typeof ConnectorUserActionWithoutConnectorIdRt>
>;

View file

@ -0,0 +1,8 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
export * from './v1';

View file

@ -4,14 +4,15 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { ConnectorTypes } from '../../connectors';
import { ActionTypes } from './common';
import { CreateCaseUserActionRt, CreateCaseUserActionWithoutConnectorIdRt } from './create_case';
import { ConnectorTypes } from '../../../../api';
import { UserActionTypes } from '../action/v1';
import { CreateCaseUserActionRt, CreateCaseUserActionWithoutConnectorIdRt } from './v1';
describe('Create case', () => {
describe('CreateCaseUserActionRt', () => {
const defaultRequest = {
type: ActionTypes.create_case,
type: UserActionTypes.create_case,
payload: {
connector: {
id: 'jira-connector-id',
@ -97,7 +98,7 @@ describe('Create case', () => {
describe('CreateCaseUserActionWithoutConnectorIdRt', () => {
const defaultRequest = {
type: ActionTypes.create_case,
type: UserActionTypes.create_case,
payload: {
connector: {
type: ConnectorTypes.jira,

View file

@ -6,21 +6,20 @@
*/
import * as rt from 'io-ts';
import { AssigneesUserActionPayloadRt } from './assignees';
import { CategoryUserActionPayloadRt } from './category';
import type { UserActionWithAttributes } from './common';
import { ActionTypes } from './common';
import { UserActionTypes } from '../action/v1';
import { AssigneesUserActionPayloadRt } from '../assignees/v1';
import { CategoryUserActionPayloadRt } from '../category/v1';
import {
ConnectorUserActionPayloadRt,
ConnectorUserActionPayloadWithoutConnectorIdRt,
} from './connector';
import { DescriptionUserActionPayloadRt } from './description';
import { SettingsUserActionPayloadRt } from './settings';
import { TagsUserActionPayloadRt } from './tags';
import { TitleUserActionPayloadRt } from './title';
} from '../connector/v1';
import { DescriptionUserActionPayloadRt } from '../description/v1';
import { SettingsUserActionPayloadRt } from '../settings/v1';
import { TagsUserActionPayloadRt } from '../tags/v1';
import { TitleUserActionPayloadRt } from '../title/v1';
export const CommonFieldsRt = rt.strict({
type: rt.literal(ActionTypes.create_case),
const CommonFieldsRt = rt.strict({
type: rt.literal(UserActionTypes.create_case),
});
const CommonPayloadAttributesRt = rt.strict({
@ -58,10 +57,3 @@ export const CreateCaseUserActionWithoutConnectorIdRt = rt.intersection([
payload: rt.intersection([ConnectorUserActionPayloadWithoutConnectorIdRt, PayloadAttributesRt]),
}),
]);
export type CreateCaseUserAction = UserActionWithAttributes<
rt.TypeOf<typeof CreateCaseUserActionRt>
>;
export type CreateCaseUserActionWithoutConnectorId = UserActionWithAttributes<
rt.TypeOf<typeof CreateCaseUserActionWithoutConnectorIdRt>
>;

View file

@ -0,0 +1,8 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
export * from './v1';

View file

@ -5,13 +5,13 @@
* 2.0.
*/
import { ActionTypes } from './common';
import { DeleteCaseUserActionRt } from './delete_case';
import { UserActionTypes } from '../action/v1';
import { DeleteCaseUserActionRt } from './v1';
describe('Delete_case', () => {
describe('DeleteCaseUserActionRt', () => {
const defaultRequest = {
type: ActionTypes.delete_case,
type: UserActionTypes.delete_case,
payload: {},
};

View file

@ -6,14 +6,9 @@
*/
import * as rt from 'io-ts';
import type { UserActionWithAttributes } from './common';
import { ActionTypes } from './common';
import { UserActionTypes } from '../action/v1';
export const DeleteCaseUserActionRt = rt.strict({
type: rt.literal(ActionTypes.delete_case),
type: rt.literal(UserActionTypes.delete_case),
payload: rt.strict({}),
});
export type DeleteCaseUserAction = UserActionWithAttributes<
rt.TypeOf<typeof DeleteCaseUserActionRt>
>;

View file

@ -0,0 +1,8 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
export * from './v1';

View file

@ -5,8 +5,8 @@
* 2.0.
*/
import { ActionTypes } from './common';
import { DescriptionUserActionPayloadRt, DescriptionUserActionRt } from './description';
import { UserActionTypes } from '../action/v1';
import { DescriptionUserActionPayloadRt, DescriptionUserActionRt } from './v1';
describe('Description', () => {
describe('DescriptionUserActionPayloadRt', () => {
@ -35,7 +35,7 @@ describe('Description', () => {
describe('DescriptionUserActionRt', () => {
const defaultRequest = {
type: ActionTypes.description,
type: UserActionTypes.description,
payload: {
description: 'this is sample description',
},

View file

@ -6,16 +6,11 @@
*/
import * as rt from 'io-ts';
import type { UserActionWithAttributes } from './common';
import { ActionTypes } from './common';
import { UserActionTypes } from '../action/v1';
export const DescriptionUserActionPayloadRt = rt.strict({ description: rt.string });
export const DescriptionUserActionRt = rt.strict({
type: rt.literal(ActionTypes.description),
type: rt.literal(UserActionTypes.description),
payload: DescriptionUserActionPayloadRt,
});
export type DescriptionUserAction = UserActionWithAttributes<
rt.TypeOf<typeof DescriptionUserActionRt>
>;

View file

@ -0,0 +1,8 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
export * from './v1';

View file

@ -0,0 +1,8 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
export * from './v1';

View file

@ -5,13 +5,13 @@
* 2.0.
*/
import { ActionTypes } from './common';
import { UserActionTypes } from '../action/v1';
import {
PushedUserActionPayloadWithoutConnectorIdRt,
PushedUserActionPayloadRt,
PushedUserActionWithoutConnectorIdRt,
PushedUserActionRt,
} from './pushed';
} from './v1';
describe('Pushed', () => {
describe('PushedUserActionPayloadWithoutConnectorIdRt', () => {
@ -112,7 +112,7 @@ describe('Pushed', () => {
describe('PushedUserActionWithoutConnectorIdRt', () => {
const defaultRequest = {
type: ActionTypes.pushed,
type: UserActionTypes.pushed,
payload: {
externalService: {
connector_name: 'My SN connector',
@ -162,7 +162,7 @@ describe('Pushed', () => {
describe('PushedUserActionRt', () => {
const defaultRequest = {
type: ActionTypes.pushed,
type: UserActionTypes.pushed,
payload: {
externalService: {
connector_id: 'servicenow-1',

View file

@ -6,9 +6,8 @@
*/
import * as rt from 'io-ts';
import { CaseUserActionExternalServiceRt, CaseExternalServiceBasicRt } from '../case';
import type { UserActionWithAttributes } from './common';
import { ActionTypes } from './common';
import { CaseExternalServiceBasicRt, CaseUserActionExternalServiceRt } from '../../../../api';
import { UserActionTypes } from '../action/v1';
export const PushedUserActionPayloadWithoutConnectorIdRt = rt.strict({
externalService: CaseUserActionExternalServiceRt,
@ -19,16 +18,11 @@ export const PushedUserActionPayloadRt = rt.strict({
});
export const PushedUserActionWithoutConnectorIdRt = rt.strict({
type: rt.literal(ActionTypes.pushed),
type: rt.literal(UserActionTypes.pushed),
payload: PushedUserActionPayloadWithoutConnectorIdRt,
});
export const PushedUserActionRt = rt.strict({
type: rt.literal(ActionTypes.pushed),
type: rt.literal(UserActionTypes.pushed),
payload: PushedUserActionPayloadRt,
});
export type PushedUserAction = UserActionWithAttributes<rt.TypeOf<typeof PushedUserActionRt>>;
export type PushedUserActionWithoutConnectorId = UserActionWithAttributes<
rt.TypeOf<typeof PushedUserActionWithoutConnectorIdRt>
>;

View file

@ -0,0 +1,8 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
export * from './v1';

View file

@ -5,8 +5,8 @@
* 2.0.
*/
import { ActionTypes } from './common';
import { SettingsUserActionPayloadRt, SettingsUserActionRt } from './settings';
import { UserActionTypes } from '../action/v1';
import { SettingsUserActionPayloadRt, SettingsUserActionRt } from './v1';
describe('Settings', () => {
describe('SettingsUserActionPayloadRt', () => {
@ -40,7 +40,7 @@ describe('Settings', () => {
describe('SettingsUserActionRt', () => {
const defaultRequest = {
type: ActionTypes.settings,
type: UserActionTypes.settings,
payload: {
settings: { syncAlerts: true },
},

View file

@ -6,15 +6,12 @@
*/
import * as rt from 'io-ts';
import type { UserActionWithAttributes } from './common';
import { ActionTypes } from './common';
import { SettingsRt } from '../case';
import { SettingsRt } from '../../../../api';
import { UserActionTypes } from '../action/v1';
export const SettingsUserActionPayloadRt = rt.strict({ settings: SettingsRt });
export const SettingsUserActionRt = rt.strict({
type: rt.literal(ActionTypes.settings),
type: rt.literal(UserActionTypes.settings),
payload: SettingsUserActionPayloadRt,
});
export type SettingsUserAction = UserActionWithAttributes<rt.TypeOf<typeof SettingsUserActionRt>>;

View file

@ -0,0 +1,8 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
export * from './v1';

View file

@ -5,9 +5,9 @@
* 2.0.
*/
import { CaseSeverity } from '../case';
import { ActionTypes } from './common';
import { SeverityUserActionPayloadRt, SeverityUserActionRt } from './severity';
import { CaseSeverity } from '../../../../api';
import { UserActionTypes } from '../action/v1';
import { SeverityUserActionPayloadRt, SeverityUserActionRt } from './v1';
describe('Severity', () => {
describe('SeverityUserActionPayloadRt', () => {
@ -36,7 +36,7 @@ describe('Severity', () => {
describe('SeverityUserActionRt', () => {
const defaultRequest = {
type: ActionTypes.severity,
type: UserActionTypes.severity,
payload: {
severity: CaseSeverity.CRITICAL,
},

View file

@ -6,15 +6,12 @@
*/
import * as rt from 'io-ts';
import { CaseSeverityRt } from '../case';
import type { UserActionWithAttributes } from './common';
import { ActionTypes } from './common';
import { CaseSeverityRt } from '../../../../api';
import { UserActionTypes } from '../action/v1';
export const SeverityUserActionPayloadRt = rt.strict({ severity: CaseSeverityRt });
export const SeverityUserActionRt = rt.strict({
type: rt.literal(ActionTypes.severity),
type: rt.literal(UserActionTypes.severity),
payload: SeverityUserActionPayloadRt,
});
export type SeverityUserAction = UserActionWithAttributes<rt.TypeOf<typeof SeverityUserActionRt>>;

View file

@ -0,0 +1,8 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
export * from './v1';

View file

@ -5,9 +5,9 @@
* 2.0.
*/
import { CaseStatuses } from '../status';
import { ActionTypes } from './common';
import { StatusUserActionPayloadRt, StatusUserActionRt } from './status';
import { CaseStatuses } from '@kbn/cases-components';
import { UserActionTypes } from '../action/v1';
import { StatusUserActionPayloadRt, StatusUserActionRt } from './v1';
describe('Status', () => {
describe('StatusUserActionPayloadRt', () => {
@ -36,7 +36,7 @@ describe('Status', () => {
describe('StatusUserActionRt', () => {
const defaultRequest = {
type: ActionTypes.status,
type: UserActionTypes.status,
payload: {
status: CaseStatuses.closed,
},

View file

@ -6,15 +6,12 @@
*/
import * as rt from 'io-ts';
import { CaseStatusRt } from '../status';
import type { UserActionWithAttributes } from './common';
import { ActionTypes } from './common';
import { CaseStatusRt } from '../../../../api';
import { UserActionTypes } from '../action/v1';
export const StatusUserActionPayloadRt = rt.strict({ status: CaseStatusRt });
export const StatusUserActionRt = rt.strict({
type: rt.literal(ActionTypes.status),
type: rt.literal(UserActionTypes.status),
payload: StatusUserActionPayloadRt,
});
export type StatusUserAction = UserActionWithAttributes<rt.TypeOf<typeof StatusUserActionRt>>;

View file

@ -0,0 +1,8 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
export * from './v1';

View file

@ -5,8 +5,8 @@
* 2.0.
*/
import { ActionTypes } from './common';
import { TagsUserActionPayloadRt, TagsUserActionRt } from './tags';
import { UserActionTypes } from '../action/v1';
import { TagsUserActionPayloadRt, TagsUserActionRt } from './v1';
describe('Tags', () => {
describe('TagsUserActionPayloadRt', () => {
@ -35,7 +35,7 @@ describe('Tags', () => {
describe('TagsUserActionRt', () => {
const defaultRequest = {
type: ActionTypes.tags,
type: UserActionTypes.tags,
payload: {
tags: ['one', '2-two'],
},

View file

@ -6,14 +6,11 @@
*/
import * as rt from 'io-ts';
import type { UserActionWithAttributes } from './common';
import { ActionTypes } from './common';
import { UserActionTypes } from '../action/v1';
export const TagsUserActionPayloadRt = rt.strict({ tags: rt.array(rt.string) });
export const TagsUserActionRt = rt.strict({
type: rt.literal(ActionTypes.tags),
type: rt.literal(UserActionTypes.tags),
payload: TagsUserActionPayloadRt,
});
export type TagsUserAction = UserActionWithAttributes<rt.TypeOf<typeof TagsUserActionRt>>;

View file

@ -0,0 +1,8 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
export * from './v1';

View file

@ -5,8 +5,8 @@
* 2.0.
*/
import { ActionTypes } from './common';
import { TitleUserActionPayloadRt, TitleUserActionRt } from './title';
import { UserActionTypes } from '../action/v1';
import { TitleUserActionPayloadRt, TitleUserActionRt } from './v1';
describe('Title', () => {
describe('TitleUserActionPayloadRt', () => {
@ -35,7 +35,7 @@ describe('Title', () => {
describe('TitleUserActionRt', () => {
const defaultRequest = {
type: ActionTypes.title,
type: UserActionTypes.title,
payload: {
title: 'sample title',
},

View file

@ -6,14 +6,11 @@
*/
import * as rt from 'io-ts';
import type { UserActionWithAttributes } from './common';
import { ActionTypes } from './common';
import { UserActionTypes } from '../action/v1';
export const TitleUserActionPayloadRt = rt.strict({ title: rt.string });
export const TitleUserActionRt = rt.strict({
type: rt.literal(ActionTypes.title),
type: rt.literal(UserActionTypes.title),
payload: TitleUserActionPayloadRt,
});
export type TitleUserAction = UserActionWithAttributes<rt.TypeOf<typeof TitleUserActionRt>>;

View file

@ -5,15 +5,15 @@
* 2.0.
*/
import { CommentType } from '../comment';
import { ActionTypes } from './common';
import { UserActionsRt, CaseUserActionStatsResponseRt } from './response';
import { CommentType } from '../../../api';
import { UserActionTypes } from './action/v1';
import { UserActionsRt } from './v1';
describe('Response', () => {
describe('User actions', () => {
describe('UserActionsRt', () => {
const defaultRequest = [
{
type: ActionTypes.comment,
type: UserActionTypes.comment,
payload: {
comment: {
comment: 'this is a sample comment',
@ -64,30 +64,4 @@ describe('Response', () => {
});
});
});
describe('CaseUserActionStatsResponseRt', () => {
const defaultRequest = {
total: 15,
total_comments: 10,
total_other_actions: 5,
};
it('has expected attributes in request', () => {
const query = CaseUserActionStatsResponseRt.decode(defaultRequest);
expect(query).toStrictEqual({
_tag: 'Right',
right: defaultRequest,
});
});
it('removes foo:bar attributes from request', () => {
const query = CaseUserActionStatsResponseRt.decode({ ...defaultRequest, foo: 'bar' });
expect(query).toStrictEqual({
_tag: 'Right',
right: defaultRequest,
});
});
});
});

View file

@ -0,0 +1,153 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import * as rt from 'io-ts';
import { UserRt } from '../../../api';
import { UserActionActionsRt } from './action/v1';
import { AssigneesUserActionRt } from './assignees/v1';
import { CategoryUserActionRt } from './category/v1';
import type { CommentUserActionPayloadWithoutIdsRt } from './comment/v1';
import { CommentUserActionRt, CommentUserActionWithoutIdsRt } from './comment/v1';
import { ConnectorUserActionRt, ConnectorUserActionWithoutConnectorIdRt } from './connector/v1';
import { CreateCaseUserActionRt, CreateCaseUserActionWithoutConnectorIdRt } from './create_case/v1';
import { DeleteCaseUserActionRt } from './delete_case/v1';
import { DescriptionUserActionRt } from './description/v1';
import { PushedUserActionRt, PushedUserActionWithoutConnectorIdRt } from './pushed/v1';
import { SettingsUserActionRt } from './settings/v1';
import { SeverityUserActionRt } from './severity/v1';
import { StatusUserActionRt } from './status/v1';
import { TagsUserActionRt } from './tags/v1';
import { TitleUserActionRt } from './title/v1';
export { UserActionTypes, UserActionActions } from './action/v1';
export { StatusUserActionRt } from './status/v1';
export type { UserActionType, UserActionAction } from './action/v1';
const UserActionCommonAttributesRt = rt.strict({
created_at: rt.string,
created_by: UserRt,
owner: rt.string,
action: UserActionActionsRt,
});
/**
* This should only be used for the getAll route and it should be removed when the route is removed
* @deprecated use CaseUserActionInjectedIdsRt instead
*/
export const CaseUserActionInjectedDeprecatedIdsRt = rt.strict({
action_id: rt.string,
case_id: rt.string,
comment_id: rt.union([rt.string, rt.null]),
});
export const CaseUserActionInjectedIdsRt = rt.strict({
comment_id: rt.union([rt.string, rt.null]),
});
const BasicUserActionsRt = rt.union([
DescriptionUserActionRt,
TagsUserActionRt,
TitleUserActionRt,
SettingsUserActionRt,
StatusUserActionRt,
SeverityUserActionRt,
AssigneesUserActionRt,
DeleteCaseUserActionRt,
CategoryUserActionRt,
]);
const CommonUserActionsWithIdsRt = rt.union([BasicUserActionsRt, CommentUserActionRt]);
const CommonUserActionsWithoutIdsRt = rt.union([BasicUserActionsRt, CommentUserActionWithoutIdsRt]);
const UserActionPayloadRt = rt.union([
CommonUserActionsWithIdsRt,
CreateCaseUserActionRt,
ConnectorUserActionRt,
PushedUserActionRt,
]);
const UserActionsWithoutIdsRt = rt.union([
CommonUserActionsWithoutIdsRt,
CreateCaseUserActionWithoutConnectorIdRt,
ConnectorUserActionWithoutConnectorIdRt,
PushedUserActionWithoutConnectorIdRt,
]);
export const CaseUserActionBasicRt = rt.intersection([
UserActionPayloadRt,
UserActionCommonAttributesRt,
]);
export const CaseUserActionWithoutReferenceIdsRt = rt.intersection([
UserActionsWithoutIdsRt,
UserActionCommonAttributesRt,
]);
/**
* This includes the comment_id but not the action_id or case_id
*/
export const UserActionAttributesRt = rt.intersection([
CaseUserActionBasicRt,
CaseUserActionInjectedIdsRt,
]);
const UserActionRt = rt.intersection([
UserActionAttributesRt,
rt.strict({
id: rt.string,
version: rt.string,
}),
]);
export const UserActionsRt = rt.array(UserActionRt);
type UserActionWithAttributes<T> = T & rt.TypeOf<typeof UserActionCommonAttributesRt>;
export type UserActionWithDeprecatedResponse<T> = T &
rt.TypeOf<typeof CaseUserActionInjectedDeprecatedIdsRt>;
export type CaseUserActionWithoutReferenceIds = rt.TypeOf<
typeof CaseUserActionWithoutReferenceIdsRt
>;
export type UserActionPayload = rt.TypeOf<typeof UserActionPayloadRt>;
export type UserActionAttributes = rt.TypeOf<typeof UserActionAttributesRt>;
export type UserActions = rt.TypeOf<typeof UserActionsRt>;
export type UserAction<T extends UserActionPayload = UserActionPayload> = Omit<
rt.TypeOf<typeof UserActionRt>,
'type' | 'payload'
> &
T;
/**
* User actions
*/
export type AssigneesUserAction = UserAction<rt.TypeOf<typeof AssigneesUserActionRt>>;
export type CategoryUserAction = UserAction<rt.TypeOf<typeof CategoryUserActionRt>>;
export type CommentUserAction = UserAction<rt.TypeOf<typeof CommentUserActionRt>>;
export type CommentUserActionPayloadWithoutIds = UserActionWithAttributes<
rt.TypeOf<typeof CommentUserActionPayloadWithoutIdsRt>
>;
export type ConnectorUserAction = UserAction<rt.TypeOf<typeof ConnectorUserActionRt>>;
export type ConnectorUserActionWithoutConnectorId = UserActionWithAttributes<
rt.TypeOf<typeof ConnectorUserActionWithoutConnectorIdRt>
>;
export type DeleteCaseUserAction = UserAction<rt.TypeOf<typeof DeleteCaseUserActionRt>>;
export type DescriptionUserAction = UserAction<rt.TypeOf<typeof DescriptionUserActionRt>>;
export type PushedUserAction = UserAction<rt.TypeOf<typeof PushedUserActionRt>>;
export type PushedUserActionWithoutConnectorId = UserActionWithAttributes<
rt.TypeOf<typeof PushedUserActionWithoutConnectorIdRt>
>;
export type SettingsUserAction = UserAction<rt.TypeOf<typeof SettingsUserActionRt>>;
export type SeverityUserAction = UserAction<rt.TypeOf<typeof SeverityUserActionRt>>;
export type StatusUserAction = UserAction<rt.TypeOf<typeof StatusUserActionRt>>;
export type TagsUserAction = UserAction<rt.TypeOf<typeof TagsUserActionRt>>;
export type TitleUserAction = UserAction<rt.TypeOf<typeof TitleUserActionRt>>;
export type CreateCaseUserAction = UserAction<rt.TypeOf<typeof CreateCaseUserActionRt>>;
export type CreateCaseUserActionWithoutConnectorId = UserActionWithAttributes<
rt.TypeOf<typeof CreateCaseUserActionWithoutConnectorIdRt>
>;

View file

@ -17,12 +17,9 @@ import type {
CaseStatuses,
User,
ActionConnector,
UserAction,
SingleCaseMetricsResponse,
Comment,
Case as CaseSnakeCase,
UserActionFindResponse,
FindTypeField as UserActionFindTypeField,
CommentResponseAlertsType,
CasesFindResponse,
CasesStatusResponse,
@ -32,10 +29,15 @@ import type {
CommentResponseTypePersistableState,
GetCaseConnectorsResponse,
GetCaseUsersResponse,
CaseUserActionStatsResponse,
} from '../api';
import type { PUSH_CASES_CAPABILITY } from '../constants';
import type { SnakeToCamelCase } from '../types';
import type { UserAction } from '../types/domain';
import type {
CaseUserActionStatsResponse,
UserActionFindRequestTypes,
UserActionFindResponse,
} from '../types/api';
type DeepRequired<T> = { [K in keyof T]: DeepRequired<T[K]> } & Required<T>;
@ -67,7 +69,7 @@ export const SeverityAll = 'all' as const;
export type CaseSeverityWithAll = CaseSeverity | typeof SeverityAll;
export const UserActionTypeAll = 'all' as const;
export type CaseUserActionTypeWithAll = UserActionFindTypeField | typeof UserActionTypeAll;
export type CaseUserActionTypeWithAll = UserActionFindRequestTypes | typeof UserActionTypeAll;
/**
* The type for the `refreshRef` prop (a `React.Ref`) defined by the `CaseViewComponentProps`.

View file

@ -6,7 +6,7 @@
*/
import { omit } from 'lodash';
import { ActionTypes } from '../api';
import { UserActionTypes } from '../types/domain';
import {
isConnectorUserAction,
isTitleUserAction,
@ -22,13 +22,13 @@ import {
describe('user action utils', () => {
const predicateMap = {
[ActionTypes.connector]: isConnectorUserAction,
[ActionTypes.title]: isTitleUserAction,
[ActionTypes.status]: isStatusUserAction,
[ActionTypes.tags]: isTagsUserAction,
[ActionTypes.comment]: isCommentUserAction,
[ActionTypes.description]: isDescriptionUserAction,
[ActionTypes.category]: isCategoryUserAction,
[UserActionTypes.connector]: isConnectorUserAction,
[UserActionTypes.title]: isTitleUserAction,
[UserActionTypes.status]: isStatusUserAction,
[UserActionTypes.tags]: isTagsUserAction,
[UserActionTypes.comment]: isCommentUserAction,
[UserActionTypes.description]: isDescriptionUserAction,
[UserActionTypes.category]: isCategoryUserAction,
};
const tests = (Object.keys(predicateMap) as Array<keyof typeof predicateMap>).map((key) => [key]);
@ -53,7 +53,7 @@ describe('user action utils', () => {
describe('isPushedUserAction', () => {
it('returns true if the user action is pushed', () => {
expect(
isPushedUserAction({ type: ActionTypes.pushed, payload: { externalService: {} } })
isPushedUserAction({ type: UserActionTypes.pushed, payload: { externalService: {} } })
).toBe(true);
});
@ -82,7 +82,7 @@ describe('user action utils', () => {
it('returns true if the user action is create_case', () => {
expect(
isCreateCaseUserAction({
type: ActionTypes.create_case,
type: UserActionTypes.create_case,
payload,
})
).toBe(true);

View file

@ -5,6 +5,7 @@
* 2.0.
*/
import type { SnakeToCamelCase } from '../types';
import type {
CategoryUserAction,
CommentUserAction,
@ -15,10 +16,9 @@ import type {
StatusUserAction,
TagsUserAction,
TitleUserAction,
UserActionTypes,
} from '../api';
import { ActionTypes } from '../api';
import type { SnakeToCamelCase } from '../types';
UserActionType,
} from '../types/domain';
import { UserActionTypes } from '../types/domain';
type SnakeCaseOrCamelCaseUserAction<
T extends 'snakeCase' | 'camelCase',
@ -27,7 +27,7 @@ type SnakeCaseOrCamelCaseUserAction<
> = T extends 'snakeCase' ? S : C;
export const isConnectorUserAction = (userAction: unknown): userAction is ConnectorUserAction =>
(userAction as ConnectorUserAction)?.type === ActionTypes.connector &&
(userAction as ConnectorUserAction)?.type === UserActionTypes.connector &&
(userAction as ConnectorUserAction)?.payload?.connector != null;
export const isPushedUserAction = <T extends 'snakeCase' | 'camelCase' = 'snakeCase'>(
@ -37,31 +37,31 @@ export const isPushedUserAction = <T extends 'snakeCase' | 'camelCase' = 'snakeC
PushedUserAction,
SnakeToCamelCase<PushedUserAction>
> =>
(userAction as PushedUserAction)?.type === ActionTypes.pushed &&
(userAction as PushedUserAction)?.type === UserActionTypes.pushed &&
(userAction as PushedUserAction)?.payload?.externalService != null;
export const isTitleUserAction = (userAction: unknown): userAction is TitleUserAction =>
(userAction as TitleUserAction)?.type === ActionTypes.title &&
(userAction as TitleUserAction)?.type === UserActionTypes.title &&
(userAction as TitleUserAction)?.payload?.title != null;
export const isStatusUserAction = (userAction: unknown): userAction is StatusUserAction =>
(userAction as StatusUserAction)?.type === ActionTypes.status &&
(userAction as StatusUserAction)?.type === UserActionTypes.status &&
(userAction as StatusUserAction)?.payload?.status != null;
export const isTagsUserAction = (userAction: unknown): userAction is TagsUserAction =>
(userAction as TagsUserAction)?.type === ActionTypes.tags &&
(userAction as TagsUserAction)?.type === UserActionTypes.tags &&
(userAction as TagsUserAction)?.payload?.tags != null;
export const isCommentUserAction = (userAction: unknown): userAction is CommentUserAction =>
(userAction as CommentUserAction)?.type === ActionTypes.comment &&
(userAction as CommentUserAction)?.type === UserActionTypes.comment &&
(userAction as CommentUserAction)?.payload?.comment != null;
export const isDescriptionUserAction = (userAction: unknown): userAction is DescriptionUserAction =>
(userAction as DescriptionUserAction)?.type === ActionTypes.description &&
(userAction as DescriptionUserAction)?.type === UserActionTypes.description &&
(userAction as DescriptionUserAction)?.payload?.description != null;
export const isCreateCaseUserAction = (userAction: unknown): userAction is CreateCaseUserAction =>
(userAction as CreateCaseUserAction)?.type === ActionTypes.create_case &&
(userAction as CreateCaseUserAction)?.type === UserActionTypes.create_case &&
/**
* Connector is needed in various places across the application where
* the isCreateCaseUserAction is being used.
@ -70,9 +70,9 @@ export const isCreateCaseUserAction = (userAction: unknown): userAction is Creat
*/
(userAction as CreateCaseUserAction)?.payload?.connector != null;
export const isUserActionType = (field: string): field is UserActionTypes =>
ActionTypes[field as UserActionTypes] != null;
export const isUserActionType = (field: string): field is UserActionType =>
UserActionTypes[field as UserActionType] != null;
export const isCategoryUserAction = (userAction: unknown): userAction is CategoryUserAction =>
(userAction as CategoryUserAction)?.type === ActionTypes.category &&
(userAction as CategoryUserAction)?.type === UserActionTypes.category &&
(userAction as CategoryUserAction)?.payload?.category !== undefined;

View file

@ -7,6 +7,7 @@
import { set } from '@kbn/safer-lodash-set';
import { isArray, camelCase, isObject, omit, get } from 'lodash';
import type { UserActions } from '../../common/types/domain';
import {
isCommentRequestTypeExternalReference,
isCommentRequestTypePersistableState,
@ -14,7 +15,6 @@ import {
import type {
CasesFindResponse,
Case,
UserActions,
CommentRequest,
Comment,
CaseResolveResponse,

View file

@ -33,11 +33,11 @@ import { useGetCaseUsers } from '../../../containers/use_get_case_users';
import { waitForComponentToUpdate } from '../../../common/test_utils';
import { getCaseConnectorsMockResponse } from '../../../common/mock/connectors';
import { defaultInfiniteUseFindCaseUserActions, defaultUseFindCaseUserActions } from '../mocks';
import { ActionTypes } from '../../../../common/api';
import { useGetCaseUserActionsStats } from '../../../containers/use_get_case_user_actions_stats';
import { useInfiniteFindCaseUserActions } from '../../../containers/use_infinite_find_case_user_actions';
import { useOnUpdateField } from '../use_on_update_field';
import { useCasesFeatures } from '../../../common/use_cases_features';
import { UserActionTypes } from '../../../../common/types/domain';
jest.mock('../../../containers/use_infinite_find_case_user_actions');
jest.mock('../../../containers/use_find_case_user_actions');
@ -602,7 +602,7 @@ describe('Case View Page activity tab', () => {
useFindCaseUserActionsMock.mockReturnValue({
...defaultUseFindCaseUserActions,
data: {
userActions: [getUserAction(ActionTypes.assignees, 'delete')],
userActions: [getUserAction(UserActionTypes.assignees, 'delete')],
},
});
@ -620,7 +620,7 @@ describe('Case View Page activity tab', () => {
...defaultUseFindCaseUserActions,
data: {
userActions: [
getUserAction(ActionTypes.assignees, 'add', {
getUserAction(UserActionTypes.assignees, 'add', {
payload: {
assignees: [
{ uid: 'not-valid' },

View file

@ -9,7 +9,7 @@ import React from 'react';
import { EuiCommentList } from '@elastic/eui';
import { render, screen } from '@testing-library/react';
import { Actions } from '../../../common/api';
import { UserActionActions } from '../../../common/types/domain';
import { elasticUser, getUserAction } from '../../containers/mock';
import { TestProviders } from '../../common/mock';
import { createAssigneesUserActionBuilder, shouldAddAnd, shouldAddComma } from './assignees';
@ -47,7 +47,7 @@ describe('createAssigneesUserActionBuilder', () => {
});
it('renders assigned users', () => {
const userAction = getUserAction('assignees', Actions.add, {
const userAction = getUserAction('assignees', UserActionActions.add, {
createdBy: {
// damaged_raccoon uid
profileUid: 'u_J41Oh6L9ki-Vo2tOogS8WRTENzhHurGtRc87NgEAlkc_0',
@ -75,7 +75,7 @@ describe('createAssigneesUserActionBuilder', () => {
});
it('renders assigned users with a comma', () => {
const userAction = getUserAction('assignees', Actions.add, {
const userAction = getUserAction('assignees', UserActionActions.add, {
createdBy: {
// damaged_raccoon uid
profileUid: 'u_J41Oh6L9ki-Vo2tOogS8WRTENzhHurGtRc87NgEAlkc_0',
@ -114,7 +114,7 @@ describe('createAssigneesUserActionBuilder', () => {
});
it('renders unassigned users', () => {
const userAction = getUserAction('assignees', Actions.delete, {
const userAction = getUserAction('assignees', UserActionActions.delete, {
createdBy: {
// damaged_raccoon uid
profileUid: 'u_J41Oh6L9ki-Vo2tOogS8WRTENzhHurGtRc87NgEAlkc_0',
@ -142,7 +142,7 @@ describe('createAssigneesUserActionBuilder', () => {
});
it('renders a single assigned user', () => {
const userAction = getUserAction('assignees', Actions.add, {
const userAction = getUserAction('assignees', UserActionActions.add, {
payload: {
assignees: [
// only render the physical dinosaur
@ -168,7 +168,7 @@ describe('createAssigneesUserActionBuilder', () => {
});
it('renders a single assigned user that is themselves using matching profile uids', () => {
const userAction = getUserAction('assignees', Actions.add, {
const userAction = getUserAction('assignees', UserActionActions.add, {
createdBy: {
...elasticUser,
profileUid: 'u_J41Oh6L9ki-Vo2tOogS8WRTENzhHurGtRc87NgEAlkc_0',
@ -198,7 +198,7 @@ describe('createAssigneesUserActionBuilder', () => {
});
it('renders a single assigned user that is themselves using matching usernames', () => {
const userAction = getUserAction('assignees', Actions.add, {
const userAction = getUserAction('assignees', UserActionActions.add, {
createdBy: {
...elasticUser,
username: 'damaged_raccoon',

View file

@ -8,14 +8,15 @@
import { EuiFlexGroup, EuiFlexItem, EuiText } from '@elastic/eui';
import type { UserProfileWithAvatar } from '@kbn/user-profile-components';
import React, { memo } from 'react';
import type { AssigneesUserAction } from '../../../common/types/domain';
import { UserActionActions } from '../../../common/types/domain';
import type { SnakeToCamelCase } from '../../../common/types';
import type { AssigneesUserAction, User } from '../../../common/api';
import { Actions } from '../../../common/api';
import type { User } from '../../../common/api';
import { getName } from '../user_profiles/display_name';
import type { Assignee } from '../user_profiles/types';
import { UserToolTip } from '../user_profiles/user_tooltip';
import { createCommonUpdateUserActionBuilder } from './common';
import type { UserActionBuilder, UserActionResponse } from './types';
import type { UserActionBuilder } from './types';
import * as i18n from './translations';
import { getUsernameDataTestSubj } from '../user_profiles/data_test_subject';
@ -126,7 +127,7 @@ const doesAssigneeMatchCreatedByUser = (
};
const getLabelTitle = (
userAction: UserActionResponse<AssigneesUserAction>,
userAction: SnakeToCamelCase<AssigneesUserAction>,
userProfiles?: Map<string, UserProfileWithAvatar>
) => {
const assignees = userAction.payload.assignees.map((assignee) => {
@ -140,8 +141,8 @@ const getLabelTitle = (
return (
<EuiFlexGroup alignItems="baseline" gutterSize="xs" component="span" responsive={false}>
<EuiFlexItem data-test-subj="ua-assignees-label" grow={false}>
{userAction.action === Actions.add && i18n.ASSIGNED}
{userAction.action === Actions.delete && i18n.UNASSIGNED}
{userAction.action === UserActionActions.add && i18n.ASSIGNED}
{userAction.action === UserActionActions.delete && i18n.UNASSIGNED}
</EuiFlexItem>
<EuiFlexItem grow={false}>
<Assignees createdByUser={userAction.createdBy} assignees={assignees} />
@ -156,7 +157,7 @@ export const createAssigneesUserActionBuilder: UserActionBuilder = ({
userProfiles,
}) => ({
build: () => {
const assigneesUserAction = userAction as UserActionResponse<AssigneesUserAction>;
const assigneesUserAction = userAction as SnakeToCamelCase<AssigneesUserAction>;
const label = getLabelTitle(assigneesUserAction, userProfiles);
const commonBuilder = createCommonUpdateUserActionBuilder({
userAction,

View file

@ -9,11 +9,11 @@ import React from 'react';
import { EuiCommentList } from '@elastic/eui';
import { render, screen } from '@testing-library/react';
import { Actions } from '../../../common/api';
import { getUserAction } from '../../containers/mock';
import { TestProviders } from '../../common/mock';
import { createCategoryUserActionBuilder } from './category';
import { getMockBuilderArgs } from './mock';
import { UserActionActions } from '../../../common/types/domain';
jest.mock('../../common/lib/kibana');
jest.mock('../../common/navigation/hooks');
@ -26,7 +26,7 @@ describe('createCategoryUserActionBuilder ', () => {
});
it('renders correctly when the category is updated', () => {
const userAction = getUserAction('category', Actions.update, {
const userAction = getUserAction('category', UserActionActions.update, {
payload: { category: 'fantasy' },
});
const builder = createCategoryUserActionBuilder({
@ -46,7 +46,7 @@ describe('createCategoryUserActionBuilder ', () => {
});
it('renders correctly when the category is removed', () => {
const userAction = getUserAction('category', Actions.delete, {
const userAction = getUserAction('category', UserActionActions.delete, {
payload: { category: null },
});
const builder = createCategoryUserActionBuilder({

View file

@ -8,14 +8,15 @@
import React from 'react';
import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
import type { CategoryUserAction } from '../../../common/api';
import type { UserActionBuilder, UserActionResponse } from './types';
import type { SnakeToCamelCase } from '../../../common/types';
import type { CategoryUserAction } from '../../../common/types/domain';
import { UserActionActions } from '../../../common/types/domain';
import type { UserActionBuilder } from './types';
import { Actions } from '../../../common/api';
import { createCommonUpdateUserActionBuilder } from './common';
import * as i18n from './translations';
const getLabelTitle = (userAction: UserActionResponse<CategoryUserAction>) => {
const getLabelTitle = (userAction: SnakeToCamelCase<CategoryUserAction>) => {
const category = userAction.payload.category ?? '';
return (
<EuiFlexGroup
@ -24,7 +25,7 @@ const getLabelTitle = (userAction: UserActionResponse<CategoryUserAction>) => {
data-test-subj={`${userAction.id}-category-user-action-title`}
responsive={false}
>
{userAction.action === Actions.update ? (
{userAction.action === UserActionActions.update ? (
<EuiFlexItem grow={false}>{`${i18n.ADD_CATEGORY} "${category}"`}</EuiFlexItem>
) : (
<EuiFlexItem grow={false}>{i18n.REMOVE_CATEGORY}</EuiFlexItem>
@ -39,7 +40,7 @@ export const createCategoryUserActionBuilder: UserActionBuilder = ({
handleOutlineComment,
}) => ({
build: () => {
const categoryUserAction = userAction as UserActionResponse<CategoryUserAction>;
const categoryUserAction = userAction as SnakeToCamelCase<CategoryUserAction>;
const label = getLabelTitle(categoryUserAction);
const commonBuilder = createCommonUpdateUserActionBuilder({
userAction,

View file

@ -12,7 +12,7 @@ import { render, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { waitForEuiPopoverOpen } from '@elastic/eui/lib/test/rtl';
import { Actions } from '../../../../common/api';
import { UserActionActions } from '../../../../common/types/domain';
import {
alertComment,
basicCase,
@ -55,7 +55,7 @@ describe('createCommentUserActionBuilder', () => {
describe('edits', () => {
it('renders correctly when editing a comment', async () => {
const userAction = getUserAction('comment', Actions.update);
const userAction = getUserAction('comment', UserActionActions.update);
const builder = createCommentUserActionBuilder({
...builderArgs,
userAction,
@ -74,7 +74,7 @@ describe('createCommentUserActionBuilder', () => {
describe('deletions', () => {
it('renders correctly when deleting a comment', async () => {
const userAction = getUserAction('comment', Actions.delete);
const userAction = getUserAction('comment', UserActionActions.delete);
const builder = createCommentUserActionBuilder({
...builderArgs,
userAction,
@ -91,7 +91,7 @@ describe('createCommentUserActionBuilder', () => {
});
it('renders correctly when deleting a single alert', async () => {
const userAction = getAlertUserAction({ action: Actions.delete });
const userAction = getAlertUserAction({ action: UserActionActions.delete });
const builder = createCommentUserActionBuilder({
...builderArgs,
userAction,
@ -108,7 +108,7 @@ describe('createCommentUserActionBuilder', () => {
});
it('renders correctly when deleting multiple alerts', async () => {
const userAction = getMultipleAlertsUserAction({ action: Actions.delete });
const userAction = getMultipleAlertsUserAction({ action: UserActionActions.delete });
const builder = createCommentUserActionBuilder({
...builderArgs,
userAction,
@ -125,7 +125,7 @@ describe('createCommentUserActionBuilder', () => {
});
it('renders correctly when deleting an external reference attachment', async () => {
const userAction = getExternalReferenceUserAction({ action: Actions.delete });
const userAction = getExternalReferenceUserAction({ action: UserActionActions.delete });
const builder = createCommentUserActionBuilder({
...builderArgs,
userAction,
@ -153,7 +153,7 @@ describe('createCommentUserActionBuilder', () => {
getAttachmentRemovalObject,
});
const userAction = getExternalReferenceUserAction({ action: Actions.delete });
const userAction = getExternalReferenceUserAction({ action: UserActionActions.delete });
const builder = createCommentUserActionBuilder({
...builderArgs,
externalReferenceAttachmentTypeRegistry,
@ -187,7 +187,7 @@ describe('createCommentUserActionBuilder', () => {
const attachment = getExternalReferenceAttachment();
externalReferenceAttachmentTypeRegistry.register(attachment);
const userAction = getExternalReferenceUserAction({ action: Actions.delete });
const userAction = getExternalReferenceUserAction({ action: UserActionActions.delete });
const builder = createCommentUserActionBuilder({
...builderArgs,
externalReferenceAttachmentTypeRegistry,
@ -205,7 +205,7 @@ describe('createCommentUserActionBuilder', () => {
});
it('renders correctly when deleting a persistable state attachment', async () => {
const userAction = getPersistableStateUserAction({ action: Actions.delete });
const userAction = getPersistableStateUserAction({ action: UserActionActions.delete });
const builder = createCommentUserActionBuilder({
...builderArgs,
userAction,
@ -233,7 +233,7 @@ describe('createCommentUserActionBuilder', () => {
getAttachmentRemovalObject,
});
const userAction = getPersistableStateUserAction({ action: Actions.delete });
const userAction = getPersistableStateUserAction({ action: UserActionActions.delete });
const builder = createCommentUserActionBuilder({
...builderArgs,
persistableStateAttachmentTypeRegistry,
@ -269,7 +269,7 @@ describe('createCommentUserActionBuilder', () => {
const attachment = getPersistableStateAttachment();
persistableStateAttachmentTypeRegistry.register(attachment);
const userAction = getPersistableStateUserAction({ action: Actions.delete });
const userAction = getPersistableStateUserAction({ action: UserActionActions.delete });
const builder = createCommentUserActionBuilder({
...builderArgs,
persistableStateAttachmentTypeRegistry,
@ -289,7 +289,7 @@ describe('createCommentUserActionBuilder', () => {
describe('user comments', () => {
it('renders correctly a user comment', async () => {
const userAction = getUserAction('comment', Actions.create, {
const userAction = getUserAction('comment', UserActionActions.create, {
commentId: basicCase.comments[0].id,
});
@ -309,7 +309,7 @@ describe('createCommentUserActionBuilder', () => {
});
it('deletes a user comment correctly', async () => {
const userAction = getUserAction('comment', Actions.create, {
const userAction = getUserAction('comment', UserActionActions.create, {
commentId: basicCase.comments[0].id,
});
@ -338,7 +338,7 @@ describe('createCommentUserActionBuilder', () => {
});
it('edits a user comment correctly', async () => {
const userAction = getUserAction('comment', Actions.create, {
const userAction = getUserAction('comment', UserActionActions.create, {
commentId: basicCase.comments[0].id,
});
@ -369,7 +369,7 @@ describe('createCommentUserActionBuilder', () => {
});
it('quotes a user comment correctly', async () => {
const userAction = getUserAction('comment', Actions.create, {
const userAction = getUserAction('comment', UserActionActions.create, {
commentId: basicCase.comments[0].id,
});

View file

@ -7,10 +7,12 @@
import type { EuiCommentProps } from '@elastic/eui';
import type { SnakeToCamelCase } from '../../../../common/types';
import type { CommentUserAction } from '../../../../common/types/domain';
import { UserActionActions } from '../../../../common/types/domain';
import type { AttachmentTypeRegistry } from '../../../../common/registry';
import type { CommentUserAction } from '../../../../common/api';
import { Actions, CommentType } from '../../../../common/api';
import type { UserActionBuilder, UserActionBuilderArgs, UserActionResponse } from '../types';
import { CommentType } from '../../../../common/api';
import type { UserActionBuilder, UserActionBuilderArgs } from '../types';
import { createCommonUpdateUserActionBuilder } from '../common';
import type { CommentUI } from '../../../containers/types';
import * as i18n from './translations';
@ -24,7 +26,7 @@ import type { AttachmentType } from '../../../client/attachment_framework/types'
const getUpdateLabelTitle = () => `${i18n.EDITED_FIELD} ${i18n.COMMENT.toLowerCase()}`;
interface DeleteLabelTitle {
userAction: UserActionResponse<CommentUserAction>;
userAction: SnakeToCamelCase<CommentUserAction>;
caseData: UserActionBuilderArgs['caseData'];
externalReferenceAttachmentTypeRegistry: UserActionBuilderArgs['externalReferenceAttachmentTypeRegistry'];
persistableStateAttachmentTypeRegistry: UserActionBuilderArgs['persistableStateAttachmentTypeRegistry'];
@ -113,7 +115,7 @@ const getDeleteCommentUserAction = ({
persistableStateAttachmentTypeRegistry,
handleOutlineComment,
}: {
userAction: UserActionResponse<CommentUserAction>;
userAction: SnakeToCamelCase<CommentUserAction>;
} & Pick<
UserActionBuilderArgs,
| 'handleOutlineComment'
@ -163,7 +165,7 @@ const getCreateCommentUserAction = ({
onShowAlertDetails,
actionsNavigation,
}: {
userAction: UserActionResponse<CommentUserAction>;
userAction: SnakeToCamelCase<CommentUserAction>;
comment: CommentUI;
} & Omit<
UserActionBuilderArgs,
@ -269,9 +271,9 @@ export const createCommentUserActionBuilder: UserActionBuilder = ({
caseConnectors,
}) => ({
build: () => {
const commentUserAction = userAction as UserActionResponse<CommentUserAction>;
const commentUserAction = userAction as SnakeToCamelCase<CommentUserAction>;
if (commentUserAction.action === Actions.delete) {
if (commentUserAction.action === UserActionActions.delete) {
return getDeleteCommentUserAction({
userAction: commentUserAction,
caseData,
@ -288,7 +290,7 @@ export const createCommentUserActionBuilder: UserActionBuilder = ({
return [];
}
if (commentUserAction.action === Actions.create) {
if (commentUserAction.action === UserActionActions.create) {
const commentAction = getCreateCommentUserAction({
appId,
caseData,

View file

@ -11,7 +11,7 @@ import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import copy from 'copy-to-clipboard';
import { Actions } from '../../../common/api';
import { UserActionActions } from '../../../common/types/domain';
import { createCommonUpdateUserActionBuilder } from './common';
import { getUserAction } from '../../containers/mock';
import { TestProviders } from '../../common/mock';
@ -30,7 +30,7 @@ describe('createCommonUpdateUserActionBuilder ', () => {
});
it('renders correctly', async () => {
const userAction = getUserAction('title', Actions.update, {
const userAction = getUserAction('title', UserActionActions.update, {
createdBy: { profileUid: userProfiles[0].uid },
});
const builder = createCommonUpdateUserActionBuilder({
@ -59,7 +59,7 @@ describe('createCommonUpdateUserActionBuilder ', () => {
});
it('renders shows the move to comment button if the user action is an edit comment', async () => {
const userAction = getUserAction('comment', Actions.update);
const userAction = getUserAction('comment', UserActionActions.update);
const builder = createCommonUpdateUserActionBuilder({
userProfiles: userProfilesMap,
userAction,
@ -79,7 +79,7 @@ describe('createCommonUpdateUserActionBuilder ', () => {
});
it('it copies the reference link when clicking the reference button', async () => {
const userAction = getUserAction('comment', Actions.update);
const userAction = getUserAction('comment', UserActionActions.update);
const builder = createCommonUpdateUserActionBuilder({
userProfiles: userProfilesMap,
userAction,
@ -100,7 +100,7 @@ describe('createCommonUpdateUserActionBuilder ', () => {
});
it('calls the handleOutlineComment when clicking the reference button', async () => {
const userAction = getUserAction('comment', Actions.update);
const userAction = getUserAction('comment', UserActionActions.update);
const builder = createCommonUpdateUserActionBuilder({
userProfiles: userProfilesMap,
userAction,

View file

@ -9,23 +9,24 @@ import React from 'react';
import type { EuiCommentProps } from '@elastic/eui';
import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
import type { ConnectorUserAction, ActionCategory } from '../../../common/api';
import { Actions } from '../../../common/api';
import type { SnakeToCamelCase } from '../../../common/types';
import type { UserActionAction, ConnectorUserAction } from '../../../common/types/domain';
import { UserActionActions } from '../../../common/types/domain';
import { UserActionTimestamp } from './timestamp';
import type { UserActionBuilder, UserActionBuilderArgs, UserActionResponse } from './types';
import type { UserActionBuilder, UserActionBuilderArgs } from './types';
import { UserActionCopyLink } from './copy_link';
import { UserActionMoveToReference } from './move_to_reference';
import { HoverableUserWithAvatarResolver } from '../user_profiles/hoverable_user_with_avatar_resolver';
interface Props {
userAction: UserActionResponse<ConnectorUserAction>;
userAction: SnakeToCamelCase<ConnectorUserAction>;
handleOutlineComment: (id: string) => void;
}
const showMoveToReference = (
action: ActionCategory,
action: UserActionAction,
commentId: string | null
): commentId is string => action === Actions.update && commentId != null;
): commentId is string => action === UserActionActions.update && commentId != null;
const CommentListActions: React.FC<Props> = React.memo(({ userAction, handleOutlineComment }) => (
<EuiFlexGroup responsive={false}>

View file

@ -9,11 +9,12 @@ import React from 'react';
import { EuiCommentList } from '@elastic/eui';
import { render, screen } from '@testing-library/react';
import { Actions, NONE_CONNECTOR_ID } from '../../../common/api';
import { NONE_CONNECTOR_ID } from '../../../common/api';
import { getUserAction, getJiraConnector } from '../../containers/mock';
import { TestProviders } from '../../common/mock';
import { createConnectorUserActionBuilder } from './connector';
import { getMockBuilderArgs } from './mock';
import { UserActionActions } from '../../../common/types/domain';
jest.mock('../../common/lib/kibana');
jest.mock('../../common/navigation/hooks');
@ -26,7 +27,7 @@ describe('createConnectorUserActionBuilder ', () => {
});
it('renders correctly', async () => {
const userAction = getUserAction('connector', Actions.update, {
const userAction = getUserAction('connector', UserActionActions.update, {
payload: { connector: getJiraConnector() },
});
@ -46,7 +47,7 @@ describe('createConnectorUserActionBuilder ', () => {
});
it('renders the removed connector label if the connector is none', async () => {
const userAction = getUserAction('connector', Actions.update, {
const userAction = getUserAction('connector', UserActionActions.update, {
payload: { connector: { ...getJiraConnector(), id: NONE_CONNECTOR_ID } },
});

View file

@ -5,13 +5,14 @@
* 2.0.
*/
import type { ConnectorUserAction } from '../../../common/api';
import type { SnakeToCamelCase } from '../../../common/types';
import type { ConnectorUserAction } from '../../../common/types/domain';
import { NONE_CONNECTOR_ID } from '../../../common/api';
import type { UserActionBuilder, UserActionResponse } from './types';
import type { UserActionBuilder } from './types';
import { createCommonUpdateUserActionBuilder } from './common';
import * as i18n from './translations';
const getLabelTitle = (userAction: UserActionResponse<ConnectorUserAction>) => {
const getLabelTitle = (userAction: SnakeToCamelCase<ConnectorUserAction>) => {
const connector = userAction.payload.connector;
if (connector == null) {
@ -31,7 +32,7 @@ export const createConnectorUserActionBuilder: UserActionBuilder = ({
handleOutlineComment,
}) => ({
build: () => {
const connectorUserAction = userAction as UserActionResponse<ConnectorUserAction>;
const connectorUserAction = userAction as SnakeToCamelCase<ConnectorUserAction>;
const label = getLabelTitle(connectorUserAction);
const commonBuilder = createCommonUpdateUserActionBuilder({
userProfiles,

View file

@ -6,14 +6,14 @@
*/
import { omit } from 'lodash';
import { ActionTypes } from '../../../common/api';
import { UserActionTypes } from '../../../common/types/domain';
import type { SupportedUserActionTypes } from './types';
export const DRAFT_COMMENT_STORAGE_ID = 'xpack.cases.commentDraft';
export const UNSUPPORTED_ACTION_TYPES = ['delete_case'] as const;
export const SUPPORTED_ACTION_TYPES: SupportedUserActionTypes[] = Object.keys(
omit(ActionTypes, UNSUPPORTED_ACTION_TYPES)
omit(UserActionTypes, UNSUPPORTED_ACTION_TYPES)
) as SupportedUserActionTypes[];
export const NEW_COMMENT_ID = 'newComment';

View file

@ -9,7 +9,7 @@ import React from 'react';
import { EuiCommentList } from '@elastic/eui';
import { render, screen } from '@testing-library/react';
import { Actions } from '../../../common/api';
import { UserActionActions } from '../../../common/types/domain';
import { getUserAction } from '../../containers/mock';
import { TestProviders } from '../../common/mock';
import { createCaseUserActionBuilder } from './create_case';
@ -26,7 +26,7 @@ describe('createCaseUserActionBuilder ', () => {
});
it('renders correctly', async () => {
const userAction = getUserAction('create_case', Actions.create);
const userAction = getUserAction('create_case', UserActionActions.create);
// @ts-ignore no need to pass all the arguments
const builder = createCaseUserActionBuilder({
...builderArgs,

View file

@ -5,12 +5,13 @@
* 2.0.
*/
import type { CreateCaseUserAction } from '../../../common/api';
import type { UserActionBuilder, UserActionResponse } from './types';
import type { SnakeToCamelCase } from '../../../common/types';
import type { CreateCaseUserAction } from '../../../common/types/domain';
import type { UserActionBuilder } from './types';
import { createCommonUpdateUserActionBuilder } from './common';
import * as i18n from './translations';
const getLabelTitle = (userAction: UserActionResponse<CreateCaseUserAction>) =>
const getLabelTitle = (userAction: SnakeToCamelCase<CreateCaseUserAction>) =>
`${i18n.CREATE_CASE.toLowerCase()} "${userAction.payload.title}"`;
export const createCaseUserActionBuilder: UserActionBuilder = ({
@ -19,7 +20,7 @@ export const createCaseUserActionBuilder: UserActionBuilder = ({
handleOutlineComment,
}) => ({
build: () => {
const createCaseUserAction = userAction as UserActionResponse<CreateCaseUserAction>;
const createCaseUserAction = userAction as SnakeToCamelCase<CreateCaseUserAction>;
const label = getLabelTitle(createCaseUserAction);
const commonBuilder = createCommonUpdateUserActionBuilder({
userAction,

View file

@ -9,7 +9,7 @@ import React from 'react';
import { EuiCommentList } from '@elastic/eui';
import { render, screen } from '@testing-library/react';
import { Actions } from '../../../common/api';
import { UserActionActions } from '../../../common/types/domain';
import { getUserAction } from '../../containers/mock';
import { TestProviders } from '../../common/mock';
import { createDescriptionUserActionBuilder } from './description';
@ -26,7 +26,7 @@ describe('createDescriptionUserActionBuilder ', () => {
});
it('renders correctly', async () => {
const userAction = getUserAction('description', Actions.update);
const userAction = getUserAction('description', UserActionActions.update);
// @ts-ignore no need to pass all the arguments
const builder = createDescriptionUserActionBuilder({
...builderArgs,

View file

@ -23,7 +23,7 @@ import {
import { UserActions } from '.';
import type { AppMockRenderer } from '../../common/mock';
import { createAppMockRenderer } from '../../common/mock';
import { Actions } from '../../../common/api';
import { UserActionActions } from '../../../common/types/domain';
import { userProfiles, userProfilesMap } from '../../containers/user_profiles/api.mock';
import { getCaseConnectorsMockResponse } from '../../common/mock/connectors';
import type { UserActivityParams } from '../user_actions_activity_bar/types';
@ -149,7 +149,7 @@ describe(`UserActions`, () => {
});
it('Switches to markdown when edit is clicked and back to panel when canceled', async () => {
const ourActions = [getUserAction('comment', Actions.create)];
const ourActions = [getUserAction('comment', UserActionActions.create)];
useFindCaseUserActionsMock.mockReturnValue({
...defaultUseFindCaseUserActions,
@ -184,7 +184,7 @@ describe(`UserActions`, () => {
});
it('calls update comment when comment markdown is saved', async () => {
const ourActions = [getUserAction('comment', Actions.create)];
const ourActions = [getUserAction('comment', UserActionActions.create)];
useFindCaseUserActionsMock.mockReturnValue({
...defaultUseFindCaseUserActions,
@ -236,7 +236,7 @@ describe(`UserActions`, () => {
it('shows quoted text in last MarkdownEditorTextArea', async () => {
const quoteableText = `> Solve this fast! \n\n`;
const ourActions = [getUserAction('comment', Actions.create)];
const ourActions = [getUserAction('comment', UserActionActions.create)];
useFindCaseUserActionsMock.mockReturnValue({
...defaultUseFindCaseUserActions,
@ -280,7 +280,7 @@ describe(`UserActions`, () => {
it('it should persist the draft of new comment while existing old comment is updated', async () => {
const editedComment = 'it is an edited comment';
const newComment = 'another cool comment';
const ourActions = [getUserAction('comment', Actions.create)];
const ourActions = [getUserAction('comment', UserActionActions.create)];
useFindCaseUserActionsMock.mockReturnValue({
...defaultUseFindCaseUserActions,
@ -512,13 +512,13 @@ describe(`UserActions`, () => {
it('shows more button visible 21st user action added', async () => {
const mockUserActions = [
...caseUserActions,
getUserAction('comment', Actions.create),
getUserAction('comment', Actions.update),
getUserAction('comment', Actions.create),
getUserAction('comment', Actions.update),
getUserAction('comment', Actions.create),
getUserAction('comment', Actions.update),
getUserAction('comment', Actions.create),
getUserAction('comment', UserActionActions.create),
getUserAction('comment', UserActionActions.update),
getUserAction('comment', UserActionActions.create),
getUserAction('comment', UserActionActions.update),
getUserAction('comment', UserActionActions.create),
getUserAction('comment', UserActionActions.update),
getUserAction('comment', UserActionActions.create),
];
useInfiniteFindCaseUserActionsMock.mockReturnValue({
...defaultInfiniteUseFindCaseUserActions,
@ -572,7 +572,7 @@ describe(`UserActions`, () => {
total: 21,
page: 2,
perPage: 10,
userActions: [getUserAction('comment', Actions.create)],
userActions: [getUserAction('comment', UserActionActions.create)],
},
],
},

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import { Actions } from '../../../common/api';
import { UserActionActions } from '../../../common/types/domain';
import { SECURITY_SOLUTION_OWNER } from '../../../common/constants';
import { ExternalReferenceAttachmentTypeRegistry } from '../../client/attachment_framework/external_reference_registry';
import { PersistableStateAttachmentTypeRegistry } from '../../client/attachment_framework/persistable_state_registry';
@ -15,7 +15,7 @@ import { userProfiles, userProfilesMap } from '../../containers/user_profiles/ap
import type { UserActionBuilderArgs } from './types';
export const getMockBuilderArgs = (): UserActionBuilderArgs => {
const userAction = getUserAction('title', Actions.update);
const userAction = getUserAction('title', UserActionActions.update);
const commentRefs = { current: {} };
const alertData = {

View file

@ -9,12 +9,13 @@ import React from 'react';
import { EuiCommentList } from '@elastic/eui';
import { render, screen } from '@testing-library/react';
import { Actions, NONE_CONNECTOR_ID } from '../../../common/api';
import { NONE_CONNECTOR_ID } from '../../../common/api';
import { getUserAction } from '../../containers/mock';
import { TestProviders } from '../../common/mock';
import { createPushedUserActionBuilder } from './pushed';
import { getMockBuilderArgs } from './mock';
import { getCaseConnectorsMockResponse } from '../../common/mock/connectors';
import { UserActionActions } from '../../../common/types/domain';
jest.mock('../../common/lib/kibana');
jest.mock('../../common/navigation/hooks');
@ -27,7 +28,7 @@ describe('createPushedUserActionBuilder ', () => {
});
it('renders correctly pushing for the first time', async () => {
const userAction = getUserAction('pushed', Actions.push_to_service);
const userAction = getUserAction('pushed', UserActionActions.push_to_service);
const builder = createPushedUserActionBuilder({
...builderArgs,
userAction,
@ -48,7 +49,7 @@ describe('createPushedUserActionBuilder ', () => {
});
it('renders correctly if oldestUserActionPushDate is not defined', async () => {
const userAction = getUserAction('pushed', Actions.push_to_service);
const userAction = getUserAction('pushed', UserActionActions.push_to_service);
const caseConnectors = getCaseConnectorsMockResponse({
'push.details.oldestUserActionPushDate': undefined,
});
@ -69,7 +70,7 @@ describe('createPushedUserActionBuilder ', () => {
});
it('renders correctly when updating an external service', async () => {
const userAction = getUserAction('pushed', Actions.push_to_service);
const userAction = getUserAction('pushed', UserActionActions.push_to_service);
const caseConnectors = getCaseConnectorsMockResponse({
'push.details.oldestUserActionPushDate': '2023-01-16T09:46:29.813Z',
});
@ -91,7 +92,7 @@ describe('createPushedUserActionBuilder ', () => {
});
it('shows only the top footer if it is the latest push and there is nothing to push', async () => {
const userAction = getUserAction('pushed', Actions.push_to_service, {
const userAction = getUserAction('pushed', UserActionActions.push_to_service, {
createdAt: '2023-01-17T09:46:29.813Z',
});
@ -118,7 +119,7 @@ describe('createPushedUserActionBuilder ', () => {
'push.needsToBePushed': true,
});
const userAction = getUserAction('pushed', Actions.push_to_service, {
const userAction = getUserAction('pushed', UserActionActions.push_to_service, {
createdAt: '2023-01-17T09:46:29.813Z',
});
const builder = createPushedUserActionBuilder({
@ -139,7 +140,7 @@ describe('createPushedUserActionBuilder ', () => {
});
it('does not show the footers if it is not the latest push', async () => {
const userAction = getUserAction('pushed', Actions.push_to_service, {
const userAction = getUserAction('pushed', UserActionActions.push_to_service, {
createdAt: '2020-01-17T09:46:29.813Z',
});
@ -170,7 +171,7 @@ describe('createPushedUserActionBuilder ', () => {
'push.details.latestUserActionPushDate': undefined,
});
const userAction = getUserAction('pushed', Actions.push_to_service, {
const userAction = getUserAction('pushed', UserActionActions.push_to_service, {
createdAt: '2023-01-17T09:46:29.813Z',
});
@ -198,7 +199,7 @@ describe('createPushedUserActionBuilder ', () => {
it('does not show the push information if the connector is none', async () => {
const caseConnectors = getCaseConnectorsMockResponse({ 'push.needsToBePushed': true });
const userAction = getUserAction('pushed', Actions.push_to_service, {
const userAction = getUserAction('pushed', UserActionActions.push_to_service, {
createdAt: '2023-01-17T09:46:29.813Z',
payload: {
externalService: { connectorId: NONE_CONNECTOR_ID, connectorName: 'none connector' },

View file

@ -9,9 +9,10 @@ import React from 'react';
import type { EuiCommentProps } from '@elastic/eui';
import { EuiFlexGroup, EuiFlexItem, EuiLink } from '@elastic/eui';
import type { PushedUserAction } from '../../../common/api';
import { Actions } from '../../../common/api';
import type { UserActionBuilder, UserActionResponse } from './types';
import type { SnakeToCamelCase } from '../../../common/types';
import type { PushedUserAction } from '../../../common/types/domain';
import { UserActionActions } from '../../../common/types/domain';
import type { UserActionBuilder } from './types';
import { createCommonUpdateUserActionBuilder } from './common';
import * as i18n from './translations';
import type { CaseConnectors } from '../../containers/types';
@ -57,7 +58,7 @@ const isFirstPush = (pushedAt: string, oldestPush: string | undefined) => {
return dates.userActionDate.getTime() <= dates.connectorDate.getTime();
};
const getLabelTitle = (action: UserActionResponse<PushedUserAction>, firstPush: boolean) => {
const getLabelTitle = (action: SnakeToCamelCase<PushedUserAction>, firstPush: boolean) => {
const externalService = action.payload.externalService;
return (
@ -85,7 +86,7 @@ const getFooters = ({
userAction,
connectorInfo,
}: {
userAction: UserActionResponse<PushedUserAction>;
userAction: SnakeToCamelCase<PushedUserAction>;
connectorInfo: CaseConnectors[string];
}): EuiCommentProps[] => {
const footers: EuiCommentProps[] = [];
@ -94,7 +95,7 @@ const getFooters = ({
connectorInfo.push.details?.latestUserActionPushDate
);
const showTopFooter = userAction.action === Actions.push_to_service && latestPush;
const showTopFooter = userAction.action === UserActionActions.push_to_service && latestPush;
const showBottomFooter = showTopFooter && connectorInfo.push.needsToBePushed;
if (showTopFooter) {
@ -125,7 +126,7 @@ export const createPushedUserActionBuilder: UserActionBuilder = ({
handleOutlineComment,
}) => ({
build: () => {
const pushedUserAction = userAction as UserActionResponse<PushedUserAction>;
const pushedUserAction = userAction as SnakeToCamelCase<PushedUserAction>;
const connectorId = pushedUserAction.payload.externalService.connectorId;
const connectorInfo = caseConnectors[connectorId];

View file

@ -7,7 +7,7 @@
import { EuiCommentList } from '@elastic/eui';
import React from 'react';
import { Actions } from '../../../common/api';
import { UserActionActions } from '../../../common/types/domain';
import type { AppMockRenderer } from '../../common/mock';
import { createAppMockRenderer } from '../../common/mock';
import { getUserAction } from '../../containers/mock';
@ -34,7 +34,7 @@ describe('createStatusUserActionBuilder ', () => {
it.each(tests)(
'renders correctly when changed setting sync-alerts to %s',
async (syncAlerts, label) => {
const userAction = getUserAction('settings', Actions.update, {
const userAction = getUserAction('settings', UserActionActions.update, {
payload: { settings: { syncAlerts } },
});
const builder = createSettingsUserActionBuilder({

View file

@ -6,13 +6,14 @@
*/
import type { ReactNode } from 'react';
import type { SettingsUserAction } from '../../../common/api';
import type { UserActionBuilder, UserActionResponse } from './types';
import type { SnakeToCamelCase } from '../../../common/types';
import type { SettingsUserAction } from '../../../common/types/domain';
import type { UserActionBuilder } from './types';
import { createCommonUpdateUserActionBuilder } from './common';
import { DISABLED_SETTING, ENABLED_SETTING, SYNC_ALERTS_LC } from './translations';
function getSettingsLabel(userAction: UserActionResponse<SettingsUserAction>): ReactNode {
function getSettingsLabel(userAction: SnakeToCamelCase<SettingsUserAction>): ReactNode {
if (userAction.payload.settings.syncAlerts) {
return `${ENABLED_SETTING} ${SYNC_ALERTS_LC}`;
} else {
@ -26,7 +27,7 @@ export const createSettingsUserActionBuilder: UserActionBuilder = ({
handleOutlineComment,
}) => ({
build: () => {
const action = userAction as UserActionResponse<SettingsUserAction>;
const action = userAction as SnakeToCamelCase<SettingsUserAction>;
if (action?.payload?.settings?.syncAlerts !== undefined) {
const commonBuilder = createCommonUpdateUserActionBuilder({
userProfiles,

View file

@ -6,13 +6,14 @@
*/
import { EuiCommentList } from '@elastic/eui';
import { Actions, CaseSeverity } from '../../../common/api';
import { CaseSeverity } from '../../../common/api';
import React from 'react';
import type { AppMockRenderer } from '../../common/mock';
import { createAppMockRenderer } from '../../common/mock';
import { getUserAction } from '../../containers/mock';
import { getMockBuilderArgs } from './mock';
import { createSeverityUserActionBuilder } from './severity';
import { UserActionActions } from '../../../common/types/domain';
jest.mock('../../common/lib/kibana');
jest.mock('../../common/navigation/hooks');
@ -24,7 +25,7 @@ describe('createSeverityUserActionBuilder', () => {
appMockRenderer = createAppMockRenderer();
});
it('renders correctly', () => {
const userAction = getUserAction('severity', Actions.update, {
const userAction = getUserAction('severity', UserActionActions.update, {
payload: { severity: CaseSeverity.LOW },
});
const builder = createSeverityUserActionBuilder({

View file

@ -7,13 +7,14 @@
import { EuiFlexGroup, EuiFlexItem, EuiHealth } from '@elastic/eui';
import React from 'react';
import type { SeverityUserAction } from '../../../common/api/cases/user_actions/severity';
import type { SnakeToCamelCase } from '../../../common/types';
import type { SeverityUserAction } from '../../../common/types/domain';
import { SET_SEVERITY_TO } from '../create/translations';
import { createCommonUpdateUserActionBuilder } from './common';
import type { UserActionBuilder, UserActionResponse } from './types';
import type { UserActionBuilder } from './types';
import { severities } from '../severity/config';
const getLabelTitle = (userAction: UserActionResponse<SeverityUserAction>) => {
const getLabelTitle = (userAction: SnakeToCamelCase<SeverityUserAction>) => {
const severity = userAction.payload.severity;
const severityData = severities[severity];
if (severityData === undefined) {
@ -40,7 +41,7 @@ export const createSeverityUserActionBuilder: UserActionBuilder = ({
handleOutlineComment,
}) => ({
build: () => {
const severityUserAction = userAction as UserActionResponse<SeverityUserAction>;
const severityUserAction = userAction as SnakeToCamelCase<SeverityUserAction>;
const label = getLabelTitle(severityUserAction);
const commonBuilder = createCommonUpdateUserActionBuilder({
userProfiles,

View file

@ -9,11 +9,12 @@ import React from 'react';
import { EuiCommentList } from '@elastic/eui';
import { render, screen } from '@testing-library/react';
import { Actions, CaseStatuses } from '../../../common/api';
import { CaseStatuses } from '../../../common/api';
import { getUserAction } from '../../containers/mock';
import { TestProviders } from '../../common/mock';
import { createStatusUserActionBuilder } from './status';
import { getMockBuilderArgs } from './mock';
import { UserActionActions } from '../../../common/types/domain';
jest.mock('../../common/lib/kibana');
jest.mock('../../common/navigation/hooks');
@ -31,7 +32,7 @@ describe('createStatusUserActionBuilder ', () => {
});
it.each(tests)('renders correctly when changed to %s status', async (status, label) => {
const userAction = getUserAction('status', Actions.update, { payload: { status } });
const userAction = getUserAction('status', UserActionActions.update, { payload: { status } });
const builder = createStatusUserActionBuilder({
...builderArgs,
userAction,

View file

@ -8,8 +8,10 @@
import React from 'react';
import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
import { Status } from '@kbn/cases-components/src/status/status';
import type { CaseStatuses, StatusUserAction } from '../../../common/api';
import type { UserActionBuilder, UserActionResponse } from './types';
import type { SnakeToCamelCase } from '../../../common/types';
import type { StatusUserAction } from '../../../common/types/domain';
import type { CaseStatuses } from '../../../common/api';
import type { UserActionBuilder } from './types';
import { createCommonUpdateUserActionBuilder } from './common';
import { statuses } from '../status';
import * as i18n from './translations';
@ -17,7 +19,7 @@ import * as i18n from './translations';
const isStatusValid = (status: string): status is CaseStatuses =>
Object.prototype.hasOwnProperty.call(statuses, status);
const getLabelTitle = (userAction: UserActionResponse<StatusUserAction>) => {
const getLabelTitle = (userAction: SnakeToCamelCase<StatusUserAction>) => {
const status = userAction.payload.status ?? '';
if (isStatusValid(status)) {
return (
@ -44,7 +46,7 @@ export const createStatusUserActionBuilder: UserActionBuilder = ({
handleOutlineComment,
}) => ({
build: () => {
const statusUserAction = userAction as UserActionResponse<StatusUserAction>;
const statusUserAction = userAction as SnakeToCamelCase<StatusUserAction>;
const label = getLabelTitle(statusUserAction);
const commonBuilder = createCommonUpdateUserActionBuilder({
userAction,

View file

@ -9,7 +9,7 @@ import React from 'react';
import { EuiCommentList } from '@elastic/eui';
import { render, screen } from '@testing-library/react';
import { Actions } from '../../../common/api';
import { UserActionActions } from '../../../common/types/domain';
import { getUserAction } from '../../containers/mock';
import { TestProviders } from '../../common/mock';
import { createTagsUserActionBuilder } from './tags';
@ -26,7 +26,7 @@ describe('createTagsUserActionBuilder ', () => {
});
it('renders correctly when adding a tag', async () => {
const userAction = getUserAction('tags', Actions.add);
const userAction = getUserAction('tags', UserActionActions.add);
const builder = createTagsUserActionBuilder({
...builderArgs,
userAction,
@ -44,7 +44,7 @@ describe('createTagsUserActionBuilder ', () => {
});
it('renders correctly when deleting a tag', async () => {
const userAction = getUserAction('tags', Actions.delete);
const userAction = getUserAction('tags', UserActionActions.delete);
const builder = createTagsUserActionBuilder({
...builderArgs,
userAction,

View file

@ -8,21 +8,23 @@
import React from 'react';
import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
import type { TagsUserAction } from '../../../common/api';
import { Actions } from '../../../common/api';
import type { UserActionBuilder, UserActionResponse } from './types';
import type { SnakeToCamelCase } from '../../../common/types';
import type { TagsUserAction } from '../../../common/types/domain';
import { UserActionActions } from '../../../common/types/domain';
import type { UserActionBuilder } from './types';
import { createCommonUpdateUserActionBuilder } from './common';
import { Tags } from '../tags/tags';
import * as i18n from './translations';
const getLabelTitle = (userAction: UserActionResponse<TagsUserAction>) => {
const getLabelTitle = (userAction: SnakeToCamelCase<TagsUserAction>) => {
const tags = userAction.payload.tags ?? [];
return (
<EuiFlexGroup alignItems="baseline" gutterSize="xs" component="span" responsive={false}>
<EuiFlexItem data-test-subj="ua-tags-label" grow={false}>
{userAction.action === Actions.add && i18n.ADDED_FIELD}
{userAction.action === Actions.delete && i18n.REMOVED_FIELD} {i18n.TAGS.toLowerCase()}
{userAction.action === UserActionActions.add && i18n.ADDED_FIELD}
{userAction.action === UserActionActions.delete && i18n.REMOVED_FIELD}{' '}
{i18n.TAGS.toLowerCase()}
</EuiFlexItem>
<EuiFlexItem grow={false}>
<Tags tags={tags} gutterSize="xs" color="hollow" />
@ -37,7 +39,7 @@ export const createTagsUserActionBuilder: UserActionBuilder = ({
handleOutlineComment,
}) => ({
build: () => {
const tagsUserAction = userAction as UserActionResponse<TagsUserAction>;
const tagsUserAction = userAction as SnakeToCamelCase<TagsUserAction>;
const label = getLabelTitle(tagsUserAction);
const commonBuilder = createCommonUpdateUserActionBuilder({
userAction,

View file

@ -9,7 +9,7 @@ import React from 'react';
import { EuiCommentList } from '@elastic/eui';
import { render, screen } from '@testing-library/react';
import { Actions } from '../../../common/api';
import { UserActionActions } from '../../../common/types/domain';
import { getUserAction } from '../../containers/mock';
import { TestProviders } from '../../common/mock';
import { createTitleUserActionBuilder } from './title';
@ -26,7 +26,7 @@ describe('createTitleUserActionBuilder ', () => {
});
it('renders correctly', async () => {
const userAction = getUserAction('title', Actions.update);
const userAction = getUserAction('title', UserActionActions.update);
// @ts-ignore no need to pass all the arguments
const builder = createTitleUserActionBuilder({
...builderArgs,

View file

@ -5,12 +5,13 @@
* 2.0.
*/
import type { TitleUserAction } from '../../../common/api';
import type { UserActionBuilder, UserActionResponse } from './types';
import type { SnakeToCamelCase } from '../../../common/types';
import type { TitleUserAction } from '../../../common/types/domain';
import type { UserActionBuilder } from './types';
import { createCommonUpdateUserActionBuilder } from './common';
import * as i18n from './translations';
const getLabelTitle = (userAction: UserActionResponse<TitleUserAction>) =>
const getLabelTitle = (userAction: SnakeToCamelCase<TitleUserAction>) =>
`${i18n.CHANGED_FIELD.toLowerCase()} ${i18n.CASE_NAME.toLowerCase()} ${i18n.TO} "${
userAction.payload.title
}"`;
@ -21,7 +22,7 @@ export const createTitleUserActionBuilder: UserActionBuilder = ({
handleOutlineComment,
}) => ({
build: () => {
const titleUserAction = userAction as UserActionResponse<TitleUserAction>;
const titleUserAction = userAction as SnakeToCamelCase<TitleUserAction>;
const label = getLabelTitle(titleUserAction);
const commonBuilder = createCommonUpdateUserActionBuilder({
userAction,

View file

@ -7,8 +7,7 @@
import type { EuiCommentProps } from '@elastic/eui';
import type { UserProfileWithAvatar } from '@kbn/user-profile-components';
import type { SnakeToCamelCase } from '../../../common/types';
import type { ActionTypes, UserActionWithResponse } from '../../../common/api';
import type { UserActionTypes } from '../../../common/types/domain';
import type {
CaseUI,
CaseConnectors,
@ -44,7 +43,10 @@ export interface UserActionTreeProps {
}
type UnsupportedUserActionTypes = typeof UNSUPPORTED_ACTION_TYPES[number];
export type SupportedUserActionTypes = keyof Omit<typeof ActionTypes, UnsupportedUserActionTypes>;
export type SupportedUserActionTypes = keyof Omit<
typeof UserActionTypes,
UnsupportedUserActionTypes
>;
export interface UserActionBuilderArgs {
appId?: string;
@ -76,7 +78,6 @@ export interface UserActionBuilderArgs {
onRuleDetailsClick?: RuleDetailsNavigation['onClick'];
}
export type UserActionResponse<T> = SnakeToCamelCase<UserActionWithResponse<T>>;
export type UserActionBuilder = (args: UserActionBuilderArgs) => {
build: () => EuiCommentProps[];
};

View file

@ -15,7 +15,7 @@ import { basicCase, caseUserActions, getUserAction } from '../../containers/mock
import { UserActionsList } from './user_actions_list';
import type { AppMockRenderer } from '../../common/mock';
import { createAppMockRenderer } from '../../common/mock';
import { Actions } from '../../../common/api';
import { UserActionActions } from '../../../common/types/domain';
import { getCaseConnectorsMockResponse } from '../../common/mock/connectors';
import { getMockBuilderArgs } from './mock';
@ -92,7 +92,7 @@ describe(`UserActionsList`, () => {
const commentId = 'basic-comment-id';
jest.spyOn(routeData, 'useParams').mockReturnValue({ commentId });
const ourActions = [getUserAction('comment', Actions.create)];
const ourActions = [getUserAction('comment', UserActionActions.create)];
const props = {
...defaultProps,
@ -108,8 +108,8 @@ describe(`UserActionsList`, () => {
it('Outlines comment when update move to link is clicked', async () => {
const ourActions = [
getUserAction('comment', Actions.create),
getUserAction('comment', Actions.update),
getUserAction('comment', UserActionActions.create),
getUserAction('comment', UserActionActions.update),
];
const props = {

View file

@ -7,6 +7,7 @@
import type { ValidFeatureId } from '@kbn/rule-data-utils';
import { BASE_RAC_ALERTS_API_PATH } from '@kbn/rule-registry-plugin/common/constants';
import type { CaseUserActionStatsResponse, UserActionFindResponse } from '../../common/types/api';
import type {
CaseConnectors,
CaseUpdateRequest,
@ -25,13 +26,11 @@ import type {
CasePatchRequest,
CasePostRequest,
CaseResolveResponse,
UserActionFindResponse,
CommentRequest,
User,
SingleCaseMetricsResponse,
CasesFindResponse,
GetCaseConnectorsResponse,
CaseUserActionStatsResponse,
Case,
Cases,
} from '../../common/api';

View file

@ -6,6 +6,14 @@
*/
import type { FileJSON } from '@kbn/shared-ux-file-types';
import type {
UserActionAction,
CommentUserAction,
UserAction,
UserActions,
UserActionType,
} from '../../common/types/domain';
import { UserActionActions, UserActionTypes } from '../../common/types/domain';
import type { ActionLicense, CaseUI, CasesStatus, UserActionUI, CommentUI } from './types';
import type {
@ -28,17 +36,9 @@ import type {
CasesFindResponse,
Cases,
CasesStatusResponse,
UserAction,
UserActions,
Comment,
ActionCategory,
UserActionTypes,
UserActionWithResponse,
CommentUserAction,
} from '../../common/api';
import {
Actions,
ActionTypes,
CaseStatuses,
CommentType,
ConnectorTypes,
@ -53,6 +53,7 @@ import type {
AttachmentViewObject,
PersistableStateAttachmentType,
} from '../client/attachment_framework/types';
import type { UserActionWithResponse } from '../../common/types/api';
export { connectorsMock } from '../common/mock/connectors';
export const basicCaseId = 'basic-case-id';
@ -614,8 +615,8 @@ export const allCasesSnake: CasesFindResponse = {
};
export const getUserAction = (
type: UserActionTypes,
action: ActionCategory,
type: UserActionType,
action: UserActionAction,
overrides?: Record<string, unknown>
): UserActionUI => {
const commonProperties = {
@ -636,29 +637,29 @@ export const getUserAction = (
};
switch (type) {
case ActionTypes.comment:
case UserActionTypes.comment:
return {
...commonProperties,
type: ActionTypes.comment,
type: UserActionTypes.comment,
payload: {
comment: { comment: 'a comment', type: CommentType.user, owner: SECURITY_SOLUTION_OWNER },
},
commentId: basicCommentId,
...overrides,
};
case ActionTypes.connector:
case UserActionTypes.connector:
return {
...commonProperties,
type: ActionTypes.connector,
type: UserActionTypes.connector,
payload: {
connector: { ...getJiraConnector() },
},
...overrides,
};
case ActionTypes.create_case:
case UserActionTypes.create_case:
return {
...commonProperties,
type: ActionTypes.create_case,
type: UserActionTypes.create_case,
payload: {
description: 'a desc',
connector: { ...getJiraConnector() },
@ -672,62 +673,62 @@ export const getUserAction = (
},
...overrides,
};
case ActionTypes.delete_case:
case UserActionTypes.delete_case:
return {
...commonProperties,
type: ActionTypes.delete_case,
type: UserActionTypes.delete_case,
payload: {},
...overrides,
};
case ActionTypes.description:
case UserActionTypes.description:
return {
...commonProperties,
type: ActionTypes.description,
type: UserActionTypes.description,
payload: { description: 'a desc' },
...overrides,
};
case ActionTypes.pushed:
case UserActionTypes.pushed:
return {
...commonProperties,
createdAt: basicPushedAt,
type: ActionTypes.pushed,
type: UserActionTypes.pushed,
payload: {
externalService,
},
...overrides,
};
case ActionTypes.settings:
case UserActionTypes.settings:
return {
...commonProperties,
type: ActionTypes.settings,
type: UserActionTypes.settings,
payload: { settings: { syncAlerts: true } },
...overrides,
};
case ActionTypes.status:
case UserActionTypes.status:
return {
...commonProperties,
type: ActionTypes.status,
type: UserActionTypes.status,
payload: { status: CaseStatuses.open },
...overrides,
};
case ActionTypes.tags:
case UserActionTypes.tags:
return {
...commonProperties,
type: ActionTypes.tags,
type: UserActionTypes.tags,
payload: { tags: ['a tag'] },
...overrides,
};
case ActionTypes.title:
case UserActionTypes.title:
return {
...commonProperties,
type: ActionTypes.title,
type: UserActionTypes.title,
payload: { title: 'a title' },
...overrides,
};
case ActionTypes.assignees:
case UserActionTypes.assignees:
return {
...commonProperties,
type: ActionTypes.assignees,
type: UserActionTypes.assignees,
payload: {
assignees: [
// These values map to uids in x-pack/plugins/cases/public/containers/user_profiles/api.mock.ts
@ -747,8 +748,8 @@ export const getUserAction = (
};
export const getUserActionSnake = (
type: UserActionTypes,
action: ActionCategory,
type: UserActionType,
action: UserActionAction,
overrides?: Record<string, unknown>
): UserAction => {
return {
@ -757,13 +758,13 @@ export const getUserActionSnake = (
};
export const caseUserActionsSnake: UserActions = [
getUserActionSnake('description', Actions.create),
getUserActionSnake('comment', Actions.create),
getUserActionSnake('description', Actions.update),
getUserActionSnake('description', UserActionActions.create),
getUserActionSnake('comment', UserActionActions.create),
getUserActionSnake('description', UserActionActions.update),
];
export const caseUserActionsWithRegisteredAttachmentsSnake: UserActions = [
getUserActionSnake('description', Actions.create),
getUserActionSnake('description', UserActionActions.create),
{
created_at: basicCreatedAt,
created_by: elasticUserSnake,
@ -819,10 +820,10 @@ export const jiraFields = { fields: { issueType: '10006', priority: null, parent
export const getAlertUserAction = (
overrides?: Record<string, unknown>
): SnakeToCamelCase<UserActionWithResponse<CommentUserAction>> => ({
...getUserAction(ActionTypes.comment, Actions.create),
...getUserAction(UserActionTypes.comment, UserActionActions.create),
id: 'alert-action-id',
commentId: 'alert-comment-id',
type: ActionTypes.comment,
type: UserActionTypes.comment,
payload: {
comment: {
type: CommentType.alert,
@ -841,10 +842,10 @@ export const getAlertUserAction = (
export const getMultipleAlertsUserAction = (
overrides?: Record<string, unknown>
): SnakeToCamelCase<UserActionWithResponse<CommentUserAction>> => ({
...getUserAction(ActionTypes.comment, Actions.create),
...getUserAction(UserActionTypes.comment, UserActionActions.create),
id: 'alert-action-id',
commentId: 'alert-comment-id',
type: ActionTypes.comment,
type: UserActionTypes.comment,
payload: {
comment: {
type: CommentType.alert,
@ -863,9 +864,9 @@ export const getMultipleAlertsUserAction = (
export const getHostIsolationUserAction = (
overrides?: Record<string, unknown>
): SnakeToCamelCase<UserActionWithResponse<CommentUserAction>> => ({
...getUserAction(ActionTypes.comment, Actions.create),
...getUserAction(UserActionTypes.comment, UserActionActions.create),
id: 'isolate-action-id',
type: ActionTypes.comment,
type: UserActionTypes.comment,
commentId: 'isolate-comment-id',
payload: {
comment: {
@ -879,13 +880,13 @@ export const getHostIsolationUserAction = (
});
export const caseUserActions: UserActionUI[] = [
getUserAction('description', Actions.create),
getUserAction('comment', Actions.create),
getUserAction('description', Actions.update),
getUserAction('description', UserActionActions.create),
getUserAction('comment', UserActionActions.create),
getUserAction('description', UserActionActions.update),
];
export const caseUserActionsWithRegisteredAttachments: UserActionUI[] = [
getUserAction('description', Actions.create),
getUserAction('description', UserActionActions.create),
{
createdAt: basicCreatedAt,
createdBy: elasticUser,
@ -956,9 +957,9 @@ export const basicCaseClosed: CaseUI = {
export const getExternalReferenceUserAction = (
overrides?: Record<string, unknown>
): SnakeToCamelCase<UserActionWithResponse<CommentUserAction>> => ({
...getUserAction(ActionTypes.comment, Actions.create),
...getUserAction(UserActionTypes.comment, UserActionActions.create),
id: 'external-reference-action-id',
type: ActionTypes.comment,
type: UserActionTypes.comment,
commentId: 'external-reference-comment-id',
payload: {
comment: {
@ -989,9 +990,9 @@ export const getExternalReferenceAttachment = (
export const getPersistableStateUserAction = (
overrides?: Record<string, unknown>
): SnakeToCamelCase<UserActionWithResponse<CommentUserAction>> => ({
...getUserAction(ActionTypes.comment, Actions.create),
...getUserAction(UserActionTypes.comment, UserActionActions.create),
id: 'persistable-state-action-id',
type: ActionTypes.comment,
type: UserActionTypes.comment,
commentId: 'persistable-state-comment-id',
payload: {
comment: {

View file

@ -11,16 +11,15 @@ import { identity } from 'fp-ts/lib/function';
import { pipe } from 'fp-ts/lib/pipeable';
import type { ToastInputFields } from '@kbn/core/public';
import type { Configuration, Configurations } from '../../common/types/domain';
import { ConfigurationRt, ConfigurationsRt } from '../../common/types/domain';
import type { CaseUserActionStatsResponse } from '../../common/types/api';
import type { Configuration, Configurations, UserActions } from '../../common/types/domain';
import { ConfigurationRt, ConfigurationsRt, UserActionsRt } from '../../common/types/domain';
import { NO_ASSIGNEES_FILTERING_KEYWORD } from '../../common/constants';
import type {
UserActions,
CasePatchRequest,
CaseResolveResponse,
SingleCaseMetricsResponse,
User,
CaseUserActionStatsResponse,
Case,
Cases,
} from '../../common/api';
@ -28,14 +27,13 @@ import {
CaseRt,
CasesRt,
throwErrors,
UserActionsRt,
CommentType,
CaseResolveResponseRt,
SingleCaseMetricsResponseRt,
CaseUserActionStatsResponseRt,
} from '../../common/api';
import type { CaseUI, FilterOptions, UpdateByKey } from './types';
import * as i18n from './translations';
import { CaseUserActionStatsResponseRt } from '../../common/types/api';
export const getTypedPayload = <T>(a: unknown): T => a as T;

View file

@ -7,8 +7,9 @@
import Boom from '@hapi/boom';
import { UserActionActions, UserActionTypes } from '../../../common/types/domain';
import type { CommentRequest, CommentRequestAlertType } from '../../../common/api';
import { Actions, ActionTypes, CommentRequestRt, decodeOrThrow } from '../../../common/api';
import { CommentRequestRt, decodeOrThrow } from '../../../common/api';
import { CASE_SAVED_OBJECT } from '../../../common/constants';
import { getAlertInfoFromComments, isCommentRequestTypeAlert } from '../../common/utils';
import type { CasesClientArgs } from '../types';
@ -121,8 +122,8 @@ export async function deleteComment(
const attachmentRequestAttributes = decodeOrThrow(CommentRequestRt)(attachment.attributes);
await userActionService.creator.createUserAction({
type: ActionTypes.comment,
action: Actions.delete,
type: UserActionTypes.comment,
action: UserActionActions.delete,
caseId: id,
attachmentId: attachmentID,
payload: { attachment: attachmentRequestAttributes },

View file

@ -9,10 +9,10 @@ import Boom from '@hapi/boom';
import { SavedObjectsUtils } from '@kbn/core/server';
import { UserActionTypes } from '../../../common/types/domain';
import type { Case, CasePostRequest } from '../../../common/api';
import {
CaseRt,
ActionTypes,
CasePostRequestRt,
CaseSeverity,
decodeWithExcessOrThrow,
@ -82,7 +82,7 @@ export const create = async (data: CasePostRequest, clientArgs: CasesClientArgs)
});
await userActionService.creator.createUserAction({
type: ActionTypes.create_case,
type: UserActionTypes.create_case,
caseId: newCase.id,
user,
payload: {

View file

@ -5,17 +5,10 @@
* 2.0.
*/
import type {
Comment,
CommentResponseAlertsType,
CaseUserActionsDeprecatedResponse,
} from '../../../common/api';
import {
CommentType,
ConnectorTypes,
Actions,
ExternalReferenceStorageType,
} from '../../../common/api';
import type { CaseUserActionsDeprecatedResponse } from '../../../common/types/api';
import { UserActionActions } from '../../../common/types/domain';
import type { Comment, CommentResponseAlertsType } from '../../../common/api';
import { CommentType, ConnectorTypes, ExternalReferenceStorageType } from '../../../common/api';
import { SECURITY_SOLUTION_OWNER } from '../../../common/constants';
export const updateUser = {
@ -243,7 +236,7 @@ export const basicParams = {
export const userActions: CaseUserActionsDeprecatedResponse = [
{
action: Actions.create,
action: UserActionActions.create,
type: 'create_case',
created_at: '2021-02-03T17:41:03.771Z',
created_by: {
@ -282,7 +275,7 @@ export const userActions: CaseUserActionsDeprecatedResponse = [
},
{
type: 'pushed',
action: Actions.push_to_service,
action: UserActionActions.push_to_service,
created_at: '2021-02-03T17:41:26.108Z',
created_by: {
email: 'elastic@elastic.co',
@ -308,7 +301,7 @@ export const userActions: CaseUserActionsDeprecatedResponse = [
},
{
type: 'comment',
action: Actions.create,
action: UserActionActions.create,
created_at: '2021-02-03T17:44:21.067Z',
created_by: {
email: 'elastic@elastic.co',
@ -331,7 +324,7 @@ export const userActions: CaseUserActionsDeprecatedResponse = [
},
{
type: 'comment',
action: Actions.create,
action: UserActionActions.create,
created_at: '2021-02-03T17:44:33.078Z',
created_by: {
email: 'elastic@elastic.co',
@ -354,7 +347,7 @@ export const userActions: CaseUserActionsDeprecatedResponse = [
},
{
type: 'comment',
action: Actions.create,
action: UserActionActions.create,
created_at: '2021-02-03T17:48:30.616Z',
created_by: {
email: 'elastic@elastic.co',
@ -376,7 +369,7 @@ export const userActions: CaseUserActionsDeprecatedResponse = [
},
{
type: 'comment',
action: Actions.create,
action: UserActionActions.create,
created_at: '2021-02-03T17:48:30.616Z',
created_by: {
email: 'elastic@elastic.co',
@ -398,7 +391,7 @@ export const userActions: CaseUserActionsDeprecatedResponse = [
},
{
type: 'comment',
action: Actions.create,
action: UserActionActions.create,
created_at: '2021-02-03T17:48:30.616Z',
created_by: {
email: 'elastic@elastic.co',
@ -420,7 +413,7 @@ export const userActions: CaseUserActionsDeprecatedResponse = [
},
{
type: 'comment',
action: Actions.create,
action: UserActionActions.create,
created_at: '2021-02-03T17:48:30.616Z',
created_by: {
email: 'elastic@elastic.co',
@ -445,7 +438,7 @@ export const userActions: CaseUserActionsDeprecatedResponse = [
},
{
type: 'comment',
action: Actions.create,
action: UserActionActions.create,
created_at: '2021-02-03T17:48:30.616Z',
created_by: {
email: 'elastic@elastic.co',
@ -467,7 +460,7 @@ export const userActions: CaseUserActionsDeprecatedResponse = [
},
{
type: 'pushed',
action: Actions.push_to_service,
action: UserActionActions.push_to_service,
created_at: '2021-02-03T17:45:29.400Z',
created_by: {
email: 'elastic@elastic.co',
@ -493,7 +486,7 @@ export const userActions: CaseUserActionsDeprecatedResponse = [
},
{
type: 'comment',
action: Actions.create,
action: UserActionActions.create,
created_at: '2021-02-03T17:48:30.616Z',
created_by: {
email: 'elastic@elastic.co',

View file

@ -13,6 +13,7 @@ import type { UserProfile } from '@kbn/security-plugin/common';
import type { SecurityPluginStart } from '@kbn/security-plugin/server';
import { asSavedObjectExecutionSource } from '@kbn/actions-plugin/server';
import type { ConfigurationAttributes } from '../../../common/types/domain';
import { UserActionTypes } from '../../../common/types/domain';
import type {
ActionConnector,
Case,
@ -20,7 +21,7 @@ import type {
CommentRequestAlertType,
CommentAttributes,
} from '../../../common/api';
import { CaseRt, CaseStatuses, ActionTypes, OWNER_FIELD, CommentType } from '../../../common/api';
import { CaseRt, CaseStatuses, OWNER_FIELD, CommentType } from '../../../common/api';
import { CASE_COMMENT_SAVED_OBJECT, CASE_SAVED_OBJECT } from '../../../common/constants';
import { createIncident, getDurationInSeconds, getUserProfiles } from './utils';
@ -252,7 +253,7 @@ export const push = async (
if (shouldMarkAsClosed) {
await userActionService.creator.createUserAction({
type: ActionTypes.status,
type: UserActionTypes.status,
payload: { status: CaseStatuses.closed },
user,
caseId,
@ -266,7 +267,7 @@ export const push = async (
}
await userActionService.creator.createUserAction({
type: ActionTypes.pushed,
type: UserActionTypes.pushed,
payload: { externalService },
user,
caseId,

View file

@ -28,12 +28,13 @@ import {
formatComments,
addKibanaInformationToDescription,
} from './utils';
import { Actions, CaseStatuses } from '../../../common/api';
import { CaseStatuses } from '../../../common/api';
import { flattenCaseSavedObject } from '../../common/utils';
import { SECURITY_SOLUTION_OWNER } from '../../../common/constants';
import { casesConnectors } from '../../connectors';
import { userProfiles, userProfilesMap } from '../user_profiles.mock';
import { mappings, mockCases } from '../../mocks';
import { UserActionActions } from '../../../common/types/domain';
const allComments = [
commentObj,
@ -979,7 +980,7 @@ describe('utils', () => {
...userActions.slice(0, 3),
{
type: 'pushed',
action: Actions.push_to_service,
action: UserActionActions.push_to_service,
created_at: '2021-02-03T17:45:29.400Z',
created_by: {
email: 'elastic@elastic.co',

Some files were not shown because too many files have changed in this diff Show more