Enable custom time ranges for saved searches (#99180)

* Enable custom time ranges for saved searches

* Add functional test

* Fix Typing

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Tim Roes 2021-05-05 16:35:39 +02:00 committed by GitHub
parent 656206cd2d
commit 792845fd75
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 60 additions and 10 deletions

View file

@ -96,6 +96,12 @@ export function DataGridProvider({ getService, getPageObjects }: FtrProviderCont
})`
);
}
public async getDocCount(): Promise<number> {
const grid = await find.byCssSelector('[data-document-number]');
return Number(await grid.getAttribute('data-document-number'));
}
public async getFields() {
const cells = await find.allByCssSelector('.euiDataGridRowCell');

View file

@ -14,7 +14,6 @@ import { CustomizeTimeRangeModal } from './customize_time_range_modal';
import { OpenModal, CommonlyUsedRange } from './types';
export const CUSTOM_TIME_RANGE = 'CUSTOM_TIME_RANGE';
const SEARCH_EMBEDDABLE_TYPE = 'search';
export interface TimeRangeInput extends EmbeddableInput {
timeRange: TimeRange;
@ -79,15 +78,7 @@ export class CustomTimeRangeAction implements Action<TimeRangeActionContext> {
const isMarkdown =
isVisualizeEmbeddable(embeddable) &&
(embeddable as VisualizeEmbeddable).getOutput().visTypeName === 'markdown';
return Boolean(
embeddable &&
hasTimeRange(embeddable) &&
// Saved searches don't listen to the time range from the container that is passed down to them so it
// won't work without a fix. For now, just leave them out.
embeddable.type !== SEARCH_EMBEDDABLE_TYPE &&
!isInputControl &&
!isMarkdown
);
return Boolean(embeddable && hasTimeRange(embeddable) && !isInputControl && !isMarkdown);
}
public async execute({ embeddable }: TimeRangeActionContext) {

View file

@ -16,6 +16,7 @@ export default function ({ loadTestFile }: FtrProviderContext) {
loadTestFile(require.resolve('./async_scripted_fields'));
loadTestFile(require.resolve('./reporting'));
loadTestFile(require.resolve('./error_handling'));
loadTestFile(require.resolve('./saved_searches'));
loadTestFile(require.resolve('./visualize_field'));
loadTestFile(require.resolve('./value_suggestions'));
});

View file

@ -0,0 +1,52 @@
/*
* 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 expect from '@kbn/expect';
import { FtrProviderContext } from '../../ftr_provider_context';
export default function ({ getService, getPageObjects }: FtrProviderContext) {
const esArchiver = getService('esArchiver');
const kibanaServer = getService('kibanaServer');
const PageObjects = getPageObjects(['common', 'header', 'discover', 'timePicker', 'dashboard']);
const dashboardAddPanel = getService('dashboardAddPanel');
const dataGrid = getService('dataGrid');
const panelActions = getService('dashboardPanelActions');
const panelActionsTimeRange = getService('dashboardPanelTimeRange');
describe('Discover Saved Searches', () => {
before('initialize tests', async () => {
await esArchiver.load('reporting/ecommerce');
await esArchiver.load('reporting/ecommerce_kibana');
await kibanaServer.uiSettings.update({ 'doc_table:legacy': false });
});
after('clean up archives', async () => {
await esArchiver.unload('reporting/ecommerce');
await esArchiver.unload('reporting/ecommerce_kibana');
await kibanaServer.uiSettings.unset('doc_table:legacy');
});
describe('Customize time range', () => {
it('should be possible to customize time range for saved searches on dashboards', async () => {
await PageObjects.common.navigateToApp('dashboard');
await PageObjects.dashboard.clickNewDashboard();
const fromTime = 'Apr 27, 2019 @ 23:56:51.374';
const toTime = 'Aug 23, 2019 @ 16:18:51.821';
await PageObjects.timePicker.setAbsoluteRange(fromTime, toTime);
await dashboardAddPanel.clickOpenAddPanel();
await dashboardAddPanel.addSavedSearch('Ecommerce Data');
expect(await dataGrid.getDocCount()).to.be(500);
await panelActions.openContextMenuMorePanel();
await panelActionsTimeRange.clickTimeRangeActionInContextMenu();
await panelActionsTimeRange.clickToggleQuickMenuButton();
await panelActionsTimeRange.clickCommonlyUsedTimeRange('Last_90 days');
await panelActionsTimeRange.clickModalPrimaryButton();
await PageObjects.header.waitUntilLoadingHasFinished();
expect(await dataGrid.hasNoResults()).to.be(true);
});
});
});
}