Skip to content

feat: separate pagination for runs and nested runs #415

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 2 commits into from
Jan 30, 2025
Merged

Conversation

RohitR311
Copy link
Collaborator

@RohitR311 RohitR311 commented Jan 29, 2025

Closes: #414

Maxun._.Open.Source.No.Code.Web.Data.Extraction.Platform.-.Brave.2025-01-29.22-57-17.mp4

Summary by CodeRabbit

  • New Features

    • Enhanced pagination management for accordion elements
    • Independent pagination controls for each accordion section
    • Improved navigation experience when browsing runs
  • Refactor

    • Restructured pagination state management to support multiple accordions
    • Updated rendering logic to handle per-accordion pagination

@RohitR311 RohitR311 added Type: Bug Something isn't working Type: Enhancement Improvements to existing features Scope: UI/UX Issues/PRs related to UI/UX labels Jan 29, 2025
Copy link

coderabbitai bot commented Jan 29, 2025

Walkthrough

The pull request introduces a comprehensive pagination management system for the RunsTable component. The changes focus on creating a more flexible pagination mechanism that allows independent pagination for each accordion element based on robotMetaId. A new PaginationState interface is introduced to track page and rows per page for individual accordions, replacing the previous global pagination approach. The modifications enhance the component's ability to handle complex data sets with multiple grouped rows more effectively.

Changes

File Change Summary
src/components/run/RunsTable.tsx - Added PaginationState interface
- Updated pagination state management
- Modified handleChangePage and handleChangeRowsPerPage functions
- Introduced getPaginationState function
- Updated rendering logic for accordion rows

Sequence Diagram

sequenceDiagram
    participant User
    participant RunsTable
    participant PaginationState
    
    User->>RunsTable: Interact with Accordion
    RunsTable->>PaginationState: Update Page/Rows
    PaginationState-->>RunsTable: Return Pagination State
    RunsTable->>RunsTable: Render Rows
Loading

Possibly related PRs

Suggested labels

Type: Feature

Suggested reviewers

  • amhsirak

Poem

🐰 Pagination's dance, a rabbit's delight,
Rows hopping freely, each accordion's might!
State tracking magic, no global constraint,
Independent pages, no longer restrained.
A table that leaps with algorithmic grace! 🌟


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@RohitR311 RohitR311 requested a review from amhsirak January 29, 2025 17:28
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
src/components/run/RunsTable.tsx (3)

160-174: Consider simplifying default pagination state initialization.
Using a setTimeout to lazily initialize missing states works but might introduce timing complexities. A direct setState check or a simple memoization could simplify the logic:

- if (!paginationStates[robotMetaId]) {
-   setTimeout(() => {
-     setPaginationStates(prev => ({
-       ...prev,
-       [robotMetaId]: defaultState
-     }));
-   }, 0);
-   return defaultState;
- }
+ // Directly check and set missing state if needed
+ if (!paginationStates[robotMetaId]) {
+   setPaginationStates(prev => ({
+     ...prev,
+     [robotMetaId]: defaultState
+   }));
+   return defaultState;
+ }

186-193: Avoid spread syntax on reduce accumulators for better performance.
Repeatedly spreading accumulators can degrade performance dramatically. Instead, create a new object once per iteration:

- const reset = Object.keys(prev).reduce((acc, robotId) => ({
-   ...acc,
-   [robotId]: { ...prev[robotId], page: 0 }
- }), {});
+ const reset: PaginationState = {};
+ Object.keys(prev).forEach(robotId => {
+   reset[robotId] = { ...prev[robotId], page: 0 };
+ });
  return reset;
🧰 Tools
🪛 Biome (1.9.4)

[error] 189-189: Avoid the use of spread (...) syntax on accumulators.

Spread syntax should be avoided on accumulators (like those in .reduce) because it causes a time complexity of O(n^2).
Consider methods such as .splice or .push instead.

(lint/performance/noAccumulatingSpread)


360-443: Validate the accordion label choice.
Using the last item’s name (index data[data.length - 1]) might be intentional, but confirm this is desired. In some cases, the first item or a shared property might be more representative of the entire group.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 98ba962 and b8d4321.

📒 Files selected for processing (1)
  • src/components/run/RunsTable.tsx (7 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
src/components/run/RunsTable.tsx

[error] 189-189: Avoid the use of spread (...) syntax on accumulators.

Spread syntax should be avoided on accumulators (like those in .reduce) because it causes a time complexity of O(n^2).
Consider methods such as .splice or .push instead.

(lint/performance/noAccumulatingSpread)

🔇 Additional comments (8)
src/components/run/RunsTable.tsx (8)

73-79: Interface definition looks solid.
No immediate issues with this dictionary-based interface for storing pagination states by robotMetaId. It’s clear and straightforward.


89-90: Naming clarity is good; no issues found.
The separate state for outer pagination (accordion-level) is clearly named and doesn’t conflict with the nested pagination logic.


123-124: Pagination states management is well-initialized.
Introducing a dedicated React state for each accordion’s pagination is a substantial improvement over a single global pagination.


131-139: Outer (accordion-level) pagination logic is clearly implemented.
The handlers handleAccordionPageChange and handleAccordionsPerPageChange neatly handle top-level pagination. No further changes needed.


140-147: Nested pagination update logic is straightforward.
Updating the page index per robotMetaId looks correct. No further suggestions here.


150-157: Rows-per-page handler is clear and resets page index correctly.
This ensures users automatically see page 0 of new page-size increments. Nicely done.


273-273: Correct retrieval of pagination state for row rendering.
Accessing the correct page and rowsPerPage per accordion ensures each group is paginated independently. Implementation is sound.


448-452: Outer pagination controls appear well-integrated.
Governing how many accordions to display on the page further refines the user’s navigational experience.

@amhsirak amhsirak merged commit 1c302e2 into develop Jan 30, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: UI/UX Issues/PRs related to UI/UX Type: Bug Something isn't working Type: Enhancement Improvements to existing features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feat: Separate paginations for runs & nested runs
2 participants