Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/scenes/src/variables/interpolation/formatRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ALL_VARIABLE_VALUE } from '../constants';
import { SceneObjectUrlSyncHandler } from '../../core/types';

export interface FormatRegistryItem extends RegistryItem {
formatter(value: VariableValue, args: string[], variable: FormatVariable): string;
formatter(value: VariableValue, args: string[], variable: FormatVariable, fieldPath?: string): string;
}

/**
Expand Down Expand Up @@ -314,9 +314,9 @@ export const formatRegistry = new Registry<FormatRegistryItem>(() => {
id: VariableFormatID.Text,
name: 'Text',
description: 'Format variables in their text representation. Example in multi-variable scenario A + B + C.',
formatter: (value, _args, variable) => {
formatter: (value, _args, variable, fieldPath) => {
if (variable.getValueText) {
return variable.getValueText();
return variable.getValueText(fieldPath);
Copy link
Collaborator

Choose a reason for hiding this comment

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

is there a bug report for someone using text formatter with fieldPath?

this feels a but messy / wrong fix, the cleaner solutionn feels like it woudl be to pass in the value and text representation to the formatter, but feels a bit bad from a performance standpoint to always call getValue and getValueText

}

return String(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function sceneInterpolator(
return match;
}

const value = formatValue(sceneObject, variable, variable.getValue(fieldPath), fmt);
const value = formatValue(sceneObject, variable, variable.getValue(fieldPath), fmt, fieldPath);

if (interpolations) {
interpolations.push({ match, variableName, fieldPath, format: fmt, value, found: value !== match });
Expand Down Expand Up @@ -85,7 +85,8 @@ function formatValue(
context: SceneObject,
variable: FormatVariable,
value: VariableValue | undefined | null,
formatNameOrFn?: InterpolationFormatParameter
formatNameOrFn?: InterpolationFormatParameter,
fieldPath?: string
): string {
if (value === null || value === undefined) {
return '';
Expand Down Expand Up @@ -133,5 +134,5 @@ function formatValue(
formatter = formatRegistry.get(VariableFormatID.Glob);
}

return formatter.formatter(value, args, variable);
return formatter.formatter(value, args, variable, fieldPath);
}