-
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.
move filter_for button in a separate file
- Loading branch information
Showing
2 changed files
with
68 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
61 changes: 61 additions & 0 deletions
61
x-pack/plugins/observability/public/pages/alerts/filter_for_value.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,61 @@ | ||
/* | ||
* 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, { useCallback, useMemo } from 'react'; | ||
import { i18n } from '@kbn/i18n'; | ||
|
||
export const FILTER_FOR_VALUE = i18n.translate('xpack.observability.hoverActions.filterForValue', { | ||
defaultMessage: 'Filter for value', | ||
}); | ||
|
||
import { EuiButtonIcon } from '@elastic/eui'; | ||
|
||
interface FilterForValueProps { | ||
Component?: typeof EuiButtonEmpty | typeof EuiButtonIcon; | ||
field: string; | ||
value: string[] | string | null | undefined; | ||
addToQuery: (value: string) => void; | ||
} | ||
|
||
const FilterForValueButton: React.FC<FilterForValueProps> = React.memo( | ||
({ Component, field, value, addToQuery }) => { | ||
const text = useMemo(() => `${field}${value != null ? `: "${value}"` : ''}`, [field, value]); | ||
const onClick = useCallback(() => { | ||
addToQuery(text); | ||
}, [text, addToQuery]); | ||
const button = useMemo( | ||
() => | ||
Component ? ( | ||
<Component | ||
aria-label={FILTER_FOR_VALUE} | ||
data-test-subj="filter-for-value" | ||
iconType="plusInCircle" | ||
onClick={onClick} | ||
title={FILTER_FOR_VALUE} | ||
> | ||
{FILTER_FOR_VALUE} | ||
</Component> | ||
) : ( | ||
<EuiButtonIcon | ||
aria-label={FILTER_FOR_VALUE} | ||
className="timelines__hoverActionButton" | ||
data-test-subj="filter-for-value" | ||
iconSize="s" | ||
iconType="plusInCircle" | ||
onClick={onClick} | ||
/> | ||
), | ||
[Component, onClick] | ||
); | ||
return button; | ||
} | ||
); | ||
|
||
FilterForValueButton.displayName = 'FilterForValueButton'; | ||
|
||
// eslint-disable-next-line import/no-default-export | ||
export { FilterForValueButton as default }; |