From d1611c7abca3ff1d866afa48e68d40cde635073f Mon Sep 17 00:00:00 2001 From: Ilya Khait Date: Fri, 8 Mar 2024 13:03:33 +0000 Subject: [PATCH] Add colophon factories & refactor --- .../ui/fragment/ColophonEditorInputs.tsx | 59 ++++++++----------- src/test-support/colophon-fixtures.ts | 39 ++++++++++++ 2 files changed, 65 insertions(+), 33 deletions(-) create mode 100644 src/test-support/colophon-fixtures.ts diff --git a/src/fragmentarium/ui/fragment/ColophonEditorInputs.tsx b/src/fragmentarium/ui/fragment/ColophonEditorInputs.tsx index 110fe5a95..020150851 100644 --- a/src/fragmentarium/ui/fragment/ColophonEditorInputs.tsx +++ b/src/fragmentarium/ui/fragment/ColophonEditorInputs.tsx @@ -8,6 +8,7 @@ import { Individual, IndividualType, } from './ColophonEditor' +import _ from 'lodash' export const ColophonStatusInput = ({ colophonStatus, @@ -118,7 +119,13 @@ export const ColophonIndividualsInput = ({ key: string, value: any ): void => { - console.log(index, field, key, value) + const updatedIndividuals = [...individuals] + const updatedField = { ...updatedIndividuals[index], [key]: value } + updatedIndividuals[index] = { + ...updatedIndividuals[index], + [field]: updatedField, + } + onChange(updatedIndividuals) } return ( @@ -149,40 +156,26 @@ const IndividualInput = ({ onUpdate: (field: keyof Individual, key: string, value: any) => void onRemove: () => void }): JSX.Element => { + const inputFields = [ + 'type', + 'name', + 'sonOf', + 'grandsonOf', + 'family', + ].map((key) => ( + + onUpdate(key as keyof Individual, 'value', event.target.value) + } + /> + )) return ( - - onUpdate('family', 'value', e.target.value)} - /> - onUpdate('name', 'value', e.target.value)} - /> - onUpdate('sonOf', 'value', e.target.value)} - /> - onUpdate('grandsonOf', 'value', e.target.value)} - /> - onUpdate('family', 'value', e.target.value)} - /> - + {inputFields}