fix(variable): compat $date (#2971)

* fix(variable): compat $date

* chore: update tests
This commit is contained in:
被雨水过滤的空气-Rain 2023-11-06 07:10:41 +08:00 committed by GitHub
parent b109a5751b
commit bafb03a228
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 103 additions and 0 deletions

View File

@ -140,6 +140,33 @@ describe('useVariables', () => {
await waitFor(async () => { await waitFor(async () => {
expect(result.current.ctxRef.current).toMatchInlineSnapshot(` 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": { "$nDate": {
"last30Days": [Function], "last30Days": [Function],
"last7Days": [Function], "last7Days": [Function],
@ -323,6 +350,33 @@ describe('useVariables', () => {
await waitFor(async () => { await waitFor(async () => {
expect(result.current.ctxRef.current).toMatchInlineSnapshot(` 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": { "$nDate": {
"last30Days": [Function], "last30Days": [Function],
"last7Days": [Function], "last7Days": [Function],
@ -379,6 +433,33 @@ describe('useVariables', () => {
await waitFor(async () => { await waitFor(async () => {
expect(result.current.ctxRef.current).toMatchInlineSnapshot(` 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": { "$nDate": {
"last30Days": [Function], "last30Days": [Function],
"last7Days": [Function], "last7Days": [Function],

View File

@ -31,6 +31,14 @@ const useBuiltInVariables = () => {
name: '$nDate', name: '$nDate',
ctx: dateVars, ctx: dateVars,
}, },
/**
* @deprecated
* `$date`
*/
{
name: '$date',
ctx: dateVars,
},
/** /**
* @deprecated * @deprecated
* `$system` * `$system`

View File

@ -4,6 +4,7 @@ import { useFormBlockContext } from '../../block-provider';
import { useCollection } from '../../collection-manager'; import { useCollection } from '../../collection-manager';
import { useRecord } from '../../record-provider'; import { useRecord } from '../../record-provider';
import { useSubFormValue } from '../../schema-component/antd/association-field/hooks'; 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 { useBlockCollection } from '../../schema-settings/VariableInput/hooks/useBlockCollection';
import { VariableOption } from '../types'; import { VariableOption } from '../types';
@ -31,6 +32,7 @@ const useLocalVariables = (props?: Props) => {
} }
return useMemo(() => { return useMemo(() => {
const dateVars = getDateRanges();
return ( return (
[ [
/** /**
@ -75,6 +77,18 @@ const useLocalVariables = (props?: Props) => {
ctx: form?.values, ctx: form?.values,
collectionName: name, collectionName: name,
}, },
{
name: '$nDate',
ctx: dateVars,
},
/**
* @deprecated
* `$date`
*/
{
name: '$date',
ctx: dateVars,
},
subFormValue && { name: '$iteration', ctx: subFormValue, collectionName: currentCollectionName }, subFormValue && { name: '$iteration', ctx: subFormValue, collectionName: currentCollectionName },
] as VariableOption[] ] as VariableOption[]
).filter(Boolean); ).filter(Boolean);