-
-
Notifications
You must be signed in to change notification settings - Fork 752
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: record history rendering issues (#1064)
* fix: record history rendering crash * fix: select editor rendering * fix: duplicate record API return value
- Loading branch information
Showing
11 changed files
with
102 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { z } from 'zod'; | ||
import { assertNever } from '../../asserts'; | ||
import { FieldType } from './constant'; | ||
import { | ||
attachmentCellValueSchema, | ||
autoNumberCellValueSchema, | ||
dataFieldCellValueSchema, | ||
getFormulaCellValueSchema, | ||
linkCellValueSchema, | ||
numberCellValueSchema, | ||
singleLineTextCelValueSchema, | ||
userCellValueSchema, | ||
} from './derivate'; | ||
import type { IFieldVo } from './field.schema'; | ||
|
||
const validateWithSchema = (schema: z.ZodType, value: unknown) => { | ||
return z | ||
.union([z.array(schema).nonempty(), schema]) | ||
.nullable() | ||
.safeParse(value); | ||
}; | ||
|
||
export const validateCellValue = (field: IFieldVo, cellValue: unknown) => { | ||
const { type, cellValueType } = field; | ||
|
||
switch (type) { | ||
case FieldType.LongText: | ||
case FieldType.SingleLineText: | ||
case FieldType.SingleSelect: | ||
case FieldType.MultipleSelect: | ||
return validateWithSchema(singleLineTextCelValueSchema, cellValue); | ||
case FieldType.Number: | ||
return validateWithSchema(numberCellValueSchema, cellValue); | ||
case FieldType.Rating: | ||
case FieldType.AutoNumber: | ||
return validateWithSchema(autoNumberCellValueSchema, cellValue); | ||
case FieldType.Attachment: | ||
return attachmentCellValueSchema.nonempty().nullable().safeParse(cellValue); | ||
case FieldType.Date: | ||
case FieldType.CreatedTime: | ||
case FieldType.LastModifiedTime: | ||
return validateWithSchema(dataFieldCellValueSchema, cellValue); | ||
case FieldType.Checkbox: | ||
return validateWithSchema(z.literal(true), cellValue); | ||
case FieldType.Link: | ||
return validateWithSchema(linkCellValueSchema, cellValue); | ||
case FieldType.User: | ||
case FieldType.CreatedBy: | ||
case FieldType.LastModifiedBy: | ||
return validateWithSchema(userCellValueSchema, cellValue); | ||
case FieldType.Rollup: | ||
case FieldType.Formula: { | ||
const schema = getFormulaCellValueSchema(cellValueType); | ||
return validateWithSchema(schema, cellValue); | ||
} | ||
case FieldType.Button: | ||
case FieldType.Count: | ||
case FieldType.Duration: | ||
throw new Error('did not implement yet'); | ||
default: | ||
assertNever(type); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters