refactor: improve SingleEntitySelect empty option (#1543)

Closes #1331

Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
Thaïs
2023-09-12 02:27:17 +02:00
committed by GitHub
parent a766c60aa5
commit 564a7c97b1
17 changed files with 297 additions and 444 deletions

View File

@ -13,29 +13,36 @@ import { useEntitySelectSearch } from '../hooks/useEntitySelectSearch';
import { EntityForSelect } from '../types/EntityForSelect';
import {
EntitiesForSingleEntitySelect,
SingleEntitySelectBase,
type SingleEntitySelectBaseProps,
} from './SingleEntitySelectBase';
export type SingleEntitySelectProps<
CustomEntityForSelect extends EntityForSelect,
> = {
disableBackgroundBlur?: boolean;
onCreate?: () => void;
width?: number;
} & Pick<
SingleEntitySelectBaseProps<CustomEntityForSelect>,
| 'EmptyIcon'
| 'emptyLabel'
| 'entitiesToSelect'
| 'loading'
| 'onCancel'
| 'onEntitySelected'
| 'selectedEntity'
>;
export function SingleEntitySelect<
CustomEntityForSelect extends EntityForSelect,
>({
entities,
onEntitySelected,
onCreate,
onCancel,
width,
disableBackgroundBlur = false,
noUser,
}: {
onCancel?: () => void;
onCreate?: () => void;
entities: EntitiesForSingleEntitySelect<CustomEntityForSelect>;
onEntitySelected: (entity: CustomEntityForSelect | null | undefined) => void;
disableBackgroundBlur?: boolean;
width?: number;
noUser?: CustomEntityForSelect;
}) {
onCancel,
onCreate,
width,
...props
}: SingleEntitySelectProps<CustomEntityForSelect>) {
const containerRef = useRef<HTMLDivElement>(null);
const { searchFilter, handleSearchFilterChange } = useEntitySelectSearch();
@ -64,12 +71,7 @@ export function SingleEntitySelect<
autoFocus
/>
<StyledDropdownMenuSeparator />
<SingleEntitySelectBase
entities={entities}
onEntitySelected={onEntitySelected}
onCancel={onCancel}
noUser={noUser}
/>
<SingleEntitySelectBase {...props} onCancel={onCancel} />
{showCreateButton && (
<>
<StyledDropdownMenuItemsContainer hasMaxHeight>