refactor(front): extract shared utils and rewire pages
This commit is contained in:
@@ -173,6 +173,20 @@ export interface NormalizedCustomFieldDefinition {
|
||||
orderIndex: number
|
||||
}
|
||||
|
||||
export interface NormalizedCustomFieldEntry {
|
||||
customFieldValueId: unknown
|
||||
id: string | undefined
|
||||
customFieldId: string | null
|
||||
name: string
|
||||
type: string
|
||||
required: boolean
|
||||
options: string[]
|
||||
optionsText: string
|
||||
defaultValue: unknown
|
||||
value: string
|
||||
readOnly: boolean
|
||||
}
|
||||
|
||||
export const normalizeCustomFieldDefinitionEntry = (
|
||||
definition: Record<string, unknown> = {},
|
||||
fallbackIndex = 0,
|
||||
@@ -237,8 +251,8 @@ export const mergeCustomFieldValuesWithDefinitions = (
|
||||
valueEntries: Record<string, unknown>[] = [],
|
||||
...definitionSources: unknown[][]
|
||||
): Record<string, unknown>[] => {
|
||||
const normalizedValues = (Array.isArray(valueEntries) ? valueEntries : [])
|
||||
.map((entry) => {
|
||||
const normalizedValues: Record<string, unknown>[] = (Array.isArray(valueEntries) ? valueEntries : [])
|
||||
.map((entry): Record<string, unknown> | null => {
|
||||
if (!entry || typeof entry !== 'object') return null
|
||||
const normalizedDefinition = normalizeCustomFieldDefinitionEntry(
|
||||
((entry as Record<string, unknown>).customField || entry) as Record<string, unknown>,
|
||||
@@ -265,7 +279,7 @@ export const mergeCustomFieldValuesWithDefinitions = (
|
||||
defaultValue: normalizedDefinition.defaultValue ?? '',
|
||||
value,
|
||||
readOnly: !!(entry as Record<string, unknown>)?.readOnly,
|
||||
}
|
||||
} as Record<string, unknown>
|
||||
})
|
||||
.filter((entry): entry is Record<string, unknown> => entry !== null)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user