Skip to content

Extract column ordering for reuse#866

Merged
rosado merged 3 commits into
mainfrom
rosado/861-column-order
Feb 6, 2025
Merged

Extract column ordering for reuse#866
rosado merged 3 commits into
mainfrom
rosado/861-column-order

Conversation

@rosado
Copy link
Copy Markdown
Contributor

@rosado rosado commented Feb 6, 2025

What type of PR is this? (check all applicable)

  • Refactoring

Description

As in the title. There will be a followup PR once #785 is merged

Related Tickets & Documents

QA Instructions, Screenshots, Recordings

Added/updated tests?

  • Yes

QA sign off

Summary by CodeRabbit

  • New Features

    • Enhanced the ordering of table fields so that key columns now appear first, providing a clearer and more intuitive display.
  • Tests

    • Added a new test suite and test case to confirm the improved table field ordering works reliably in various scenarios.

This will be needed by check tool's issue details page.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 6, 2025

Walkthrough

This pull request introduces a new utility function, splitByLeading, in the table utilities module to categorise field names into leading and trailing arrays. The middleware is updated to utilise this function, replacing manual iteration logic. Additionally, a new test suite is added to verify the proper categorisation of fields, particularly ensuring that "reference" and "name" are prioritised.

Changes

File(s) Change Summary
src/utils/table.js, src/middleware/dataview.middleware.js Added a new splitByLeading function to categorise fields and updated middleware to use this function for constructing table parameters, simplifying the logic and improving readability.
test/unit/util.test.js Introduced a new test suite for table utilities verifying that the "name" and "reference" fields are prioritised in the leading array while other fields are correctly placed in the trailing array.

Sequence Diagram(s)

sequenceDiagram
    participant Req as Request
    participant MW as DataView Middleware
    participant UT as Table Utils

    Req->>MW: Send HTTP request
    MW->>UT: Call splitByLeading({ fields })
    UT-->>MW: Return { leading, trailing }
    MW->>MW: Construct req.tableParams using returned data
    MW->>Req: Pass modified request to next middleware
Loading

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • DilwoarH

Poem

I'm a bunny in the code, hopping with glee,
Splitting fields with a flick, as neat as can be.
"Reference" and "name" lead the parade so bright,
While others trail quietly into the night.
With tests and middleware dancing in sync,
My carrot of code makes bugs shrink!
🥕🐇

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8e96457 and ba92178.

📒 Files selected for processing (1)
  • src/middleware/dataview.middleware.js (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/middleware/dataview.middleware.js
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: test
  • GitHub Check: run-tests / test

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 6, 2025

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 69.24% 5751 / 8305
🔵 Statements 69.24% 5751 / 8305
🔵 Functions 67.94% 231 / 340
🔵 Branches 81.34% 724 / 890
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/middleware/dataview.middleware.js 100% 100% 50% 100%
src/utils/table.js 100% 100% 100% 100%
Generated in workflow #744 for commit 1c31a67 by the Vitest Coverage Report Action

Copy link
Copy Markdown
Contributor

@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: 1

🧹 Nitpick comments (2)
src/utils/table.js (1)

11-24: Consider using array methods for improved readability.

While the current implementation is correct, it could be more concise using array methods.

Here's an alternative implementation:

-export const splitByLeading = ({ fields }) => {
-  const leading = []
-  const trailing = []
-  for (const field of fields) {
-    if (field === 'reference') {
-      leading.splice(0, 0, field)
-    } else if (field === 'name') {
-      leading.push(field)
-    } else {
-      trailing.push(field)
-    }
-  }
-  return { leading, trailing }
-}
+export const splitByLeading = ({ fields = [] }) => {
+  const reference = fields.filter(field => field === 'reference')
+  const name = fields.filter(field => field === 'name')
+  const trailing = fields.filter(field => !['reference', 'name'].includes(field))
+  return { leading: [...reference, ...name], trailing }
+}
test/unit/util.test.js (1)

118-125: Add test cases for edge scenarios.

The current test suite covers the basic scenarios well. Consider adding tests for:

  • Multiple occurrences of 'name' or 'reference'
  • Invalid inputs (undefined/null fields)

Here's an example of additional test cases:

 describe('table utils', () => {
   it('puts the "name" and "reference" columns first', () => {
     expect(table.splitByLeading({ fields: [] })).toStrictEqual({ leading: [], trailing: [] })
     expect(table.splitByLeading({ fields: ['foo', 'bar'] })).toStrictEqual({ leading: [], trailing: ['foo', 'bar'] })
     expect(table.splitByLeading({ fields: ['foo', 'name', 'bar'] })).toStrictEqual({ leading: ['name'], trailing: ['foo', 'bar'] })
     expect(table.splitByLeading({ fields: ['foo', 'name', 'reference'] })).toStrictEqual({ leading: ['reference', 'name'], trailing: ['foo'] })
+    // Test duplicate fields
+    expect(table.splitByLeading({ fields: ['foo', 'name', 'reference', 'name'] }))
+      .toStrictEqual({ leading: ['reference', 'name', 'name'], trailing: ['foo'] })
+    // Test undefined fields
+    expect(table.splitByLeading({ fields: undefined })).toStrictEqual({ leading: [], trailing: [] })
   })
 })
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b1a3d65 and 8e96457.

📒 Files selected for processing (3)
  • src/middleware/dataview.middleware.js (2 hunks)
  • src/utils/table.js (1 hunks)
  • test/unit/util.test.js (2 hunks)
🔇 Additional comments (2)
src/utils/table.js (1)

1-10: Well-documented utility function!

The JSDoc comments clearly explain the purpose, parameters and return type.

src/middleware/dataview.middleware.js (1)

5-5: LGTM!

Clean import of the new utility function.

Comment thread src/middleware/dataview.middleware.js Outdated
@eveleighoj eveleighoj temporarily deployed to submit-pr-866 February 6, 2025 12:17 Inactive
@rosado rosado merged commit e8e6321 into main Feb 6, 2025
@rosado rosado deleted the rosado/861-column-order branch February 6, 2025 12:39
@neilfwar neilfwar moved this from Done to Done Archived in Providers team (BACKLOG) Apr 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Status: Done Archived

Development

Successfully merging this pull request may close these issues.

4 participants