Commit f09c5339 authored by Kushal Pandya's avatar Kushal Pandya

Fix filters not clearing on clear button click

Fixes a bug where clearing plain text search would not
refetch unfiltered results.
parent 6123dff4
...@@ -462,16 +462,18 @@ export default { ...@@ -462,16 +462,18 @@ export default {
}, },
handleFilterRequirements(filters = []) { handleFilterRequirements(filters = []) {
const authors = []; const authors = [];
let textSearch = '';
filters.forEach(filter => { filters.forEach(filter => {
if (typeof filter === 'string') { if (typeof filter === 'string') {
this.textSearch = filter; textSearch = filter;
} else if (filter.value.data !== ANY_AUTHOR) { } else if (filter.value.data !== ANY_AUTHOR) {
authors.push(filter.value.data); authors.push(filter.value.data);
} }
}); });
this.authorUsernames = [...authors]; this.authorUsernames = [...authors];
this.textSearch = textSearch;
this.currentPage = 1; this.currentPage = 1;
this.prevPageCursor = ''; this.prevPageCursor = '';
this.nextPageCursor = ''; this.nextPageCursor = '';
......
...@@ -667,6 +667,18 @@ describe('RequirementsRoot', () => { ...@@ -667,6 +667,18 @@ describe('RequirementsRoot', () => {
`http://localhost/?page=1&state=opened&search=foo&sort=created_desc&author_username%5B%5D=root&author_username%5B%5D=john.doe`, `http://localhost/?page=1&state=opened&search=foo&sort=created_desc&author_username%5B%5D=root&author_username%5B%5D=john.doe`,
); );
}); });
it('updates props `textSearch` and `authorUsernames` with empty values when passed filters param is empty', () => {
wrapper.setData({
authorUsernames: ['foo'],
textSearch: 'bar',
});
wrapper.vm.handleFilterRequirements([]);
expect(wrapper.vm.authorUsernames).toEqual([]);
expect(wrapper.vm.textSearch).toBe('');
});
}); });
describe('handleSortRequirements', () => { describe('handleSortRequirements', () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment