-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[RAM] Add shareable rule status filter #130705
Merged
Merged
Changes from 3 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
b337f96
rule state filter
JiaweiWu 0576f50
turn off experiment
JiaweiWu 31aa11b
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine 2e6ded4
Merge branch 'main' into issue-130160-state-filter
kibanamachine b42c959
Status filter API call
JiaweiWu 10ece1c
Fix tests
JiaweiWu 6f1b580
Merge branch 'main' into issue-130160-state-filter
kibanamachine c18a582
rename state to status, added tests
JiaweiWu be1505c
merge conflicts
JiaweiWu 6882021
Address comments and fix tests
JiaweiWu 82170a2
Revert experiment flag
JiaweiWu 1084bbb
Remove unused translations
JiaweiWu c59e3d8
Addressed comments
JiaweiWu 0be9814
Merge branch 'main' into issue-130160-state-filter
kibanamachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
...ui/public/application/internal/shareable_components_sandbox/rule_state_filter_sandbox.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,24 @@ | ||
/* | ||
* 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, { useState } from 'react'; | ||
import { RuleStateFilterProps } from '../../../types'; | ||
import { getRuleStateFilterLazy } from '../../../common/get_rule_state_filter'; | ||
|
||
export const RuleStateFilterSandbox = () => { | ||
const [selectedStates, setSelectedStates] = useState<RuleStateFilterProps['selectedStates']>([]); | ||
|
||
return ( | ||
<div style={{ flex: 1 }}> | ||
{getRuleStateFilterLazy({ | ||
selectedStates, | ||
onChange: setSelectedStates, | ||
})} | ||
<div>Selected states: {JSON.stringify(selectedStates)}</div> | ||
</div> | ||
); | ||
}; |
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
58 changes: 58 additions & 0 deletions
58
...s_actions_ui/public/application/sections/rules_list/components/rule_state_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,58 @@ | ||
/* | ||
* 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 from 'react'; | ||
import { mountWithIntl } from '@kbn/test-jest-helpers'; | ||
import { EuiFilterButton, EuiFilterSelectItem } from '@elastic/eui'; | ||
import { RuleStateFilter } from './rule_state_filter'; | ||
|
||
const onChangeMock = jest.fn(); | ||
|
||
describe('rule_state_filter', () => { | ||
beforeEach(() => { | ||
onChangeMock.mockReset(); | ||
}); | ||
|
||
it('renders correctly', () => { | ||
const wrapper = mountWithIntl(<RuleStateFilter selectedStates={[]} onChange={onChangeMock} />); | ||
|
||
expect(wrapper.find(EuiFilterSelectItem).exists()).toBeFalsy(); | ||
expect(wrapper.find(EuiFilterButton).exists()).toBeTruthy(); | ||
|
||
expect(wrapper.find('.euiNotificationBadge').text()).toEqual('0'); | ||
}); | ||
|
||
it('can open the popover correctly', () => { | ||
const wrapper = mountWithIntl(<RuleStateFilter selectedStates={[]} onChange={onChangeMock} />); | ||
|
||
expect(wrapper.find('[data-test-subj="ruleStateFilterSelect"]').exists()).toBeFalsy(); | ||
|
||
wrapper.find(EuiFilterButton).simulate('click'); | ||
|
||
const statusItems = wrapper.find(EuiFilterSelectItem); | ||
expect(statusItems.length).toEqual(3); | ||
}); | ||
|
||
it('can select states', () => { | ||
const wrapper = mountWithIntl(<RuleStateFilter selectedStates={[]} onChange={onChangeMock} />); | ||
|
||
wrapper.find(EuiFilterButton).simulate('click'); | ||
|
||
wrapper.find(EuiFilterSelectItem).at(0).simulate('click'); | ||
expect(onChangeMock).toHaveBeenCalledWith(['enabled']); | ||
|
||
wrapper.setProps({ | ||
selectedStates: ['enabled'], | ||
}); | ||
|
||
wrapper.find(EuiFilterSelectItem).at(0).simulate('click'); | ||
expect(onChangeMock).toHaveBeenCalledWith([]); | ||
|
||
wrapper.find(EuiFilterSelectItem).at(1).simulate('click'); | ||
expect(onChangeMock).toHaveBeenCalledWith(['enabled', 'disabled']); | ||
}); | ||
}); |
97 changes: 97 additions & 0 deletions
97
...iggers_actions_ui/public/application/sections/rules_list/components/rule_state_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,97 @@ | ||
/* | ||
* 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, { useState, useCallback } from 'react'; | ||
import { FormattedMessage } from '@kbn/i18n-react'; | ||
import { EuiFilterButton, EuiPopover, EuiFilterGroup, EuiFilterSelectItem } from '@elastic/eui'; | ||
|
||
type State = 'enabled' | 'muted' | 'disabled'; | ||
|
||
const states: State[] = ['enabled', 'disabled', 'muted']; | ||
|
||
const optionStyles = { | ||
textTransform: 'capitalize' as const, | ||
}; | ||
|
||
const getOptionDataTestSubj = (state: State) => `ruleStateFilterOption-${state}`; | ||
|
||
export interface RuleStateFilterProps { | ||
selectedStates: State[]; | ||
dataTestSubj?: string; | ||
buttonDataTestSubj?: string; | ||
optionDataTestSubj?: (state: State) => string; | ||
onChange: (selectedStates: State[]) => void; | ||
} | ||
|
||
export const RuleStateFilter = (props: RuleStateFilterProps) => { | ||
const { | ||
selectedStates = [], | ||
dataTestSubj = 'ruleStateFilterSelect', | ||
buttonDataTestSubj = 'ruleStateFilterButton', | ||
optionDataTestSubj = getOptionDataTestSubj, | ||
onChange = () => {}, | ||
} = props; | ||
|
||
const [isPopoverOpen, setIsPopoverOpen] = useState<boolean>(false); | ||
|
||
const onFilterItemClick = useCallback( | ||
(newOption: State) => () => { | ||
if (selectedStates.includes(newOption)) { | ||
onChange(selectedStates.filter((option) => option !== newOption)); | ||
return; | ||
} | ||
onChange([...selectedStates, newOption]); | ||
}, | ||
[selectedStates, onChange] | ||
); | ||
|
||
const onClick = useCallback(() => { | ||
setIsPopoverOpen((prevIsOpen) => !prevIsOpen); | ||
}, [setIsPopoverOpen]); | ||
|
||
return ( | ||
<EuiFilterGroup> | ||
<EuiPopover | ||
isOpen={isPopoverOpen} | ||
closePopover={() => setIsPopoverOpen(false)} | ||
button={ | ||
<EuiFilterButton | ||
data-test-subj={buttonDataTestSubj} | ||
iconType="arrowDown" | ||
hasActiveFilters={selectedStates.length > 0} | ||
numActiveFilters={selectedStates.length} | ||
numFilters={selectedStates.length} | ||
onClick={onClick} | ||
> | ||
<FormattedMessage | ||
id="xpack.triggersActionsUI.sections.ruleDetails.ruleStateFilterButton" | ||
defaultMessage="State" | ||
/> | ||
</EuiFilterButton> | ||
} | ||
> | ||
<div data-test-subj={dataTestSubj}> | ||
{states.map((state) => { | ||
return ( | ||
<EuiFilterSelectItem | ||
key={state} | ||
style={optionStyles} | ||
data-test-subj={optionDataTestSubj(state)} | ||
onClick={onFilterItemClick(state)} | ||
checked={selectedStates.includes(state) ? 'on' : undefined} | ||
> | ||
{state} | ||
</EuiFilterSelectItem> | ||
); | ||
})} | ||
</div> | ||
</EuiPopover> | ||
</EuiFilterGroup> | ||
); | ||
}; | ||
|
||
// eslint-disable-next-line import/no-default-export | ||
export { RuleStateFilter as default }; |
14 changes: 14 additions & 0 deletions
14
x-pack/plugins/triggers_actions_ui/public/common/get_rule_state_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,14 @@ | ||
/* | ||
* 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 from 'react'; | ||
import { RuleStateFilter } from '../application/sections'; | ||
import type { RuleStateFilterProps } from '../application/sections/rules_list/components/rule_state_filter'; | ||
|
||
export const getRuleStateFilterLazy = (props: RuleStateFilterProps) => { | ||
return <RuleStateFilter {...props} />; | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ import { getAddAlertFlyoutLazy } from './common/get_add_alert_flyout'; | |
import { getEditAlertFlyoutLazy } from './common/get_edit_alert_flyout'; | ||
import { getAlertsTableLazy } from './common/get_alerts_table'; | ||
import { getRuleStatusDropdownLazy } from './common/get_rule_status_dropdown'; | ||
import { getRuleStateFilterLazy } from './common/get_rule_state_filter'; | ||
import { ExperimentalFeaturesService } from './common/experimental_features_service'; | ||
import { | ||
ExperimentalFeatures, | ||
|
@@ -45,6 +46,7 @@ import type { | |
ConnectorEditFlyoutProps, | ||
AlertsTableProps, | ||
RuleStatusDropdownProps, | ||
RuleStateFilterProps, | ||
AlertsTableConfigurationRegistry, | ||
} from './types'; | ||
import { TriggersActionsUiConfigType } from '../common/types'; | ||
|
@@ -75,6 +77,7 @@ export interface TriggersAndActionsUIPublicPluginStart { | |
) => ReactElement<RuleEditProps>; | ||
getAlertsTable: (props: AlertsTableProps) => ReactElement<AlertsTableProps>; | ||
getRuleStatusDropdown: (props: RuleStatusDropdownProps) => ReactElement<RuleStatusDropdownProps>; | ||
getRuleStateFilter: (props: RuleStateFilterProps) => ReactElement<RuleStateFilterProps>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @JiaweiWu Do you think we should call it |
||
} | ||
|
||
interface PluginsSetup { | ||
|
@@ -244,6 +247,9 @@ export class Plugin | |
getRuleStatusDropdown: (props: RuleStatusDropdownProps) => { | ||
return getRuleStatusDropdownLazy(props); | ||
}, | ||
getRuleStateFilter: (props: RuleStateFilterProps) => { | ||
return getRuleStateFilterLazy(props); | ||
}, | ||
}; | ||
} | ||
|
||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JiaweiWu I know this PR is still a draft, but I would like to give an input at this stage. It should be
snoozed
instead ofmuted