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

[Security Solution] [Cases] Various Cases cleanups #102103

Merged
merged 27 commits into from
Jun 17, 2021
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
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
11 changes: 11 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,17 @@ module.exports = {
},
},

/**
* Cases overrides
*/
{
files: ['x-pack/plugins/cases/**/*.{js,mjs,ts,tsx}'],
rules: {
'arrow-body-style': ['warn', 'as-needed'],
'no-duplicate-imports': 'error',
Copy link
Contributor

Choose a reason for hiding this comment

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

🎉

},
},

/**
* 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
16 changes: 8 additions & 8 deletions x-pack/plugins/cases/public/components/__mock__/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ export const mockHistory = {
length: 2,
location,
action: pop,
push: jest.fn(),
replace: jest.fn(),
go: jest.fn(),
goBack: jest.fn(),
goForward: jest.fn(),
block: jest.fn(),
createHref: jest.fn(),
listen: jest.fn(),
push: () => {},
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we still have some tests using this mock now that we removed them from the file below?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point no i dont think so, there is one but its import routeData from 'react-router';. ill take care of it

replace: () => {},
go: () => {},
goBack: () => {},
goForward: () => {},
block: () => {},
createHref: () => {},
listen: () => {},
};

export const mockLocation = {
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