import React from 'react'; import { PanelSection } from '../PanelSection'; import { useSegmentationTableContext, SegmentationExpandedProvider, useSegmentationExpanded, } from './contexts'; import { useTranslation } from 'react-i18next'; import { Button, Icons, DropdownMenu, DropdownMenuTrigger, Tooltip, TooltipTrigger, TooltipContent, Select, SelectTrigger, SelectContent, SelectItem, SelectValue, } from '../../components'; // Main header component const SegmentationCollapsedHeader = ({ children }: { children: React.ReactNode }) => { return (
{children}
); }; // Dropdown menu component - specifically for dropdown menu content const SegmentationCollapsedDropdownMenu = ({ children }: { children: React.ReactNode }) => { return ( {children} ); }; // Selector component - for the segmentation selection dropdown const SegmentationCollapsedSelector = () => { const { t } = useTranslation('SegmentationPanel.HeaderCollapsed'); const { data, onSegmentationClick, segmentationRepresentationTypes } = useSegmentationTableContext('SegmentationCollapsedSelector'); const { segmentation } = useSegmentationExpanded('SegmentationCollapsedSelector'); if (!data?.length) { return null; } const segmentations = data // Only show segmentations of the representation type for this panel. Show all segmentations if no type is specified. .filter( seg => !segmentationRepresentationTypes || segmentationRepresentationTypes.includes(seg.representation?.type) ) .map(seg => ({ id: seg.segmentation.segmentationId, label: seg.segmentation.label, })); return ( ); }; // Info component - for displaying the info tooltip const SegmentationCollapsedInfo = () => { const { data, activeSegmentationId } = useSegmentationTableContext('SegmentationCollapsedInfo'); const activeSegmentationObj = data.find( seg => seg.segmentation.segmentationId === activeSegmentationId ); const info = activeSegmentationObj?.segmentation.cachedStats?.info; return ( {info} ); }; // Content component - for the main collapsed view content const SegmentationCollapsedContent = ({ children }: { children: React.ReactNode }) => { return
{children}
; }; // Main compound component const SegmentationCollapsedRoot: React.FC<{ children?: React.ReactNode }> = ({ children = null, }) => { const { mode, data, segmentationRepresentationTypes, selectedSegmentationIdForType } = useSegmentationTableContext('SegmentationCollapsed'); // Find the segmentations for the representation type for this collapsed view. const segmentations = data.filter( segmentation => !segmentationRepresentationTypes || segmentationRepresentationTypes.includes(segmentation.representation?.type) ); // Check if we should render. if (mode !== 'collapsed' || !data || data.length === 0 || segmentations.length === 0) { return null; } // Find the selected segmentation info for the representation type, or default to the first one. const selectedSegmentationInfo = segmentations.find( segmentation => segmentation.segmentation.segmentationId === selectedSegmentationIdForType ) ?? segmentations[0]; return (
{}} // No-op since it's already the active one > {children}
); }; // Add the subcomponents to the main component const SegmentationCollapsed = Object.assign(SegmentationCollapsedRoot, { Header: SegmentationCollapsedHeader, DropdownMenu: SegmentationCollapsedDropdownMenu, Selector: SegmentationCollapsedSelector, Info: SegmentationCollapsedInfo, Content: SegmentationCollapsedContent, }); // Export the component export { SegmentationCollapsed };