Skip to content

Commit

Permalink
fix: allow same prop to be filtered multiple times (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
frederikbache authored Sep 14, 2024
1 parent a363cae commit 15974d8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/createStores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,25 @@ function parseFilters(filterSettings: any) {
filters[field] = obj;
} else if (obj && typeof obj === 'object') {
let operator = '';
let val;
['gt', 'lt', 'gte', 'lte', 'contains'].forEach((op) => {
if (op in obj) {
operator = op;
val = (obj as any)[op];
const val = (obj as any)[op];
if (val) {
filters[`${field}[${operator}]`] = val;
}
}
});

['between'].forEach((op) => {
if (op in obj) {
operator = op;
val = (obj as any)[op].join(',');
const val = (obj as any)[op].join(',');
if (val) {
filters[`${field}[${operator}]`] = val;
}
}
});
if (val) {
filters[`${field}[${operator}]`] = val;
}
}
});

Expand Down
14 changes: 14 additions & 0 deletions test/uselist.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,20 @@ describe('Use list', () => {
]);
});

it('Can use same filter multiple times', async () => {
vroom.db.author.createMany({
name: 'CS Lewis',
});
const wrapper = getWrapper('author', {
filter: { id: { gte: '2', lte: '3' } },
});
await new Promise((r) => setTimeout(r, 2));
expect(wrapper.vm.items).toStrictEqual([
{ id: '2', name: 'George R.R. Martin' },
{ id: '3', name: 'CS Lewis' },
]);
});

it('Can sort', async () => {
const sortDir = ref('ASC');
const sortField = ref('name');
Expand Down

0 comments on commit 15974d8

Please sign in to comment.