Support template variables in command menu item labels (#18707)
- Adds template variable interpolation (`${...}`) to command menu item
labels and short labels, enabling dynamic text like `Create new
${capitalize(objectMetadataItem.labelSingular)}` instead of static
`Create new record`.
- Supports `capitalize` and `lowercase` transform functions within
template expressions.
This commit is contained in:
+21
@@ -0,0 +1,21 @@
|
||||
import { isNonEmptyString } from '@sniptt/guards';
|
||||
import { type EvaluationContext } from 'expr-eval-fork';
|
||||
|
||||
import { conditionalAvailabilityParser } from './conditionalAvailabilityParser';
|
||||
|
||||
export const evaluateConditionalAvailabilityExpression = (
|
||||
expression: string | null | undefined,
|
||||
context: EvaluationContext,
|
||||
): boolean => {
|
||||
if (!isNonEmptyString(expression)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
const parsed = conditionalAvailabilityParser.parse(expression);
|
||||
|
||||
return parsed.evaluate(context) === true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user