Fix referencetab crashing after type change

This commit is contained in:
arttu
2024-06-07 12:12:51 +03:00
parent 28a0e3cd10
commit 737ffc9b59
2 changed files with 6 additions and 4 deletions
@@ -21,7 +21,7 @@ import { EditDataType } from '@/backendTypes'
const fieldWidth = '14em'
export type DropdownOption = { value: string; display: string }
export type DropdownOption = { value: string | number; display: string }
export const DropdownSelector = <T extends object>({
options,
@@ -13,23 +13,25 @@ export const ReferenceTab = () => {
const referenceTypeOptions = referenceTypes
.map(refType => ({
display: refType.ref_type ?? 'Unknown',
value: refType.ref_type_id + '',
value: refType.ref_type_id,
}))
.sort((a, b) => a.display.localeCompare(b.display))
const refTypeSelection = [['Reference type', dropdown('ref_type_id', referenceTypeOptions, 'Reference type')]]
const selectedRefType = referenceTypes.find(refType => {
if (mode.read) {
return data.ref_type_id === refType.ref_type_id
}
return editData.ref_type_id === refType.ref_type_id
})
const fields = selectedRefType?.ref_field_name.filter(field => field.display)
const fieldsArray = fields!.map(field => [
const fieldsArray = fields?.map(field => [
field.ref_field_name,
textField(field.field_name! as keyof ReferenceDetailsType),
])
]) ?? [['Encountered error. Field type could not be found. Please contact project administrators.']]
return (
<>