Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[Cases] Renaming comment type #156086

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions x-pack/plugins/cases/common/api/cases/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as rt from 'io-ts';

import { NumberFromString } from '../saved_object';
import { UserRt } from '../user';
import { CommentResponseRt } from './comment';
import { CommentRt } from './comment';
import { CasesStatusResponseRt, CaseStatusRt } from './status';
import { CaseConnectorRt } from '../connectors/connector';
import { CaseAssigneesRt } from './assignee';
Expand Down Expand Up @@ -258,7 +258,7 @@ export const CaseRt = rt.intersection([
version: rt.string,
}),
rt.partial({
comments: rt.array(CommentResponseRt),
comments: rt.array(CommentRt),
}),
]);

Expand Down
14 changes: 7 additions & 7 deletions x-pack/plugins/cases/common/api/cases/comment/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export const CommentRequestRt = rt.union([
PersistableStateAttachmentRt,
]);

export const CommentResponseRt = rt.intersection([
export const CommentRt = rt.intersection([
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use the new terminology and rename it to AttachmentRt? I am not sure 🙂.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea, we'll do those renames on a separate PR.

CommentAttributesRt,
rt.type({
id: rt.string,
Expand Down Expand Up @@ -233,7 +233,7 @@ export const CommentResponseTypePersistableStateRt = rt.intersection([
}),
]);

export const AllCommentsResponseRT = rt.array(CommentResponseRt);
export const AllCommentsResponseRT = rt.array(CommentRt);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be CommentsRt and the CommentsRt should be CommentsFindResponseRt. We can do it on another PR as we have the same issue for Cases.

Copy link
Member

@cnasikas cnasikas May 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this seems like a duplicate of AllCommentsResponseRt. They differ in the last letter (capital T).


export const CommentPatchRequestRt = rt.intersection([
/**
Expand Down Expand Up @@ -266,14 +266,14 @@ export const CommentPatchAttributesRt = rt.intersection([
rt.partial(CommentAttributesBasicRt.props),
]);

export const CommentsResponseRt = rt.type({
comments: rt.array(CommentResponseRt),
export const CommentsRt = rt.type({
comments: rt.array(CommentRt),
page: rt.number,
per_page: rt.number,
total: rt.number,
});

export const AllCommentsResponseRt = rt.array(CommentResponseRt);
export const AllCommentsResponseRt = rt.array(CommentRt);

export const FindQueryParamsRt = rt.partial({
...SavedObjectFindOptionsRt.props,
Expand Down Expand Up @@ -314,7 +314,7 @@ export type CommentAttributesNoSO = rt.TypeOf<typeof CommentAttributesNoSORt>;
export type CommentAttributesWithoutRefs = rt.TypeOf<typeof CommentAttributesWithoutRefsRt>;
export type CommentRequest = rt.TypeOf<typeof CommentRequestRt>;
export type BulkCreateCommentRequest = rt.TypeOf<typeof BulkCreateCommentRequestRt>;
export type CommentResponse = rt.TypeOf<typeof CommentResponseRt>;
export type Comment = rt.TypeOf<typeof CommentRt>;
export type CommentResponseUserType = rt.TypeOf<typeof CommentResponseTypeUserRt>;
export type CommentResponseAlertsType = rt.TypeOf<typeof CommentResponseTypeAlertsRt>;
export type CommentResponseTypePersistableState = rt.TypeOf<
Expand All @@ -325,7 +325,7 @@ export type CommentResponseExternalReferenceType = rt.TypeOf<
>;
export type CommentResponseActionsType = rt.TypeOf<typeof CommentResponseTypeActionsRt>;
export type AllCommentsResponse = rt.TypeOf<typeof AllCommentsResponseRt>;
export type CommentsResponse = rt.TypeOf<typeof CommentsResponseRt>;
export type Comments = rt.TypeOf<typeof CommentsRt>;
export type CommentPatchRequest = rt.TypeOf<typeof CommentPatchRequestRt>;
export type CommentPatchAttributes = rt.TypeOf<typeof CommentPatchAttributesRt>;
export type CommentRequestUserType = rt.TypeOf<typeof ContextTypeUserRt>;
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/cases/common/ui/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type {
ActionConnector,
CaseUserActionResponse,
SingleCaseMetricsResponse,
CommentResponse,
Comment,
Case as CaseSnakeCase,
UserActionFindResponse,
FindTypeField as UserActionFindTypeField,
Expand Down Expand Up @@ -83,7 +83,7 @@ export type CaseViewRefreshPropInterface = null | {
refreshCase: () => Promise<void>;
};

export type Comment = SnakeToCamelCase<CommentResponse>;
export type CommentUI = SnakeToCamelCase<Comment>;
export type AlertComment = SnakeToCamelCase<CommentResponseAlertsType>;
export type ExternalReferenceComment = SnakeToCamelCase<CommentResponseExternalReferenceType>;
export type PersistableComment = SnakeToCamelCase<CommentResponseTypePersistableState>;
Expand All @@ -92,7 +92,7 @@ export type FindCaseUserActions = Omit<SnakeToCamelCase<UserActionFindResponse>,
userActions: CaseUserActions[];
};
export type CaseUserActionsStats = SnakeToCamelCase<CaseUserActionStatsResponse>;
export type CaseUI = Omit<SnakeToCamelCase<CaseSnakeCase>, 'comments'> & { comments: Comment[] };
export type CaseUI = Omit<SnakeToCamelCase<CaseSnakeCase>, 'comments'> & { comments: CommentUI[] };
export type CasesUI = Omit<SnakeToCamelCase<CasesFindResponse>, 'cases'> & { cases: CaseUI[] };
export type CasesStatus = SnakeToCamelCase<CasesStatusResponse>;
export type CasesMetrics = SnakeToCamelCase<CasesMetricsResponse>;
Expand Down
14 changes: 7 additions & 7 deletions x-pack/plugins/cases/public/api/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import type {
Case,
CaseUserActionsResponse,
CommentRequest,
CommentResponse,
Comment,
CaseResolveResponse,
Cases,
} from '../../common/api';
import { isCommentUserAction } from '../../common/utils/user_actions';
import type { CasesUI, CaseUI, Comment, ResolvedCase } from '../containers/types';
import type { CasesUI, CaseUI, CommentUI, ResolvedCase } from '../containers/types';

export const convertArrayToCamelCase = (arrayOfSnakes: unknown[]): unknown[] =>
arrayOfSnakes.reduce((acc: unknown[], value) => {
Expand Down Expand Up @@ -65,11 +65,11 @@ export const convertCaseResolveToCamelCase = (res: CaseResolveResponse): Resolve
};
};

export const convertAttachmentsToCamelCase = (attachments: CommentResponse[]): Comment[] => {
export const convertAttachmentsToCamelCase = (attachments: Comment[]): CommentUI[] => {
return attachments.map((attachment) => convertAttachmentToCamelCase(attachment));
};

export const convertAttachmentToCamelCase = (attachment: CommentRequest): Comment => {
export const convertAttachmentToCamelCase = (attachment: CommentRequest): CommentUI => {
if (isCommentRequestTypeExternalReference(attachment)) {
return convertAttachmentToCamelExceptProperty(attachment, 'externalReferenceMetadata');
}
Expand All @@ -78,7 +78,7 @@ export const convertAttachmentToCamelCase = (attachment: CommentRequest): Commen
return convertAttachmentToCamelExceptProperty(attachment, 'persistableStateAttachmentState');
}

return convertToCamelCase<CommentRequest, Comment>(attachment);
return convertToCamelCase<CommentRequest, CommentUI>(attachment);
};

export const convertUserActionsToCamelCase = (userActions: CaseUserActionsResponse) => {
Expand All @@ -102,15 +102,15 @@ export const convertUserActionsToCamelCase = (userActions: CaseUserActionsRespon
const convertAttachmentToCamelExceptProperty = (
attachment: CommentRequest,
key: string
): Comment => {
): CommentUI => {
const intactValue = get(attachment, key);
const attachmentWithoutIntactValue = omit(attachment, key);
const camelCaseAttachmentWithoutIntactValue = convertToCamelCase(attachmentWithoutIntactValue);

return {
...camelCaseAttachmentWithoutIntactValue,
[key]: intactValue,
} as Comment;
} as CommentUI;
};

export const convertAllCasesToCamel = (snakeCases: CasesFindResponse): CasesUI => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
*/

import { CommentType } from '../../../../common/api';
import type { Comment } from '../../../containers/types';
import type { CommentUI } from '../../../containers/types';

export const getManualAlertIds = (comments: Comment[]): string[] => {
const dedupeAlerts = comments.reduce((alertIds, comment: Comment) => {
export const getManualAlertIds = (comments: CommentUI[]): string[] => {
const dedupeAlerts = comments.reduce((alertIds, comment: CommentUI) => {
if (comment.type === CommentType.alert) {
const ids = Array.isArray(comment.alertId) ? comment.alertId : [comment.alertId];
ids.forEach((id) => alertIds.add(id));
Expand All @@ -20,8 +20,8 @@ export const getManualAlertIds = (comments: Comment[]): string[] => {
return Array.from(dedupeAlerts);
};

export const getRegistrationContextFromAlerts = (comments: Comment[]): string[] => {
const dedupeRegistrationContext = comments.reduce((registrationContexts, comment: Comment) => {
export const getRegistrationContextFromAlerts = (comments: CommentUI[]): string[] => {
const dedupeRegistrationContext = comments.reduce((registrationContexts, comment: CommentUI) => {
if (comment.type === CommentType.alert) {
const indices = Array.isArray(comment.index) ? comment.index : [comment.index];
indices.forEach((index) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type { CommentUserAction } from '../../../../common/api';
import { Actions, CommentType } from '../../../../common/api';
import type { UserActionBuilder, UserActionBuilderArgs, UserActionResponse } from '../types';
import { createCommonUpdateUserActionBuilder } from '../common';
import type { Comment } from '../../../containers/types';
import type { CommentUI } from '../../../containers/types';
import * as i18n from './translations';
import { createUserAttachmentUserActionBuilder } from './user';
import { createAlertAttachmentUserActionBuilder } from './alert';
Expand Down Expand Up @@ -164,7 +164,7 @@ const getCreateCommentUserAction = ({
actionsNavigation,
}: {
userAction: UserActionResponse<CommentUserAction>;
comment: Comment;
comment: CommentUI;
} & Omit<
UserActionBuilderArgs,
'comments' | 'index' | 'handleOutlineComment' | 'currentUserProfile'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import type {
import { AttachmentActionType } from '../../../client/attachment_framework/types';
import { UserActionTimestamp } from '../timestamp';
import type { AttachmentTypeRegistry } from '../../../../common/registry';
import type { CommentResponse } from '../../../../common/api';
import type { Comment } from '../../../../common/api';
import type { UserActionBuilder, UserActionBuilderArgs } from '../types';
import type { SnakeToCamelCase } from '../../../../common/types';
import {
Expand Down Expand Up @@ -69,7 +69,7 @@ const getAttachmentRenderer = memoize(() => {
});

export const createRegisteredAttachmentUserActionBuilder = <
C extends CommentResponse,
C extends Comment,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
R extends AttachmentTypeRegistry<AttachmentType<any>>
>({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

import { CommentType } from '../../../common/api';
import { SECURITY_SOLUTION_OWNER } from '../../../common/constants';
import type { Comment } from '../../containers/types';
import type { CommentUI } from '../../containers/types';
import { isUserActionTypeSupported, getManualAlertIdsWithNoRuleId } from './helpers';

const comments: Comment[] = [
const comments: CommentUI[] = [
{
type: CommentType.alert,
alertId: 'alert-id-1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
import { isEmpty } from 'lodash';

import { CommentType } from '../../../common/api';
import type { Comment } from '../../containers/types';
import type { CommentUI } from '../../containers/types';
import { SUPPORTED_ACTION_TYPES } from './constants';
import type { SupportedUserActionTypes } from './types';

export const isUserActionTypeSupported = (type: string): type is SupportedUserActionTypes =>
SUPPORTED_ACTION_TYPES.includes(type as SupportedUserActionTypes);

export const getManualAlertIdsWithNoRuleId = (comments: Comment[]): string[] => {
const dedupeAlerts = comments.reduce((alertIds, comment: Comment) => {
export const getManualAlertIdsWithNoRuleId = (comments: CommentUI[]): string[] => {
const dedupeAlerts = comments.reduce((alertIds, comment: CommentUI) => {
if (comment.type === CommentType.alert && isEmpty(comment.rule.id)) {
const ids = Array.isArray(comment.alertId) ? comment.alertId : [comment.alertId];
ids.forEach((id) => alertIds.add(id));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type {
CaseUI,
CaseConnectors,
CaseUserActions,
Comment,
CommentUI,
UseFetchAlertData,
CaseUserActionsStats,
} from '../../containers/types';
Expand Down Expand Up @@ -55,7 +55,7 @@ export interface UserActionBuilderArgs {
persistableStateAttachmentTypeRegistry: PersistableStateAttachmentTypeRegistry;
caseConnectors: CaseConnectors;
userAction: CaseUserActions;
comments: Comment[];
comments: CommentUI[];
index: number;
commentRefs: React.MutableRefObject<
Record<string, AddCommentRefObject | UserActionMarkdownRefObject | null | undefined>
Expand Down
18 changes: 9 additions & 9 deletions x-pack/plugins/cases/public/containers/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type {
CaseUI,
CasesStatus,
CaseUserActions,
Comment,
CommentUI,
} from './types';

import type {
Expand All @@ -35,7 +35,7 @@ import type {
CasesStatusResponse,
CaseUserActionResponse,
CaseUserActionsResponse,
CommentResponse,
Comment,
UserAction,
UserActionTypes,
UserActionWithResponse,
Expand Down Expand Up @@ -80,7 +80,7 @@ export const elasticUser = {

export const tags: string[] = ['coke', 'pepsi'];

export const basicComment: Comment = {
export const basicComment: CommentUI = {
comment: 'Solve this fast!',
type: CommentType.user,
id: basicCommentId,
Expand Down Expand Up @@ -132,7 +132,7 @@ export const alertCommentWithIndices: AlertComment = {
version: 'WzQ3LDFc',
};

export const hostIsolationComment = (overrides?: Record<string, unknown>): Comment => {
export const hostIsolationComment = (overrides?: Record<string, unknown>): CommentUI => {
return {
type: CommentType.actions,
comment: 'I just isolated the host!',
Expand All @@ -158,7 +158,7 @@ export const hostIsolationComment = (overrides?: Record<string, unknown>): Comme
};
};

export const hostReleaseComment: () => Comment = () => {
export const hostReleaseComment: () => CommentUI = () => {
return {
type: CommentType.actions,
comment: 'I just released the host!',
Expand Down Expand Up @@ -370,7 +370,7 @@ export const basicCasePost: CaseUI = {
updatedBy: null,
};

export const basicCommentPatch: Comment = {
export const basicCommentPatch: CommentUI = {
...basicComment,
updatedAt: basicUpdatedAt,
updatedBy: {
Expand Down Expand Up @@ -476,7 +476,7 @@ export const elasticUserSnake = {
email: '[email protected]',
};

export const basicCommentSnake: CommentResponse = {
export const basicCommentSnake: Comment = {
comment: 'Solve this fast!',
type: CommentType.user,
id: basicCommentId,
Expand All @@ -490,7 +490,7 @@ export const basicCommentSnake: CommentResponse = {
version: 'WzQ3LDFc',
};

export const externalReferenceAttachmentSnake: CommentResponse = {
export const externalReferenceAttachmentSnake: Comment = {
type: CommentType.externalReference,
id: 'external-reference-comment-id',
externalReferenceId: 'my-id',
Expand All @@ -507,7 +507,7 @@ export const externalReferenceAttachmentSnake: CommentResponse = {
version: 'WzQ3LDFc',
};

export const persistableStateAttachmentSnake: CommentResponse = {
export const persistableStateAttachmentSnake: Comment = {
type: CommentType.persistableState,
id: 'persistable-state-comment-id',
persistableStateAttachmentState: { test_foo: 'foo' },
Expand Down
8 changes: 4 additions & 4 deletions x-pack/plugins/cases/server/client/attachments/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import type {
AllCommentsResponse,
BulkGetAttachmentsResponse,
Case,
CommentResponse,
CommentsResponse,
Comment,
Comments,
} from '../../../common/api';
import type { CasesClient } from '../client';

Expand Down Expand Up @@ -60,7 +60,7 @@ export interface AttachmentsSubClient {
/**
* Retrieves all comments matching the search criteria.
*/
find(findArgs: FindArgs): Promise<CommentsResponse>;
find(findArgs: FindArgs): Promise<Comments>;
/**
* Retrieves all alerts attach to a case given a single case ID
*/
Expand All @@ -72,7 +72,7 @@ export interface AttachmentsSubClient {
/**
* Retrieves a single attachment for a case.
*/
get(getArgs: GetArgs): Promise<CommentResponse>;
get(getArgs: GetArgs): Promise<Comment>;
/**
* Updates a specific attachment.
*
Expand Down
Loading