Skip to content

Commit

Permalink
[discover] Enable data view editing from flyout (elastic#149453)
Browse files Browse the repository at this point in the history
## 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 elastic#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>
  • Loading branch information
3 people authored and kqualters-elastic committed Feb 6, 2023
1 parent 97d3790 commit 9697e20
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -220,6 +230,7 @@ export const DiscoverTopNav = ({
textBasedLanguages: supportedTextBasedLanguages as DataViewPickerProps['textBasedLanguages'],
adHocDataViews,
savedDataViews,
onEditDataView,
};

const onTextBasedSavedAndExit = useCallback(
Expand Down
89 changes: 89 additions & 0 deletions test/functional/apps/discover/group2/_data_view_edit.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
}
1 change: 1 addition & 0 deletions test/functional/apps/discover/group2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
});
}
28 changes: 26 additions & 2 deletions test/functional/page_objects/unified_search_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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', () => {
Expand Down

0 comments on commit 9697e20

Please sign in to comment.