Skip to content
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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

yuenler
Copy link
Collaborator

@yuenler yuenler commented Oct 30, 2024

No description provided.

const query: any = {};

/* -------------- Date Filter ------------- */
const { startDate, endDate } = filters.dateFilterState;
Copy link
Contributor

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).

@@ -267,13 +263,144 @@ const initServer = (
);
}

// Build MongoDB query based on filters
const query: any = {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type { [k: string]: any }


/* ------------ Context Filter ------------ */
const { contextFilterState } = filters;
const contextConditions: any[] = [];
Copy link
Contributor

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"

Copy link
Contributor

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.

}

if (actionErrorFilterState.type === 'error' && actionErrorFilterState.errorMessage) {
query.errorMessage = { $regex: actionErrorFilterState.errorMessage, $options: 'i' };
Copy link
Contributor

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

query.type = actionErrorFilterState.type;
}

if (actionErrorFilterState.type === 'error' && actionErrorFilterState.errorMessage) {
Copy link
Contributor

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

}

if (advancedFilterState.userId) {
query.userId = parseInt(advancedFilterState.userId, 10);
Copy link
Contributor

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 }];
Copy link
Contributor

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

}

if (advancedFilterState.courseId) {
query.courseId = parseInt(advancedFilterState.courseId, 10);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Number.parseInt

}

if (advancedFilterState.isMobile !== undefined) {
query['device.isMobile'] = advancedFilterState.isMobile;
Copy link
Contributor

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,
Copy link
Contributor

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

contextFilterState: ContextFilterState,
tagFilterState: TagFilterState,
actionErrorFilterState: ActionErrorFilterState,
advancedFilterState: AdvancedFilterState,
Copy link
Contributor

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

}
} else {
// At least one subcontext is selected
if (Object.values(value).some((subcontextValue) => { return subcontextValue; })) {
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants