Skip to content

Commit

Permalink
Improve types
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Apr 21, 2023
1 parent c8c87de commit 5fcfe98
Show file tree
Hide file tree
Showing 142 changed files with 778 additions and 713 deletions.
2 changes: 0 additions & 2 deletions x-pack/plugins/cases/common/api/saved_object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,3 @@ export const SavedObjectFindOptionsRt = rt.partial({
*/
sortOrder: rt.union([rt.literal('desc'), rt.literal('asc')]),
});

export type SavedObjectFindOptions = rt.TypeOf<typeof SavedObjectFindOptionsRt>;
4 changes: 3 additions & 1 deletion x-pack/plugins/cases/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ export {

export type {
Case,
Cases,
CasesBulkGetRequestCertainFields,
CasesBulkGetResponseCertainFields,
} from './api';

export type {
Case,
CaseUI,
CasesUI,
Ecs,
CasesFeatures,
CaseViewRefreshPropInterface,
Expand Down
10 changes: 5 additions & 5 deletions x-pack/plugins/cases/common/ui/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type {
CaseUserActionResponse,
SingleCaseMetricsResponse,
CommentResponse,
Case,
Case as CaseSnakeCase,
UserActionFindResponse,
FindTypeField as UserActionFindTypeField,
CommentResponseAlertsType,
Expand Down Expand Up @@ -92,16 +92,16 @@ export type FindCaseUserActions = Omit<SnakeToCamelCase<UserActionFindResponse>,
userActions: CaseUserActions[];
};
export type CaseUserActionsStats = SnakeToCamelCase<CaseUserActionStatsResponse>;
export type Case = Omit<SnakeToCamelCase<Case>, 'comments'> & { comments: Comment[] };
export type Cases = Omit<SnakeToCamelCase<CasesFindResponse>, 'cases'> & { cases: Case[] };
export type CaseUI = Omit<SnakeToCamelCase<CaseSnakeCase>, 'comments'> & { comments: Comment[] };
export type CasesUI = Omit<SnakeToCamelCase<CasesFindResponse>, 'cases'> & { cases: CaseUI[] };
export type CasesStatus = SnakeToCamelCase<CasesStatusResponse>;
export type CasesMetrics = SnakeToCamelCase<CasesMetricsResponse>;
export type CaseUpdateRequest = SnakeToCamelCase<CasePatchRequest>;
export type CaseConnectors = SnakeToCamelCase<GetCaseConnectorsResponse>;
export type CaseUsers = GetCaseUsersResponse;

export interface ResolvedCase {
case: Case;
case: CaseUI;
outcome: ResolvedSimpleSavedObject['outcome'];
aliasTargetId?: ResolvedSimpleSavedObject['alias_target_id'];
aliasPurpose?: ResolvedSimpleSavedObject['alias_purpose'];
Expand Down Expand Up @@ -191,7 +191,7 @@ export type UpdateKey = keyof Pick<
export interface UpdateByKey {
updateKey: UpdateKey;
updateValue: CasePatchRequest[UpdateKey];
caseData: Case;
caseData: CaseUI;
onSuccess?: () => void;
onError?: () => void;
}
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/cases/public/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import type { HttpStart } from '@kbn/core/public';
import type { Cases, CasesStatus, CasesMetrics } from '../../common/ui';
import type { CasesUI, CasesStatus, CasesMetrics } from '../../common/ui';
import {
CASE_FIND_URL,
CASE_METRICS_URL,
Expand Down Expand Up @@ -41,7 +41,7 @@ export const getCases = async ({
http,
signal,
query,
}: HTTPService & { query: CasesFindRequest }): Promise<Cases> => {
}: HTTPService & { query: CasesFindRequest }): Promise<CasesUI> => {
const res = await http.get<CasesFindResponse>(CASE_FIND_URL, { query, signal });
return convertAllCasesToCamel(decodeCasesFindResponse(res));
};
Expand Down
11 changes: 6 additions & 5 deletions x-pack/plugins/cases/public/api/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import type {
Cases,
} from '../../common/api';
import { isCommentUserAction } from '../../common/utils/user_actions';
import type { Cases, Case, Comment, ResolvedCase } from '../containers/types';
import type { CasesUI, CaseUI, Comment, ResolvedCase } from '../containers/types';

export const convertArrayToCamelCase = (arrayOfSnakes: unknown[]): unknown[] =>
arrayOfSnakes.reduce((acc: unknown[], value) => {
Expand All @@ -46,15 +46,16 @@ export const convertToCamelCase = <T, U extends {}>(obj: T): U =>
return acc;
}, {} as U);

export const convertCaseToCamelCase = (theCase: Case): Case => {
export const convertCaseToCamelCase = (theCase: Case): CaseUI => {
const { comments, ...restCase } = theCase;
return {
...convertToCamelCase<Case, Case>(restCase),
...convertToCamelCase<Case, CaseUI>(restCase),
...(comments != null ? { comments: convertAttachmentsToCamelCase(comments) } : {}),
};
};

export const convertCasesToCamelCase = (cases: Cases): Case[] => cases.map(convertCaseToCamelCase);
export const convertCasesToCamelCase = (cases: Cases): CaseUI[] =>
cases.map(convertCaseToCamelCase);

export const convertCaseResolveToCamelCase = (res: CaseResolveResponse): ResolvedCase => {
const { case: theCase, ...rest } = res;
Expand Down Expand Up @@ -112,7 +113,7 @@ const convertAttachmentToCamelExceptProperty = (
} as Comment;
};

export const convertAllCasesToCamel = (snakeCases: CasesFindResponse): Cases => ({
export const convertAllCasesToCamel = (snakeCases: CasesFindResponse): CasesUI => ({
cases: convertCasesToCamelCase(snakeCases.cases),
countOpenCases: snakeCases.count_open_cases,
countInProgressCases: snakeCases.count_in_progress_cases,
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/cases/public/client/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type {
CasesMetricsRequest,
} from '../../../common/api';
import { getCasesFromAlertsUrl } from '../../../common/api';
import type { Cases, CasesStatus, CasesMetrics } from '../../../common/ui';
import type { CasesUI, CasesStatus, CasesMetrics } from '../../../common/ui';
import { bulkGetCases, getCases, getCasesMetrics, getCasesStatus } from '../../api';
import type { CasesUiStart } from '../../types';

Expand All @@ -26,7 +26,7 @@ export const createClientAPI = ({ http }: { http: HttpStart }): CasesUiStart['ap
): Promise<CasesByAlertId> =>
http.get<CasesByAlertId>(getCasesFromAlertsUrl(alertId), { query }),
cases: {
find: (query: CasesFindRequest, signal?: AbortSignal): Promise<Cases> =>
find: (query: CasesFindRequest, signal?: AbortSignal): Promise<CasesUI> =>
getCases({ http, query, signal }),
getCasesStatus: (query: CasesStatusRequest, signal?: AbortSignal): Promise<CasesStatus> =>
getCasesStatus({ http, query, signal }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type {
CommentRequestExternalReferenceType,
CommentRequestPersistableStateType,
} from '../../../common/api';
import type { Case } from '../../containers/types';
import type { CaseUI } from '../../containers/types';

export enum AttachmentActionType {
BUTTON = 'button',
Expand Down Expand Up @@ -48,7 +48,7 @@ export interface AttachmentViewObject<Props = {}> {
}

export interface CommonAttachmentViewProps {
caseData: Pick<Case, 'id' | 'title'>;
caseData: Pick<CaseUI, 'id' | 'title'>;
}

export interface ExternalReferenceAttachmentViewProps extends CommonAttachmentViewProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@ const getFeatureID = (owner: CasesOwners) => {
return FEATURE_ID;
}

return `${owner}Cases`;
return `${owner}CasesUI`;
};
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('cases transactions', () => {

result.current.startTransaction({ appId });

expect(mockStartTransaction).toHaveBeenCalledWith(`Cases [${appId}] createCase`);
expect(mockStartTransaction).toHaveBeenCalledWith(`CasesUI [${appId}] createCase`);
expect(mockAddLabels).not.toHaveBeenCalled();
});

Expand All @@ -66,7 +66,9 @@ describe('cases transactions', () => {

result.current.startTransaction({ appId, attachments: singleAttachments });

expect(mockStartTransaction).toHaveBeenCalledWith(`Cases [${appId}] addAttachmentToNewCase`);
expect(mockStartTransaction).toHaveBeenCalledWith(
`CasesUI [${appId}] addAttachmentToNewCase`
);
expect(mockAddLabels).not.toHaveBeenCalled();
});

Expand All @@ -76,7 +78,7 @@ describe('cases transactions', () => {
result.current.startTransaction({ appId, attachments: bulkAttachments });

expect(mockStartTransaction).toHaveBeenCalledWith(
`Cases [${appId}] bulkAddAttachmentsToNewCase`
`CasesUI [${appId}] bulkAddAttachmentsToNewCase`
);
expect(mockAddLabels).toHaveBeenCalledWith({ alert_count: 3 });
});
Expand All @@ -89,7 +91,7 @@ describe('cases transactions', () => {
result.current.startTransaction({ appId, attachments: singleAttachments });

expect(mockStartTransaction).toHaveBeenCalledWith(
`Cases [${appId}] addAttachmentToExistingCase`
`CasesUI [${appId}] addAttachmentToExistingCase`
);
expect(mockAddLabels).not.toHaveBeenCalled();
});
Expand All @@ -100,7 +102,7 @@ describe('cases transactions', () => {
result.current.startTransaction({ appId, attachments: bulkAttachments });

expect(mockStartTransaction).toHaveBeenCalledWith(
`Cases [${appId}] bulkAddAttachmentsToExistingCase`
`CasesUI [${appId}] bulkAddAttachmentsToExistingCase`
);
expect(mockAddLabels).toHaveBeenCalledWith({ alert_count: 3 });
});
Expand Down
12 changes: 7 additions & 5 deletions x-pack/plugins/cases/public/common/apm/use_cases_transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@ export const useCreateCaseWithAttachmentsTransaction = () => {
useCallback<StartCreateCaseWithAttachmentsTransaction>(
({ appId, attachments }) => {
if (!attachments) {
return startTransaction(`Cases [${appId}] ${CREATE_CASE}`);
return startTransaction(`CasesUI [${appId}] ${CREATE_CASE}`);
}
const alertCount = getAlertCount(attachments);
if (alertCount <= 1) {
return startTransaction(`Cases [${appId}] ${ADD_ATTACHMENT_TO_NEW_CASE}`);
return startTransaction(`CasesUI [${appId}] ${ADD_ATTACHMENT_TO_NEW_CASE}`);
}

const transaction = startTransaction(`Cases [${appId}] ${BULK_ADD_ATTACHMENT_TO_NEW_CASE}`);
const transaction = startTransaction(
`CasesUI [${appId}] ${BULK_ADD_ATTACHMENT_TO_NEW_CASE}`
);
transaction?.addLabels({ alert_count: alertCount });
return transaction;
},
Expand All @@ -61,10 +63,10 @@ export const useAddAttachmentToExistingCaseTransaction = () => {
({ appId, attachments }) => {
const alertCount = getAlertCount(attachments);
if (alertCount <= 1) {
return startTransaction(`Cases [${appId}] ${ADD_ATTACHMENT_TO_EXISTING_CASE}`);
return startTransaction(`CasesUI [${appId}] ${ADD_ATTACHMENT_TO_EXISTING_CASE}`);
}
const transaction = startTransaction(
`Cases [${appId}] ${BULK_ADD_ATTACHMENT_TO_EXISTING_CASE}`
`CasesUI [${appId}] ${BULK_ADD_ATTACHMENT_TO_EXISTING_CASE}`
);
transaction?.addLabels({ alert_count: alertCount });
return transaction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { useCallback } from 'react';
import type { TransactionOptions } from '@elastic/apm-rum';
import { useKibana } from '../lib/kibana';

export type CasesApmTransactionName = `Cases [${string}] ${string}`;
export type CasesApmTransactionName = `CasesUI [${string}] ${string}`;

interface StartTransactionOptions {
type?: string;
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/cases/public/common/lib/kibana/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class KibanaServices {

private static throwUninitializedError(): never {
throw new Error(
'Kibana services not initialized - are you trying to import this module from outside of the Cases app?'
'Kibana services not initialized - are you trying to import this module from outside of the CasesUI app?'
);
}
}
24 changes: 12 additions & 12 deletions x-pack/plugins/cases/public/common/navigation/deep_links.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ describe('getCasesDeepLinks', () => {
expect(deepLinks).toEqual({
id: 'cases',
path: '/cases',
title: 'Cases',
title: 'CasesUI',
deepLinks: [
{
id: 'cases_create',
path: '/cases/create',
title: 'Create New Case',
title: 'Create New CaseUI',
},
{
id: 'cases_configure',
path: '/cases/configure',
title: 'Configure Cases',
title: 'Configure CasesUI',
},
],
});
Expand All @@ -35,17 +35,17 @@ describe('getCasesDeepLinks', () => {
expect(deepLinks).toEqual({
id: 'cases',
path: '/test',
title: 'Cases',
title: 'CasesUI',
deepLinks: [
{
id: 'cases_create',
path: '/test/create',
title: 'Create New Case',
title: 'Create New CaseUI',
},
{
id: 'cases_configure',
path: '/test/configure',
title: 'Configure Cases',
title: 'Configure CasesUI',
},
],
});
Expand All @@ -69,19 +69,19 @@ describe('getCasesDeepLinks', () => {
expect(deepLinks).toEqual({
id: 'cases',
path: '/cases',
title: 'Cases',
title: 'CasesUI',
searchable: false,
deepLinks: [
{
id: 'cases_create',
path: '/cases/create',
title: 'Create New Case',
title: 'Create New CaseUI',
navLinkStatus: AppNavLinkStatus.hidden,
},
{
id: 'cases_configure',
path: '/cases/configure',
title: 'Configure Cases',
title: 'Configure CasesUI',
order: 8002,
},
],
Expand Down Expand Up @@ -110,17 +110,17 @@ describe('getCasesDeepLinks', () => {
expect(deepLinks).toEqual({
id: 'cases',
path: '/cases',
title: 'Cases',
title: 'CasesUI',
deepLinks: [
{
id: 'cases_create',
path: '/cases/create',
title: 'Create New Case',
title: 'Create New CaseUI',
},
{
id: 'cases_configure',
path: '/cases/configure',
title: 'Configure Cases',
title: 'Configure CasesUI',
},
],
});
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/cases/public/common/navigation/deep_links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ export const getCasesDeepLinks = <T extends AppDeepLink = AppDeepLink>({
extend?: Partial<Record<ICasesDeepLinkId, Partial<T>>>;
}) => ({
title: i18n.translate('xpack.cases.navigation.cases', {
defaultMessage: 'Cases',
defaultMessage: 'CasesUI',
}),
...(extend[CasesDeepLinkId.cases] ?? {}),
id: CasesDeepLinkId.cases,
path: basePath,
deepLinks: [
{
title: i18n.translate('xpack.cases.navigation.create', {
defaultMessage: 'Create New Case',
defaultMessage: 'Create New CaseUI',
}),
...(extend[CasesDeepLinkId.casesCreate] ?? {}),
id: CasesDeepLinkId.casesCreate,
path: getCreateCasePath(basePath),
},
{
title: i18n.translate('xpack.cases.navigation.configure', {
defaultMessage: 'Configure Cases',
defaultMessage: 'Configure CasesUI',
}),
...(extend[CasesDeepLinkId.casesConfigure] ?? {}),
id: CasesDeepLinkId.casesConfigure,
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/cases/public/common/navigation/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const useCasesNavigation = ({
};

/**
* Cases can be either be part of a solution or a standalone application
* CasesUI can be either be part of a solution or a standalone application
* The standalone application is registered from the cases plugin and is called
* the main application. The main application uses paths and the solutions
* deep links.
Expand Down
Loading

0 comments on commit 5fcfe98

Please sign in to comment.