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

[Discover][Alerting] Implement editing of dataView, query & filters #131688

Merged
merged 28 commits into from
May 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
27815b1
[Discover] introduce params editing using unified search
dimaanj May 6, 2022
4ea804d
Merge branch 'main' into introduce-alert-params-editing
kibanamachine May 6, 2022
a24986f
[Discover] fix unit tests
dimaanj May 10, 2022
6dc6d0d
[Discover] fix functional tests
dimaanj May 10, 2022
13a6b2f
Merge branch 'main' of https://github.com/elastic/kibana into introdu…
dimaanj May 10, 2022
ffa8223
[Discover] fix unit tests
dimaanj May 10, 2022
96bdee0
[Discover] return test subject name
dimaanj May 10, 2022
5c47d08
Merge branch 'main' into introduce-alert-params-editing
kibanamachine May 10, 2022
79ee6c0
[Discover] fix alert functional test
dimaanj May 11, 2022
016bcca
Update x-pack/plugins/stack_alerts/public/alert_types/es_query/expres…
dimaanj May 11, 2022
8f3a757
Update x-pack/plugins/stack_alerts/public/alert_types/es_query/expres…
dimaanj May 11, 2022
787c93b
Merge branch 'main' of https://github.com/elastic/kibana into introdu…
dimaanj May 15, 2022
9d94e88
[Discover] hide filter panel options
dimaanj May 16, 2022
24ac72e
[Discover] improve functional test
dimaanj May 16, 2022
544b7f7
[Discover] apply suggestions
dimaanj May 17, 2022
6327df9
[Discover] change data view selector
dimaanj May 17, 2022
3806fc5
[Discover] fix tests
dimaanj May 17, 2022
7716341
[Discover] apply suggestions, fix lang mode toggler
dimaanj May 18, 2022
f3880f8
[Discover] mote interface to types file, clean up diff
dimaanj May 18, 2022
68f8f50
Merge branch 'main' into introduce-alert-params-editing
kibanamachine May 18, 2022
ee9da9e
[Discover] fix saved query issue
dimaanj May 18, 2022
199ab96
Update x-pack/plugins/stack_alerts/server/alert_types/es_query/alert_…
dimaanj May 19, 2022
17687d3
[Discover] remove zIndex
dimaanj May 19, 2022
84820c5
[Discover] omit null searchType from esQuery completely, add isEsQuer…
dimaanj May 19, 2022
d3de199
[Discover] set searchType to esQuery when needed
dimaanj May 19, 2022
8f14292
[Discover] fix unit tests
dimaanj May 19, 2022
5d6d227
Update x-pack/plugins/stack_alerts/server/alert_types/es_query/alert_…
dimaanj May 20, 2022
7ee6dab
Update x-pack/plugins/stack_alerts/server/alert_types/es_query/alert_…
dimaanj May 20, 2022
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
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 @@ -31,7 +31,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(),
timefilter: timefilterServiceMock.createStartContract(),
getEsQuery: jest.fn(),
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) {
kertal marked this conversation as resolved.
Show resolved Hide resolved
return (
<EuiPopover
panelClassName="globalFilterItem__readonlyPanel"
anchorPosition="upCenter"
{...popoverProps}
>
<FilterView {...filterViewProps} hideAlias />
</EuiPopover>
);
}

return (
<EuiPopover anchorPosition="downLeft" {...popoverProps}>
{renderedComponent === 'menu' ? (
Expand Down
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 @@ -469,6 +471,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 @@ -478,6 +481,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"
kertal marked this conversation as resolved.
Show resolved Hide resolved
],
"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