Skip to content

Commit ad5ccfd

Browse files
authored
[Discover] Remove column from sorting array when removed from table (#65990)
1 parent a075264 commit ad5ccfd

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

src/plugins/discover/public/application/angular/discover.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,11 @@ function discoverController(
10111011
$scope.indexPattern.popularizeField(columnName, 1);
10121012
}
10131013
const columns = columnActions.removeColumn($scope.state.columns, columnName);
1014-
setAppState({ columns });
1014+
// The state's sort property is an array of [sortByColumn,sortDirection]
1015+
const sort = $scope.state.sort.length
1016+
? $scope.state.sort.filter((subArr) => subArr[0] !== columnName)
1017+
: [];
1018+
setAppState({ columns, sort });
10151019
};
10161020

10171021
$scope.moveColumn = function moveColumn(columnName, newIndex) {

test/functional/apps/discover/_discover.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import expect from '@kbn/expect';
2121

2222
export default function ({ getService, getPageObjects }) {
23+
const browser = getService('browser');
2324
const log = getService('log');
2425
const retry = getService('retry');
2526
const esArchiver = getService('esArchiver');
@@ -268,5 +269,19 @@ export default function ({ getService, getPageObjects }) {
268269
expect(toastMessage).to.be('Invalid time range');
269270
});
270271
});
272+
273+
describe('managing fields', function () {
274+
it('should add a field, sort by it, remove it and also sorting by it', async function () {
275+
await PageObjects.timePicker.setDefaultAbsoluteRangeViaUiSettings();
276+
await PageObjects.common.navigateToApp('discover');
277+
await PageObjects.discover.clickFieldListItemAdd('_score');
278+
await PageObjects.discover.clickFieldSort('_score');
279+
const currentUrlWithScore = await browser.getCurrentUrl();
280+
expect(currentUrlWithScore).to.contain('_score');
281+
await PageObjects.discover.clickFieldListItemAdd('_score');
282+
const currentUrlWithoutScore = await browser.getCurrentUrl();
283+
expect(currentUrlWithoutScore).not.to.contain('_score');
284+
});
285+
});
271286
});
272287
}

test/functional/page_objects/discover_page.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ export function DiscoverPageProvider({ getService, getPageObjects }: FtrProvider
242242
return await testSubjects.click(`field-${field}`);
243243
}
244244

245+
public async clickFieldSort(field: string) {
246+
return await testSubjects.click(`docTableHeaderFieldSort_${field}`);
247+
}
248+
245249
public async clickFieldListItemAdd(field: string) {
246250
await testSubjects.moveMouseTo(`field-${field}`);
247251
await testSubjects.click(`fieldToggle-${field}`);

0 commit comments

Comments
 (0)