mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
[Discover] Handle no data views state for esQuery
alert (#145052)
## Summary Fixes #145020 This PR adjusts typing for search source alert to handle no data views state in flyout. ### Checklist - [X] [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 Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
ca49da1470
commit
32cf768f05
4 changed files with 42 additions and 17 deletions
|
@ -26,7 +26,7 @@ import { useTriggerUiActionServices } from '../es_query/util';
|
|||
import { EsQueryRuleMetaData } from '../es_query/types';
|
||||
|
||||
export interface DataViewSelectPopoverProps {
|
||||
dataView: DataView;
|
||||
dataView?: DataView;
|
||||
metadata?: EsQueryRuleMetaData;
|
||||
onSelectDataView: (selectedDataView: DataView) => void;
|
||||
onChangeMetaData: (metadata: EsQueryRuleMetaData) => void;
|
||||
|
@ -150,7 +150,7 @@ export const DataViewSelectPopover: React.FunctionComponent<DataViewSelectPopove
|
|||
defaultMessage: 'data view',
|
||||
})}
|
||||
value={
|
||||
dataView.getName() ??
|
||||
dataView?.getName() ??
|
||||
i18n.translate('xpack.stackAlerts.components.ui.alertParams.dataViewPlaceholder', {
|
||||
defaultMessage: 'Select a data view',
|
||||
})
|
||||
|
@ -159,7 +159,7 @@ export const DataViewSelectPopover: React.FunctionComponent<DataViewSelectPopove
|
|||
onClick={() => {
|
||||
setDataViewPopoverOpen(true);
|
||||
}}
|
||||
isInvalid={!dataView.id}
|
||||
isInvalid={!dataView?.id}
|
||||
/>
|
||||
}
|
||||
isOpen={dataViewPopoverOpen}
|
||||
|
@ -191,7 +191,7 @@ export const DataViewSelectPopover: React.FunctionComponent<DataViewSelectPopove
|
|||
</EuiFlexGroup>
|
||||
</EuiPopoverTitle>
|
||||
<DataViewSelector
|
||||
currentDataViewId={dataView.id}
|
||||
currentDataViewId={dataView?.id}
|
||||
dataViewsList={allDataViewItems}
|
||||
setPopoverIsOpen={setDataViewPopoverOpen}
|
||||
onChangeDataView={onChangeDataView}
|
||||
|
|
|
@ -79,7 +79,7 @@ export const SearchSourceExpression = ({
|
|||
|
||||
data.search.searchSource
|
||||
.create(initialSearchConfiguration)
|
||||
.then((fetchedSearchSource) => setSearchSource(fetchedSearchSource))
|
||||
.then(setSearchSource)
|
||||
.catch(setParamsError);
|
||||
};
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ const HIDDEN_FILTER_PANEL_OPTIONS: SearchBarProps['hiddenFilterPanelOptions'] =
|
|||
];
|
||||
|
||||
interface LocalState {
|
||||
index: DataView;
|
||||
index?: DataView;
|
||||
filter: Filter[];
|
||||
query: Query;
|
||||
thresholdComparator: CommonRuleParams['thresholdComparator'];
|
||||
|
@ -100,7 +100,7 @@ export const SearchSourceExpressionForm = (props: SearchSourceExpressionFormProp
|
|||
return { ...currentState, [action.type]: action.payload };
|
||||
},
|
||||
{
|
||||
index: searchSource.getField('index')!,
|
||||
index: searchSource.getField('index'),
|
||||
query: searchSource.getField('query')! as Query,
|
||||
filter: mapAndFlattenFilters(searchSource.getField('filter') as Filter[]),
|
||||
threshold: ruleParams.threshold ?? DEFAULT_VALUES.THRESHOLD,
|
||||
|
|
|
@ -151,9 +151,6 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
|
|||
supertest.delete(`/api/actions/connector/${id}`).set('kbn-xsrf', 'foo').expect(204, '');
|
||||
|
||||
const defineSearchSourceAlert = async (alertName: string) => {
|
||||
await testSubjects.click('discoverAlertsButton');
|
||||
await testSubjects.click('discoverCreateAlertButton');
|
||||
|
||||
await retry.waitFor('rule name value is correct', async () => {
|
||||
await testSubjects.setValue('ruleNameInput', alertName);
|
||||
const ruleName = await testSubjects.getAttribute('ruleNameInput', 'value');
|
||||
|
@ -175,6 +172,24 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
|
|||
await testSubjects.click('saveRuleButton');
|
||||
};
|
||||
|
||||
const openDiscoverAlertFlyout = async () => {
|
||||
await testSubjects.click('discoverAlertsButton');
|
||||
await testSubjects.click('discoverCreateAlertButton');
|
||||
};
|
||||
|
||||
const openManagementAlertFlyout = async () => {
|
||||
await PageObjects.common.navigateToApp('management');
|
||||
await PageObjects.header.waitUntilLoadingHasFinished();
|
||||
await testSubjects.click('triggersActions');
|
||||
await PageObjects.header.waitUntilLoadingHasFinished();
|
||||
await testSubjects.click('createFirstRuleButton');
|
||||
await PageObjects.header.waitUntilLoadingHasFinished();
|
||||
await testSubjects.click('.es-query-SelectOption');
|
||||
await PageObjects.header.waitUntilLoadingHasFinished();
|
||||
await testSubjects.click('queryFormType_searchSource');
|
||||
await PageObjects.header.waitUntilLoadingHasFinished();
|
||||
};
|
||||
|
||||
const getResultsLink = async () => {
|
||||
// getting the link
|
||||
await dataGrid.clickRowToggle();
|
||||
|
@ -237,15 +252,8 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
|
|||
log.debug('create output index');
|
||||
await createOutputDataIndex();
|
||||
|
||||
log.debug('create data views');
|
||||
const sourceDataViewResponse = await createDataView(SOURCE_DATA_INDEX);
|
||||
const outputDataViewResponse = await createDataView(OUTPUT_DATA_INDEX);
|
||||
|
||||
log.debug('create connector');
|
||||
connectorId = await createConnector();
|
||||
|
||||
sourceDataViewId = sourceDataViewResponse.body.data_view.id;
|
||||
outputDataViewId = outputDataViewResponse.body.data_view.id;
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
|
@ -257,6 +265,21 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
|
|||
await security.testUser.restoreDefaults();
|
||||
});
|
||||
|
||||
it('should create an alert when there is no data view', async () => {
|
||||
await openManagementAlertFlyout();
|
||||
|
||||
// should not have data view selected by default
|
||||
const dataViewSelector = await testSubjects.find('selectDataViewExpression');
|
||||
expect(await dataViewSelector.getVisibleText()).to.eql('DATA VIEW\nSelect a data view');
|
||||
|
||||
log.debug('create data views');
|
||||
const sourceDataViewResponse = await createDataView(SOURCE_DATA_INDEX);
|
||||
const outputDataViewResponse = await createDataView(OUTPUT_DATA_INDEX);
|
||||
|
||||
sourceDataViewId = sourceDataViewResponse.body.data_view.id;
|
||||
outputDataViewId = outputDataViewResponse.body.data_view.id;
|
||||
});
|
||||
|
||||
it('should navigate to alert results via view in app link', async () => {
|
||||
await PageObjects.common.navigateToApp('discover');
|
||||
await PageObjects.discover.waitUntilSearchingHasFinished();
|
||||
|
@ -264,6 +287,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
|
|||
await PageObjects.timePicker.setCommonlyUsedTime('Last_15 minutes');
|
||||
|
||||
// create an alert
|
||||
await openDiscoverAlertFlyout();
|
||||
await defineSearchSourceAlert(RULE_NAME);
|
||||
await PageObjects.header.waitUntilLoadingHasFinished();
|
||||
|
||||
|
@ -377,6 +401,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
|
|||
await PageObjects.discover.addRuntimeField('runtime-message-field', `emit('mock-message')`);
|
||||
|
||||
// create an alert
|
||||
await openDiscoverAlertFlyout();
|
||||
await defineSearchSourceAlert('test-adhoc-alert');
|
||||
await PageObjects.header.waitUntilLoadingHasFinished();
|
||||
sourceAdHocDataViewId = await PageObjects.discover.getCurrentDataViewId();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue