Fix SingleRecordSelectMenuItemsWithSearch (#8932)

- Fix all fields being selected when opening dropdown
- Fix not being able to set back to no selection when a record is
selected and there is only one record to select

Before:



https://github.com/user-attachments/assets/31185a05-7e1a-4550-aa2a-591683934224


After:


https://github.com/user-attachments/assets/e3cd388b-44de-42e2-970b-b4d4f31253bc
This commit is contained in:
Raphaël Bosi
2024-12-06 17:41:58 +01:00
committed by GitHub
parent e1a0259154
commit 9c67a109af

View File

@ -59,6 +59,9 @@ export const SingleRecordSelectMenuItemsWithSearch = ({
/> />
); );
const shouldDisplayDropdownMenuItems =
records.recordsToSelect.length + records.selectedRecords?.length > 0;
return ( return (
<> <>
{dropdownPlacement?.includes('end') && ( {dropdownPlacement?.includes('end') && (
@ -67,15 +70,11 @@ export const SingleRecordSelectMenuItemsWithSearch = ({
{createNewButton} {createNewButton}
</DropdownMenuItemsContainer> </DropdownMenuItemsContainer>
{records.recordsToSelect.length > 0 && <DropdownMenuSeparator />} {records.recordsToSelect.length > 0 && <DropdownMenuSeparator />}
{records.recordsToSelect.length > 0 && ( {shouldDisplayDropdownMenuItems && (
<SingleRecordSelectMenuItems <SingleRecordSelectMenuItems
recordsToSelect={records.recordsToSelect} recordsToSelect={records.recordsToSelect}
loading={records.loading} loading={records.loading}
selectedRecord={ selectedRecord={records.selectedRecords?.[0]}
records.recordsToSelect.length === 1
? records.recordsToSelect[0]
: undefined
}
shouldSelectEmptyOption={selectedRecordIds?.length === 0} shouldSelectEmptyOption={selectedRecordIds?.length === 0}
hotkeyScope={recordPickerInstanceId} hotkeyScope={recordPickerInstanceId}
isFiltered={!!recordPickerSearchFilter} isFiltered={!!recordPickerSearchFilter}
@ -95,15 +94,11 @@ export const SingleRecordSelectMenuItemsWithSearch = ({
isUndefinedOrNull(dropdownPlacement)) && ( isUndefinedOrNull(dropdownPlacement)) && (
<> <>
<DropdownMenuSeparator /> <DropdownMenuSeparator />
{records.recordsToSelect.length > 0 && ( {shouldDisplayDropdownMenuItems && (
<SingleRecordSelectMenuItems <SingleRecordSelectMenuItems
recordsToSelect={records.recordsToSelect} recordsToSelect={records.recordsToSelect}
loading={records.loading} loading={records.loading}
selectedRecord={ selectedRecord={records.selectedRecords?.[0]}
records.recordsToSelect.length === 1
? records.recordsToSelect[0]
: undefined
}
shouldSelectEmptyOption={selectedRecordIds?.length === 0} shouldSelectEmptyOption={selectedRecordIds?.length === 0}
hotkeyScope={recordPickerInstanceId} hotkeyScope={recordPickerInstanceId}
isFiltered={!!recordPickerSearchFilter} isFiltered={!!recordPickerSearchFilter}