Skip to content

Commit

Permalink
[Discover][Alerting] Implement editing of dataView, query & filters (e…
Browse files Browse the repository at this point in the history
…lastic#131688)

* [Discover] introduce params editing using unified search

* [Discover] fix unit tests

* [Discover] fix functional tests

* [Discover] fix unit tests

* [Discover] return test subject name

* [Discover] fix alert functional test

* Update x-pack/plugins/stack_alerts/public/alert_types/es_query/expression/search_source_expression_form.tsx

Co-authored-by: Julia Rechkunova <[email protected]>

* Update x-pack/plugins/stack_alerts/public/alert_types/es_query/expression/search_source_expression_form.tsx

Co-authored-by: Matthias Wilhelm <[email protected]>

* [Discover] hide filter panel options

* [Discover] improve functional test

* [Discover] apply suggestions

* [Discover] change data view selector

* [Discover] fix tests

* [Discover] apply suggestions, fix lang mode toggler

* [Discover] mote interface to types file, clean up diff

* [Discover] fix saved query issue

* Update x-pack/plugins/stack_alerts/server/alert_types/es_query/alert_type.ts

Co-authored-by: Matthias Wilhelm <[email protected]>

* [Discover] remove zIndex

* [Discover] omit null searchType from esQuery completely, add isEsQueryAlert check for useSavedObjectReferences hook

* [Discover] set searchType to esQuery when needed

* [Discover] fix unit tests

* Update x-pack/plugins/stack_alerts/server/alert_types/es_query/alert_type_params.ts

Co-authored-by: Matthias Wilhelm <[email protected]>

* Update x-pack/plugins/stack_alerts/server/alert_types/es_query/alert_type.ts

Co-authored-by: Matthias Wilhelm <[email protected]>

Co-authored-by: Julia Rechkunova <[email protected]>
Co-authored-by: Matthias Wilhelm <[email protected]>
  • Loading branch information
3 people authored May 20, 2022
1 parent d344088 commit bc31053
Show file tree
Hide file tree
Showing 34 changed files with 799 additions and 415 deletions.
1 change: 1 addition & 0 deletions src/plugins/data/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const createStartContract = (): Start => {
}),
get: jest.fn().mockReturnValue(Promise.resolve({})),
clearCache: jest.fn(),
getIdsWithTitle: jest.fn(),
} as unknown as DataViewsContract;

return {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/public/query/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const createStartContractMock = () => {
addToQueryLog: jest.fn(),
filterManager: createFilterManagerMock(),
queryString: queryStringManagerMock.createStartContract(),
savedQueries: jest.fn() as any,
savedQueries: { getSavedQuery: jest.fn() } as any,
state$: new Observable(),
getState: jest.fn(),
timefilter: timefilterServiceMock.createStartContract(),
Expand Down
1 change: 1 addition & 0 deletions src/plugins/data_views/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const createStartContract = (): Start => {
get: jest.fn().mockReturnValue(Promise.resolve({})),
clearCache: jest.fn(),
getCanSaveSync: jest.fn(),
getIdsWithTitle: jest.fn(),
} as unknown as jest.Mocked<DataViewsContract>;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export const getTopNavLinks = ({
anchorElement,
searchSource: savedSearch.searchSource,
services,
savedQueryId: state.appStateContainer.getState().savedQuery,
});
},
testId: 'discoverAlertsButton',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@ interface AlertsPopoverProps {
onClose: () => void;
anchorElement: HTMLElement;
searchSource: ISearchSource;
savedQueryId?: string;
}

export function AlertsPopover({ searchSource, anchorElement, onClose }: AlertsPopoverProps) {
export function AlertsPopover({
searchSource,
anchorElement,
savedQueryId,
onClose,
}: AlertsPopoverProps) {
const dataView = searchSource.getField('index')!;
const services = useDiscoverServices();
const { triggersActionsUi } = services;
Expand All @@ -49,8 +55,9 @@ export function AlertsPopover({ searchSource, anchorElement, onClose }: AlertsPo
return {
searchType: 'searchSource',
searchConfiguration: nextSearchSource.getSerializedFields(),
savedQueryId,
};
}, [searchSource, services]);
}, [savedQueryId, searchSource, services]);

const SearchThresholdAlertFlyout = useMemo(() => {
if (!alertFlyoutVisible) {
Expand Down Expand Up @@ -156,11 +163,13 @@ export function openAlertsPopover({
anchorElement,
searchSource,
services,
savedQueryId,
}: {
I18nContext: I18nStart['Context'];
anchorElement: HTMLElement;
searchSource: ISearchSource;
services: DiscoverServices;
savedQueryId?: string;
}) {
if (isOpen) {
closeAlertsPopover();
Expand All @@ -177,6 +186,7 @@ export function openAlertsPopover({
onClose={closeAlertsPopover}
anchorElement={anchorElement}
searchSource={searchSource}
savedQueryId={savedQueryId}
/>
</KibanaContextProvider>
</I18nContext>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export interface FilterItemProps {
uiSettings: IUiSettingsClient;
hiddenPanelOptions?: FilterPanelOption[];
timeRangeForSuggestionsOverride?: boolean;
readonly?: boolean;
}

type FilterPopoverProps = HTMLAttributes<HTMLDivElement> & EuiPopoverProps;
Expand Down Expand Up @@ -364,7 +363,6 @@ export function FilterItem(props: FilterItemProps) {
iconOnClick: handleIconClick,
onClick: handleBadgeClick,
'data-test-subj': getDataTestSubj(valueLabelConfig),
readonly: props.readonly,
};

const popoverProps: FilterPopoverProps = {
Expand All @@ -379,18 +377,6 @@ export function FilterItem(props: FilterItemProps) {
panelPaddingSize: 'none',
};

if (props.readonly) {
return (
<EuiPopover
panelClassName="globalFilterItem__readonlyPanel"
anchorPosition="upCenter"
{...popoverProps}
>
<FilterView {...filterViewProps} hideAlias />
</EuiPopover>
);
}

return (
<EuiPopover anchorPosition="downLeft" {...popoverProps}>
{renderedComponent === 'menu' ? (
Expand Down
62 changes: 22 additions & 40 deletions src/plugins/unified_search/public/filter_bar/filter_view/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ interface Props {
fieldLabel?: string;
filterLabelStatus: FilterLabelStatus;
errorMessage?: string;
readonly?: boolean;
hideAlias?: boolean;
[propName: string]: any;
}
Expand All @@ -32,7 +31,6 @@ export const FilterView: FC<Props> = ({
fieldLabel,
errorMessage,
filterLabelStatus,
readonly,
hideAlias,
...rest
}: Props) => {
Expand All @@ -56,45 +54,29 @@ export const FilterView: FC<Props> = ({
})} ${title}`;
}

const badgeProps: EuiBadgeProps = readonly
? {
title,
color: 'hollow',
onClick,
onClickAriaLabel: i18n.translate(
'unifiedSearch.filter.filterBar.filterItemReadOnlyBadgeAriaLabel',
{
defaultMessage: 'Filter entry',
}
),
iconOnClick,
const badgeProps: EuiBadgeProps = {
title,
color: 'hollow',
iconType: 'cross',
iconSide: 'right',
closeButtonProps: {
// Removing tab focus on close button because the same option can be obtained through the context menu
// Also, we may want to add a `DEL` keyboard press functionality
tabIndex: -1,
},
iconOnClick,
iconOnClickAriaLabel: i18n.translate(
'unifiedSearch.filter.filterBar.filterItemBadgeIconAriaLabel',
{
defaultMessage: 'Delete {filter}',
values: { filter: innerText },
}
: {
title,
color: 'hollow',
iconType: 'cross',
iconSide: 'right',
closeButtonProps: {
// Removing tab focus on close button because the same option can be obtained through the context menu
// Also, we may want to add a `DEL` keyboard press functionality
tabIndex: -1,
},
iconOnClick,
iconOnClickAriaLabel: i18n.translate(
'unifiedSearch.filter.filterBar.filterItemBadgeIconAriaLabel',
{
defaultMessage: 'Delete {filter}',
values: { filter: innerText },
}
),
onClick,
onClickAriaLabel: i18n.translate(
'unifiedSearch.filter.filterBar.filterItemBadgeAriaLabel',
{
defaultMessage: 'Filter actions',
}
),
};
),
onClick,
onClickAriaLabel: i18n.translate('unifiedSearch.filter.filterBar.filterItemBadgeAriaLabel', {
defaultMessage: 'Filter actions',
}),
};

return (
<EuiBadge {...badgeProps} {...rest}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { shallowEqual } from '../utils/shallow_equal';
import { AddFilterPopover } from './add_filter_popover';
import { DataViewPicker, DataViewPickerProps } from '../dataview_picker';
import { FilterButtonGroup } from '../filter_bar/filter_button_group/filter_button_group';
import type { SuggestionsListSize } from '../typeahead/suggestions_component';
import './query_bar.scss';

const SuperDatePicker = React.memo(
Expand Down Expand Up @@ -88,6 +89,7 @@ export interface QueryBarTopRowProps {
filterBar?: React.ReactNode;
showDatePickerAsBadge?: boolean;
showSubmitButton?: boolean;
suggestionsSize?: SuggestionsListSize;
isScreenshotMode?: boolean;
}

Expand Down Expand Up @@ -483,6 +485,7 @@ export const QueryBarTopRow = React.memo(
timeRangeForSuggestionsOverride={props.timeRangeForSuggestionsOverride}
disableLanguageSwitcher={true}
prepend={renderFilterMenuOnly() && renderFilterButtonGroup()}
size={props.suggestionsSize}
/>
</EuiFlexItem>
)}
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/unified_search/public/search_bar/search_bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { QueryBarMenu, QueryBarMenuProps } from '../query_string_input/query_bar
import type { DataViewPickerProps } from '../dataview_picker';
import QueryBarTopRow from '../query_string_input/query_bar_top_row';
import { FilterBar, FilterItems } from '../filter_bar';
import type { SuggestionsListSize } from '../typeahead/suggestions_component';
import { searchBarStyles } from './search_bar.styles';

export interface SearchBarInjectedDeps {
Expand Down Expand Up @@ -88,6 +89,8 @@ export interface SearchBarOwnProps {
fillSubmitButton?: boolean;
dataViewPickerComponentProps?: DataViewPickerProps;
showSubmitButton?: boolean;
// defines size of suggestions query popover
suggestionsSize?: SuggestionsListSize;
isScreenshotMode?: boolean;
}

Expand Down Expand Up @@ -485,6 +488,7 @@ class SearchBarUI extends Component<SearchBarProps & WithEuiThemeProps, State> {
dataViewPickerComponentProps={this.props.dataViewPickerComponentProps}
showDatePickerAsBadge={this.shouldShowDatePickerAsBadge()}
filterBar={filterBar}
suggestionsSize={this.props.suggestionsSize}
isScreenshotMode={this.props.isScreenshotMode}
/>
</div>
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/stack_alerts/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"triggersActionsUi",
"kibanaReact",
"savedObjects",
"data"
"data",
"kibanaUtils"
],
"configPath": ["xpack", "stack_alerts"],
"requiredBundles": ["esUiShared"],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* 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 from 'react';
import { mountWithIntl, nextTick } from '@kbn/test-jest-helpers';
import { DataViewSelectPopover } from './data_view_select_popover';
import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
import { dataViewPluginMocks } from '@kbn/data-views-plugin/public/mocks';
import { act } from 'react-dom/test-utils';

const props = {
onSelectDataView: () => {},
initialDataViewTitle: 'kibana_sample_data_logs',
initialDataViewId: 'mock-data-logs-id',
};

const dataViewOptions = [
{
id: 'mock-data-logs-id',
namespaces: ['default'],
title: 'kibana_sample_data_logs',
},
{
id: 'mock-flyghts-id',
namespaces: ['default'],
title: 'kibana_sample_data_flights',
},
{
id: 'mock-ecommerce-id',
namespaces: ['default'],
title: 'kibana_sample_data_ecommerce',
typeMeta: {},
},
{
id: 'mock-test-id',
namespaces: ['default'],
title: 'test',
typeMeta: {},
},
];

const mount = () => {
const dataViewsMock = dataViewPluginMocks.createStartContract();
dataViewsMock.getIdsWithTitle.mockImplementation(() => Promise.resolve(dataViewOptions));

return {
wrapper: mountWithIntl(
<KibanaContextProvider services={{ data: { dataViews: dataViewsMock } }}>
<DataViewSelectPopover {...props} />
</KibanaContextProvider>
),
dataViewsMock,
};
};

describe('DataViewSelectPopover', () => {
test('renders properly', async () => {
const { wrapper, dataViewsMock } = mount();

await act(async () => {
await nextTick();
wrapper.update();
});

expect(dataViewsMock.getIdsWithTitle).toHaveBeenCalled();
expect(wrapper.find('[data-test-subj="selectDataViewExpression"]').exists()).toBeTruthy();

const getIdsWithTitleResult = await dataViewsMock.getIdsWithTitle.mock.results[0].value;
expect(getIdsWithTitleResult).toBe(dataViewOptions);
});
});
Loading

0 comments on commit bc31053

Please sign in to comment.