[8.7] [Discover] Fix issue where editing a data view causes the UI to become out of sync (#150830) (#151391)

# Backport

This will backport the following commits from `main` to `8.7`:
- [[Discover] Fix issue where editing a data view causes the UI to
become out of sync
(#150830)](https://github.com/elastic/kibana/pull/150830)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Davis
McPhee","email":"davis.mcphee@elastic.co"},"sourceCommit":{"committedDate":"2023-02-15T23:53:23Z","message":"[Discover]
Fix issue where editing a data view causes the UI to become out of sync
(#150830)\n\n## Summary\r\n\r\nLet's try this again with a simpler and
hopefully more robust approach.\r\nThis PR fixes the issue where editing
a data view in Discover causes the\r\nUI to become out of sync with the
current data view due to the stable\r\nobject identity.\r\n\r\nFixes
#149857.\r\nFixes #150740.\r\n\r\n### Checklist\r\n\r\n- [ ] ~Any text
added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)~\r\n-
[
]\r\n~[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials~\r\n- [x] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] ~Any UI
touched in this PR is usable by keyboard only (learn more\r\nabout
[keyboard\r\naccessibility](https://webaim.org/techniques/keyboard/))~\r\n-
[ ] ~Any UI touched in this PR does not create any new axe
failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))~\r\n-
[ ] ~If a plugin configuration key changed, check if it needs to
be\r\nallowlisted in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)~\r\n-
[ ] ~This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))~\r\n-
[ ] ~This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)~\r\n\r\n###
For maintainers\r\n\r\n- [ ] This was checked for breaking API changes
and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"4525c4b4e47a7267de8d5c6d30a3a2f668dd2425","branchLabelMapping":{"^v8.8.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Discover","release_note:skip","Team:DataDiscovery","v8.7.0","v8.8.0"],"number":150830,"url":"https://github.com/elastic/kibana/pull/150830","mergeCommit":{"message":"[Discover]
Fix issue where editing a data view causes the UI to become out of sync
(#150830)\n\n## Summary\r\n\r\nLet's try this again with a simpler and
hopefully more robust approach.\r\nThis PR fixes the issue where editing
a data view in Discover causes the\r\nUI to become out of sync with the
current data view due to the stable\r\nobject identity.\r\n\r\nFixes
#149857.\r\nFixes #150740.\r\n\r\n### Checklist\r\n\r\n- [ ] ~Any text
added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)~\r\n-
[
]\r\n~[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials~\r\n- [x] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] ~Any UI
touched in this PR is usable by keyboard only (learn more\r\nabout
[keyboard\r\naccessibility](https://webaim.org/techniques/keyboard/))~\r\n-
[ ] ~Any UI touched in this PR does not create any new axe
failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))~\r\n-
[ ] ~If a plugin configuration key changed, check if it needs to
be\r\nallowlisted in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)~\r\n-
[ ] ~This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))~\r\n-
[ ] ~This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)~\r\n\r\n###
For maintainers\r\n\r\n- [ ] This was checked for breaking API changes
and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"4525c4b4e47a7267de8d5c6d30a3a2f668dd2425"}},"sourceBranch":"main","suggestedTargetBranches":["8.7"],"targetPullRequestStates":[{"branch":"8.7","label":"v8.7.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.8.0","labelRegex":"^v8.8.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/150830","number":150830,"mergeCommit":{"message":"[Discover]
Fix issue where editing a data view causes the UI to become out of sync
(#150830)\n\n## Summary\r\n\r\nLet's try this again with a simpler and
hopefully more robust approach.\r\nThis PR fixes the issue where editing
a data view in Discover causes the\r\nUI to become out of sync with the
current data view due to the stable\r\nobject identity.\r\n\r\nFixes
#149857.\r\nFixes #150740.\r\n\r\n### Checklist\r\n\r\n- [ ] ~Any text
added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)~\r\n-
[
]\r\n~[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials~\r\n- [x] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] ~Any UI
touched in this PR is usable by keyboard only (learn more\r\nabout
[keyboard\r\naccessibility](https://webaim.org/techniques/keyboard/))~\r\n-
[ ] ~Any UI touched in this PR does not create any new axe
failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))~\r\n-
[ ] ~If a plugin configuration key changed, check if it needs to
be\r\nallowlisted in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)~\r\n-
[ ] ~This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))~\r\n-
[ ] ~This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)~\r\n\r\n###
For maintainers\r\n\r\n- [ ] This was checked for breaking API changes
and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"4525c4b4e47a7267de8d5c6d30a3a2f668dd2425"}}]}]
BACKPORT-->

Co-authored-by: Davis McPhee <davis.mcphee@elastic.co>
This commit is contained in:
Kibana Machine 2023-02-15 20:01:38 -05:00 committed by GitHub
parent 477834a881
commit 38c25b3612
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 76 additions and 12 deletions

View file

@ -186,10 +186,13 @@ export const DiscoverTopNav = ({
);
const onEditDataView = async (editedDataView: DataView) => {
if (!editedDataView.isPersisted()) {
await updateAdHocDataViewId(editedDataView);
if (editedDataView.isPersisted()) {
// Clear the current data view from the cache and create a new instance
// of it, ensuring we have a new object reference to trigger a re-render
dataViews.clearInstanceCache(editedDataView.id);
stateContainer.actions.setDataView(await dataViews.create(editedDataView.toSpec(), true));
} else {
stateContainer.actions.setDataView(editedDataView);
await updateAdHocDataViewId(editedDataView);
}
stateContainer.actions.loadDataViewList();
stateContainer.dataState.fetch();

View file

@ -45,9 +45,13 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
path: '/my-index-000002',
method: 'DELETE',
});
await es.transport.request({
path: '/my-index-000003',
method: 'DELETE',
});
});
it('create data view', async function () {
it('create ad hoc data view', async function () {
const initialPattern = 'my-index-';
await es.transport.request({
path: '/my-index-000001/_doc',
@ -78,10 +82,10 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
expect((await PageObjects.discover.getAllFieldNames()).length).to.be(3);
});
it('update data view', async function () {
it('create saved data view', async function () {
const updatedPattern = 'my-index-000001';
await PageObjects.discover.clickIndexPatternActions();
await PageObjects.unifiedSearch.editDataView(updatedPattern);
await PageObjects.unifiedSearch.createNewDataView(updatedPattern, false, true);
await retry.try(async () => {
expect(await PageObjects.discover.getHitCountInt()).to.be(1);
@ -90,5 +94,53 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await PageObjects.discover.waitUntilSidebarHasLoaded();
expect((await PageObjects.discover.getAllFieldNames()).length).to.be(2);
});
it('update data view with a different time field', async function () {
const updatedPattern = 'my-index-000003';
await es.transport.request({
path: '/my-index-000003/_doc',
method: 'POST',
body: {
timestamp: new Date('1970-01-01').toISOString(),
c: 'GET /search HTTP/1.1 200 1070000',
d: 'GET /search HTTP/1.1 200 1070000',
},
});
for (let i = 0; i < 3; i++) {
await es.transport.request({
path: '/my-index-000003/_doc',
method: 'POST',
body: {
timestamp: new Date().toISOString(),
c: 'GET /search HTTP/1.1 200 1070000',
d: 'GET /search HTTP/1.1 200 1070000',
},
});
}
await PageObjects.discover.clickIndexPatternActions();
await PageObjects.unifiedSearch.editDataView(updatedPattern, 'timestamp');
await retry.try(async () => {
expect(await PageObjects.discover.getHitCountInt()).to.be(3);
});
await PageObjects.discover.waitUntilSidebarHasLoaded();
expect((await PageObjects.discover.getAllFieldNames()).length).to.be(3);
expect(await PageObjects.discover.isChartVisible()).to.be(true);
expect(await PageObjects.timePicker.timePickerExists()).to.be(true);
});
it('update data view with no time field', async function () {
await PageObjects.discover.clickIndexPatternActions();
await PageObjects.unifiedSearch.editDataView(
undefined,
"--- I don't want to use the time filter ---"
);
await retry.try(async () => {
expect(await PageObjects.discover.getHitCountInt()).to.be(4);
});
await PageObjects.discover.waitUntilSidebarHasLoaded();
expect((await PageObjects.discover.getAllFieldNames()).length).to.be(3);
expect(await PageObjects.discover.isChartVisible()).to.be(false);
expect(await PageObjects.timePicker.timePickerExists()).to.be(false);
});
});
}

View file

@ -12,6 +12,7 @@ export class UnifiedSearchPageObject extends FtrService {
private readonly retry = this.ctx.getService('retry');
private readonly testSubjects = this.ctx.getService('testSubjects');
private readonly find = this.ctx.getService('find');
private readonly comboBox = this.ctx.getService('comboBox');
public async switchDataView(
switchButtonSelector: string,
@ -90,13 +91,21 @@ 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,
});
public async editDataView(newPattern?: string, newTimeField?: string) {
await this.clickEditDataView();
if (newPattern) {
await this.testSubjects.setValue('createIndexPatternTitleInput', newPattern, {
clearWithKeyboard: true,
typeCharByChar: true,
});
}
if (newTimeField) {
await this.comboBox.set('timestampField', newTimeField);
}
await this.testSubjects.click('saveIndexPatternButton');
if (await this.testSubjects.exists('confirmModalConfirmButton')) {
await this.testSubjects.click('confirmModalConfirmButton');
}
}
public async isAdHocDataView() {