Skip to content
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

[RAC] Enable workflow status filtering #108215

Merged
merged 24 commits into from
Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b208bda
Move filter buttons to the left
Aug 11, 2021
5b1b2be
Change filter button labels and add "acknowledged" filter
Aug 11, 2021
fd9c7e0
Switch button widget
Aug 11, 2021
b4296c0
Automated removal of unused translations via scripts/i18n_check --fix
jasonrhodes Aug 12, 2021
ed182a7
Fixed broken tests
jasonrhodes Aug 12, 2021
3f69056
Fixes for workflow status change
jasonrhodes Aug 13, 2021
a1d8f22
Updated translations
jasonrhodes Aug 13, 2021
bcb8dfe
Fixes broken type
jasonrhodes Aug 13, 2021
63b9b2a
Adds default 'open' value for lifecycle helper rules
jasonrhodes Aug 13, 2021
6fd20bd
Workflow status change again
jasonrhodes Aug 13, 2021
13055ba
Workflow status type fixes
jasonrhodes Aug 13, 2021
dcc73d2
Workflow status test updates
jasonrhodes Aug 13, 2021
69a0af5
Fixes more type failures and test failures that only show up in CI
jasonrhodes Aug 13, 2021
37221a4
Merge branch 'master' into 107629-workflow-status-filters
kibanamachine Aug 13, 2021
2f6f3e3
Prevent workflow status from overwrites
Aug 17, 2021
6443a57
Merge branch 'master' into 107629-workflow-status-filters
Aug 17, 2021
69c07d2
Remove duplicate import
Aug 17, 2021
c913475
Merge branch 'master' into 107629-workflow-status-filters
Aug 18, 2021
d935414
Tweak io-ts types
Aug 18, 2021
8f9027b
Remove outdated type cast
Aug 18, 2021
df7d0eb
Restore the correct field for the status column
Aug 18, 2021
8473684
Narrow down the valid IDs for the filter options
Aug 19, 2021
98517bd
Merge branch 'master' into 107629-workflow-status-filters
Aug 19, 2021
f2b0e2d
Merge branch 'master' into 107629-workflow-status-filters
Aug 19, 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
8 changes: 6 additions & 2 deletions x-pack/plugins/observability/common/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ import * as t from 'io-ts';

export type Maybe<T> = T | null | undefined;

export const alertStatusRt = t.union([t.literal('all'), t.literal('open'), t.literal('closed')]);
export type AlertStatus = t.TypeOf<typeof alertStatusRt>;
export const alertWorkflowStatusRt = t.keyof({
open: null,
acknowledged: null,
closed: null,
});
export type AlertWorkflowStatus = t.TypeOf<typeof alertWorkflowStatusRt>;

export interface ApmIndicesConfig {
/* eslint-disable @typescript-eslint/naming-convention */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,24 @@
import {
AlertConsumers as AlertConsumersTyped,
ALERT_DURATION as ALERT_DURATION_TYPED,
ALERT_SEVERITY_LEVEL as ALERT_SEVERITY_LEVEL_TYPED,
ALERT_STATUS as ALERT_STATUS_TYPED,
ALERT_REASON as ALERT_REASON_TYPED,
ALERT_RULE_CONSUMER,
ALERT_SEVERITY_LEVEL as ALERT_SEVERITY_LEVEL_TYPED,
ALERT_STATUS as ALERT_STATUS_TYPED,
ALERT_WORKFLOW_STATUS as ALERT_WORKFLOW_STATUS_TYPED,
} from '@kbn/rule-data-utils';
// @ts-expect-error importing from a place other than root because we want to limit what we import from this package
import { AlertConsumers as AlertConsumersNonTyped } from '@kbn/rule-data-utils/target_node/alerts_as_data_rbac';
import {
ALERT_DURATION as ALERT_DURATION_NON_TYPED,
ALERT_REASON as ALERT_REASON_NON_TYPED,
ALERT_SEVERITY_LEVEL as ALERT_SEVERITY_LEVEL_NON_TYPED,
ALERT_STATUS as ALERT_STATUS_NON_TYPED,
ALERT_REASON as ALERT_REASON_NON_TYPED,
ALERT_WORKFLOW_STATUS as ALERT_WORKFLOW_STATUS_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';

// @ts-expect-error importing from a place other than root because we want to limit what we import from this package
import { AlertConsumers as AlertConsumersNonTyped } from '@kbn/rule-data-utils/target_node/alerts_as_data_rbac';

import {
EuiButtonIcon,
EuiDataGridColumn,
Expand All @@ -49,7 +50,7 @@ import type { TopAlert } from './';
import { useKibana } from '../../../../../../src/plugins/kibana_react/public';
import type {
ActionProps,
AlertStatus,
AlertWorkflowStatus,
ColumnHeaderOptions,
RowRenderer,
} from '../../../../timelines/common';
Expand All @@ -65,22 +66,23 @@ import { CoreStart } from '../../../../../../src/core/public';

const AlertConsumers: typeof AlertConsumersTyped = AlertConsumersNonTyped;
const ALERT_DURATION: typeof ALERT_DURATION_TYPED = ALERT_DURATION_NON_TYPED;
const ALERT_REASON: typeof ALERT_REASON_TYPED = ALERT_REASON_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_REASON: typeof ALERT_REASON_TYPED = ALERT_REASON_NON_TYPED;
const ALERT_WORKFLOW_STATUS: typeof ALERT_WORKFLOW_STATUS_TYPED = ALERT_WORKFLOW_STATUS_NON_TYPED;

interface AlertsTableTGridProps {
indexName: string;
rangeFrom: string;
rangeTo: string;
kuery: string;
status: string;
workflowStatus: AlertWorkflowStatus;
setRefetch: (ref: () => void) => void;
addToQuery: (value: string) => void;
}

interface ObservabilityActionsProps extends ActionProps {
currentStatus: AlertStatus;
currentStatus: AlertWorkflowStatus;
setFlyoutAlert: React.Dispatch<React.SetStateAction<TopAlert | undefined>>;
}

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

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

const [flyoutAlert, setFlyoutAlert] = useState<TopAlert | undefined>(undefined);
Expand All @@ -324,14 +326,14 @@ export function AlertsTableTGrid(props: AlertsTableTGridProps) {
return (
<ObservabilityActions
{...actionProps}
currentStatus={status as AlertStatus}
currentStatus={workflowStatus}
setFlyoutAlert={setFlyoutAlert}
/>
);
},
},
];
}, [status]);
}, [workflowStatus]);

const tGridProps = useMemo(() => {
const type: TGridType = 'standalone';
Expand All @@ -356,7 +358,7 @@ export function AlertsTableTGrid(props: AlertsTableTGridProps) {
defaultMessage: 'alerts',
}),
query: {
query: `${ALERT_STATUS}: ${status}${kuery !== '' ? ` and ${kuery}` : ''}`,
query: `${ALERT_WORKFLOW_STATUS}: ${workflowStatus}${kuery !== '' ? ` and ${kuery}` : ''}`,
language: 'kuery',
},
renderCellValue: getRenderCellValue({ rangeFrom, rangeTo, setFlyoutAlert }),
Expand All @@ -370,7 +372,7 @@ export function AlertsTableTGrid(props: AlertsTableTGridProps) {
sortDirection,
},
],
filterStatus: status as AlertStatus,
filterStatus: workflowStatus as AlertWorkflowStatus,
afgomez marked this conversation as resolved.
Show resolved Hide resolved
leadingControlColumns,
trailingControlColumns,
unit: (totalAlerts: number) =>
Expand All @@ -387,7 +389,7 @@ export function AlertsTableTGrid(props: AlertsTableTGridProps) {
rangeFrom,
rangeTo,
setRefetch,
status,
workflowStatus,
addToQuery,
]);
const handleFlyoutClose = () => setFlyoutAlert(undefined);
Expand Down
50 changes: 24 additions & 26 deletions x-pack/plugins/observability/public/pages/alerts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import { i18n } from '@kbn/i18n';
import React, { useCallback, useMemo, useRef } from 'react';
import { useHistory } from 'react-router-dom';
import { ParsedTechnicalFields } from '../../../../rule_registry/common/parse_technical_fields';
import type { AlertStatus } from '../../../common/typings';
import type { AlertWorkflowStatus } from '../../../common/typings';
import { ExperimentalBadge } from '../../components/shared/experimental_badge';
import { useBreadcrumbs } from '../../hooks/use_breadcrumbs';
import { useFetcher } from '../../hooks/use_fetcher';
import { usePluginContext } from '../../hooks/use_plugin_context';
import { RouteParams } from '../../routes';
import { callObservabilityApi } from '../../services/call_observability_api';
import { AlertsSearchBar } from './alerts_search_bar';
import { AlertsTableTGrid } from './alerts_table_t_grid';
import { StatusFilter } from './status_filter';
import { useFetcher } from '../../hooks/use_fetcher';
import { callObservabilityApi } from '../../services/call_observability_api';
import { WorkflowStatusFilter } from './workflow_status_filter';
import './styles.scss';

export interface TopAlert {
Expand All @@ -44,7 +44,7 @@ export function AlertsPage({ routeParams }: AlertsPageProps) {
rangeFrom = 'now-15m',
rangeTo = 'now',
kuery = 'kibana.alert.status: "open"', // TODO change hardcoded values as part of another PR
status = 'open',
workflowStatus = 'open',
},
} = routeParams;

Expand Down Expand Up @@ -72,10 +72,10 @@ export function AlertsPage({ routeParams }: AlertsPageProps) {
[dynamicIndexPatternResp]
);

const setStatusFilter = useCallback(
(value: AlertStatus) => {
const setWorkflowStatusFilter = useCallback(
(value: AlertWorkflowStatus) => {
const nextSearchParams = new URLSearchParams(history.location.search);
nextSearchParams.set('status', value);
nextSearchParams.set('workflowStatus', value);
history.push({
...history.location,
search: nextSearchParams.toString(),
Expand Down Expand Up @@ -172,28 +172,26 @@ export function AlertsPage({ routeParams }: AlertsPageProps) {
onQueryChange={onQueryChange}
/>
</EuiFlexItem>

<EuiFlexItem>
<EuiFlexGroup direction="column">
<EuiFlexItem>
<EuiFlexGroup justifyContent="flexStart">
<EuiFlexItem grow={false}>
<StatusFilter status={status} onChange={setStatusFilter} />
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlexItem>
<EuiFlexItem>
<AlertsTableTGrid
indexName={dynamicIndexPattern.length > 0 ? dynamicIndexPattern[0].title : ''}
rangeFrom={rangeFrom}
rangeTo={rangeTo}
kuery={kuery}
status={status}
setRefetch={setRefetch}
addToQuery={addToQuery}
/>
<EuiFlexGroup justifyContent="spaceBetween" alignItems="center">
<EuiFlexItem grow={false}>
<WorkflowStatusFilter status={workflowStatus} onChange={setWorkflowStatusFilter} />
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlexItem>

<EuiFlexItem>
<AlertsTableTGrid
indexName={dynamicIndexPattern.length > 0 ? dynamicIndexPattern[0].title : ''}
rangeFrom={rangeFrom}
rangeTo={rangeTo}
kuery={kuery}
workflowStatus={workflowStatus}
setRefetch={setRefetch}
addToQuery={addToQuery}
/>
</EuiFlexItem>
</EuiFlexGroup>
</ObservabilityPageTemplate>
);
Expand Down
56 changes: 0 additions & 56 deletions x-pack/plugins/observability/public/pages/alerts/status_filter.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@
*/

import React, { ComponentProps, useState } from 'react';
import type { AlertStatus } from '../../../common/typings';
import { StatusFilter } from './status_filter';
import type { AlertWorkflowStatus } from '../../../common/typings';
import { WorkflowStatusFilter } from './workflow_status_filter';

type Args = ComponentProps<typeof StatusFilter>;
type Args = ComponentProps<typeof WorkflowStatusFilter>;

export default {
title: 'app/Alerts/StatusFilter',
component: StatusFilter,
component: WorkflowStatusFilter,
argTypes: {
onChange: { action: 'change' },
},
};

export function Example({ onChange }: Args) {
const [status, setStatus] = useState<AlertStatus>('open');
const [status, setStatus] = useState<AlertWorkflowStatus>('open');

return (
<StatusFilter
<WorkflowStatusFilter
status={status}
onChange={(value) => {
setStatus(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@

import { render } from '@testing-library/react';
import React from 'react';
import type { AlertStatus } from '../../../common/typings';
import { StatusFilter } from './status_filter';
import type { AlertWorkflowStatus } from '../../../common/typings';
import { WorkflowStatusFilter } from './workflow_status_filter';

describe('StatusFilter', () => {
describe('render', () => {
it('renders', () => {
const onChange = jest.fn();
const status: AlertStatus = 'all';
const status: AlertWorkflowStatus = 'open';
const props = { onChange, status };

expect(() => render(<StatusFilter {...props} />)).not.toThrowError();
expect(() => render(<WorkflowStatusFilter {...props} />)).not.toThrowError();
});

(['all', 'open', 'closed'] as AlertStatus[]).map((status) => {
(['open', 'acknowledged', 'closed'] as AlertWorkflowStatus[]).map((status) => {
describe(`when clicking the ${status} button`, () => {
it('calls the onChange callback with "${status}"', () => {
const onChange = jest.fn();
const props = { onChange, status };

const { getByTestId } = render(<StatusFilter {...props} />);
const button = getByTestId(`StatusFilter ${status} button`);
const { getByTestId } = render(<WorkflowStatusFilter {...props} />);
const button = getByTestId(`WorkflowStatusFilter ${status} button`);

button.click();

Expand Down
Loading