-
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.
- Loading branch information
Showing
28 changed files
with
391 additions
and
301 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
24 changes: 0 additions & 24 deletions
24
...ui/public/application/internal/shareable_components_sandbox/rule_state_filter_sandbox.tsx
This file was deleted.
Oops, something went wrong.
26 changes: 26 additions & 0 deletions
26
...i/public/application/internal/shareable_components_sandbox/rule_status_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,26 @@ | ||
/* | ||
* 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 { RuleStatusFilterProps } from '../../../types'; | ||
import { getRuleStatusFilterLazy } from '../../../common/get_rule_status_filter'; | ||
|
||
export const RuleStatusFilterSandbox = () => { | ||
const [selectedStatuses, setSelectedStatuses] = useState< | ||
RuleStatusFilterProps['selectedStatuses'] | ||
>([]); | ||
|
||
return ( | ||
<div style={{ flex: 1 }}> | ||
{getRuleStatusFilterLazy({ | ||
selectedStatuses, | ||
onChange: setSelectedStatuses, | ||
})} | ||
<div>Selected states: {JSON.stringify(selectedStatuses)}</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
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
107 changes: 107 additions & 0 deletions
107
...ons_ui/public/application/sections/rules_list/components/rule_execution_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,107 @@ | ||
/* | ||
* 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, { useEffect, useState } from 'react'; | ||
import { FormattedMessage } from '@kbn/i18n-react'; | ||
import { | ||
EuiFilterGroup, | ||
EuiPopover, | ||
EuiFilterButton, | ||
EuiFilterSelectItem, | ||
EuiHealth, | ||
} from '@elastic/eui'; | ||
import { RuleExecutionStatuses, RuleExecutionStatusValues } from '@kbn/alerting-plugin/common'; | ||
import { rulesStatusesTranslationsMapping } from '../translations'; | ||
|
||
interface RuleExecutionStatusFilterProps { | ||
selectedStatuses: string[]; | ||
onChange?: (selectedRuleStatusesIds: string[]) => void; | ||
} | ||
|
||
export const RuleExecutionStatusFilter: React.FunctionComponent<RuleExecutionStatusFilterProps> = ({ | ||
selectedStatuses, | ||
onChange, | ||
}: RuleExecutionStatusFilterProps) => { | ||
const [selectedValues, setSelectedValues] = useState<string[]>(selectedStatuses); | ||
const [isPopoverOpen, setIsPopoverOpen] = useState<boolean>(false); | ||
|
||
useEffect(() => { | ||
if (onChange) { | ||
onChange(selectedValues); | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [selectedValues]); | ||
|
||
useEffect(() => { | ||
setSelectedValues(selectedStatuses); | ||
}, [selectedStatuses]); | ||
|
||
return ( | ||
<EuiFilterGroup> | ||
<EuiPopover | ||
isOpen={isPopoverOpen} | ||
closePopover={() => setIsPopoverOpen(false)} | ||
button={ | ||
<EuiFilterButton | ||
iconType="arrowDown" | ||
hasActiveFilters={selectedValues.length > 0} | ||
numActiveFilters={selectedValues.length} | ||
numFilters={selectedValues.length} | ||
onClick={() => setIsPopoverOpen(!isPopoverOpen)} | ||
data-test-subj="ruleExecutionStatusFilterButton" | ||
> | ||
<FormattedMessage | ||
id="xpack.triggersActionsUI.sections.rulesList.ruleExecutionStatusFilterLabel" | ||
defaultMessage="Last response" | ||
/> | ||
</EuiFilterButton> | ||
} | ||
> | ||
<div className="euiFilterSelect__items"> | ||
{[...RuleExecutionStatusValues].sort().map((item: RuleExecutionStatuses) => { | ||
const healthColor = getHealthColor(item); | ||
return ( | ||
<EuiFilterSelectItem | ||
key={item} | ||
style={{ textTransform: 'capitalize' }} | ||
onClick={() => { | ||
const isPreviouslyChecked = selectedValues.includes(item); | ||
if (isPreviouslyChecked) { | ||
setSelectedValues(selectedValues.filter((val) => val !== item)); | ||
} else { | ||
setSelectedValues(selectedValues.concat(item)); | ||
} | ||
}} | ||
checked={selectedValues.includes(item) ? 'on' : undefined} | ||
data-test-subj={`ruleExecutionStatus${item}FilterOption`} | ||
> | ||
<EuiHealth color={healthColor}>{rulesStatusesTranslationsMapping[item]}</EuiHealth> | ||
</EuiFilterSelectItem> | ||
); | ||
})} | ||
</div> | ||
</EuiPopover> | ||
</EuiFilterGroup> | ||
); | ||
}; | ||
|
||
export function getHealthColor(status: RuleExecutionStatuses) { | ||
switch (status) { | ||
case 'active': | ||
return 'success'; | ||
case 'error': | ||
return 'danger'; | ||
case 'ok': | ||
return 'primary'; | ||
case 'pending': | ||
return 'accent'; | ||
case 'warning': | ||
return 'warning'; | ||
default: | ||
return 'subdued'; | ||
} | ||
} |
Oops, something went wrong.