Conversation
|
Caution Review failedThe pull request is closed. """ WalkthroughThe changes refactor variable value extraction logic in the data source by removing custom pattern matching and multi-support handling. The Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant DataSource
participant TemplateSrv
Caller->>DataSource: query(options)
DataSource->>DataSource: getVariables(scopedVars)
DataSource->>TemplateSrv: replace($varName, scopedVars)
TemplateSrv-->>DataSource: resolvedValue
DataSource-->>Caller: query result
""" Note ⚡️ AI Code Reviews for VS Code, Cursor, WindsurfCodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback. Note ⚡️ Faster reviews with cachingCodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. 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 (
|
There was a problem hiding this comment.
Pull Request Overview
This PR replaces a custom multi-value extraction helper with Grafana’s built-in templateSrv.replace to interpret template variables, and switches variable indexing from id to name to support Grafana 12.
- Remove
valueFromVariableWithMultiSupport.tsand its imports - Update
getVariablesmethod to accept existing scoped vars, usetemplateSrv.replace, and key byvariable.name - Adjust merging of scoped variables before query execution
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/variable/valueFromVariableWithMultiSupport.ts | Removed deprecated helper for multi-value variable extraction |
| src/DataSource.ts | Refactored getVariables to use templateSrv.replace and index by name |
Comments suppressed due to low confidence (1)
src/DataSource.ts:291
- The key type for
variableOptionsshould reflect the new use ofvariable.name(a string) instead ofVariableWithMultiSupport['id']. Update the record type toRecord<string, VariableOption>or a more specific alias.
const variableOptions: Record<VariableWithMultiSupport['id'], VariableOption> = {};
There was a problem hiding this comment.
Actionable comments posted: 1
🔭 Outside diff range comments (1)
src/DataSource.ts (1)
290-312:⚠️ Potential issueKey type does not match the new indexing strategy
variableOptionsis declared as
Record<VariableWithMultiSupport['id'], VariableOption>(i.e. a number key),
yet keys are now populated withvariable.name(a string).
This will failtscwithTS2322in strict projects.-const variableOptions: Record<VariableWithMultiSupport['id'], VariableOption> = {}; +const variableOptions: Record<string, VariableOption> = {};After this change you can also remove the still-imported but now unused
VariableWithMultiSupporttype alias at the top of the file.
🧹 Nitpick comments (2)
src/DataSource.ts (2)
303-304: Pass an explicit format totemplateSrv.replace
templateSrv.replacedefaults to the string formatter, which performs un-escaped substitutions inside JSON strings.
When variables are used in JSON payloads, this may lead to malformed JSON or double-quoting issues.-const value = getTemplateSrv().replace('$' + variable.name, scopedVars); +const value = getTemplateSrv().replace('$' + variable.name, scopedVars, 'json');Using
json(orregexwhere appropriate) ensures safe escaping and mirrors
the formatters used elsewhere in the file (processPayload,listMetrics, …).
305-308: Preserveselectedstate instead of hard-codingfalseThe builder UI might rely on the
selectedflag to render the current value.
Using a constantfalsedrops that information:-variableOptions[variable.name] = { - selected: false, - text: variable.current.text, - value: value, -}; +variableOptions[variable.name] = { + selected: variable.current.selected ?? false, + text: variable.current.text, + value, +};
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/DataSource.ts(3 hunks)src/variable/valueFromVariableWithMultiSupport.ts(0 hunks)
💤 Files with no reviewable changes (1)
- src/variable/valueFromVariableWithMultiSupport.ts
🧰 Additional context used
🪛 GitHub Actions: CI
src/DataSource.ts
[error] 1-1: Prettier formatting check failed. Run 'prettier --write' to fix code style issues in this file.
🔇 Additional comments (1)
src/DataSource.ts (1)
1-315: Run Prettier ‑ formatting check is failingCI reports a Prettier failure for this file.
Runprettier --write src/DataSource.ts(ornpm run format) to keep the
commit stream green.🧰 Tools
🪛 Biome (1.9.4)
[error] 220-220: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
🪛 GitHub Actions: CI
[error] 1-1: Prettier formatting check failed. Run 'prettier --write' to fix code style issues in this file.
Index by name property. Grafana 12 does not have `variable.id` property (checked on b674c3157915f1bd16257b46889ae3a28bb790a5)
Index by name property. Grafana 12 does not have
variable.idproperty (checked on b674c3157915f1bd16257b46889ae3a28bb790a5)Summary by CodeRabbit