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

Update homepage with log records from DB + pagination #77

Merged
merged 29 commits into from
Jun 20, 2023

Conversation

kevin-pierce
Copy link
Contributor

@kevin-pierce kevin-pierce commented May 31, 2023

GH ticket link

Pagination Component on Homepage

Related ticket
Update Homepage table to render data from DB

Implementation description

  • Updated get_log_records service + associated endpoint to take in results_per_page as parameter, allowing for chunked request sizes
  • Created Pagination component as per functional description + Figma designs
  • Extracted code for log records table into common/LogRecordsTable.tsx component
  • Lifted logic for SearchAndFilters into pages/LogRecords
  • Narrowed typing of common API client for log records

Functional Testing

  1. Perform testing steps as outlined in Log Records Seeding Script #74 (this will setup enough sample data locally to test the remainder of this PR)
  2. Verify that the total number of entries is correctly displayed under the left hand side of the table
  3. Verify that the total number of pages corresponds to the (total number of entries / entries per page) + 1
  4. Verify that the number of displayed records adheres to the currently selected records per page option
  5. Verify that upon changing the records per page, we are sent back to page 1
  6. Verify that the displayed records change upon changing pages
  7. Verify that we can manually type in a page to navigate to in the page number text field
  8. Verify that the "next" and "previous" page buttons are disabled when you're on the first / last page respectively
  9. Verify that the container holding the log record entries is scrollable

What should reviewers focus on?

  • Structuring of the pages/LogRecords ; the design choice of lifting SearchAndFilters was done due to weird rendering issues, but we'd still like to get a second pair of 👀 on that
  • Should we be always resetting to Page 1 upon changing the results per page parameter?

Checklist

  • My PR name is descriptive and in imperative tense
  • My commit messages are descriptive and in imperative tense. My commits are atomic and trivial commits are squashed or fixup'd into non-trivial commits
  • I have run the appropriate linter(s)
  • I have requested a review from the PL, as well as other devs who have background knowledge on this PR or who will be building on top of this PR
  • If I have made API changes, I have updated the REST API Docs
  • IF I have made changes to the db/models, I have updated the Data Models Page
  • I have updated other Docs as needed

@kevin-pierce kevin-pierce marked this pull request as ready for review June 1, 2023 04:53
@kevin-pierce kevin-pierce requested a review from Safewaan June 1, 2023 04:54
@kevin-pierce kevin-pierce force-pushed the kevin/connor/pagination-component-on-homepage branch from 8c089a2 to 39233c8 Compare June 1, 2023 04:54
@Safewaan Safewaan requested a review from danielk1345 June 1, 2023 16:41
@kevin-pierce kevin-pierce added the front-end involves front-end work label Jun 3, 2023
@Safewaan Safewaan mentioned this pull request Jun 4, 2023
2 tasks
@Safewaan Safewaan force-pushed the kevin/connor/pagination-component-on-homepage branch from ccb0e70 to 39233c8 Compare June 5, 2023 04:23
Copy link
Collaborator

@Safewaan Safewaan left a comment

Choose a reason for hiding this comment

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

awesome stuff 💯 you guys popped off with this and got it done quickly, but there are a few front-end issues that should be fixed so #try-again #skill-issue #be-happy

frontend/src/components/common/LogRecordsTable.tsx Outdated Show resolved Hide resolved
return (
<Tr key={record.logId} style={{ verticalAlign: "middle" }}>
<Td width="5%">
{`${dateObj.getMonth()} ${dateObj.getDate()} ${dateObj.getFullYear()}`}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it be possible to show an abbreviated form for the month instead of the number? For example, instead of "9 2 2023", we would see Sept 9th, 2023.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved ; used the following const array for the months. Let me know if you want any of these to be changed:

const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Following up on this ; the year is not included in the designs ; this was accidentally included by us. On that note though, is the year something we want to include?

Copy link
Collaborator

Choose a reason for hiding this comment

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

yeah, might be confusing if you have two logs that are both jan 18th (but one is 2023, the other 2024)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will do

Copy link
Collaborator

Choose a reason for hiding this comment

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

the months are correct, but the year isn't showing:
image

frontend/src/components/common/LogRecordsTable.tsx Outdated Show resolved Hide resolved
frontend/src/components/common/Pagination.tsx Outdated Show resolved Hide resolved
frontend/src/components/common/LogRecordsTable.tsx Outdated Show resolved Hide resolved
frontend/src/components/common/Pagination.tsx Show resolved Hide resolved
frontend/src/components/pages/LogRecords.tsx Show resolved Hide resolved
frontend/src/components/pages/LogRecords.tsx Outdated Show resolved Hide resolved
@@ -22,7 +22,7 @@ code {
text-align: center;
color: #2d3748;
width: 75%;
padding-top: 10%;
padding-top: 2%;
Copy link
Collaborator

Choose a reason for hiding this comment

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

this probably needs to get updated in #76 when that's merged

<Box padding="12px 0px 33px">
<Flex justifyContent="space-between" alignItems="center">
<Box>
<Text color="#6D8788">{getNumRecordsStr()}</Text>
Copy link
Collaborator

Choose a reason for hiding this comment

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

some manual styling will need to be updated when #76 is merged

@kevin-pierce
Copy link
Contributor Author

TODOs:

  • Fix weird behaviour with page number text input
  • Add "Day Logs" header to table
  • Scrollbar should be reset to the top of the container when navigating to new page

@Safewaan
Copy link
Collaborator

Safewaan commented Jun 6, 2023

@connor-bechthold @kevin-pierce can you folks also test the performance of the pagination? I noticed there was a slight delay when navigating to another page, but I don't have any issues with this unless the delay is notably longer with more log records. Please test to see what the delay is with like 10k log records and lmk 🐱

@owen-sellner owen-sellner mentioned this pull request Jun 7, 2023
7 tasks
Copy link
Contributor

@danielk1345 danielk1345 left a comment

Choose a reason for hiding this comment

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

Not too many added comments since I think Safwaan covered most of them, but overall good work! I think the main changes and/or things to think about are the ones that Safwaan commented on (and the bug!)

@@ -28,7 +28,7 @@ def add_record(self, log_record):
pass

@abstractmethod
def get_log_records(self, page_number, filters=None):
def get_log_records(self, page_number, results_per_page, filters=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

If we have the default value for the results_per_page =1 in the implementations, maybe we should consider doing it the same for here

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good catch, will add 🙏

frontend/src/components/common/Pagination.tsx Show resolved Hide resolved
Copy link
Collaborator

@Safewaan Safewaan left a comment

Choose a reason for hiding this comment

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

just some issues with the input for the page number, let's sync with the designers to iron them out

>
<Text>Page</Text>
<NumberInput
maxW="60px"
Copy link
Collaborator

Choose a reason for hiding this comment

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

an issue with this is if there are 1000s of pages, the input box only shows 2 digits. This may be confusing to the user. I don't know what the width should be, but my (naïve) solution would be just to use a width that accommodates the largest possible integer.

Syncing with the designers on this would be a good first step.

width="210px"
>
<Text>Page</Text>
<NumberInput
Copy link
Collaborator

Choose a reason for hiding this comment

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

noticing if you keep typing numbers it'll go to infinity then back to 0 lol

Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe lets cap the input to the max number of pages (meaning if there are 400 pages and I'm at 300, I add another digit, it'll just go to 400 and won't let me add new numbers)

newUserPageNum >= 1 &&
newUserPageNum <= numPages
) {
getLogRecords(newUserPageNum);
Copy link
Collaborator

Choose a reason for hiding this comment

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

one issue I have with getting the new logs whenever the input changes is that the pagination gets really slow (I'm testing with 100000 logs) and its hard to tell when you're on the right page. I think it makes more sense to get the log records once the input is actually submitted.

For example, if I start on page 1, and want to go to page 300, it'll fetch the logs for page 3, then page 30, then finally page 300. It should only retrieve the page 300 log records at the end, either by hitting enter on the input or clicking out of it.

A lot of this headache is coming from the designs 😖 maybe we can approach the UI for this differently

@@ -14,6 +14,15 @@ code {
monospace;
}

.records-hero {
Copy link
Collaborator

Choose a reason for hiding this comment

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

#76 is merged, so merge main and move these changes to the theme dir

Copy link
Collaborator

@Safewaan Safewaan left a comment

Choose a reason for hiding this comment

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

lgtm! there's a few thing we need to improve (dealing with large page numbers, when to call the API, etc) but I'm happy with merging it in :D

Awesome work guys 🚀 now write 300 jest tests on pagination.

Copy link
Contributor

@danielk1345 danielk1345 left a comment

Choose a reason for hiding this comment

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

LGTM! There's a few small things with the linter and whatnot but it looks good to me!

@connor-bechthold connor-bechthold merged commit 2f334fd into main Jun 20, 2023
@connor-bechthold connor-bechthold deleted the kevin/connor/pagination-component-on-homepage branch June 20, 2023 03:56
@Safewaan Safewaan linked an issue Jun 20, 2023 that may be closed by this pull request
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
front-end involves front-end work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update Homepage table to render data from DB
4 participants