Files
twenty/packages/twenty-front/src/modules/side-panel/pages/navigation-menu-item/components/SidePanelNewSidebarItemViewObjectPickerSubView.tsx
T
Baptiste Devessier 2a6fcfcfb3 Side Panel Sub Page Framework® (#18579)
Replace hard-coded implementations for sub pages in the side panel with
a proper framework
2026-03-12 15:17:29 +00:00

95 lines
3.6 KiB
TypeScript

import { useLingui } from '@lingui/react/macro';
import { IconSettings, useIcons } from 'twenty-ui/display';
import { CommandMenuItem } from '@/command-menu/components/CommandMenuItem';
import { NavigationMenuItemStyleIcon } from '@/navigation-menu-item/components/NavigationMenuItemStyleIcon';
import { getStandardObjectIconColor } from '@/navigation-menu-item/utils/getStandardObjectIconColor';
import { type ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
import { SidePanelGroup } from '@/side-panel/components/SidePanelGroup';
import { SidePanelList } from '@/side-panel/components/SidePanelList';
import { SidePanelSubViewWithSearch } from '@/side-panel/components/SidePanelSubViewWithSearch';
import { useSidePanelFilteredPickerItems } from '@/side-panel/hooks/useSidePanelFilteredPickerItems';
import { SelectableListItem } from '@/ui/layout/selectable-list/components/SelectableListItem';
type SidePanelNewSidebarItemViewObjectPickerSubViewProps = {
objects: ObjectMetadataItem[];
searchValue: string;
onSearchChange: (value: string) => void;
onOpenSystemPicker: () => void;
onSelectObject: (objectMetadataItem: ObjectMetadataItem) => void;
showSystemObjectsOption?: boolean;
};
export const SidePanelNewSidebarItemViewObjectPickerSubView = ({
objects,
searchValue,
onSearchChange,
onOpenSystemPicker,
onSelectObject,
showSystemObjectsOption = true,
}: SidePanelNewSidebarItemViewObjectPickerSubViewProps) => {
const { t } = useLingui();
const { getIcon } = useIcons();
const { filteredItems, selectableItemIds, isEmpty, hasSearchQuery } =
useSidePanelFilteredPickerItems({
items: objects,
searchQuery: searchValue,
getSearchableValues: (item) => [item.labelPlural],
appendSelectableIds: showSystemObjectsOption ? ['system'] : [],
});
const noResultsText = hasSearchQuery
? t`No results found`
: t`No objects with views found`;
return (
<SidePanelSubViewWithSearch
searchPlaceholder={t`Search an object...`}
searchValue={searchValue}
onSearchChange={onSearchChange}
>
<SidePanelList
commandGroups={[]}
selectableItemIds={selectableItemIds}
noResults={isEmpty}
noResultsText={noResultsText}
>
<SidePanelGroup heading={t`Objects`}>
{filteredItems.map((objectMetadataItem) => (
<SelectableListItem
key={objectMetadataItem.id}
itemId={objectMetadataItem.id}
onEnter={() => onSelectObject(objectMetadataItem)}
>
<CommandMenuItem
Icon={() => (
<NavigationMenuItemStyleIcon
Icon={getIcon(objectMetadataItem.icon)}
color={getStandardObjectIconColor(
objectMetadataItem.nameSingular,
)}
/>
)}
label={objectMetadataItem.labelPlural}
id={objectMetadataItem.id}
hasSubMenu
onClick={() => onSelectObject(objectMetadataItem)}
/>
</SelectableListItem>
))}
{showSystemObjectsOption && (
<SelectableListItem itemId="system" onEnter={onOpenSystemPicker}>
<CommandMenuItem
Icon={() => <NavigationMenuItemStyleIcon Icon={IconSettings} />}
label={t`System objects`}
id="system"
hasSubMenu={true}
onClick={onOpenSystemPicker}
/>
</SelectableListItem>
)}
</SidePanelGroup>
</SidePanelList>
</SidePanelSubViewWithSearch>
);
};