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] Case ui enhancement #91863

Merged
merged 36 commits into from
Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
4803fcf
ui enhancement
angorayc Feb 18, 2021
c1acfba
Merge branch 'master' of github.com:elastic/kibana into case-ui-fix
angorayc Feb 18, 2021
fab3950
fix actions
angorayc Feb 18, 2021
9b80fa9
unit test
angorayc Feb 18, 2021
6dc3ca6
update row actions
angorayc Feb 19, 2021
5e8dcc3
add case status all
angorayc Feb 19, 2021
46335f0
update find status
angorayc Feb 22, 2021
baef996
fix type
angorayc Feb 22, 2021
0ed83b3
remove all case count from dropdown
angorayc Feb 22, 2021
0bddbf9
fix type error
angorayc Feb 23, 2021
d7107bd
fix unit test
angorayc Feb 23, 2021
e0c29b7
disable bulk actions on status all
angorayc Feb 23, 2021
5342462
clean up
angorayc Feb 23, 2021
f412d15
Merge branch 'case-ui-fix' of github.com:angorayc/kibana into case-ui…
angorayc Feb 23, 2021
b9da2f9
fix types
angorayc Feb 23, 2021
8e0251e
fix cypress tests
angorayc Feb 24, 2021
08e3516
Merge branch 'case-ui-fix' of github.com:angorayc/kibana into case-ui…
angorayc Feb 24, 2021
6986423
Merge branch 'master' into case-ui-fix
kibanamachine Feb 24, 2021
46e4684
review
angorayc Mar 1, 2021
385a6fa
Merge branch 'master' of github.com:elastic/kibana into case-ui-fix
angorayc Mar 1, 2021
d7554cd
review
angorayc Mar 1, 2021
1d4f9ab
update status is only available for individual cases
angorayc Mar 1, 2021
067b20e
update available actions on status all
angorayc Mar 1, 2021
94da327
fix unit test
angorayc Mar 1, 2021
e1c285f
remove lodash get
angorayc Mar 2, 2021
c1508ba
rename status all
angorayc Mar 2, 2021
a453269
omit status if it is set to all
angorayc Mar 2, 2021
a812a98
do not sent status if itis set to all
angorayc Mar 2, 2021
f4624bc
Merge branch 'master' of github.com:elastic/kibana into case-ui-fix
angorayc Mar 2, 2021
d05c171
Merge branch 'master' of github.com:elastic/kibana into case-ui-fix
angorayc Mar 2, 2021
89be6cf
Remove all status from the backend
cnasikas Mar 2, 2021
173dac0
Merge branch 'case-ui-fix' of github.com:angorayc/kibana into case-ui…
cnasikas Mar 2, 2021
a6c372c
Merge branch 'case-ui-fix' of github.com:angorayc/kibana into case-ui…
cnasikas Mar 2, 2021
b250898
Hide actions on all status
cnasikas Mar 2, 2021
92a57fd
Merge branch 'case-ui-fix' of github.com:angorayc/kibana into case-ui…
angorayc Mar 2, 2021
efdaf6e
fix unit test
angorayc Mar 2, 2021
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/case/common/api/cases/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import * as rt from 'io-ts';
import { NumberFromString } from '../saved_object';
import { UserRT } from '../user';
import { CommentResponseRt } from './comment';
import { CasesStatusResponseRt, CaseStatusRt } from './status';
import { CasesStatusResponseRt, CaseStatusFilterRt, CaseStatusRt } from './status';
import { CaseConnectorRt, ESCaseConnector } from '../connectors';
import { SubCaseResponseRt } from './sub_case';

Expand Down Expand Up @@ -102,7 +102,7 @@ export const CasePostRequestRt = rt.intersection([
export const CasesFindRequestRt = rt.partial({
type: CaseTypeRt,
tags: rt.union([rt.array(rt.string), rt.string]),
status: CaseStatusRt,
status: CaseStatusFilterRt,
reporters: rt.union([rt.array(rt.string), rt.string]),
defaultSearchOperator: rt.union([rt.literal('AND'), rt.literal('OR')]),
fields: rt.array(rt.string),
Expand Down
7 changes: 7 additions & 0 deletions x-pack/plugins/case/common/api/cases/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import * as rt from 'io-ts';

export const AllCaseType = 'all' as const;

export enum CaseStatuses {
open = 'open',
'in-progress' = 'in-progress',
Expand All @@ -21,6 +23,11 @@ export const CaseStatusRt = rt.union([

export const caseStatuses = Object.values(CaseStatuses);

export const CaseStatusFilterRt = rt.union([rt.literal(AllCaseType), ...CaseStatusRt.types]);
Copy link
Contributor

@jonathan-buttner jonathan-buttner Mar 1, 2021

Choose a reason for hiding this comment

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

Do you think there's a way we could avoid adding all to the status types? If we add it here that means a case could potentially have a status of type all which wouldn't really make sense 🤔

Would it be easy to have the API call from the front end just not include any status in the query parameters? On the backend we'll automatically get all of them.

Copy link
Member

Choose a reason for hiding this comment

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

@angorayc I agree with @jonathan-buttner . It will nice if we can avoid it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see how you meant. I have CaseStatusRt that doesn't include all for cases, and use CaseStatusFilterRt just for rendering the filter relevant stuff.
I also remove the status from api call if the filter is set to all. Hope this makes it a bit clearer.

Copy link
Member

Choose a reason for hiding this comment

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

@angorayc As we discuss I removed the CaseStatusFilterRt.


export const caseStatusFilter = Object.values(CaseStatusFilterRt);
export type CaseStatusFilter = rt.TypeOf<typeof CaseStatusFilterRt>;

export const CasesStatusResponseRt = rt.type({
count_open_cases: rt.number,
count_in_progress_cases: rt.number,
Expand Down
6 changes: 2 additions & 4 deletions x-pack/plugins/case/server/routes/api/cases/find_cases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
CasesFindRequestRt,
throwErrors,
caseStatuses,
AllCaseType,
} from '../../../../common/api';
import { transformCases, wrapError, escapeHatch } from '../utils';
import { RouteDeps } from '../types';
Expand All @@ -37,17 +38,14 @@ export function initFindCasesApi({ caseService, router, logger }: RouteDeps) {
CasesFindRequestRt.decode(request.query),
fold(throwErrors(Boom.badRequest), identity)
);

const queryArgs = {
tags: queryParams.tags,
reporters: queryParams.reporters,
sortByField: queryParams.sortField,
status: queryParams.status,
status: queryParams.status === AllCaseType ? undefined : queryParams.status,
Copy link
Member

Choose a reason for hiding this comment

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

What happens if the status is undefined. Does the backend strips out the variable automatically?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we use status to build query statement, if it is undefined, it won't appear in the statement.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm could we instead not pass status to the backend at all? If we don't pass status it will be undefined and the backend will return everything anyway.

caseType: queryParams.type,
};

const caseQueries = constructQueryOptions(queryArgs);

const cases = await caseService.findCasesGroupedByID({
client,
caseOptions: { ...queryParams, ...caseQueries.case },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
backToCases,
createCase,
fillCasesMandatoryfields,
filterStatusOpen,
} from '../../tasks/create_new_case';
import { loginAndWaitForPageWithoutDateRange } from '../../tasks/login';

Expand Down Expand Up @@ -74,6 +75,7 @@ describe('Cases', () => {
attachTimeline(this.mycase);
createCase();
backToCases();
filterStatusOpen();

cy.get(ALL_CASES_PAGE_TITLE).should('have.text', 'Cases');
cy.get(ALL_CASES_OPEN_CASES_STATS).should('have.text', 'Open cases1');
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/security_solution/cypress/screens/all_cases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export const ALL_CASES_NAME = '[data-test-subj="case-details-link"]';

export const ALL_CASES_OPEN_CASES_COUNT = '[data-test-subj="case-status-filter"]';

export const ALL_CASES_OPEN_FILTER = '[data-test-subj="case-status-filter-open"]';

export const ALL_CASES_OPEN_CASES_STATS = '[data-test-subj="openStatsHeader"]';

export const ALL_CASES_OPENED_ON = '[data-test-subj="case-table-column-createdAt"]';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
ServiceNowconnectorOptions,
TestCase,
} from '../objects/case';
import { ALL_CASES_OPEN_CASES_COUNT, ALL_CASES_OPEN_FILTER } from '../screens/all_cases';

import {
BACK_TO_CASES_BTN,
Expand Down Expand Up @@ -40,6 +41,11 @@ export const backToCases = () => {
cy.get(BACK_TO_CASES_BTN).click({ force: true });
};

export const filterStatusOpen = () => {
cy.get(ALL_CASES_OPEN_CASES_COUNT).click();
cy.get(ALL_CASES_OPEN_FILTER).click();
};

export const fillCasesMandatoryfields = (newCase: TestCase) => {
cy.get(TITLE_INPUT).type(newCase.name, { force: true });
newCase.tags.forEach((tag) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,22 @@ import { Case, SubCase } from '../../containers/types';
import { UpdateCase } from '../../containers/use_get_cases';
import { statuses } from '../status';
import * as i18n from './translations';
import { isIndividual } from './helpers';

interface GetActions {
caseStatus: string;
dispatchUpdate: Dispatch<Omit<UpdateCase, 'refetchCasesStatus'>>;
deleteCaseOnClick: (deleteCase: Case) => void;
}

const hasSubCases = (subCases: SubCase[] | null | undefined) =>
subCases != null && subCases?.length > 0;

export const getActions = ({
caseStatus,
dispatchUpdate,
deleteCaseOnClick,
}: GetActions): Array<DefaultItemIconButtonAction<Case>> => {
const openCaseAction = {
available: (item: Case) => caseStatus !== CaseStatuses.open && !hasSubCases(item.subCases),
available: (item: Case | SubCase) => caseStatus !== CaseStatuses.open,
enabled: (item: Case | SubCase) => isIndividual(item) && item.status !== CaseStatuses.open,
description: statuses[CaseStatuses.open].actions.single.title,
icon: statuses[CaseStatuses.open].icon,
name: statuses[CaseStatuses.open].actions.single.title,
Expand All @@ -45,8 +44,9 @@ export const getActions = ({
};

const makeInProgressAction = {
available: (item: Case) =>
caseStatus !== CaseStatuses['in-progress'] && !hasSubCases(item.subCases),
available: (item: Case) => caseStatus !== CaseStatuses['in-progress'],
enabled: (item: Case | SubCase) =>
isIndividual(item) && item.status !== CaseStatuses['in-progress'],
description: statuses[CaseStatuses['in-progress']].actions.single.title,
icon: statuses[CaseStatuses['in-progress']].icon,
name: statuses[CaseStatuses['in-progress']].actions.single.title,
Expand All @@ -62,7 +62,8 @@ export const getActions = ({
};

const closeCaseAction = {
available: (item: Case) => caseStatus !== CaseStatuses.closed && !hasSubCases(item.subCases),
available: (item: Case | SubCase) => caseStatus !== CaseStatuses.closed,
enabled: (item: Case | SubCase) => isIndividual(item) && item.status !== CaseStatuses.closed,
description: statuses[CaseStatuses.closed].actions.single.title,
icon: statuses[CaseStatuses.closed].icon,
name: statuses[CaseStatuses.closed].actions.single.title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { RIGHT_ALIGNMENT } from '@elastic/eui/lib/services';
import styled from 'styled-components';
import { DefaultItemIconButtonAction } from '@elastic/eui/src/components/basic_table/action_types';

import { CaseStatuses } from '../../../../../case/common/api';
import { CaseStatuses, CaseType } from '../../../../../case/common/api';
import { getEmptyTagValue } from '../../../common/components/empty_value';
import { Case, SubCase } from '../../containers/types';
import { FormattedRelativePreferenceDate } from '../../../common/components/formatted_date';
Expand Down Expand Up @@ -204,7 +204,7 @@ export const getCasesColumns = (
name: i18n.STATUS,
render: (theCase: Case) => {
if (theCase?.subCases == null || theCase.subCases.length === 0) {
if (theCase.status == null) {
if (theCase.status == null || theCase.type === CaseType.collection) {
return getEmptyTagValue();
}
return <Status type={theCase.status} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,24 @@
*/

import { filter } from 'lodash/fp';
import { AssociationType, CaseStatuses } from '../../../../../case/common/api';
import { AssociationType, CaseStatuses, CaseType } from '../../../../../case/common/api';
import { Case, SubCase } from '../../containers/types';
import { statuses } from '../status';

export const isSelectedCasesIncludeCollections = (selectedCases: Case[]) =>
selectedCases.length > 0 &&
selectedCases.some((caseObj: Case) => caseObj.type === CaseType.collection);

export const isSubCase = (theCase: Case | SubCase): theCase is SubCase =>
(theCase as SubCase).caseParentId !== undefined &&
(theCase as SubCase).associationType === AssociationType.subCase;

export const isCollection = (theCase: Case | SubCase | null | undefined) =>
theCase != null && (theCase as Case).type === CaseType.collection;

export const isIndividual = (theCase: Case | SubCase | null | undefined) =>
theCase != null && (theCase as Case).type === CaseType.individual;

export const getSubCasesStatusCountsBadges = (
subCases: SubCase[]
): Array<{ name: CaseStatuses; color: string; count: number }> => {
Expand Down
Loading