Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: paginate workspaces page #4647

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

Merged
merged 44 commits into from
Oct 20, 2022
Merged

feat: paginate workspaces page #4647

merged 44 commits into from
Oct 20, 2022

Conversation

presleyp
Copy link
Contributor

  • add count endpoint to backend
  • add count call to frontend
  • put pagination widget in workspaces page
  • made pagination widget mobile friendly (shows only the current page button)

The frontend test is not ideal but I wanted to get reviews before demo time!

@presleyp presleyp requested a review from a team as a code owner October 19, 2022 03:45
@presleyp presleyp removed the request for review from a team October 19, 2022 03:45
@presleyp presleyp requested review from Kira-Pilot and f0ssel October 19, 2022 03:45
severity={
workspaceRefs !== undefined && workspaceRefs.length > 0
? "warning"
: "error"
Copy link
Member

Choose a reason for hiding this comment

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

What does the AlertBanner look like with the error prop passed through, but also a severity of warning? JC because I only ever tested the warning case with the text prop, as opposed to the error prop.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just added a story for this!

@@ -206,160 +206,255 @@ interface WorkspacesContext {
workspaceRefs?: WorkspaceItemMachineRef[]
filter: string
getWorkspacesError?: Error | unknown
getCountError?: Error | unknown
Copy link
Member

Choose a reason for hiding this comment

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

Could these additions be pulled out into a separate machine for pagination? Not sure if there's a way to call a machine state from another machine.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe via spawn? I saw that being used below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that's the idea I mentioned!

One way would be for the pagination widget to have its own machine. I believe both machines would need to be aware of the other, so we'd have to hard-code in their machine ids. I wasn't sure I liked that. I think someday XState will make stuff like that easier.

Another way would be to have a pagination machine that doesn't operate on its own, but the workspaces page invokes it. I didn't go that route only because the pagination machine would have no states, and I didn't think people would want an extra machine for something simple.

But if you're in favor, I can reconsider.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I see! I forgot about the machine IDs.

I do like the idea of a pagination machine. Otherwise, I think we'll have to duplicate the logic you've written here to each page machine.

getWorkspacesError: (_, event) => event.data,
}),
clearGetWorkspacesError: (context) =>
assign({ ...context, getWorkspacesError: undefined }),
Copy link
Member

Choose a reason for hiding this comment

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

curious why we overwrite the the whole context here instead of just updating the getWorkspaceError to be undefined.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh so something not great about this diff is that I used the XState editor and it rearranged some code, so some stuff looks new that isn't. This is just an old pattern that we found a better way of writing since then.

@Kira-Pilot
Copy link
Member

Kira-Pilot commented Oct 19, 2022

The empty state is a bit off - neither buttons are disabled, and when clicked, I get this error:
Screen Shot 2022-10-19 at 10 18 36 AM

Also, I'm surprised to see the widget for 0 entries, but if there are less than 25 entries, I don't see it.

Copy link
Member

@Kira-Pilot Kira-Pilot left a comment

Choose a reason for hiding this comment

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

Great job! I do think we should make a pagination machine and also explore showing the pagination widget at all times, even if there is only 1 page.

But not gonna block this sweet PR over it! 🥳

@presleyp
Copy link
Contributor Author

@Kira-Pilot some of the weirdness is because I got rid of conditions in the page that block the widget, but I didn't change the conditions in the widget. Partly I'm trying to leave it for that other ticket and partly I'm afraid to change the widget before testing the audit log page. I think the widget enables the page turning buttons when count is undefined, so it's usable without a count, but doesn't distinguish between 0 and undefined, so in the meantime I'm not rendering it when count is 0.

q.mutex.RLock()
defer q.mutex.RUnlock()

workspaces := make([]database.Workspace, 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

You could probably save some code by just converting this from database.GetWorkspaceCountParams to database.GetWorkspaceParams and then calling q.GetAuthorizedWorkspace but completely optional.

Copy link
Member

Choose a reason for hiding this comment

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

I agree with this!

@presleyp presleyp merged commit 7c238f1 into main Oct 20, 2022
@presleyp presleyp deleted the paginate-ws/presleyp branch October 20, 2022 17:23
@github-actions github-actions bot locked and limited conversation to collaborators Oct 20, 2022
Copy link
Member

@kylecarbs kylecarbs left a comment

Choose a reason for hiding this comment

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

Sorry for the late review!

q.mutex.RLock()
defer q.mutex.RUnlock()

workspaces := make([]database.Workspace, 0)
Copy link
Member

Choose a reason for hiding this comment

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

I agree with this!

Comment on lines +148 to +149
-- this duplicates the filtering in GetWorkspaces
-- name: GetWorkspaceCount :one
Copy link
Member

Choose a reason for hiding this comment

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

I left an ad-hoc comment on the commit, but I think this is quite bug-prone.

It's not extremely obvious that you have to change this when introducing a new filter type, which could lead to a mismatch with the workspaces and count.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, Colin thought this was the best thing for now but we have an issue to clean it up #4604

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

Successfully merging this pull request may close these issues.

4 participants