Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] [Discover] Remove column from sorting array when removed from table (#65990) #70360

Merged
merged 2 commits into from
Jul 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -293,5 +294,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