Skip to content

Commit

Permalink
[Security Solution] [Cases] Various Cases cleanups (elastic#102103) (e…
Browse files Browse the repository at this point in the history
  • Loading branch information
stephmilovic committed Jun 17, 2021
1 parent a499e98 commit a78a84d
Show file tree
Hide file tree
Showing 170 changed files with 1,087 additions and 1,633 deletions.
10 changes: 10 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,16 @@ module.exports = {
},
},

/**
* Cases overrides
*/
{
files: ['x-pack/plugins/cases/**/*.{js,mjs,ts,tsx}'],
rules: {
'no-duplicate-imports': 'error',
},
},

/**
* Security Solution overrides
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-optimizer/limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,6 @@ pageLoadAssetSize:
banners: 17946
mapsEms: 26072
timelines: 28613
cases: 162385
screenshotMode: 17856
visTypePie: 35583
cases: 144442
3 changes: 1 addition & 2 deletions x-pack/plugins/cases/common/api/cases/sub_case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import * as rt from 'io-ts';
import { NumberFromString } from '../saved_object';
import { UserRT } from '../user';
import { CommentResponseRt } from './comment';
import { CasesStatusResponseRt } from './status';
import { CaseStatusRt } from './status';
import { CaseStatusRt, CasesStatusResponseRt } from './status';

const SubCaseBasicRt = rt.type({
/**
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/cases/public/common/lib/kibana/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import moment from 'moment-timezone';
import { useCallback, useEffect, useState } from 'react';
import { i18n } from '@kbn/i18n';

import { DEFAULT_DATE_FORMAT, DEFAULT_DATE_FORMAT_TZ } from '../../../../common/constants';
import { DEFAULT_DATE_FORMAT, DEFAULT_DATE_FORMAT_TZ } from '../../../../common';
import { AuthenticatedUser } from '../../../../../security/common/model';
import { convertToCamelCase } from '../../../containers/utils';
import { StartServices } from '../../../types';
Expand Down
16 changes: 7 additions & 9 deletions x-pack/plugins/cases/public/common/mock/match_media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
* 2.0.
*/

window.matchMedia = jest.fn().mockImplementation((query) => {
return {
matches: false,
media: query,
onchange: null,
addListener: jest.fn(),
removeListener: jest.fn(),
};
});
window.matchMedia = jest.fn().mockImplementation((query) => ({
matches: false,
media: query,
onchange: null,
addListener: jest.fn(),
removeListener: jest.fn(),
}));
44 changes: 21 additions & 23 deletions x-pack/plugins/cases/public/common/mock/test_providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,24 @@ const TestProvidersComponent: React.FC<Props> = ({ children }) => (

export const TestProviders = React.memo(TestProvidersComponent);

export const useFormFieldMock = <T,>(options?: Partial<FieldHook<T>>): FieldHook<T> => {
return {
path: 'path',
type: 'type',
value: ('mockedValue' as unknown) as T,
isPristine: false,
isValidating: false,
isValidated: false,
isChangingValue: false,
errors: [],
isValid: true,
getErrorsMessages: jest.fn(),
onChange: jest.fn(),
setValue: jest.fn(),
setErrors: jest.fn(),
clearErrors: jest.fn(),
validate: jest.fn(),
reset: jest.fn(),
__isIncludedInOutput: true,
__serializeValue: jest.fn(),
...options,
};
};
export const useFormFieldMock = <T,>(options?: Partial<FieldHook<T>>): FieldHook<T> => ({
path: 'path',
type: 'type',
value: ('mockedValue' as unknown) as T,
isPristine: false,
isValidating: false,
isValidated: false,
isChangingValue: false,
errors: [],
isValid: true,
getErrorsMessages: jest.fn(),
onChange: jest.fn(),
setValue: jest.fn(),
setErrors: jest.fn(),
clearErrors: jest.fn(),
validate: jest.fn(),
reset: jest.fn(),
__isIncludedInOutput: true,
__serializeValue: jest.fn(),
...options,
});
27 changes: 0 additions & 27 deletions x-pack/plugins/cases/public/common/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,6 @@

import { i18n } from '@kbn/i18n';

export const CASES_FEATURE_NO_PERMISSIONS_TITLE = i18n.translate(
'xpack.cases.caseFeatureNoPermissionsTitle',
{
defaultMessage: 'Kibana feature privileges required',
}
);

export const CASES_FEATURE_NO_PERMISSIONS_MSG = i18n.translate(
'xpack.cases.caseFeatureNoPermissionsMessage',
{
defaultMessage:
'To view cases, you must have privileges for the Cases feature in the Kibana space. For more information, contact your Kibana administrator.',
}
);

export const BACK_TO_ALL = i18n.translate('xpack.cases.caseView.backLabel', {
defaultMessage: 'Back to cases',
});
Expand Down Expand Up @@ -58,10 +43,6 @@ export const PARTICIPANTS = i18n.translate('xpack.cases.caseView.particpantsLabe
defaultMessage: 'Participants',
});

export const CREATE_BC_TITLE = i18n.translate('xpack.cases.caseView.breadcrumb', {
defaultMessage: 'Create',
});

export const CREATE_TITLE = i18n.translate('xpack.cases.caseView.create', {
defaultMessage: 'Create new case',
});
Expand Down Expand Up @@ -181,18 +162,10 @@ export const SAVE = i18n.translate('xpack.cases.caseView.description.save', {
defaultMessage: 'Save',
});

export const GO_TO_DOCUMENTATION = i18n.translate('xpack.cases.caseView.goToDocumentationButton', {
defaultMessage: 'View documentation',
});

export const CONNECTORS = i18n.translate('xpack.cases.caseView.connectors', {
defaultMessage: 'External Incident Management System',
});

export const EDIT_CONNECTOR = i18n.translate('xpack.cases.caseView.editConnector', {
defaultMessage: 'Change external incident management system',
});

export const NO_CONNECTOR = i18n.translate('xpack.cases.common.noConnector', {
defaultMessage: 'No connector selected',
});
Expand Down
22 changes: 5 additions & 17 deletions x-pack/plugins/cases/public/components/add_comment/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { waitFor, act } from '@testing-library/react';
import { noop } from 'lodash/fp';

import { TestProviders } from '../../common/mock';
import { Router, routeData, mockHistory, mockLocation } from '../__mock__/router';

import { CommentRequest, CommentType, SECURITY_SOLUTION_OWNER } from '../../../common';
import { usePostComment } from '../../containers/use_post_comment';
Expand Down Expand Up @@ -51,15 +50,12 @@ describe('AddComment ', () => {
beforeEach(() => {
jest.clearAllMocks();
usePostCommentMock.mockImplementation(() => defaultPostComment);
jest.spyOn(routeData, 'useLocation').mockReturnValue(mockLocation);
});

it('should post comment on submit click', async () => {
const wrapper = mount(
<TestProviders>
<Router history={mockHistory}>
<AddComment {...addCommentProps} />
</Router>
<AddComment {...addCommentProps} />
</TestProviders>
);

Expand Down Expand Up @@ -88,9 +84,7 @@ describe('AddComment ', () => {
usePostCommentMock.mockImplementation(() => ({ ...defaultPostComment, isLoading: true }));
const wrapper = mount(
<TestProviders>
<Router history={mockHistory}>
<AddComment {...{ ...addCommentProps, showLoading: true }} />
</Router>
<AddComment {...{ ...addCommentProps, showLoading: true }} />
</TestProviders>
);

Expand All @@ -104,9 +98,7 @@ describe('AddComment ', () => {
usePostCommentMock.mockImplementation(() => ({ ...defaultPostComment, isLoading: true }));
const wrapper = mount(
<TestProviders>
<Router history={mockHistory}>
<AddComment {...{ ...addCommentProps, disabled: true }} />
</Router>
<AddComment {...{ ...addCommentProps, disabled: true }} />
</TestProviders>
);

Expand All @@ -120,9 +112,7 @@ describe('AddComment ', () => {
const ref = React.createRef<AddCommentRefObject>();
const wrapper = mount(
<TestProviders>
<Router history={mockHistory}>
<AddComment {...{ ...addCommentProps }} ref={ref} />
</Router>
<AddComment {...{ ...addCommentProps }} ref={ref} />
</TestProviders>
);

Expand Down Expand Up @@ -153,9 +143,7 @@ describe('AddComment ', () => {
const wrapper = mount(
<TestProviders>
<CasesTimelineIntegrationProvider timelineIntegration={mockTimelineIntegration}>
<Router history={mockHistory}>
<AddComment {...{ ...addCommentProps }} />
</Router>
<AddComment {...{ ...addCommentProps }} />
</CasesTimelineIntegrationProvider>
</TestProviders>
);
Expand Down
36 changes: 17 additions & 19 deletions x-pack/plugins/cases/public/components/all_cases/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,20 @@ export const isIndividual = (theCase: Case | SubCase | null | undefined) =>

export const getSubCasesStatusCountsBadges = (
subCases: SubCase[]
): Array<{ name: CaseStatuses; color: string; count: number }> => {
return [
{
name: CaseStatuses.open,
color: statuses[CaseStatuses.open].color,
count: filter({ status: CaseStatuses.open }, subCases).length,
},
{
name: CaseStatuses['in-progress'],
color: statuses[CaseStatuses['in-progress']].color,
count: filter({ status: CaseStatuses['in-progress'] }, subCases).length,
},
{
name: CaseStatuses.closed,
color: statuses[CaseStatuses.closed].color,
count: filter({ status: CaseStatuses.closed }, subCases).length,
},
];
};
): Array<{ name: CaseStatuses; color: string; count: number }> => [
{
color: statuses[CaseStatuses.open].color,
count: filter({ status: CaseStatuses.open }, subCases).length,
name: CaseStatuses.open,
},
{
color: statuses[CaseStatuses['in-progress']].color,
count: filter({ status: CaseStatuses['in-progress'] }, subCases).length,
name: CaseStatuses['in-progress'],
},
{
color: statuses[CaseStatuses.closed].color,
count: filter({ status: CaseStatuses.closed }, subCases).length,
name: CaseStatuses.closed,
},
];
12 changes: 5 additions & 7 deletions x-pack/plugins/cases/public/components/all_cases/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ export interface AllCasesProps extends Owner {
userCanCrud: boolean;
}

export const AllCases: React.FC<AllCasesProps> = (props) => {
return (
<OwnerProvider owner={props.owner}>
<AllCasesGeneric {...props} />
</OwnerProvider>
);
};
export const AllCases: React.FC<AllCasesProps> = (props) => (
<OwnerProvider owner={props.owner}>
<AllCasesGeneric {...props} />
</OwnerProvider>
);

// eslint-disable-next-line import/no-default-export
export { AllCases as default };
10 changes: 5 additions & 5 deletions x-pack/plugins/cases/public/components/bulk_actions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,27 @@ interface GetBulkItems {
caseStatus: CaseStatusWithAllStatus;
closePopover: () => void;
deleteCasesAction: (cases: Case[]) => void;
includeCollections: boolean;
selectedCases: Case[];
updateCaseStatus: (status: string) => void;
includeCollections: boolean;
}

export const getBulkItems = ({
caseStatus,
closePopover,
deleteCasesAction,
includeCollections,
selectedCases,
updateCaseStatus,
includeCollections,
}: GetBulkItems) => {
let statusMenuItems: JSX.Element[] = [];

const openMenuItem = (
<EuiContextMenuItem
data-test-subj="cases-bulk-open-button"
disabled={selectedCases.length === 0 || includeCollections}
key="cases-bulk-open-button"
icon={statuses[CaseStatuses.open].icon}
key="cases-bulk-open-button"
onClick={() => {
closePopover();
updateCaseStatus(CaseStatuses.open);
Expand All @@ -51,8 +51,8 @@ export const getBulkItems = ({
<EuiContextMenuItem
data-test-subj="cases-bulk-in-progress-button"
disabled={selectedCases.length === 0 || includeCollections}
key="cases-bulk-in-progress-button"
icon={statuses[CaseStatuses['in-progress']].icon}
key="cases-bulk-in-progress-button"
onClick={() => {
closePopover();
updateCaseStatus(CaseStatuses['in-progress']);
Expand All @@ -66,8 +66,8 @@ export const getBulkItems = ({
<EuiContextMenuItem
data-test-subj="cases-bulk-close-button"
disabled={selectedCases.length === 0 || includeCollections}
key="cases-bulk-close-button"
icon={statuses[CaseStatuses.closed].icon}
key="cases-bulk-close-button"
onClick={() => {
closePopover();
updateCaseStatus(CaseStatuses.closed);
Expand Down
Loading

0 comments on commit a78a84d

Please sign in to comment.