-
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.
Open/Closed filter for observability alerts page (#99217)
- Loading branch information
Showing
16 changed files
with
274 additions
and
25 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
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
34 changes: 34 additions & 0 deletions
34
x-pack/plugins/observability/public/pages/alerts/status_filter.stories.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,34 @@ | ||
/* | ||
* 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, { ComponentProps, useState } from 'react'; | ||
import type { AlertStatus } from '../../../common/typings'; | ||
import { StatusFilter } from './status_filter'; | ||
|
||
type Args = ComponentProps<typeof StatusFilter>; | ||
|
||
export default { | ||
title: 'app/Alerts/StatusFilter', | ||
component: StatusFilter, | ||
argTypes: { | ||
onChange: { action: 'change' }, | ||
}, | ||
}; | ||
|
||
export function Example({ onChange }: Args) { | ||
const [status, setStatus] = useState<AlertStatus>('open'); | ||
|
||
return ( | ||
<StatusFilter | ||
status={status} | ||
onChange={(value) => { | ||
setStatus(value); | ||
onChange(value); | ||
}} | ||
/> | ||
); | ||
} |
39 changes: 39 additions & 0 deletions
39
x-pack/plugins/observability/public/pages/alerts/status_filter.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,39 @@ | ||
/* | ||
* 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 { render } from '@testing-library/react'; | ||
import React from 'react'; | ||
import type { AlertStatus } from '../../../common/typings'; | ||
import { StatusFilter } from './status_filter'; | ||
|
||
describe('StatusFilter', () => { | ||
describe('render', () => { | ||
it('renders', () => { | ||
const onChange = jest.fn(); | ||
const status: AlertStatus = 'all'; | ||
const props = { onChange, status }; | ||
|
||
expect(() => render(<StatusFilter {...props} />)).not.toThrowError(); | ||
}); | ||
|
||
(['all', 'open', 'closed'] as AlertStatus[]).map((status) => { | ||
describe(`when clicking the ${status} button`, () => { | ||
it('calls the onChange callback with "${status}"', () => { | ||
const onChange = jest.fn(); | ||
const props = { onChange, status }; | ||
|
||
const { getByTestId } = render(<StatusFilter {...props} />); | ||
const button = getByTestId(`StatusFilter ${status} button`); | ||
|
||
button.click(); | ||
|
||
expect(onChange).toHaveBeenCalledWith(status); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
56 changes: 56 additions & 0 deletions
56
x-pack/plugins/observability/public/pages/alerts/status_filter.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,56 @@ | ||
/* | ||
* 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 { EuiFilterButton, EuiFilterGroup } from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
import React from 'react'; | ||
import type { AlertStatus } from '../../../common/typings'; | ||
|
||
export interface StatusFilterProps { | ||
status: AlertStatus; | ||
onChange: (value: AlertStatus) => void; | ||
} | ||
|
||
export function StatusFilter({ status = 'open', onChange }: StatusFilterProps) { | ||
return ( | ||
<EuiFilterGroup | ||
aria-label={i18n.translate('xpack.observability.alerts.statusFilterAriaLabel', { | ||
defaultMessage: 'Filter alerts by open and closed status', | ||
})} | ||
> | ||
<EuiFilterButton | ||
data-test-subj="StatusFilter open button" | ||
hasActiveFilters={status === 'open'} | ||
onClick={() => onChange('open')} | ||
withNext={true} | ||
> | ||
{i18n.translate('xpack.observability.alerts.statusFilter.openButtonLabel', { | ||
defaultMessage: 'Open', | ||
})} | ||
</EuiFilterButton> | ||
<EuiFilterButton | ||
data-test-subj="StatusFilter closed button" | ||
hasActiveFilters={status === 'closed'} | ||
onClick={() => onChange('closed')} | ||
withNext={true} | ||
> | ||
{i18n.translate('xpack.observability.alerts.statusFilter.closedButtonLabel', { | ||
defaultMessage: 'Closed', | ||
})} | ||
</EuiFilterButton> | ||
<EuiFilterButton | ||
data-test-subj="StatusFilter all button" | ||
hasActiveFilters={status === 'all'} | ||
onClick={() => onChange('all')} | ||
> | ||
{i18n.translate('xpack.observability.alerts.statusFilter.allButtonLabel', { | ||
defaultMessage: 'All', | ||
})} | ||
</EuiFilterButton> | ||
</EuiFilterGroup> | ||
); | ||
} |
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
Oops, something went wrong.