[discover] Enable data view editing from flyout (#149453)

## Summary

Currently, changes to a data view require a round trip to management
when you're in discover. This PR allows editing of data views via flyout
from within discover.

Closes https://github.com/elastic/kibana/issues/144801


### Checklist

Delete any items that are not applicable to this PR.

- [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: Matthias Wilhelm <ankertal@gmail.com>
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Matthew Kime 2023-01-30 08:42:58 -06:00 committed by GitHub
parent 3d3a885ad7
commit a64027deed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 131 additions and 6 deletions

View file

@ -185,6 +185,16 @@ export const DiscoverTopNav = ({
]
);
const onEditDataView = async (editedDataView: DataView) => {
if (!editedDataView.isPersisted()) {
await updateAdHocDataViewId(editedDataView);
} else {
stateContainer.actions.setDataView(editedDataView);
}
stateContainer.actions.loadDataViewList();
stateContainer.dataState.fetch();
};
const updateSavedQueryId = (newSavedQueryId: string | undefined) => {
const { appState, setAppState } = stateContainer;
if (newSavedQueryId) {
@ -220,6 +230,7 @@ export const DiscoverTopNav = ({
textBasedLanguages: supportedTextBasedLanguages as DataViewPickerProps['textBasedLanguages'],
adHocDataViews,
savedDataViews,
onEditDataView,
};
const onTextBasedSavedAndExit = useCallback(

View file

@ -0,0 +1,89 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
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 security = getService('security');
const es = getService('es');
const retry = getService('retry');
const PageObjects = getPageObjects([
'common',
'unifiedSearch',
'discover',
'timePicker',
'dashboard',
]);
describe('data view flyout', function () {
before(async () => {
await security.testUser.setRoles(['kibana_admin', 'test_logstash_reader']);
await kibanaServer.importExport.load('test/functional/fixtures/kbn_archiver/discover.json');
await esArchiver.loadIfNeeded('test/functional/fixtures/es_archiver/logstash_functional');
await PageObjects.timePicker.setDefaultAbsoluteRangeViaUiSettings();
await PageObjects.common.navigateToApp('discover');
await PageObjects.timePicker.setCommonlyUsedTime('This_week');
});
after(async () => {
await kibanaServer.savedObjects.cleanStandardList();
await esArchiver.unload('x-pack/test/functional/es_archives/logstash_functional');
await es.transport.request({
path: '/my-index-000001',
method: 'DELETE',
});
await es.transport.request({
path: '/my-index-000002',
method: 'DELETE',
});
});
it('create data view', async function () {
const initialPattern = 'my-index-';
await es.transport.request({
path: '/my-index-000001/_doc',
method: 'POST',
body: {
'@timestamp': new Date().toISOString(),
a: 'GET /search HTTP/1.1 200 1070000',
},
});
await es.transport.request({
path: '/my-index-000002/_doc',
method: 'POST',
body: {
'@timestamp': new Date().toISOString(),
b: 'GET /search HTTP/1.1 200 1070000',
},
});
await PageObjects.discover.createAdHocDataView(initialPattern, true);
expect(await PageObjects.discover.getCurrentlySelectedDataView()).to.be(`${initialPattern}*`);
await PageObjects.discover.waitUntilSidebarHasLoaded();
expect(await PageObjects.discover.getHitCountInt()).to.be(2);
expect((await PageObjects.discover.getAllFieldNames()).length).to.be(3);
});
it('update data view', async function () {
const updatedPattern = 'my-index-000001';
await PageObjects.discover.clickIndexPatternActions();
await PageObjects.unifiedSearch.editDataView(updatedPattern);
await retry.try(async () => {
expect(await PageObjects.discover.getHitCountInt()).to.be(1);
});
expect((await PageObjects.discover.getAllFieldNames()).length).to.be(2);
});
});
}

View file

@ -40,5 +40,6 @@ export default function ({ getService, loadTestFile }: FtrProviderContext) {
loadTestFile(require.resolve('./_chart_hidden'));
loadTestFile(require.resolve('./_context_encoded_url_params'));
loadTestFile(require.resolve('./_hide_announcements'));
loadTestFile(require.resolve('./_data_view_edit'));
});
}

View file

@ -60,9 +60,24 @@ export class UnifiedSearchPageObject extends FtrService {
await (await this.find.byClassName('indexPatternEditor__form')).click();
}
public async createNewDataView(dataViewName: string, adHoc = false, hasTimeField = false) {
public async clickEditDataView() {
await this.retry.waitForWithTimeout('data create new to be visible', 15000, async () => {
return await this.testSubjects.isDisplayed('indexPattern-manage-field');
});
await this.testSubjects.click('indexPattern-manage-field');
await this.retry.waitForWithTimeout(
'index pattern editor form to be visible',
15000,
async () => {
return await (await this.find.byClassName('indexPatternEditor__form')).isDisplayed();
}
);
await (await this.find.byClassName('indexPatternEditor__form')).click();
}
public async createNewDataView(dataViewPattern: string, adHoc = false, hasTimeField = false) {
await this.clickCreateNewDataView();
await this.testSubjects.setValue('createIndexPatternTitleInput', dataViewName, {
await this.testSubjects.setValue('createIndexPatternTitleInput', dataViewPattern, {
clearWithKeyboard: true,
typeCharByChar: true,
});
@ -75,6 +90,15 @@ export class UnifiedSearchPageObject extends FtrService {
await this.testSubjects.click(adHoc ? 'exploreIndexPatternButton' : 'saveIndexPatternButton');
}
public async editDataView(newPattern: string) {
await this.clickCreateNewDataView();
await this.testSubjects.setValue('createIndexPatternTitleInput', newPattern, {
clearWithKeyboard: true,
typeCharByChar: true,
});
await this.testSubjects.click('saveIndexPatternButton');
}
public async isAdHocDataView() {
const dataViewSwitcher = await this.testSubjects.find('discover-dataView-switch-link');
const dataViewName = await dataViewSwitcher.getVisibleText();

View file

@ -289,8 +289,8 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await testSubjects.click('indexPattern-manage-field');
await PageObjects.header.waitUntilLoadingHasFinished();
const titleElem = await testSubjects.find('currentIndexPatternTitle');
expect(await titleElem.getVisibleText()).to.equal(dataView);
const titleElem = await testSubjects.find('createIndexPatternTitleInput');
expect(await titleElem.getAttribute('value')).to.equal(dataView);
};
const checkUpdatedDataViewState = async (dataView: string) => {
@ -302,8 +302,8 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await testSubjects.click('indexPattern-manage-field');
await PageObjects.header.waitUntilLoadingHasFinished();
const titleElem = await testSubjects.find('currentIndexPatternTitle');
expect(await titleElem.getVisibleText()).to.equal(dataView);
const titleElem = await testSubjects.find('createIndexPatternTitleInput');
expect(await titleElem.getAttribute('value')).to.equal(dataView);
};
describe('Search source Alert', () => {