Improved search filtering (#940)

* Filter search by collectionId

* Improve spec, remove recursive import

* Add userId filter for documents.search

* 💚

* Search filter UI

* WIP UI

* Date filtering
Prevent dupe menu

* Refactor

* button

* Added year option, improved hover states

* Add new indexes

* Remove manual string interpolation in SQL construction

* Move dateFilter validation to controller

* Fixes: Double query when changing filter
Fixes: Visual jump between filters in dropdown

* Add option to clear filters

* More clearly define dropdowns in dark mode

* Checkbox -> Checkmark
This commit is contained in:
Tom Moor
2019-04-23 07:31:20 -07:00
committed by GitHub
parent a256eba856
commit da7fdfef0a
23 changed files with 679 additions and 76 deletions

View File

@ -410,7 +410,7 @@ describe('#documents.search', async () => {
it('should return draft documents created by user', async () => {
const { user } = await seed();
await buildDocument({
const document = await buildDocument({
title: 'search term',
text: 'search term',
publishedAt: null,
@ -424,7 +424,7 @@ describe('#documents.search', async () => {
expect(res.status).toEqual(200);
expect(body.data.length).toEqual(1);
expect(body.data[0].document.text).toEqual('search term');
expect(body.data[0].document.id).toEqual(document.id);
});
it('should not return draft documents created by other users', async () => {
@ -482,7 +482,70 @@ describe('#documents.search', async () => {
expect(res.status).toEqual(200);
expect(body.data.length).toEqual(1);
expect(body.data[0].document.text).toEqual('search term');
expect(body.data[0].document.id).toEqual(document.id);
});
it('should return documents for a specific user', async () => {
const { user } = await seed();
const document = await buildDocument({
title: 'search term',
text: 'search term',
teamId: user.teamId,
userId: user.id,
});
// This one will be filtered out
await buildDocument({
title: 'search term',
text: 'search term',
teamId: user.teamId,
});
const res = await server.post('/api/documents.search', {
body: {
token: user.getJwtToken(),
query: 'search term',
userId: user.id,
},
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body.data.length).toEqual(1);
expect(body.data[0].document.id).toEqual(document.id);
});
it('should return documents for a specific collection', async () => {
const { user } = await seed();
const collection = await buildCollection();
const document = await buildDocument({
title: 'search term',
text: 'search term',
teamId: user.teamId,
});
// This one will be filtered out
await buildDocument({
title: 'search term',
text: 'search term',
teamId: user.teamId,
collectionId: collection.id,
});
const res = await server.post('/api/documents.search', {
body: {
token: user.getJwtToken(),
query: 'search term',
collectionId: document.collectionId,
},
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body.data.length).toEqual(1);
expect(body.data[0].document.id).toEqual(document.id);
});
it('should not return documents in private collections not a member of', async () => {
@ -505,6 +568,20 @@ describe('#documents.search', async () => {
expect(body.data.length).toEqual(0);
});
it('should not allow unknown dateFilter values', async () => {
const { user } = await seed();
const res = await server.post('/api/documents.search', {
body: {
token: user.getJwtToken(),
query: 'search term',
dateFilter: 'DROP TABLE students;',
},
});
expect(res.status).toEqual(400);
});
it('should require authentication', async () => {
const res = await server.post('/api/documents.search');
const body = await res.json();