From 9281f1ca48bb40efdbda0a72c7d33cb5c8a3ab40 Mon Sep 17 00:00:00 2001 From: Joshua Chudy Date: Mon, 26 Aug 2024 16:53:01 -0700 Subject: [PATCH] remove state variable for row that is selected --- src/components/input-switch/foreignkey-field.tsx | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/components/input-switch/foreignkey-field.tsx b/src/components/input-switch/foreignkey-field.tsx index dbe625a96..f7f8721f2 100644 --- a/src/components/input-switch/foreignkey-field.tsx +++ b/src/components/input-switch/foreignkey-field.tsx @@ -82,7 +82,6 @@ const ForeignkeyField = (props: ForeignkeyFieldProps): JSX.Element => { const { setValue, getValues } = useFormContext(); const [recordsetModalProps, setRecordsetModalProps] = useState(null); - const [inputSelectedRow, setInputSelectedRow] = useState(null); const [showSpinner, setShowSpinner] = useState(false); const ellipsisRef = useRef(null); @@ -100,8 +99,6 @@ const ForeignkeyField = (props: ForeignkeyFieldProps): JSX.Element => { const onClear = () => { const column = props.columnModel.column; - setInputSelectedRow(null); - if (props.foreignKeyCallbacks?.updateAssociationSelectedRows) { props.foreignKeyCallbacks.updateAssociationSelectedRows(usedFormNumber); } @@ -152,10 +149,9 @@ const ForeignkeyField = (props: ForeignkeyFieldProps): JSX.Element => { getValues ); - let currentSelectedRow = inputSelectedRow; + let currentSelectedRow; // there is a value in the input but no selected row yet because of prefill showing an association picker on recordedit page load - if (getValues(props.name) && !currentSelectedRow && props.foreignKeyCallbacks?.prefillAssociationSelectedRows) { - + if (getValues(props.name) && props.foreignKeyCallbacks?.prefillAssociationSelectedRows) { // find row in prefillAssociationSelectedRows currentSelectedRow = props.foreignKeyCallbacks.prefillAssociationSelectedRows.filter((row: SelectedRow) => { // if an input is empty, there won't be a row defined in `prefillAssociationSelectedRows` @@ -190,8 +186,6 @@ const ForeignkeyField = (props: ForeignkeyFieldProps): JSX.Element => { const selectedRow = selectedRows[0]; const column = props.columnModel.column; - setInputSelectedRow(selectedRow); - // if the recordedit page's table is an association table with a unique key pair, track the selected rows if (props.foreignKeyCallbacks?.updateAssociationSelectedRows) { props.foreignKeyCallbacks.updateAssociationSelectedRows(usedFormNumber, selectedRow);