Skip to content

Commit

Permalink
Remove all status from the backend
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Mar 2, 2021
1 parent d05c171 commit 89be6cf
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 69 deletions.
7 changes: 0 additions & 7 deletions x-pack/plugins/case/common/api/cases/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

import * as rt from 'io-ts';

export const StatusAll = 'all' as const;

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

export const caseStatuses = Object.values(CaseStatuses);

export const CaseStatusFilterRt = rt.union([rt.literal(StatusAll), ...CaseStatusRt.types]);

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
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@

import React, { memo } from 'react';
import { EuiSuperSelect, EuiSuperSelectOption, EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
import { StatusAll, CaseStatusFilter } from '../../../../../case/common/api';
import { Status, statuses } from '../status';
import { Status, statuses, StatusAll, CaseStatusWithAllStatus } from '../status';

interface Props {
stats: Record<CaseStatusFilter, number | null>;
selectedStatus: CaseStatusFilter;
onStatusChanged: (status: CaseStatusFilter) => void;
disabledStatuses?: CaseStatusFilter[];
stats: Record<CaseStatusWithAllStatus, number | null>;
selectedStatus: CaseStatusWithAllStatus;
onStatusChanged: (status: CaseStatusWithAllStatus) => void;
disabledStatuses?: CaseStatusWithAllStatus[];
}

const StatusFilterComponent: React.FC<Props> = ({
Expand All @@ -23,22 +22,23 @@ const StatusFilterComponent: React.FC<Props> = ({
onStatusChanged,
disabledStatuses = [],
}) => {
const caseStatuses = Object.keys(statuses) as CaseStatusFilter[];
const options: Array<EuiSuperSelectOption<CaseStatusFilter>> = [StatusAll, ...caseStatuses].map(
(status) => ({
value: status,
inputDisplay: (
<EuiFlexGroup gutterSize="xs" alignItems={'center'}>
<EuiFlexItem grow={false}>
<Status type={status} />
</EuiFlexItem>
{status !== StatusAll && <EuiFlexItem grow={false}>{` (${stats[status]})`}</EuiFlexItem>}
</EuiFlexGroup>
),
disabled: disabledStatuses.includes(status),
'data-test-subj': `case-status-filter-${status}`,
})
);
const caseStatuses = Object.keys(statuses) as CaseStatusWithAllStatus[];
const options: Array<EuiSuperSelectOption<CaseStatusWithAllStatus>> = [
StatusAll,
...caseStatuses,
].map((status) => ({
value: status,
inputDisplay: (
<EuiFlexGroup gutterSize="xs" alignItems={'center'}>
<EuiFlexItem grow={false}>
<Status type={status} />
</EuiFlexItem>
{status !== StatusAll && <EuiFlexItem grow={false}>{` (${stats[status]})`}</EuiFlexItem>}
</EuiFlexGroup>
),
disabled: disabledStatuses.includes(status),
'data-test-subj': `case-status-filter-${status}`,
}));

return (
<EuiSuperSelect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import { isEqual } from 'lodash/fp';
import styled from 'styled-components';
import { EuiFlexGroup, EuiFlexItem, EuiFieldSearch, EuiFilterGroup } from '@elastic/eui';

import { StatusAll, CaseStatuses, CaseStatusFilter } from '../../../../../case/common/api';
import { CaseStatuses } from '../../../../../case/common/api';
import { FilterOptions } from '../../containers/types';
import { useGetTags } from '../../containers/use_get_tags';
import { useGetReporters } from '../../containers/use_get_reporters';
import { FilterPopover } from '../filter_popover';
import { CaseStatusWithAllStatus, StatusAll } from '../status';
import { StatusFilter } from './status_filter';

import * as i18n from './translations';
Expand Down Expand Up @@ -131,7 +132,7 @@ const CasesTableFiltersComponent = ({
);

const onStatusChanged = useCallback(
(status: CaseStatusFilter) => {
(status: CaseStatusWithAllStatus) => {
onFilterChanged({ status });
},
[onFilterChanged]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import React from 'react';
import { EuiContextMenuItem } from '@elastic/eui';

import { CaseStatuses, CaseStatusFilter } from '../../../../../case/common/api';
import { statuses } from '../status';
import { CaseStatuses } from '../../../../../case/common/api';
import { statuses, CaseStatusWithAllStatus } from '../status';
import * as i18n from './translations';

interface GetBulkItems {
caseStatus: CaseStatusFilter;
caseStatus: CaseStatusWithAllStatus;
closePopover: () => void;
deleteCasesAction: (cases: string[]) => void;
selectedCaseIds: string[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,9 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { EuiIconType } from '@elastic/eui/src/components/icon/icon';
import { StatusAll, CaseStatuses } from '../../../../../case/common/api';
import { CaseStatuses } from '../../../../../case/common/api';
import * as i18n from './translations';

type AllCaseStatus = Record<typeof StatusAll, { color: string; label: string }>;

type Statuses = Record<
CaseStatuses,
{
color: string;
label: string;
icon: EuiIconType;
actions: {
bulk: {
title: string;
};
single: {
title: string;
description?: string;
};
};
actionBar: {
title: string;
};
button: {
label: string;
};
stats: {
title: string;
};
}
>;
import { AllCaseStatus, Statuses, StatusAll } from './types';

export const allCaseStatus: AllCaseStatus = {
[StatusAll]: { color: 'hollow', label: i18n.ALL },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
export * from './status';
export * from './config';
export * from './stats';
export * from './types';
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import React, { memo, useMemo } from 'react';
import { noop } from 'lodash/fp';
import { EuiBadge } from '@elastic/eui';

import { StatusAll, CaseStatusFilter } from '../../../../../case/common/api';
import { allCaseStatus, statuses } from './config';
import { CaseStatusWithAllStatus, StatusAll } from './types';
import * as i18n from './translations';

interface Props {
type: CaseStatusFilter;
type: CaseStatusWithAllStatus;
withArrow?: boolean;
onClick?: () => void;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { EuiIconType } from '@elastic/eui/src/components/icon/icon';
import { CaseStatuses } from '../../../../../case/common/api';

export const StatusAll = 'all' as const;
type StatusAllType = typeof StatusAll;

export type CaseStatusWithAllStatus = CaseStatuses | StatusAllType;

export type AllCaseStatus = Record<StatusAllType, { color: string; label: string }>;

export type Statuses = Record<
CaseStatuses,
{
color: string;
label: string;
icon: EuiIconType;
actions: {
bulk: {
title: string;
};
single: {
title: string;
description?: string;
};
};
actionBar: {
title: string;
};
button: {
label: string;
};
stats: {
title: string;
};
}
>;
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import {
CasePatchRequest,
CaseType,
AssociationType,
CaseStatusFilter,
} from '../../../../case/common/api';
import { CaseStatusWithAllStatus } from '../components/status';

export { CaseConnector, ActionConnector, CaseStatuses } from '../../../../case/common/api';

Expand Down Expand Up @@ -95,7 +95,7 @@ export interface QueryParams {

export interface FilterOptions {
search: string;
status: CaseStatusFilter;
status: CaseStatusWithAllStatus;
tags: string[];
reporters: User[];
onlyCollectionType?: boolean;
Expand Down

0 comments on commit 89be6cf

Please sign in to comment.