Extract column ordering for reuse#866
Conversation
This will be needed by check tool's issue details page.
WalkthroughThis pull request introduces a new utility function, Changes
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
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Tip 🌐 Web search-backed reviews and chat
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (2)
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Coverage Report
File Coverage
|
||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
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
📒 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.
What type of PR is this? (check all applicable)
Description
As in the title. There will be a followup PR once #785 is merged
Related Tickets & Documents
QA Instructions, Screenshots, RecordingsAdded/updated tests?
QA sign offSummary by CodeRabbit
New Features
Tests