- 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.
22 lines
558 B
TypeScript
22 lines
558 B
TypeScript
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;
|
|
}
|
|
};
|