From ad5ccfd7dfadbf5a79a6ecb82266d8d81c049ff9 Mon Sep 17 00:00:00 2001 From: Matthias Wilhelm Date: Tue, 30 Jun 2020 21:28:21 +0200 Subject: [PATCH] [Discover] Remove column from sorting array when removed from table (#65990) --- .../public/application/angular/discover.js | 6 +++++- test/functional/apps/discover/_discover.js | 15 +++++++++++++++ test/functional/page_objects/discover_page.ts | 4 ++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/plugins/discover/public/application/angular/discover.js b/src/plugins/discover/public/application/angular/discover.js index 05ca748c777bf..9b8b32b51cfd8 100644 --- a/src/plugins/discover/public/application/angular/discover.js +++ b/src/plugins/discover/public/application/angular/discover.js @@ -1011,7 +1011,11 @@ function discoverController( $scope.indexPattern.popularizeField(columnName, 1); } const columns = columnActions.removeColumn($scope.state.columns, columnName); - setAppState({ columns }); + // The state's sort property is an array of [sortByColumn,sortDirection] + const sort = $scope.state.sort.length + ? $scope.state.sort.filter((subArr) => subArr[0] !== columnName) + : []; + setAppState({ columns, sort }); }; $scope.moveColumn = function moveColumn(columnName, newIndex) { diff --git a/test/functional/apps/discover/_discover.js b/test/functional/apps/discover/_discover.js index de9606f3d02ed..906f0b83e99e7 100644 --- a/test/functional/apps/discover/_discover.js +++ b/test/functional/apps/discover/_discover.js @@ -20,6 +20,7 @@ import expect from '@kbn/expect'; export default function ({ getService, getPageObjects }) { + const browser = getService('browser'); const log = getService('log'); const retry = getService('retry'); const esArchiver = getService('esArchiver'); @@ -268,5 +269,19 @@ export default function ({ getService, getPageObjects }) { expect(toastMessage).to.be('Invalid time range'); }); }); + + describe('managing fields', function () { + it('should add a field, sort by it, remove it and also sorting by it', async function () { + await PageObjects.timePicker.setDefaultAbsoluteRangeViaUiSettings(); + await PageObjects.common.navigateToApp('discover'); + await PageObjects.discover.clickFieldListItemAdd('_score'); + await PageObjects.discover.clickFieldSort('_score'); + const currentUrlWithScore = await browser.getCurrentUrl(); + expect(currentUrlWithScore).to.contain('_score'); + await PageObjects.discover.clickFieldListItemAdd('_score'); + const currentUrlWithoutScore = await browser.getCurrentUrl(); + expect(currentUrlWithoutScore).not.to.contain('_score'); + }); + }); }); } diff --git a/test/functional/page_objects/discover_page.ts b/test/functional/page_objects/discover_page.ts index 9ba3c9c1c2c88..7e083d41895b6 100644 --- a/test/functional/page_objects/discover_page.ts +++ b/test/functional/page_objects/discover_page.ts @@ -242,6 +242,10 @@ export function DiscoverPageProvider({ getService, getPageObjects }: FtrProvider return await testSubjects.click(`field-${field}`); } + public async clickFieldSort(field: string) { + return await testSubjects.click(`docTableHeaderFieldSort_${field}`); + } + public async clickFieldListItemAdd(field: string) { await testSubjects.moveMouseTo(`field-${field}`); await testSubjects.click(`fieldToggle-${field}`);