More typings
This commit is contained in:
parent
26d1243e68
commit
be1eef2976
|
@ -19,17 +19,12 @@ const columnTypeManyParser = {
|
||||||
field: {
|
field: {
|
||||||
timeOnly?: boolean
|
timeOnly?: boolean
|
||||||
dateOnly?: boolean
|
dateOnly?: boolean
|
||||||
ignoreTimezones?: boolean
|
|
||||||
}
|
}
|
||||||
) => {
|
) => {
|
||||||
function parseDate(value: any) {
|
function parseDate(value: any) {
|
||||||
const { timeOnly, dateOnly, ignoreTimezones } = field || {}
|
const { timeOnly, dateOnly } = field || {}
|
||||||
const enableTime = !dateOnly
|
const enableTime = !dateOnly
|
||||||
const parsedValue = Helpers.parseDate(value, {
|
const parsedValue = Helpers.parseDate(value, { enableTime })
|
||||||
timeOnly,
|
|
||||||
enableTime,
|
|
||||||
ignoreTimezones,
|
|
||||||
})
|
|
||||||
const parsed = Helpers.getDateDisplayValue(parsedValue, {
|
const parsed = Helpers.getDateDisplayValue(parsedValue, {
|
||||||
enableTime,
|
enableTime,
|
||||||
timeOnly,
|
timeOnly,
|
||||||
|
@ -51,40 +46,44 @@ const columnTypeManyParser = {
|
||||||
|
|
||||||
export function enrichSchemaWithRelColumns(
|
export function enrichSchemaWithRelColumns(
|
||||||
schema: Record<string, UIFieldSchema>
|
schema: Record<string, UIFieldSchema>
|
||||||
) {
|
): Record<string, UIFieldSchema> {
|
||||||
if (!schema) {
|
if (!schema) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const result = Object.keys(schema).reduce((result, fieldName) => {
|
const result = Object.keys(schema).reduce<Record<string, UIFieldSchema>>(
|
||||||
const field = schema[fieldName]
|
(result, fieldName) => {
|
||||||
result[fieldName] = field
|
const field = schema[fieldName]
|
||||||
|
result[fieldName] = field
|
||||||
|
|
||||||
if (
|
if (
|
||||||
field.visible !== false &&
|
field.visible !== false &&
|
||||||
isRelationshipField(field) &&
|
isRelationshipField(field) &&
|
||||||
field.columns
|
field.columns
|
||||||
) {
|
) {
|
||||||
const fromSingle =
|
const fromSingle =
|
||||||
field?.relationshipType === RelationshipType.ONE_TO_MANY
|
field?.relationshipType === RelationshipType.ONE_TO_MANY
|
||||||
|
|
||||||
for (const relColumn of Object.keys(field.columns)) {
|
for (const relColumn of Object.keys(field.columns)) {
|
||||||
const relField = field.columns[relColumn]
|
const relField = field.columns[relColumn]
|
||||||
if (!relField.visible) {
|
if (!relField.visible) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
const name = `${field.name}.${relColumn}`
|
const name = `${field.name}.${relColumn}`
|
||||||
result[name] = {
|
result[name] = {
|
||||||
...relField,
|
...relField,
|
||||||
name,
|
type: null, // TODO
|
||||||
related: { field: fieldName, subField: relColumn },
|
name,
|
||||||
cellRenderType:
|
related: { field: fieldName, subField: relColumn },
|
||||||
(!fromSingle && columnTypeManyTypeOverrides[relField.type]) ||
|
cellRenderType:
|
||||||
relField.type,
|
(!fromSingle && columnTypeManyTypeOverrides[relField.type]) ||
|
||||||
|
relField.type,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
return result
|
||||||
return result
|
},
|
||||||
}, {})
|
{}
|
||||||
|
)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,5 +7,10 @@ import {
|
||||||
export type UIFieldSchema = FieldSchema &
|
export type UIFieldSchema = FieldSchema &
|
||||||
BasicViewFieldMetadata & {
|
BasicViewFieldMetadata & {
|
||||||
related?: { field: string; subField: string }
|
related?: { field: string; subField: string }
|
||||||
columns?: Record<string, RelationSchemaField & { type?: string }>
|
columns?: Record<string, UIRelationSchemaField & { type?: string }>
|
||||||
|
cellRenderType?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface UIRelationSchemaField extends RelationSchemaField {
|
||||||
|
type: string
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue