-
Notifications
You must be signed in to change notification settings - Fork 546
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
Fix RGB mask targets when hex color codes are lowercase #4852
Conversation
WalkthroughThe changes introduce a new test suite for the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant convertTargets
participant Test Suite
User->>convertTargets: Call with #ffffff
convertTargets->>convertTargets: Convert to uppercase
convertTargets->>Test Suite: Return { "#FFFFFF": { label: "white", intTarget: 1 } }
Test Suite->>User: Verify output
Poem
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
Documentation and Community
|
There was a problem hiding this 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
🧹 Outside diff range and nitpick comments (1)
app/packages/state/src/utils.test.ts (1)
5-9
: Test case effectively covers the main functionality.The test case correctly verifies that lowercase hex color codes are converted to uppercase, which aligns with the PR objectives. It also checks the structure of the output object, including the label and integer target.
Consider adding more test cases to cover:
- Multiple color targets in a single input.
- Edge cases like empty input or invalid hex codes.
- Different color values (e.g., black, primary colors) to ensure consistent behavior.
Example:
it("handles multiple color targets", () => { expect( convertTargets([ { target: "#ffffff", value: "white" }, { target: "#000000", value: "black" } ]) ).toStrictEqual({ "#FFFFFF": { label: "white", intTarget: 1 }, "#000000": { label: "black", intTarget: 2 } }); }); it("handles invalid input", () => { expect(() => convertTargets([{ target: "#gggggg", value: "invalid" }])) .toThrow(); });
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (2)
- app/packages/state/src/utils.test.ts (1 hunks)
- app/packages/state/src/utils.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
app/packages/state/src/utils.test.ts (1)
Pattern
**/*.{ts,tsx}
: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.app/packages/state/src/utils.ts (1)
Pattern
**/*.{ts,tsx}
: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.
🔇 Additional comments (7)
app/packages/state/src/utils.test.ts (3)
1-2
: Imports look good.The necessary testing functions are imported from 'vitest', and the function under test is correctly imported from the local 'utils' module.
4-10
: Test suite structure is appropriate.The test suite is well-structured using the
describe
block, which clearly indicates the function being tested (convertTargets
).
1-10
: Overall, this is a good start for testing theconvertTargets
function.The test file is well-structured and effectively addresses the main issue described in the PR objectives. It verifies that lowercase hex color codes are correctly converted to uppercase.
To further improve the test coverage:
- Consider adding more test cases as suggested earlier.
- Ensure that the
convertTargets
function inutils.ts
is fully covered by these tests.To verify the implementation of
convertTargets
, let's check its definition:✅ Verification successful
Verification Successful:
convertTargets
Function Exists.The
convertTargets
function is correctly exported fromutils.ts
as a constant. The existing test inutils.test.ts
properly targets and verifies its functionality.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Find the implementation of convertTargets function ast-grep --lang typescript --pattern 'export function convertTargets($_) { $$$ }'Length of output: 85
Script:
#!/bin/bash # Description: Find 'convertTargets' exported as a constant arrow function ast-grep --lang typescript --pattern 'export const convertTargets = $_ => { $$$ }' # Description: Search for any function named 'convertTargets' in the codebase rg 'function\s+convertTargets\s*\('Length of output: 122
Script:
#!/bin/bash # Description: Find any function declarations named 'convertTargets' regardless of export style ast-grep --lang typescript --pattern 'function convertTargets($_) { $$$ }' # Description: Search for 'convertTargets' defined as a variable or constant rg 'const\s+convertTargets\s*='Length of output: 174
app/packages/state/src/utils.ts (4)
121-121
: Good job on adding an explicit return typeAdding an explicit return type
{ [key: string]: { label: string; intTarget: number } | string }
improves type safety and code readability. This change is beneficial for maintaining and understanding the code.
124-124
: Improved numeric checkThe change from
!isNaN(Number(target))
to!Number.isNaN(Number(target))
is a good improvement. The new check is more explicit and reliable, as it avoids potential issues with the globalisNaN
function.
131-131
: Fix for lowercase hex color codesConverting the
target
to uppercase (target.toUpperCase()
) directly addresses the PR objective of fixing RGB mask targets when hex color codes are lowercase. This change ensures consistent handling of hex color codes regardless of their case.
116-116
: Consider the implications of makingconvertTargets
publicThe function has been made public by adding the
export
keyword. Ensure that this change is intentional and aligns with the module's design. If the function is meant to be used externally, this change is appropriate. However, if it's only for internal use within this module, consider keeping it private.✅ Verification successful
convertTargets
is only used in test filesThe
convertTargets
function is solely referenced inutils.test.ts
. If its exposure beyond this module isn't necessary, consider keeping it private to maintain encapsulation.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify if convertTargets is used outside this file rg --type typescript -g '!app/packages/state/src/utils.ts' 'convertTargets'Length of output: 110
Script:
#!/bin/bash # Verify if convertTargets is used outside this file rg --type ts -g '!app/packages/state/src/utils.ts' 'convertTargets'Length of output: 317
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested and LGTM 🙇
What changes are proposed in this pull request?
RGB masks in looker expect an uppercase hex color
How is this patch tested? If it is not, please explain why.
Unit test
Release Notes
What areas of FiftyOne does this PR affect?
fiftyone
Python library changesSummary by CodeRabbit
New Features
convertTargets
function to ensure accurate color conversion.Improvements
convertTargets
function publicly accessible and defined its return type for clarity.