Skip to content

Conversation

@ktx-vaidehi
Copy link
Collaborator

@ktx-vaidehi ktx-vaidehi commented Sep 22, 2025

PR Type

Bug fix


Description

  • Fix alias lowercase conversion with non-strings

Diagram Walkthrough

flowchart LR
  getDataValue["getDataValue in aliasUtils.ts"]
  aliasInput["alias input (any type)"]
  toStringLower["toString() then toLowerCase()"]
  propertyAccess["Safe property access on obj"]

  aliasInput -- "fallback path" --> toStringLower
  toStringLower -- "compute lowercase key" --> propertyAccess
  propertyAccess -- "return value" --> getDataValue
Loading

File Walkthrough

Relevant files
Bug fix
aliasUtils.ts
Safe lowercase conversion for alias keys                                 

web/src/utils/dashboard/aliasUtils.ts

  • Add toString() before toLowerCase().
  • Prevent errors when alias isn't a string.
+1/-1     

@github-actions github-actions bot added the ☢️ Bug Something isn't working label Sep 22, 2025
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Summary

This PR fixes a runtime error in the dashboard's data value retrieval system by adding type safety to the getDataValue function in aliasUtils.ts. The core change is on line 17, where alias?.toLowerCase() is replaced with alias?.toString()?.toLowerCase(). This modification prevents TypeError exceptions that occur when the alias parameter is not a string type (e.g., numbers, objects, or other data types).

The getDataValue function is a utility that retrieves values from objects using either an exact alias match or a case-insensitive lookup. This function appears to be used extensively throughout the dashboard system, particularly in data processing pipelines where object keys might originate from various sources and could be different data types. The dashboard panel system (as evidenced by the useDashboardPanel.ts context) dynamically assigns aliases to fields like x_axis_1, y_axis_1, etc., and these aliases flow through the data processing chain.

By adding toString() before toLowerCase(), the function becomes more defensive and robust, ensuring it can handle various data types that might be used as object keys in dashboard configurations. This is particularly important in dynamic environments where field names and aliases might come from user input, API responses, or computed values that aren't guaranteed to be strings.

Confidence score: 4/5

  • This PR is safe to merge with minimal risk as it's a defensive programming improvement that prevents runtime crashes
  • Score reflects a straightforward type safety fix that handles edge cases without changing core functionality or introducing breaking changes
  • No files require special attention as this is an isolated utility function fix with clear intent

1 file reviewed, no comments

Edit Code Review Bot Settings | Greptile

@github-actions
Copy link
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 1 🔵⚪⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Behavior Change

Using alias?.toString()?.toLowerCase() changes behavior for non-string aliases (e.g., numbers, symbols, objects). Confirm this is intended and that downstream usage expects stringified keys rather than previous behavior (which would have thrown for non-strings).

return obj?.[alias] || obj?.[alias?.toString()?.toLowerCase()];
Falsy Value Handling

Using || may skip valid falsy values (0, false, ''), incorrectly falling back to lowercase key. Consider using nullish coalescing (??) to avoid masking valid falsy data.

return obj?.[alias] || obj?.[alias?.toString()?.toLowerCase()];

@github-actions
Copy link
Contributor

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Guard type and simplify call

Avoid double optional chaining on a non-null result from toString(), and ensure only
string aliases are lowercased. This prevents unexpected behavior when alias is an
object with custom toString or when it's nullish.

web/src/utils/dashboard/aliasUtils.ts [17]

-return obj?.[alias] || obj?.[alias?.toString()?.toLowerCase()];
+return obj?.[alias] || (typeof alias === 'string' ? obj?.[alias.toLowerCase()] : undefined);
Suggestion importance[1-10]: 6

__

Why: The existing code lowercases alias?.toString()?.toLowerCase(), which can coerce non-strings and uses redundant optional chaining; guarding with typeof alias === 'string' is safer and clearer. Impact is moderate as it improves robustness but not a critical bug fix.

Low

@ktx-vaidehi ktx-vaidehi force-pushed the fix/dashboard/lowercase-issue branch 5 times, most recently from 15af534 to 58a6f55 Compare September 22, 2025 11:53
@ktx-vaidehi ktx-vaidehi force-pushed the fix/dashboard/lowercase-issue branch from 58a6f55 to 5ce131b Compare September 23, 2025 05:16
@ktx-vaidehi ktx-vaidehi merged commit 02fb65d into main Sep 23, 2025
42 of 44 checks passed
@ktx-vaidehi ktx-vaidehi deleted the fix/dashboard/lowercase-issue branch September 23, 2025 06:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

☢️ Bug Something isn't working Review effort 1/5

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants