mirror of
https://gitee.com/nocobase/nocobase.git
synced 2024-12-02 12:18:15 +08:00
fix(variable): compat $date (#2971)
* fix(variable): compat $date * chore: update tests
This commit is contained in:
parent
b109a5751b
commit
bafb03a228
@ -140,6 +140,33 @@ describe('useVariables', () => {
|
||||
await waitFor(async () => {
|
||||
expect(result.current.ctxRef.current).toMatchInlineSnapshot(`
|
||||
{
|
||||
"$date": {
|
||||
"last30Days": [Function],
|
||||
"last7Days": [Function],
|
||||
"last90Days": [Function],
|
||||
"lastIsoWeek": [Function],
|
||||
"lastMonth": [Function],
|
||||
"lastQuarter": [Function],
|
||||
"lastWeek": [Function],
|
||||
"lastYear": [Function],
|
||||
"next30Days": [Function],
|
||||
"next7Days": [Function],
|
||||
"next90Days": [Function],
|
||||
"nextIsoWeek": [Function],
|
||||
"nextMonth": [Function],
|
||||
"nextQuarter": [Function],
|
||||
"nextWeek": [Function],
|
||||
"nextYear": [Function],
|
||||
"now": [Function],
|
||||
"thisIsoWeek": [Function],
|
||||
"thisMonth": [Function],
|
||||
"thisQuarter": [Function],
|
||||
"thisWeek": [Function],
|
||||
"thisYear": [Function],
|
||||
"today": [Function],
|
||||
"tomorrow": [Function],
|
||||
"yesterday": [Function],
|
||||
},
|
||||
"$nDate": {
|
||||
"last30Days": [Function],
|
||||
"last7Days": [Function],
|
||||
@ -323,6 +350,33 @@ describe('useVariables', () => {
|
||||
await waitFor(async () => {
|
||||
expect(result.current.ctxRef.current).toMatchInlineSnapshot(`
|
||||
{
|
||||
"$date": {
|
||||
"last30Days": [Function],
|
||||
"last7Days": [Function],
|
||||
"last90Days": [Function],
|
||||
"lastIsoWeek": [Function],
|
||||
"lastMonth": [Function],
|
||||
"lastQuarter": [Function],
|
||||
"lastWeek": [Function],
|
||||
"lastYear": [Function],
|
||||
"next30Days": [Function],
|
||||
"next7Days": [Function],
|
||||
"next90Days": [Function],
|
||||
"nextIsoWeek": [Function],
|
||||
"nextMonth": [Function],
|
||||
"nextQuarter": [Function],
|
||||
"nextWeek": [Function],
|
||||
"nextYear": [Function],
|
||||
"now": [Function],
|
||||
"thisIsoWeek": [Function],
|
||||
"thisMonth": [Function],
|
||||
"thisQuarter": [Function],
|
||||
"thisWeek": [Function],
|
||||
"thisYear": [Function],
|
||||
"today": [Function],
|
||||
"tomorrow": [Function],
|
||||
"yesterday": [Function],
|
||||
},
|
||||
"$nDate": {
|
||||
"last30Days": [Function],
|
||||
"last7Days": [Function],
|
||||
@ -379,6 +433,33 @@ describe('useVariables', () => {
|
||||
await waitFor(async () => {
|
||||
expect(result.current.ctxRef.current).toMatchInlineSnapshot(`
|
||||
{
|
||||
"$date": {
|
||||
"last30Days": [Function],
|
||||
"last7Days": [Function],
|
||||
"last90Days": [Function],
|
||||
"lastIsoWeek": [Function],
|
||||
"lastMonth": [Function],
|
||||
"lastQuarter": [Function],
|
||||
"lastWeek": [Function],
|
||||
"lastYear": [Function],
|
||||
"next30Days": [Function],
|
||||
"next7Days": [Function],
|
||||
"next90Days": [Function],
|
||||
"nextIsoWeek": [Function],
|
||||
"nextMonth": [Function],
|
||||
"nextQuarter": [Function],
|
||||
"nextWeek": [Function],
|
||||
"nextYear": [Function],
|
||||
"now": [Function],
|
||||
"thisIsoWeek": [Function],
|
||||
"thisMonth": [Function],
|
||||
"thisQuarter": [Function],
|
||||
"thisWeek": [Function],
|
||||
"thisYear": [Function],
|
||||
"today": [Function],
|
||||
"tomorrow": [Function],
|
||||
"yesterday": [Function],
|
||||
},
|
||||
"$nDate": {
|
||||
"last30Days": [Function],
|
||||
"last7Days": [Function],
|
||||
|
@ -31,6 +31,14 @@ const useBuiltInVariables = () => {
|
||||
name: '$nDate',
|
||||
ctx: dateVars,
|
||||
},
|
||||
/**
|
||||
* @deprecated
|
||||
* 兼容旧版本的 `$date` 变量,新版本已弃用
|
||||
*/
|
||||
{
|
||||
name: '$date',
|
||||
ctx: dateVars,
|
||||
},
|
||||
/**
|
||||
* @deprecated
|
||||
* 兼容旧版本的 `$system` 变量,新版本已弃用
|
||||
|
@ -4,6 +4,7 @@ import { useFormBlockContext } from '../../block-provider';
|
||||
import { useCollection } from '../../collection-manager';
|
||||
import { useRecord } from '../../record-provider';
|
||||
import { useSubFormValue } from '../../schema-component/antd/association-field/hooks';
|
||||
import { getDateRanges } from '../../schema-component/antd/date-picker/util';
|
||||
import { useBlockCollection } from '../../schema-settings/VariableInput/hooks/useBlockCollection';
|
||||
import { VariableOption } from '../types';
|
||||
|
||||
@ -31,6 +32,7 @@ const useLocalVariables = (props?: Props) => {
|
||||
}
|
||||
|
||||
return useMemo(() => {
|
||||
const dateVars = getDateRanges();
|
||||
return (
|
||||
[
|
||||
/**
|
||||
@ -75,6 +77,18 @@ const useLocalVariables = (props?: Props) => {
|
||||
ctx: form?.values,
|
||||
collectionName: name,
|
||||
},
|
||||
{
|
||||
name: '$nDate',
|
||||
ctx: dateVars,
|
||||
},
|
||||
/**
|
||||
* @deprecated
|
||||
* 兼容旧版本的 `$date` 变量,新版本已弃用
|
||||
*/
|
||||
{
|
||||
name: '$date',
|
||||
ctx: dateVars,
|
||||
},
|
||||
subFormValue && { name: '$iteration', ctx: subFormValue, collectionName: currentCollectionName },
|
||||
] as VariableOption[]
|
||||
).filter(Boolean);
|
||||
|
Loading…
Reference in New Issue
Block a user