mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-08 23:19:26 +08:00
feat: update extractTemplateElements to return helpers and refactor usage in VariablesProvider
This commit is contained in:
parent
21d45bf59a
commit
967724929c
@ -277,7 +277,7 @@ const VariablesProvider = ({ children, filterVariables }: any) => {
|
|||||||
fieldOperator?: string | void;
|
fieldOperator?: string | void;
|
||||||
},
|
},
|
||||||
) => {
|
) => {
|
||||||
const { fullVariable, filters } = extractTemplateElements(str);
|
const { fullVariable, helpers } = extractTemplateElements(str);
|
||||||
if (!fullVariable) {
|
if (!fullVariable) {
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
@ -288,8 +288,8 @@ const VariablesProvider = ({ children, filterVariables }: any) => {
|
|||||||
|
|
||||||
const path = getPath(str);
|
const path = getPath(str);
|
||||||
const result = await getResult(path, localVariables as VariableOption[], options);
|
const result = await getResult(path, localVariables as VariableOption[], options);
|
||||||
if (Array.isArray(filters) && filters.length > 0) {
|
if (Array.isArray(helpers) && helpers.length > 0) {
|
||||||
result.value = filters.reduce((acc, filter) => filter.handler(...[acc, ...filter.args]), result.value);
|
result.value = helpers.reduce((acc, helper) => helper.handler(...[acc, ...helper.args]), result.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -28,7 +28,11 @@ export function extractTemplateVariable(template: string): string | null {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function extractTemplateElements(template: string) {
|
export function extractTemplateElements(template: string): {
|
||||||
|
fullVariable: string | null;
|
||||||
|
variableSegments: string[];
|
||||||
|
helpers: Filter[];
|
||||||
|
} {
|
||||||
const escapedTemplate = escape(template ?? '');
|
const escapedTemplate = escape(template ?? '');
|
||||||
try {
|
try {
|
||||||
const fullVariable = engine.fullVariablesSync(escapedTemplate)[0] ?? '';
|
const fullVariable = engine.fullVariablesSync(escapedTemplate)[0] ?? '';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user