Files
ohif-viewer/platform/ui-next/src/components/SegmentationTable/AddSegmentationRow.tsx
T

56 lines
1.7 KiB
TypeScript
Raw Normal View History

2024-11-06 07:15:27 -05:00
import React from 'react';
import { Icons } from '../Icons';
import { useTranslation } from 'react-i18next';
import { useSegmentationTableContext } from './contexts';
2024-11-06 07:15:27 -05:00
export const AddSegmentationRow: React.FC<{ children?: React.ReactNode }> = ({
children = null,
}) => {
2025-12-12 16:46:56 +01:00
const { t } = useTranslation('SegmentationPanel');
2024-11-06 07:15:27 -05:00
const {
onSegmentationAdd,
data,
disableEditing,
mode,
disabled,
segmentationRepresentationTypes,
} = useSegmentationTableContext('AddSegmentationRow');
2024-11-06 07:15:27 -05:00
// Check if we have at least one segmentation of the representation type for the panel this component is contained in.
const hasRepresentationType =
(!segmentationRepresentationTypes && data.length > 0) ||
data.some(info => segmentationRepresentationTypes?.includes(info.representation?.type));
2024-11-06 07:15:27 -05:00
if (hasRepresentationType && mode === 'collapsed') {
2024-11-06 07:15:27 -05:00
return null;
}
if (disableEditing) {
return null;
}
return (
<div
data-cy="addSegmentation"
2024-11-06 07:15:27 -05:00
className={`group ${disabled ? 'pointer-events-none cursor-not-allowed opacity-70' : ''}`}
onClick={() =>
!disabled &&
onSegmentationAdd({
segmentationId: '',
segmentationRepresentationType: segmentationRepresentationTypes?.[0],
})
}
2024-11-06 07:15:27 -05:00
>
{children}
<div className="text-primary group-hover:bg-secondary-dark flex items-center rounded-[4px] pl-1 group-hover:cursor-pointer">
2024-11-06 07:15:27 -05:00
<div className="grid h-[28px] w-[28px] place-items-center">
{disabled ? <Icons.Info /> : <Icons.Add />}
</div>
<span className="text-[13px]">
{t(disabled ? 'Segmentation not supported' : 'Add segmentation')}
2024-11-06 07:15:27 -05:00
</span>
</div>
</div>
);
};