Skip to content

Commit

Permalink
remove state variable for row that is selected
Browse files Browse the repository at this point in the history
  • Loading branch information
jrchudy committed Aug 26, 2024
1 parent 53f33cf commit 9281f1c
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/components/input-switch/foreignkey-field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ const ForeignkeyField = (props: ForeignkeyFieldProps): JSX.Element => {
const { setValue, getValues } = useFormContext();

const [recordsetModalProps, setRecordsetModalProps] = useState<RecordsetProps | null>(null);
const [inputSelectedRow, setInputSelectedRow] = useState<SelectedRow | null>(null);
const [showSpinner, setShowSpinner] = useState<boolean>(false);

const ellipsisRef = useRef(null);
Expand All @@ -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);
}
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 9281f1c

Please sign in to comment.