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

feat: add pagination support in templates page #1131

Merged
merged 12 commits into from
Sep 4, 2022
Merged

feat: add pagination support in templates page #1131

merged 12 commits into from
Sep 4, 2022

Conversation

jainpawan21
Copy link
Member

  • What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
    feature: add pagination support in templates page.
  • What is the current behavior? (You can also link to an open issue here)
    Long list of notifications. User have to scroll a lot
  • What is the new behavior (if this is a feature change)?
Screen.Recording.2022-08-26.at.10.51.31.PM.mov
  • Other information:

@vercel
Copy link

vercel bot commented Aug 26, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
docs ✅ Ready (Inspect) Visit Preview Aug 26, 2022 at 5:25PM (UTC)

@netlify
Copy link

netlify bot commented Aug 26, 2022

Deploy Preview for docs-novu canceled.

Name Link
🔨 Latest commit dcdd9a3
🔍 Latest deploy log https://app.netlify.com/sites/docs-novu/deploys/630ddb47e95bd30009ab1d3d

Copy link
Contributor

@scopsy scopsy left a comment

Choose a reason for hiding this comment

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

This is amazing @jainpawan21!!! We are so humbled to have you as a contributor.
My main note here would be to avoid using the usePagination flag on the API and enable pagination by default while allowing the user passing LIMIT with some limits. Let me know what you think

return this.getNotificationTemplatesUsecase.execute(
GetNotificationTemplatesCommand.create({
organizationId: user.organizationId,
userId: user._id,
environmentId: user.environmentId,
page: query.page ? Number(query.page) : 0,
usePagination: query.usePagination === 0 ? false : true,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that if we are going this direction we can just enable pagination by default, and instead of passing usePagination, we can allow the user to pass the limit property which by default would be for example 15 entries~ and maximum value allowed would be 100 for some API usecases. Wdyt?

async execute(command: GetNotificationTemplatesCommand): Promise<NotificationTemplateEntity[]> {
const list = await this.notificationTemplateRepository.getList(command.organizationId, command.environmentId);
async execute(command: GetNotificationTemplatesCommand): Promise<NotificationTemplatesResponseDto> {
const LIMIT = 10;
Copy link
Contributor

Choose a reason for hiding this comment

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

This limit could be passed from the API User with a default of 10 and maximum at 100, you can validate using class-validators on the API usecase. if you could also verify in other places of the application if we use this usecase aswell in case we do some "client-side" search on the server

@@ -21,7 +21,7 @@ interface IFiltersForm {
}

export function ActivitiesPage() {
const { templates, loading: loadingTemplates } = useTemplates();
const { templates, loading: loadingTemplates } = useTemplates(0, false);
Copy link
Contributor

Choose a reason for hiding this comment

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

Here instead of passing the usePagiatnion, we can just pass the maximum value 100, and in the future just do a server side text search to fix the large scale issues here.

Comment on lines +62 to +65
getNotificationTemplates(
@UserSession() user: IJwtPayload,
@Query() query: NotificationTemplatesRequestDto
): Promise<NotificationTemplatesResponseDto> {
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 amazing, could we also add a e2e API tests for the behaviour of pagination ?

@jainpawan21
Copy link
Member Author

jainpawan21 commented Aug 28, 2022

This is amazing @jainpawan21!!! We are so humbled to have you as a contributor. My main note here would be to avoid using the usePagination flag on the API and enable pagination by default while allowing the user passing LIMIT with some limits. Let me know what you think

Thanks for your kind words Dima 🙏🏻,
I was also thinking first to enable pagination by default. But there are some places where we need all notification templates. One such place is activities page, where we apply template filter, there we have to show all the notifications in drop down
One thing we can do, if we want to use pagination by default, we can add load more option in drop down?

@scopsy
Copy link
Contributor

scopsy commented Aug 29, 2022

@jainpawan21 for now we can just make sure to load the maximum page amount of 100~ templates on initial loads and than we can load all the subsequent pages if they are exist. I think it's a bit of an edge case for now so shouldn't be a problem for most of our users.

@vercel
Copy link

vercel bot commented Aug 29, 2022

@scopsy is attempting to deploy a commit to the Novu Team on Vercel.

A member of the Team first needs to authorize it.

@scopsy scopsy merged commit 7c0d158 into novuhq:main Sep 4, 2022
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.

None yet

2 participants