-
Notifications
You must be signed in to change notification settings - Fork 1
/
getFieldType.ts
55 lines (51 loc) · 1.66 KB
/
getFieldType.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// @ts-nocheck
import { ISchemaFieldMap, FieldDataType } from "./types/index.types";
export function getFieldType(fieldSchema: ISchemaFieldMap): FieldDataType {
if (!fieldSchema) return;
if (Object.hasOwnProperty.call(fieldSchema, "extension_uid")) {
return FieldDataType.CUSTOM_FIELD;
}
switch (fieldSchema.data_type) {
case "text": {
if (fieldSchema.field_metadata?.multiline) {
return FieldDataType.MULTILINE;
} else if (fieldSchema.field_metadata?.allow_rich_text) {
return FieldDataType.HTML_RTE;
} else if (fieldSchema.field_metadata?.markdown) {
return FieldDataType.MARKDOWN_RTE;
} else if (fieldSchema.enum) {
return FieldDataType.SELECT;
} else if (
fieldSchema.uid === "url" &&
fieldSchema.field_metadata?._default
) {
return FieldDataType.URL;
} else {
return FieldDataType.SINGLELINE;
}
}
case "json": {
if (fieldSchema.field_metadata?.allow_json_rte) {
return FieldDataType.JSON_RTE;
}
break;
}
case "blocks": {
return "modular_block";
}
case "link":
case "isodate":
case "boolean":
case "block":
case "number":
case "reference":
case "group":
case "experience_container":
case "file":
case "taxonomy":
case "global_field": {
return FieldDataType[fieldSchema.data_type.toUpperCase()];
}
}
return "";
}