mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[ML] AIOps: Add filter action for the Change point detection results (#155256)
## Summary Part of https://github.com/elastic/kibana/issues/151592 Adds actions to quickly filter for and filter out split field values.  ### Checklist - [x] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [x] Any UI touched in this PR is usable by keyboard only (learn more about [keyboard accessibility](https://webaim.org/techniques/keyboard/)) - [x] Any UI touched in this PR does not create any new axe failures (run axe in browser: [FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/), [Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US)) - [x] This renders correctly on smaller devices using a responsive layout. (You can test this [in your browser](https://www.browserstack.com/guide/responsive-testing-on-local-server)) - [x] This was checked for [cross-browser compatibility](https://www.elastic.co/support/matrix#matrix_browsers)
This commit is contained in:
parent
2d576c575e
commit
f0964823de
1 changed files with 98 additions and 1 deletions
|
@ -12,11 +12,14 @@ import {
|
|||
EuiIcon,
|
||||
EuiInMemoryTable,
|
||||
EuiToolTip,
|
||||
type DefaultItemAction,
|
||||
} from '@elastic/eui';
|
||||
import React, { type FC, useMemo } from 'react';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { FormattedMessage } from '@kbn/i18n-react';
|
||||
import { EuiTableSelectionType } from '@elastic/eui/src/components/basic_table/table_types';
|
||||
import { type Filter, FilterStateStore } from '@kbn/es-query';
|
||||
import { useDataSource } from '../../hooks/use_data_source';
|
||||
import { useCommonChartProps } from './use_common_chart_props';
|
||||
import {
|
||||
type ChangePointAnnotation,
|
||||
|
@ -33,13 +36,49 @@ export interface ChangePointsTableProps {
|
|||
onSelectionChange: (update: SelectedChangePoint[]) => void;
|
||||
}
|
||||
|
||||
function getFilterConfig(
|
||||
index: string,
|
||||
item: Required<ChangePointAnnotation>,
|
||||
negate: boolean
|
||||
): Filter {
|
||||
return {
|
||||
meta: {
|
||||
disabled: false,
|
||||
negate,
|
||||
alias: null,
|
||||
index,
|
||||
key: `${item.group.name}_${item.group.value}`,
|
||||
// @ts-ignore FilterMeta type definition misses the field property
|
||||
field: item.group.name,
|
||||
params: {
|
||||
query: item.group.value,
|
||||
},
|
||||
type: 'phrase',
|
||||
},
|
||||
query: {
|
||||
match_phrase: {
|
||||
[item.group.name]: item.group.value,
|
||||
},
|
||||
},
|
||||
$state: {
|
||||
store: FilterStateStore.APP_STATE,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export const ChangePointsTable: FC<ChangePointsTableProps> = ({
|
||||
isLoading,
|
||||
annotations,
|
||||
fieldConfig,
|
||||
onSelectionChange,
|
||||
}) => {
|
||||
const { fieldFormats } = useAiopsAppContext();
|
||||
const {
|
||||
fieldFormats,
|
||||
data: {
|
||||
query: { filterManager },
|
||||
},
|
||||
} = useAiopsAppContext();
|
||||
const { dataView } = useDataSource();
|
||||
|
||||
const dateFormatter = useMemo(() => fieldFormats.deserialize({ id: 'date' }), [fieldFormats]);
|
||||
|
||||
|
@ -51,6 +90,8 @@ export const ChangePointsTable: FC<ChangePointsTableProps> = ({
|
|||
},
|
||||
};
|
||||
|
||||
const hasActions = fieldConfig.splitField !== undefined;
|
||||
|
||||
const columns: Array<EuiBasicTableColumn<ChangePointAnnotation>> = [
|
||||
{
|
||||
field: 'timestamp',
|
||||
|
@ -126,6 +167,61 @@ export const ChangePointsTable: FC<ChangePointsTableProps> = ({
|
|||
truncateText: false,
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
name: i18n.translate('xpack.aiops.changePointDetection.actionsColumn', {
|
||||
defaultMessage: 'Actions',
|
||||
}),
|
||||
actions: [
|
||||
{
|
||||
name: i18n.translate(
|
||||
'xpack.aiops.changePointDetection.actions.filterForValueAction',
|
||||
{
|
||||
defaultMessage: 'Filter for value',
|
||||
}
|
||||
),
|
||||
description: i18n.translate(
|
||||
'xpack.aiops.changePointDetection.actions.filterForValueAction',
|
||||
{
|
||||
defaultMessage: 'Filter for value',
|
||||
}
|
||||
),
|
||||
icon: 'plusInCircle',
|
||||
color: 'primary',
|
||||
type: 'icon',
|
||||
onClick: (item) => {
|
||||
filterManager.addFilters(
|
||||
getFilterConfig(dataView.id!, item as Required<ChangePointAnnotation>, false)!
|
||||
);
|
||||
},
|
||||
isPrimary: true,
|
||||
'data-test-subj': 'aiopsChangePointFilterForValue',
|
||||
},
|
||||
{
|
||||
name: i18n.translate(
|
||||
'xpack.aiops.changePointDetection.actions.filterOutValueAction',
|
||||
{
|
||||
defaultMessage: 'Filter out value',
|
||||
}
|
||||
),
|
||||
description: i18n.translate(
|
||||
'xpack.aiops.changePointDetection.actions.filterOutValueAction',
|
||||
{
|
||||
defaultMessage: 'Filter out value',
|
||||
}
|
||||
),
|
||||
icon: 'minusInCircle',
|
||||
color: 'primary',
|
||||
type: 'icon',
|
||||
onClick: (item) => {
|
||||
filterManager.addFilters(
|
||||
getFilterConfig(dataView.id!, item as Required<ChangePointAnnotation>, true)!
|
||||
);
|
||||
},
|
||||
isPrimary: true,
|
||||
'data-test-subj': 'aiopsChangePointFilterForValue',
|
||||
},
|
||||
] as Array<DefaultItemAction<ChangePointAnnotation>>,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
];
|
||||
|
@ -155,6 +251,7 @@ export const ChangePointsTable: FC<ChangePointsTableProps> = ({
|
|||
columns={columns}
|
||||
pagination={{ pageSizeOptions: [5, 10, 15] }}
|
||||
sorting={defaultSorting}
|
||||
hasActions={hasActions}
|
||||
message={
|
||||
isLoading ? (
|
||||
<EuiEmptyPrompt
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue