-
Notifications
You must be signed in to change notification settings - Fork 2
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
Server side filtering and pagination #17
base: main
Are you sure you want to change the base?
Conversation
src/server/initServer.ts
Outdated
const query: any = {}; | ||
|
||
/* -------------- Date Filter ------------- */ | ||
const { startDate, endDate } = filters.dateFilterState; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's cast filters to the correct type (use same type as client, add to server and import it here).
src/server/initServer.ts
Outdated
@@ -267,13 +263,144 @@ const initServer = ( | |||
); | |||
} | |||
|
|||
// Build MongoDB query based on filters | |||
const query: any = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type { [k: string]: any }
src/server/initServer.ts
Outdated
|
||
/* ------------ Context Filter ------------ */ | ||
const { contextFilterState } = filters; | ||
const contextConditions: any[] = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Be more precise than "any"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we go for a more straightforward query for contexts? Something like:
{
context: { $in: selectedContexts },
subcontext: { $in: selectedSubcontexts },
}
Contexts and sub contexts must be unique, so we don't need to be super precise here.
src/server/initServer.ts
Outdated
} | ||
|
||
if (actionErrorFilterState.type === 'error' && actionErrorFilterState.errorMessage) { | ||
query.errorMessage = { $regex: actionErrorFilterState.errorMessage, $options: 'i' }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If users can use regexes, let's describe this in the UI
src/server/initServer.ts
Outdated
query.type = actionErrorFilterState.type; | ||
} | ||
|
||
if (actionErrorFilterState.type === 'error' && actionErrorFilterState.errorMessage) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move the filter types to the server, then npm run copy-server-types
to get them on the client. Then, reference the types: actionErrorFilterState.type === ActionType.Error
src/server/initServer.ts
Outdated
} | ||
|
||
if (advancedFilterState.userId) { | ||
query.userId = parseInt(advancedFilterState.userId, 10); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Number.parseInt
roles.push({ isAdmin: true }); | ||
} | ||
if (roles.length > 0) { | ||
query.$and = [{ $or: roles }]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is complex. Explain in a comment
src/server/initServer.ts
Outdated
} | ||
|
||
if (advancedFilterState.courseId) { | ||
query.courseId = parseInt(advancedFilterState.courseId, 10); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Number.parseInt
src/server/initServer.ts
Outdated
} | ||
|
||
if (advancedFilterState.isMobile !== undefined) { | ||
query['device.isMobile'] = advancedFilterState.isMobile; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be sure, let's cast to boolean
}, | ||
perPage: 1000, | ||
query, | ||
perPage: 50, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally, needs a lot of comments because this code is super complicated. Good work! I just want others to be able to understand it
src/server/initServer.ts
Outdated
contextFilterState: ContextFilterState, | ||
tagFilterState: TagFilterState, | ||
actionErrorFilterState: ActionErrorFilterState, | ||
advancedFilterState: AdvancedFilterState, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make this into a type? LogReviewerFilters
perhaps? That would be a folder containing an index.ts
which was this thing:
dateFilterState: DateFilterState,
contextFilterState: ContextFilterState,
tagFilterState: TagFilterState,
actionErrorFilterState: ActionErrorFilterState,
advancedFilterState: AdvancedFilterState,
plus all the other types would be subtypes of this one and would be inside that folder too
src/server/initServer.ts
Outdated
} | ||
} else { | ||
// At least one subcontext is selected | ||
if (Object.values(value).some((subcontextValue) => { return subcontextValue; })) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please put this in a separate variable
No description provided.