Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e6c7edd
filter for value
mgiota Aug 14, 2021
5cc7824
code clean up
mgiota Aug 16, 2021
bb9757f
Merge branch 'master' of github.com:elastic/kibana into 108119_filter…
mgiota Aug 16, 2021
2ddfb3f
fix i18n tests
mgiota Aug 16, 2021
5193de7
fix type errors
mgiota Aug 16, 2021
c28adfe
revert changes to reason field to make reason field clickable again
mgiota Aug 16, 2021
7ea274e
[RAC Observability] fix reason field
mgiota Aug 16, 2021
6c22709
fix type issues
mgiota Aug 17, 2021
0897318
Merge branch 'master' into 108119_filter_actions
kibanamachine Aug 17, 2021
96694b9
filter my kibana.alert. status on load (will refactor)
mgiota Aug 17, 2021
b37f722
refactor filter for alert status on load
mgiota Aug 17, 2021
64bd109
remove rest params
mgiota Aug 17, 2021
2238357
fix eslint errors
mgiota Aug 17, 2021
89f2bdc
Merge branch 'master' into 108119_filter_actions
kibanamachine Aug 17, 2021
481c7d0
hard code alert status for now, will be fixed in another PR
mgiota Aug 17, 2021
c6c74dc
move filter_for button in a separate file
mgiota Aug 17, 2021
a1cf76d
fix errors
mgiota Aug 17, 2021
ac2bdd2
comply with kibana i18n guideines
mgiota Aug 17, 2021
3320eae
simpler implementation for default filtering
mgiota Aug 17, 2021
bcead95
Merge branch 'master' into 108119_filter_actions
kibanamachine Aug 17, 2021
fbd4cd8
fix syntax error
mgiota Aug 17, 2021
9108e1c
fix type errors
mgiota Aug 17, 2021
b411bab
fix eslint errors
mgiota Aug 17, 2021
008e198
fix eslint errors
mgiota Aug 17, 2021
09d16c7
Merge branch 'master' of github.com:elastic/kibana into 108119_filter…
mgiota Aug 17, 2021
505dfa3
Merge branch 'master' of github.com:elastic/kibana into 108119_filter…
mgiota Aug 17, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ import {
ALERT_DURATION as ALERT_DURATION_TYPED,
ALERT_SEVERITY_LEVEL as ALERT_SEVERITY_LEVEL_TYPED,
ALERT_STATUS as ALERT_STATUS_TYPED,
ALERT_RULE_NAME as ALERT_RULE_NAME_TYPED,
ALERT_REASON as ALERT_REASON_TYPED,
ALERT_RULE_CONSUMER,
} from '@kbn/rule-data-utils';
import {
ALERT_DURATION as ALERT_DURATION_NON_TYPED,
ALERT_SEVERITY_LEVEL as ALERT_SEVERITY_LEVEL_NON_TYPED,
ALERT_STATUS as ALERT_STATUS_NON_TYPED,
ALERT_RULE_NAME as ALERT_RULE_NAME_NON_TYPED,
ALERT_REASON as ALERT_REASON_NON_TYPED,
TIMESTAMP,
// @ts-expect-error importing from a place other than root because we want to limit what we import from this package
} from '@kbn/rule-data-utils/target_node/technical_field_names';
Expand All @@ -41,7 +41,6 @@ import {
import { i18n } from '@kbn/i18n';
import styled from 'styled-components';
import React, { Suspense, useMemo, useState, useCallback } from 'react';

import { get } from 'lodash';
import { useGetUserAlertsPermissions } from '../../hooks/use_alert_permission';
import type { TimelinesUIStart, TGridType, SortDirection } from '../../../../timelines/public';
Expand All @@ -68,7 +67,7 @@ const AlertConsumers: typeof AlertConsumersTyped = AlertConsumersNonTyped;
const ALERT_DURATION: typeof ALERT_DURATION_TYPED = ALERT_DURATION_NON_TYPED;
const ALERT_SEVERITY_LEVEL: typeof ALERT_SEVERITY_LEVEL_TYPED = ALERT_SEVERITY_LEVEL_NON_TYPED;
const ALERT_STATUS: typeof ALERT_STATUS_TYPED = ALERT_STATUS_NON_TYPED;
const ALERT_RULE_NAME: typeof ALERT_RULE_NAME_TYPED = ALERT_RULE_NAME_NON_TYPED;
const ALERT_REASON: typeof ALERT_REASON_TYPED = ALERT_REASON_NON_TYPED;

interface AlertsTableTGridProps {
indexName: string;
Expand All @@ -77,6 +76,7 @@ interface AlertsTableTGridProps {
kuery: string;
status: string;
setRefetch: (ref: () => void) => void;
addToQuery: (value: string) => void;
}

interface ObservabilityActionsProps extends ActionProps {
Expand Down Expand Up @@ -147,8 +147,8 @@ export const columns: Array<
displayAsText: i18n.translate('xpack.observability.alertsTGrid.reasonColumnDescription', {
defaultMessage: 'Reason',
}),
id: ALERT_REASON,
linkField: '*',
id: ALERT_RULE_NAME,
},
];

Expand Down Expand Up @@ -299,7 +299,7 @@ function ObservabilityActions({
}

export function AlertsTableTGrid(props: AlertsTableTGridProps) {
const { indexName, rangeFrom, rangeTo, kuery, status, setRefetch } = props;
const { indexName, rangeFrom, rangeTo, kuery, status, setRefetch, addToQuery } = props;
const { timelines } = useKibana<{ timelines: TimelinesUIStart }>().services;

const [flyoutAlert, setFlyoutAlert] = useState<TopAlert | undefined>(undefined);
Expand Down Expand Up @@ -343,7 +343,7 @@ export function AlertsTableTGrid(props: AlertsTableTGridProps) {
type,
columns,
deletedEventIds: [],
defaultCellActions: getDefaultCellActions({ enableFilterActions: false }),
defaultCellActions: getDefaultCellActions({ addToQuery }),
end: rangeTo,
filters: [],
indexNames: [indexName],
Expand Down Expand Up @@ -388,6 +388,7 @@ export function AlertsTableTGrid(props: AlertsTableTGridProps) {
rangeTo,
setRefetch,
status,
addToQuery,
]);
const handleFlyoutClose = () => setFlyoutAlert(undefined);
const { observabilityRuleTypeRegistry } = usePluginContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@
*/

import React from 'react';

import { i18n } from '@kbn/i18n';
import { ObservabilityPublicPluginsStart } from '../..';
import { getMappedNonEcsValue } from './render_cell_value';
import FilterForValueButton from './filter_for_value';
import { useKibana } from '../../../../../../src/plugins/kibana_react/public';
import { TimelineNonEcsData } from '../../../../timelines/common/search_strategy';
import { TGridCellAction } from '../../../../timelines/common/types/timeline';
import { TimelinesUIStart } from '../../../../timelines/public';

/** a noop required by the filter in / out buttons */
const onFilterAdded = () => {};
export const FILTER_FOR_VALUE = i18n.translate('xpack.observability.hoverActions.filterForValue', {
defaultMessage: 'Filter for value',
});

/** a hook to eliminate the verbose boilerplate required to use common services */
const useKibanaServices = () => {
Expand All @@ -31,32 +33,10 @@ const useKibanaServices = () => {
return { timelines, filterManager };
};

/** actions for adding filters to the search bar */
const filterCellActions: TGridCellAction[] = [
({ data }: { data: TimelineNonEcsData[][] }) => ({ rowIndex, columnId, Component }) => {
const { timelines, filterManager } = useKibanaServices();

const value = getMappedNonEcsValue({
data: data[rowIndex],
fieldName: columnId,
});

return (
<>
{timelines.getHoverActions().getFilterForValueButton({
Component,
field: columnId,
filterManager,
onFilterAdded,
ownFocus: false,
showTooltip: false,
value,
})}
</>
);
},
/** actions common to all cells (e.g. copy to clipboard) */
const commonCellActions: TGridCellAction[] = [
({ data }: { data: TimelineNonEcsData[][] }) => ({ rowIndex, columnId, Component }) => {
const { timelines, filterManager } = useKibanaServices();
const { timelines } = useKibanaServices();

const value = getMappedNonEcsValue({
data: data[rowIndex],
Expand All @@ -65,11 +45,10 @@ const filterCellActions: TGridCellAction[] = [

return (
<>
{timelines.getHoverActions().getFilterOutValueButton({
{timelines.getHoverActions().getCopyButton({
Component,
field: columnId,
filterManager,
onFilterAdded,
isHoverAction: false,
ownFocus: false,
showTooltip: false,
value,
Expand All @@ -79,31 +58,27 @@ const filterCellActions: TGridCellAction[] = [
},
];

/** actions common to all cells (e.g. copy to clipboard) */
const commonCellActions: TGridCellAction[] = [
/** actions for adding filters to the search bar */
const buildFilterCellActions = (addToQuery: (value: string) => void): TGridCellAction[] => [
({ data }: { data: TimelineNonEcsData[][] }) => ({ rowIndex, columnId, Component }) => {
const { timelines } = useKibanaServices();

const value = getMappedNonEcsValue({
data: data[rowIndex],
fieldName: columnId,
});

return (
<>
{timelines.getHoverActions().getCopyButton({
Component,
field: columnId,
isHoverAction: false,
ownFocus: false,
showTooltip: false,
value,
})}
</>
<FilterForValueButton
Component={Component}
field={columnId}
value={value}
addToQuery={addToQuery}
/>
);
},
];

/** returns the default actions shown in `EuiDataGrid` cells */
export const getDefaultCellActions = ({ enableFilterActions }: { enableFilterActions: boolean }) =>
enableFilterActions ? [...filterCellActions, ...commonCellActions] : [...commonCellActions];
export const getDefaultCellActions = ({ addToQuery }: { addToQuery: (value: string) => void }) => [
...buildFilterCellActions(addToQuery),
...commonCellActions,
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* 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 filterForValueButtonLabel = i18n.translate(
'xpack.observability.hoverActions.filterForValueButtonLabel',
{
defaultMessage: 'Filter for value',
}
);

import { EuiButtonIcon, EuiButtonEmpty } 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={filterForValueButtonLabel}
data-test-subj="filter-for-value"
iconType="plusInCircle"
onClick={onClick}
title={filterForValueButtonLabel}
>
{filterForValueButtonLabel}
</Component>
) : (
<EuiButtonIcon
aria-label={filterForValueButtonLabel}
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 };
22 changes: 21 additions & 1 deletion x-pack/plugins/observability/public/pages/alerts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ export function AlertsPage({ routeParams }: AlertsPageProps) {
const history = useHistory();
const refetch = useRef<() => void>();
const {
query: { rangeFrom = 'now-15m', rangeTo = 'now', kuery = '', status = 'open' },
query: {
rangeFrom = 'now-15m',
rangeTo = 'now',
kuery = 'kibana.alert.status: "open"', // TODO change hardcoded values as part of another PR
status = 'open',
},
} = routeParams;

useBreadcrumbs([
Expand Down Expand Up @@ -98,6 +103,20 @@ export function AlertsPage({ routeParams }: AlertsPageProps) {
[history, rangeFrom, rangeTo, kuery]
);

const addToQuery = useCallback(
(value: string) => {
let output = value;
if (kuery !== '') {
output = `${kuery} and ${value}`;
}
onQueryChange({
dateRange: { from: rangeFrom, to: rangeTo },
query: output,
});
},
[kuery, onQueryChange, rangeFrom, rangeTo]
);

const setRefetch = useCallback((ref) => {
refetch.current = ref;
}, []);
Expand Down Expand Up @@ -170,6 +189,7 @@ export function AlertsPage({ routeParams }: AlertsPageProps) {
kuery={kuery}
status={status}
setRefetch={setRefetch}
addToQuery={addToQuery}
/>
</EuiFlexItem>
</EuiFlexGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import type {
ALERT_DURATION as ALERT_DURATION_TYPED,
ALERT_SEVERITY_LEVEL as ALERT_SEVERITY_LEVEL_TYPED,
ALERT_STATUS as ALERT_STATUS_TYPED,
ALERT_RULE_NAME as ALERT_RULE_NAME_TYPED,
ALERT_REASON as ALERT_REASON_TYPED,
} from '@kbn/rule-data-utils';
import {
ALERT_DURATION as ALERT_DURATION_NON_TYPED,
ALERT_SEVERITY_LEVEL as ALERT_SEVERITY_LEVEL_NON_TYPED,
ALERT_STATUS as ALERT_STATUS_NON_TYPED,
ALERT_RULE_NAME as ALERT_RULE_NAME_NON_TYPED,
ALERT_REASON as ALERT_REASON_NON_TYPED,
TIMESTAMP,
// @ts-expect-error importing from a place other than root because we want to limit what we import from this package
} from '@kbn/rule-data-utils/target_node/technical_field_names';
Expand All @@ -38,7 +38,7 @@ import { usePluginContext } from '../../hooks/use_plugin_context';
const ALERT_DURATION: typeof ALERT_DURATION_TYPED = ALERT_DURATION_NON_TYPED;
const ALERT_SEVERITY_LEVEL: typeof ALERT_SEVERITY_LEVEL_TYPED = ALERT_SEVERITY_LEVEL_NON_TYPED;
const ALERT_STATUS: typeof ALERT_STATUS_TYPED = ALERT_STATUS_NON_TYPED;
const ALERT_RULE_NAME: typeof ALERT_RULE_NAME_TYPED = ALERT_RULE_NAME_NON_TYPED;
const ALERT_REASON: typeof ALERT_REASON_TYPED = ALERT_REASON_NON_TYPED;

export const getMappedNonEcsValue = ({
data,
Expand Down Expand Up @@ -110,7 +110,7 @@ export const getRenderCellValue = ({
return asDuration(Number(value));
case ALERT_SEVERITY_LEVEL:
return <SeverityBadge severityLevel={value ?? undefined} />;
case ALERT_RULE_NAME:
case ALERT_REASON:
const dataFieldEs = data.reduce((acc, d) => ({ ...acc, [d.field]: d.value }), {});
const alert = parseAlert(observabilityRuleTypeRegistry)(dataFieldEs);

Expand Down