Skip to content

Commit

Permalink
[Discover] Remove column from sorting array when removed from table (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
kertal authored Jun 30, 2020
1 parent a075264 commit ad5ccfd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/plugins/discover/public/application/angular/discover.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
15 changes: 15 additions & 0 deletions test/functional/apps/discover/_discover.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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');
});
});
});
}
4 changes: 4 additions & 0 deletions test/functional/page_objects/discover_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down

0 comments on commit ad5ccfd

Please sign in to comment.