-
Notifications
You must be signed in to change notification settings - Fork 5
feat: replace builtin variables in string #27
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
Conversation
| ): string { | ||
| const variableSyntax = '$' + varName; | ||
| const alternativeVariableSyntax = '${' + varName + (varFormat ? ':' + varFormat : '') + '}'; | ||
| const builtInVariableSyntax = varName.includes('__') ? varName : undefined; |
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.
this will assume that variable names containing __ are not possible or are mistaken by builtIn variables. something__not__built_in
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.
Sorry I didn't get this comment.
Could you make a realistic example?
A custom variable will be found and replaced with the following patterns
- $var
- ${var}
It seems built-in variables always start with __
{
"builtin": {
"__from": {
"loading": false,
"value": "1768229967725"
},
"__to": {
"loading": false,
"value": "1768233567725"
},
/* some others */
}
}Am I missing something?
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.
this validation will take this as a builtIn variable something__not__a__built__in__variable
2036e3b to
c30015d
Compare
| // 3. ${variableName:format} - This is a more complex format that allows specifying a format interpolation. | ||
|
|
||
| const VARIABLE_REGEX = /\$(\w+)|\${(\w+)(?:\.([^:^}]+))?(?::([^}]+))?}/gm; | ||
| const VARIABLE_REGEX = /\$(\w+)|\${(\w+)(?:\.([^:^}]+))?(?::([^}]+))?}|__(\w+)/gm; |
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.
| const VARIABLE_REGEX = /\$(\w+)|\${(\w+)(?:\.([^:^}]+))?(?::([^}]+))?}|__(\w+)/gm; | |
| const VARIABLE_REGEX = /\$(\w+)|\${(\w+)(?:\.([^:^}]+))?(?::([^}]+))?}|^__(\w+)/gm; |
Signed-off-by: Mahmoud Shahrokni <seyedmahmoud.shahrokni@amadeus.com> Signed-off-by: Mahmoud Shahrokni <seyedmahmoud.shahrokni@amadeus.com> Signed-off-by: Mahmoud Shahrokni <seyedmahmoud.shahrokni@amadeus.com> Signed-off-by: Mahmoud Shahrokni <seyedmahmoud.shahrokni@amadeus.com>
c30015d to
61961b1
Compare
| { | ||
| text: 'hello $var1 $var1', | ||
| variableValues: { var1: { value: 'world', loading: false } }, | ||
| variableValues: { var1: { value: 'world', loading: false } } as VariableStateMap, |
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.
instead of casting each value we could add the correct type to the const
| expected: 'world world 123 456', | ||
| }, | ||
| { | ||
| text: '$from __from', |
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.
aren't the built in variables in the format $__<variable>? meaning they will be already covered in __<variable> as the match is $(\w+)
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.
I think Built-in variables (which start with __ ) should be placed directly into a string. (As long as I understood)
I am checking other dashboarding applications, and if I am not mistaken they are suggesting we should be able to put the built-in variables directly into a dataLink.
Please take a look at this and let me know if it makes sense
https://grafana.com/docs/grafana/latest/visualizations/panels-visualizations/configure-data-links/
This test specifically
This test simply checks if it is possible to have a custom variable, identical to a built-in one
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.
IIUC, when they are searched on text, either queries or links. all the variables have the format $<variable> or ${<variable>}. Built in variables fall into the first format $__<built-in-variable>
Description 🖊️
A dataLink may include built-in variables. Ideally all variables could be placed in the dataLink.
So far, the function which has been responsible for the variable replacement has not covered the built-in variables.
This change finds the built-in variables in a string and replace them with their respective values.
The new regex covers the built-in variables
Checklist
[<catalog_entry>] <commit message>naming convention using one of thefollowing
catalog_entryvalues:FEATURE,ENHANCEMENT,BUGFIX,BREAKINGCHANGE,DOC,IGNORE.UI Changes
See e2e docs for more details. Common issues include: