-
Notifications
You must be signed in to change notification settings - Fork 80
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
chore(app): Create isMediaString util #3827
Conversation
WalkthroughA new function Changes
Sequence Diagram(s)sequenceDiagram
participant C as Client
participant F as isMediaString Function
participant A as MediaStrings Array
C->>F: Call isMediaString(type)
F->>A: Check if type exists in mediaStrings
A-->>F: Return match result (true/false)
F-->>C: Return type predicate (boolean)
Poem
✨ Finishing Touches
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 comments (1)
weave-js/src/common/types/media.ts (1)
149-172
:⚠️ Potential issueType inconsistency between MediaString type and mediaStrings array.
The
mediaStrings
array includes 'partitioned-table' and 'joined-table' at lines 152-153, but these values are not included in theMediaString
type definition (lines 126-147). This could lead to type inconsistencies, whereisMediaString
might return true for strings that aren't actually in theMediaString
type.export type MediaString = | 'data-frame' | 'table' | 'table-file' + | 'partitioned-table' + | 'joined-table' | 'images' | 'images/separated' | 'image-file' | 'videos' | 'video-file' | 'audio' | 'audio-file' | 'html' | 'html-file' | 'plotly' | 'plotly-file' | 'object3D' | 'object3D-file' | 'bokeh' | 'bokeh-file' | 'molecule' | 'molecule-file' | 'media'; // media is used for MessageMediaNotFound
🧹 Nitpick comments (2)
weave-js/src/common/types/media.ts (2)
229-231
: Add JSDoc comment to improve documentation.Consider adding a JSDoc comment to explain the function's purpose, similar to other functions in the file.
+/** + * Type predicate to check if a string is a valid MediaString type + * @param type - The string to check + * @returns boolean indicating if the string is a MediaString + */ export const isMediaString = (type: string): type is MediaString => { return _.includes(mediaStrings, type); };
229-231
: Consider validating the input parameter.Add null/undefined check for the input parameter to make the function more robust, especially if it might be called with potentially undefined values.
export const isMediaString = (type: string): type is MediaString => { - return _.includes(mediaStrings, type); + return Boolean(type) && _.includes(mediaStrings, type); };
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
weave-js/src/common/types/media.ts
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{js,jsx,ts,tsx}`: Focus on architectural and logical i...
**/*.{js,jsx,ts,tsx}
: Focus on architectural and logical issues rather than style (assuming ESLint is in place).
Flag potential memory leaks and performance bottlenecks.
Check for proper error handling and async/await usage.
Avoid strict enforcement of try/catch blocks - accept Promise chains, early returns, and other clear error handling patterns. These are acceptable as long as they maintain clarity and predictability.
Ensure proper type usage in TypeScript files.
Look for security vulnerabilities in data handling.
Don't comment on formatting if prettier is configured.
Verify proper React hooks usage and component lifecycle.
Check for proper state management patterns.
weave-js/src/common/types/media.ts
⏰ Context from checks skipped due to timeout of 90000ms (175)
- GitHub Check: WeaveJS Lint and Compile
- GitHub Check: Trace nox tests (3, 13, pandas-test)
- GitHub Check: Trace nox tests (3, 13, llamaindex)
- GitHub Check: Trace nox tests (3, 13, trace_server)
- GitHub Check: Trace nox tests (3, 13, trace)
- GitHub Check: Trace nox tests (3, 12, scorers)
- GitHub Check: Trace nox tests (3, 12, llamaindex)
- GitHub Check: Trace nox tests (3, 12, trace_server)
- GitHub Check: Trace nox tests (3, 12, trace)
- GitHub Check: Trace nox tests (3, 11, scorers)
- GitHub Check: Trace nox tests (3, 11, llamaindex)
- GitHub Check: Trace nox tests (3, 11, trace_server)
- GitHub Check: Trace nox tests (3, 11, trace)
- GitHub Check: Trace nox tests (3, 10, scorers)
- GitHub Check: Trace nox tests (3, 10, llamaindex)
- GitHub Check: Trace nox tests (3, 10, trace_server)
- GitHub Check: Trace nox tests (3, 10, trace)
- GitHub Check: Trace nox tests (3, 9, scorers)
- GitHub Check: WeaveJS Lint and Compile
- GitHub Check: Trace nox tests (3, 13, pandas-test)
- GitHub Check: Trace nox tests (3, 13, llamaindex)
- GitHub Check: Trace nox tests (3, 13, trace_server)
- GitHub Check: Trace nox tests (3, 13, trace)
- GitHub Check: Trace nox tests (3, 12, scorers)
- GitHub Check: Trace nox tests (3, 12, llamaindex)
- GitHub Check: Trace nox tests (3, 12, trace_server)
- GitHub Check: Trace nox tests (3, 12, trace)
- GitHub Check: Trace nox tests (3, 11, scorers)
- GitHub Check: Trace nox tests (3, 11, llamaindex)
- GitHub Check: Trace nox tests (3, 11, trace_server)
- GitHub Check: Trace nox tests (3, 11, trace)
- GitHub Check: Trace nox tests (3, 10, scorers)
- GitHub Check: Trace nox tests (3, 10, llamaindex)
- GitHub Check: Trace nox tests (3, 10, trace_server)
- GitHub Check: Trace nox tests (3, 10, trace)
- GitHub Check: Trace nox tests (3, 9, scorers)
- GitHub Check: WeaveJS Lint and Compile
- GitHub Check: Trace nox tests (3, 13, pandas-test)
- GitHub Check: Trace nox tests (3, 13, llamaindex)
- GitHub Check: Trace nox tests (3, 13, trace_server)
- GitHub Check: Trace nox tests (3, 13, trace)
- GitHub Check: Trace nox tests (3, 12, scorers)
- GitHub Check: Trace nox tests (3, 12, llamaindex)
- GitHub Check: Trace nox tests (3, 12, trace_server)
- GitHub Check: Trace nox tests (3, 12, trace)
- GitHub Check: Trace nox tests (3, 11, scorers)
- GitHub Check: Trace nox tests (3, 11, llamaindex)
- GitHub Check: Trace nox tests (3, 11, trace_server)
- GitHub Check: Trace nox tests (3, 11, trace)
- GitHub Check: Trace nox tests (3, 10, scorers)
- GitHub Check: Trace nox tests (3, 10, llamaindex)
- GitHub Check: Trace nox tests (3, 10, trace_server)
- GitHub Check: Trace nox tests (3, 10, trace)
- GitHub Check: Trace nox tests (3, 9, scorers)
- GitHub Check: WeaveJS Lint and Compile
- GitHub Check: Trace nox tests (3, 13, pandas-test)
- GitHub Check: Trace nox tests (3, 13, llamaindex)
- GitHub Check: Trace nox tests (3, 13, trace_server)
- GitHub Check: Trace nox tests (3, 13, trace)
- GitHub Check: Trace nox tests (3, 12, scorers)
- GitHub Check: Trace nox tests (3, 12, llamaindex)
- GitHub Check: Trace nox tests (3, 12, trace_server)
- GitHub Check: Trace nox tests (3, 12, trace)
- GitHub Check: Trace nox tests (3, 11, scorers)
- GitHub Check: Trace nox tests (3, 11, llamaindex)
- GitHub Check: Trace nox tests (3, 11, trace_server)
- GitHub Check: Trace nox tests (3, 11, trace)
- GitHub Check: Trace nox tests (3, 10, scorers)
- GitHub Check: Trace nox tests (3, 10, llamaindex)
- GitHub Check: Trace nox tests (3, 10, trace_server)
- GitHub Check: Trace nox tests (3, 10, trace)
- GitHub Check: Trace nox tests (3, 9, scorers)
- GitHub Check: WeaveJS Lint and Compile
- GitHub Check: Trace nox tests (3, 13, pandas-test)
- GitHub Check: Trace nox tests (3, 13, llamaindex)
- GitHub Check: Trace nox tests (3, 13, trace_server)
- GitHub Check: Trace nox tests (3, 13, trace)
- GitHub Check: Trace nox tests (3, 12, scorers)
- GitHub Check: Trace nox tests (3, 12, llamaindex)
- GitHub Check: Trace nox tests (3, 12, trace_server)
- GitHub Check: Trace nox tests (3, 12, trace)
- GitHub Check: Trace nox tests (3, 11, scorers)
- GitHub Check: Trace nox tests (3, 11, llamaindex)
- GitHub Check: Trace nox tests (3, 11, trace_server)
- GitHub Check: Trace nox tests (3, 11, trace)
- GitHub Check: Trace nox tests (3, 10, scorers)
- GitHub Check: Trace nox tests (3, 10, llamaindex)
- GitHub Check: Trace nox tests (3, 10, trace_server)
- GitHub Check: Trace nox tests (3, 10, trace)
- GitHub Check: Trace nox tests (3, 9, scorers)
- GitHub Check: WeaveJS Lint and Compile
- GitHub Check: Trace nox tests (3, 13, pandas-test)
- GitHub Check: Trace nox tests (3, 13, llamaindex)
- GitHub Check: Trace nox tests (3, 13, trace_server)
- GitHub Check: Trace nox tests (3, 13, trace)
- GitHub Check: Trace nox tests (3, 12, scorers)
- GitHub Check: Trace nox tests (3, 12, llamaindex)
- GitHub Check: Trace nox tests (3, 12, trace_server)
- GitHub Check: Trace nox tests (3, 12, trace)
- GitHub Check: Trace nox tests (3, 11, scorers)
- GitHub Check: Trace nox tests (3, 11, llamaindex)
- GitHub Check: Trace nox tests (3, 11, trace_server)
- GitHub Check: Trace nox tests (3, 11, trace)
- GitHub Check: Trace nox tests (3, 10, scorers)
- GitHub Check: Trace nox tests (3, 10, llamaindex)
- GitHub Check: Trace nox tests (3, 10, trace_server)
- GitHub Check: Trace nox tests (3, 10, trace)
- GitHub Check: Trace nox tests (3, 9, scorers)
- GitHub Check: WeaveJS Lint and Compile
- GitHub Check: Trace nox tests (3, 13, pandas-test)
- GitHub Check: Trace nox tests (3, 13, llamaindex)
- GitHub Check: Trace nox tests (3, 13, trace_server)
- GitHub Check: Trace nox tests (3, 13, trace)
- GitHub Check: Trace nox tests (3, 12, scorers)
- GitHub Check: Trace nox tests (3, 12, llamaindex)
- GitHub Check: Trace nox tests (3, 12, trace_server)
- GitHub Check: Trace nox tests (3, 12, trace)
- GitHub Check: Trace nox tests (3, 11, scorers)
- GitHub Check: Trace nox tests (3, 11, llamaindex)
- GitHub Check: Trace nox tests (3, 11, trace_server)
- GitHub Check: Trace nox tests (3, 11, trace)
- GitHub Check: Trace nox tests (3, 10, scorers)
- GitHub Check: Trace nox tests (3, 10, llamaindex)
- GitHub Check: Trace nox tests (3, 10, trace_server)
- GitHub Check: Trace nox tests (3, 10, trace)
- GitHub Check: Trace nox tests (3, 9, scorers)
- GitHub Check: WeaveJS Lint and Compile
- GitHub Check: Trace nox tests (3, 13, pandas-test)
- GitHub Check: Trace nox tests (3, 13, llamaindex)
- GitHub Check: Trace nox tests (3, 13, trace_server)
- GitHub Check: Trace nox tests (3, 13, trace)
- GitHub Check: Trace nox tests (3, 12, scorers)
- GitHub Check: Trace nox tests (3, 12, llamaindex)
- GitHub Check: Trace nox tests (3, 12, trace_server)
- GitHub Check: Trace nox tests (3, 12, trace)
- GitHub Check: Trace nox tests (3, 11, scorers)
- GitHub Check: Trace nox tests (3, 11, llamaindex)
- GitHub Check: Trace nox tests (3, 11, trace_server)
- GitHub Check: Trace nox tests (3, 11, trace)
- GitHub Check: Trace nox tests (3, 10, scorers)
- GitHub Check: Trace nox tests (3, 10, trace_server)
- GitHub Check: Trace nox tests (3, 10, trace)
- GitHub Check: Trace nox tests (3, 9, scorers)
- GitHub Check: WeaveJS Lint and Compile
- GitHub Check: Trace nox tests (3, 13, pandas-test)
- GitHub Check: Trace nox tests (3, 13, llamaindex)
- GitHub Check: Trace nox tests (3, 13, trace_server)
- GitHub Check: Trace nox tests (3, 13, trace)
- GitHub Check: Trace nox tests (3, 12, scorers)
- GitHub Check: Trace nox tests (3, 12, llamaindex)
- GitHub Check: Trace nox tests (3, 12, trace_server)
- GitHub Check: Trace nox tests (3, 12, trace)
- GitHub Check: Trace nox tests (3, 11, scorers)
- GitHub Check: Trace nox tests (3, 11, trace_server)
- GitHub Check: Trace nox tests (3, 11, trace)
- GitHub Check: Trace nox tests (3, 10, scorers)
- GitHub Check: Trace nox tests (3, 10, trace_server)
- GitHub Check: Trace nox tests (3, 10, trace)
- GitHub Check: Trace nox tests (3, 9, scorers)
- GitHub Check: WeaveJS Lint and Compile
- GitHub Check: Trace nox tests (3, 13, pandas-test)
- GitHub Check: Trace nox tests (3, 13, llamaindex)
- GitHub Check: Trace nox tests (3, 13, trace_server)
- GitHub Check: Trace nox tests (3, 13, trace)
- GitHub Check: Trace nox tests (3, 12, scorers)
- GitHub Check: Trace nox tests (3, 12, llamaindex)
- GitHub Check: Trace nox tests (3, 12, trace_server)
- GitHub Check: Trace nox tests (3, 12, trace)
- GitHub Check: Trace nox tests (3, 11, scorers)
- GitHub Check: Trace nox tests (3, 11, trace_server)
- GitHub Check: Trace nox tests (3, 11, trace)
- GitHub Check: Trace nox tests (3, 10, scorers)
- GitHub Check: Trace nox tests (3, 10, trace_server)
- GitHub Check: Trace nox tests (3, 10, trace)
- GitHub Check: Trace nox tests (3, 9, scorers)
🔇 Additional comments (2)
weave-js/src/common/types/media.ts (2)
229-231
: Good implementation of the new utility function.The
isMediaString
function is a well-implemented TypeScript type predicate that follows the existing pattern of theisMediaCardType
function. This will enhance type safety when checking for valid media string types.
229-231
:❓ Verification inconclusive
Verify usage in the codebase.
To ensure all call sites are properly using this new function, it would be good to verify any existing code that might need to be updated to use this function instead of ad-hoc checks.
🏁 Script executed:
#!/bin/bash # Search for code that might be doing manual checks that could be replaced with isMediaString echo "Looking for potential places to use the new isMediaString function..." # Search for includes with mediaStrings rg -t ts -t tsx "includes.*mediaStrings" --ignore-file=src/common/types/media.ts # Search for other manual checks of media types rg -t ts -t tsx "(type\s*===\s*['\"](images|audio|html|table|plotly|video|object3D|bokeh|molecule|data-frame))" \ --ignore-file=src/common/types/media.tsLength of output: 575
🏁 Script executed:
#!/bin/bash # Corrected search for potential manual checks that could be replaced with isMediaString. echo "Searching for potential places to use the new isMediaString function..." # Using corrected ignore file path since the file is located at weave-js/src/common/types/media.ts rg -g "*.ts" -g "*.tsx" "includes.*mediaStrings" --ignore-file=weave-js/src/common/types/media.ts rg -g "*.ts" -g "*.tsx" "(type\s*===\s*['\"](images|audio|html|table|plotly|video|object3D|bokeh|molecule|data-frame))" --ignore-file=weave-js/src/common/types/media.tsLength of output: 14305
Manual Verification of Media Type Checks Required
The new
isMediaString
implementation looks correct. However, our automated search for legacy ad-hoc checks (using inclusion or strict equality against media type strings) yielded inconclusive results due to regex parsing issues. Please manually verify the following:
- Confirm that no call sites are performing manual checks against media types (e.g., using direct comparisons or
includes
onmediaStrings
) that should instead useisMediaString
.- Review components and functions related to media handling to ensure consistency in media type validation.
Preview this PR with FeatureBee: https://beta.wandb.ai/?betaVersion=06406b84f1e4501067dcee686bee7923467a66c3 |
Description
Creates a util for checking the metric type if it's a media string.
Testing
How was this PR tested?
See https://github.com/wandb/core/pull/27744
Summary by CodeRabbit