diff --git a/packages/core/src/formula/visitor.spec.ts b/packages/core/src/formula/visitor.spec.ts index a1ef68bbd..64d784aac 100644 --- a/packages/core/src/formula/visitor.spec.ts +++ b/packages/core/src/formula/visitor.spec.ts @@ -1,8 +1,14 @@ /* eslint-disable sonarjs/no-duplicate-string */ /* eslint-disable @typescript-eslint/no-explicit-any */ import { plainToInstance } from 'class-transformer'; +import { DateFormattingPreset, TimeFormatting } from '../models'; import { CellValueType, DbFieldType, FieldType } from '../models/field/constant'; -import { LinkFieldCore, FormulaFieldCore, NumberFieldCore } from '../models/field/derivate'; +import { + LinkFieldCore, + FormulaFieldCore, + NumberFieldCore, + DateFieldCore, +} from '../models/field/derivate'; import type { FieldCore } from '../models/field/field'; import type { IRecord } from '../models/record'; import { evaluate } from './evaluate'; @@ -15,6 +21,7 @@ describe('EvalVisitor', () => { fldNumber: 8, fldMultipleNumber: [1, 2, 3], fldMultipleLink: [{ id: 'recxxxxxxx' }, { id: 'recyyyyyyy', title: 'A2' }], + fldDate: new Date('2024-01-01'), }, createdTime: new Date().toISOString(), }; @@ -31,6 +38,21 @@ describe('EvalVisitor', () => { cellValueType: CellValueType.Number, }; + const dateFieldJson = { + id: 'fldDate', + name: 'fldDateName', + description: 'A test date field', + type: FieldType.Date, + options: { + formatting: { + date: DateFormattingPreset.ISO, + time: TimeFormatting.None, + timeZone: 'Asia/Shanghai', + }, + }, + cellValueType: CellValueType.DateTime, + }; + const multipleNumberFieldJson = { id: 'fldMultipleNumber', name: 'fldMultipleNumberName', @@ -58,10 +80,12 @@ describe('EvalVisitor', () => { const numberField = plainToInstance(NumberFieldCore, numberFieldJson); const multipleNumberField = plainToInstance(NumberFieldCore, multipleNumberFieldJson); const multipleLinkField = plainToInstance(LinkFieldCore, multipleLinkFieldJson); + const dateField = plainToInstance(DateFieldCore, dateFieldJson); fieldContext = { [numberField.id]: numberField, [multipleNumberField.id]: multipleNumberField, [multipleLinkField.id]: multipleLinkField, + [dateField.id]: dateField, }; }); @@ -220,6 +244,10 @@ describe('EvalVisitor', () => { expect(() => evalFormula('{}', fieldContext, record)).toThrowError(); }); + it('should calculate date field when value type is Date', () => { + expect(evalFormula('{fldDate}', fieldContext, record)).toEqual('2024-01-01'); + }); + it('should calculate multiple number field', () => { expect(evalFormula('{fldMultipleNumber}', fieldContext, record)).toEqual([1, 2, 3]); }); diff --git a/packages/core/src/formula/visitor.ts b/packages/core/src/formula/visitor.ts index 26c8efc34..eeeb41b72 100644 --- a/packages/core/src/formula/visitor.ts +++ b/packages/core/src/formula/visitor.ts @@ -297,7 +297,11 @@ export class EvalVisitor private createTypedValueByField(field: FieldCore) { let value: any = this.record ? this.record.fields[field.id] : null; - if (value == null || field.cellValueType !== CellValueType.String) { + + if ( + value == null || + ![CellValueType.String, CellValueType.DateTime].includes(field.cellValueType) + ) { return new TypedValue(value, field.cellValueType, field.isMultipleCellValue, field); } diff --git a/packages/sdk/src/components/grid-enhancements/hooks/use-grid-selection.ts b/packages/sdk/src/components/grid-enhancements/hooks/use-grid-selection.ts index 031078fb1..6b6679925 100644 --- a/packages/sdk/src/components/grid-enhancements/hooks/use-grid-selection.ts +++ b/packages/sdk/src/components/grid-enhancements/hooks/use-grid-selection.ts @@ -173,12 +173,6 @@ export const useGridSelection = (props: IUseGridSelectionProps) => { if (recordMap[rowIndex]?.id === activeRecordId) return; - const isVisibleRecord = Object.values(recordMap).find( - (record) => record?.id === activeRecordId - ); - - if (isVisibleRecord) return; - mutateGetRecordStatus({ tableId, recordId: activeCell.recordId,