-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Cases] Show the Average time to close stat in the all cases page (#1…
- Loading branch information
Showing
16 changed files
with
469 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
x-pack/plugins/cases/public/components/all_cases/cases_metrics.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* 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 { within } from '@testing-library/dom'; | ||
import React from 'react'; | ||
import { AppMockRenderer, createAppMockRenderer } from '../../common/mock'; | ||
import { useGetCasesMetrics } from '../../containers/use_get_cases_metrics'; | ||
import { useGetCasesStatus } from '../../containers/use_get_cases_status'; | ||
import { CasesMetrics } from './cases_metrics'; | ||
|
||
jest.mock('../../containers/use_get_cases_metrics'); | ||
jest.mock('../../containers/use_get_cases_status'); | ||
|
||
const useGetCasesMetricsMock = useGetCasesMetrics as jest.Mock; | ||
const useGetCasesStatusMock = useGetCasesStatus as jest.Mock; | ||
|
||
describe('Cases metrics', () => { | ||
useGetCasesStatusMock.mockReturnValue({ | ||
countOpenCases: 2, | ||
countInProgressCases: 3, | ||
countClosedCases: 4, | ||
isLoading: false, | ||
fetchCasesStatus: jest.fn(), | ||
}); | ||
useGetCasesMetricsMock.mockReturnValue({ | ||
// 600 seconds = 10m | ||
mttr: 600, | ||
isLoading: false, | ||
fetchCasesMetrics: jest.fn(), | ||
}); | ||
|
||
let appMockRenderer: AppMockRenderer; | ||
|
||
beforeEach(() => { | ||
appMockRenderer = createAppMockRenderer(); | ||
}); | ||
|
||
it('renders the correct stats', () => { | ||
const result = appMockRenderer.render(<CasesMetrics refresh={1} />); | ||
expect(result.getByTestId('cases-metrics-stats')).toBeTruthy(); | ||
expect(within(result.getByTestId('openStatsHeader')).getByText(2)).toBeTruthy(); | ||
expect(within(result.getByTestId('inProgressStatsHeader')).getByText(3)).toBeTruthy(); | ||
expect(within(result.getByTestId('closedStatsHeader')).getByText(4)).toBeTruthy(); | ||
expect(within(result.getByTestId('mttrStatsHeader')).getByText('10m')).toBeTruthy(); | ||
}); | ||
}); |
119 changes: 119 additions & 0 deletions
119
x-pack/plugins/cases/public/components/all_cases/cases_metrics.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
* 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 React, { FunctionComponent, useEffect, useMemo } from 'react'; | ||
import { | ||
EuiDescriptionList, | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiIcon, | ||
EuiLoadingSpinner, | ||
EuiToolTip, | ||
} from '@elastic/eui'; | ||
import styled, { css } from 'styled-components'; | ||
import prettyMilliseconds from 'pretty-ms'; | ||
import { CaseStatuses } from '../../../common/api'; | ||
import { useGetCasesStatus } from '../../containers/use_get_cases_status'; | ||
import { StatusStats } from '../status/status_stats'; | ||
import { useGetCasesMetrics } from '../../containers/use_get_cases_metrics'; | ||
import { ATTC_DESCRIPTION, ATTC_STAT } from './translations'; | ||
|
||
interface CountProps { | ||
refresh?: number; | ||
} | ||
const MetricsFlexGroup = styled.div` | ||
${({ theme }) => css` | ||
.euiFlexGroup { | ||
border: ${theme.eui.euiBorderThin}; | ||
border-radius: ${theme.eui.euiBorderRadius}; | ||
margin: 0 0 ${theme.eui.euiSizeL} 0; | ||
} | ||
@media only screen and (max-width: ${theme.eui.euiBreakpoints.s}) { | ||
.euiFlexGroup { | ||
padding: ${theme.eui.euiSizeM}; | ||
} | ||
} | ||
`} | ||
`; | ||
|
||
export const CasesMetrics: FunctionComponent<CountProps> = ({ refresh }) => { | ||
const { | ||
countOpenCases, | ||
countInProgressCases, | ||
countClosedCases, | ||
isLoading: isCasesStatusLoading, | ||
fetchCasesStatus, | ||
} = useGetCasesStatus(); | ||
|
||
const { mttr, isLoading: isCasesMetricsLoading, fetchCasesMetrics } = useGetCasesMetrics(); | ||
|
||
const mttrValue = useMemo( | ||
() => (mttr ? prettyMilliseconds(mttr * 1000, { compact: true, verbose: false }) : '-'), | ||
[mttr] | ||
); | ||
|
||
useEffect(() => { | ||
if (refresh != null) { | ||
fetchCasesStatus(); | ||
fetchCasesMetrics(); | ||
} | ||
}, [fetchCasesMetrics, fetchCasesStatus, refresh]); | ||
|
||
return ( | ||
<MetricsFlexGroup> | ||
<EuiFlexGroup responsive={true} data-test-subj="cases-metrics-stats"> | ||
<EuiFlexItem grow={true}> | ||
<StatusStats | ||
dataTestSubj="openStatsHeader" | ||
caseCount={countOpenCases} | ||
caseStatus={CaseStatuses.open} | ||
isLoading={isCasesStatusLoading} | ||
/> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={true}> | ||
<StatusStats | ||
dataTestSubj="inProgressStatsHeader" | ||
caseCount={countInProgressCases} | ||
caseStatus={CaseStatuses['in-progress']} | ||
isLoading={isCasesStatusLoading} | ||
/> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={true}> | ||
<StatusStats | ||
dataTestSubj="closedStatsHeader" | ||
caseCount={countClosedCases} | ||
caseStatus={CaseStatuses.closed} | ||
isLoading={isCasesStatusLoading} | ||
/> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={true}> | ||
<EuiDescriptionList | ||
data-test-subj={'mttrStatsHeader'} | ||
textStyle="reverse" | ||
listItems={[ | ||
{ | ||
title: ( | ||
<EuiToolTip position="right" content={ATTC_DESCRIPTION}> | ||
<> | ||
{ATTC_STAT} <EuiIcon type="questionInCircle" /> | ||
</> | ||
</EuiToolTip> | ||
), | ||
description: isCasesMetricsLoading ? ( | ||
<EuiLoadingSpinner data-test-subj={`mttr-stat-loading-spinner`} /> | ||
) : ( | ||
mttrValue | ||
), | ||
}, | ||
]} | ||
/> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</MetricsFlexGroup> | ||
); | ||
}; | ||
CasesMetrics.displayName = 'CasesMetrics'; |
59 changes: 0 additions & 59 deletions
59
x-pack/plugins/cases/public/components/all_cases/count.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.