Merge pull request #6723 from nixocio/ui_issue_6244

Fix Page Size toggle does not persist after a search

Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
softwarefactory-project-zuul[bot] 2020-04-16 20:25:41 +00:00 committed by GitHub
commit b565ed2077
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 72 additions and 1 deletions

View File

@ -65,7 +65,13 @@ class ListHeader extends React.Component {
}
handleRemoveAll() {
this.pushHistoryState(null);
// remove everything in oldParams except for page_size and order_by
const { location, qsConfig } = this.props;
const oldParams = parseQueryString(qsConfig, location.search);
const oldParamsClone = { ...oldParams };
delete oldParamsClone.page_size;
delete oldParamsClone.order_by;
this.pushHistoryState(removeParams(qsConfig, oldParams, oldParamsClone));
}
handleSort(key, order) {

View File

@ -46,4 +46,69 @@ describe('ListHeader', () => {
// since order_by = name is the default, that should be strip out of the search
expect(history.location.search).toEqual('');
});
test('should test clear all', () => {
const query = '?item.page_size=5&item.name=foo';
const history = createMemoryHistory({
initialEntries: [`/organizations/1/teams${query}`],
});
const wrapper = mountWithContexts(
<ListHeader
itemCount={7}
qsConfig={qsConfig}
searchColumns={[{ name: 'foo', key: 'foo', isDefault: true }]}
sortColumns={[{ name: 'foo', key: 'foo' }]}
/>,
{ context: { router: { history } } }
);
expect(history.location.search).toEqual(query);
const toolbar = wrapper.find('DataListToolbar');
toolbar.prop('clearAllFilters')();
expect(history.location.search).toEqual('?item.page_size=5');
});
test('should test handle search', () => {
const query = '?item.page_size=10';
const history = createMemoryHistory({
initialEntries: [`/organizations/1/teams${query}`],
});
const wrapper = mountWithContexts(
<ListHeader
itemCount={7}
qsConfig={qsConfig}
searchColumns={[{ name: 'foo', key: 'foo', isDefault: true }]}
sortColumns={[{ name: 'foo', key: 'foo' }]}
/>,
{ context: { router: { history } } }
);
expect(history.location.search).toEqual(query);
const toolbar = wrapper.find('DataListToolbar');
toolbar.prop('onSearch')('name__icontains', 'foo');
expect(history.location.search).toEqual(
'?item.name__icontains=foo&item.page_size=10'
);
});
test('should test handle remove', () => {
const query = '?item.name__icontains=foo&item.page_size=10';
const history = createMemoryHistory({
initialEntries: [`/organizations/1/teams${query}`],
});
const wrapper = mountWithContexts(
<ListHeader
itemCount={7}
qsConfig={qsConfig}
searchColumns={[{ name: 'foo', key: 'foo', isDefault: true }]}
sortColumns={[{ name: 'foo', key: 'foo' }]}
/>,
{ context: { router: { history } } }
);
expect(history.location.search).toEqual(query);
const toolbar = wrapper.find('DataListToolbar');
toolbar.prop('onRemove')('name__icontains', 'foo');
expect(history.location.search).toEqual('?item.page_size=10');
});
});