feat: simplify imports in HelperList and update ctx-func test to use extractTemplateVariable

This commit is contained in:
Sheldon Guo 2025-03-13 10:02:10 +08:00
parent d385c2b325
commit 4c92a8a788
3 changed files with 5 additions and 10 deletions

View File

@ -7,14 +7,8 @@
* For more information, please refer to: https://www.nocobase.com/agreement.
*/
import React, { useState, useMemo, useContext } from 'react';
import React from 'react';
import { observer } from '@formily/reactive-react';
import type { MenuProps } from 'antd';
import { Dropdown, Popover } from 'antd';
import { FilterOutlined } from '@ant-design/icons';
import { useCompile } from '../../../hooks';
import { useApp } from '../../../../application';
import { addHelper } from './observables';
import { helpersObs } from './observables';
import { Helper } from './Helper';
const _HelperList = () => {

View File

@ -8,14 +8,15 @@
*/
import get from 'lodash/get';
import { createJSONTemplateParser } from '../parser';
import { extractTemplateVariable } from '../utils';
const parser = createJSONTemplateParser();
describe('ctx function', () => {
it('should handle basic context function', () => {
const template = '{{}}';
const variable = parser.engine.fullVariablesSync(template);
console.log(variable);
const variable = extractTemplateVariable(template);
expect(variable).toBe(null);
});
it('should handle basic context function with state', () => {
const template = '{{$user.id}} - {{$user.name}}';

View File

@ -176,7 +176,7 @@ export const parseFilter = async (filter: any, opts: ParseFilterOptions = {}) =>
if (typeof value === 'string') {
const match = re.exec(value);
if (match) {
const { fullVariable: key, filters: helpers } = extractTemplateElements(value);
const { fullVariable: key, helpers } = extractTemplateElements(value);
const val = getValuesByPath(vars, key, null);
const field = getField?.(path);
if (key.startsWith('$date') || key.startsWith('$nDate')) {