2024-11-06 07:15:27 -05:00
|
|
|
import React from 'react';
|
|
|
|
|
import { Icons } from '../Icons';
|
|
|
|
|
import { useTranslation } from 'react-i18next';
|
2025-03-17 22:34:34 -04:00
|
|
|
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
|
|
|
|
2025-10-29 14:15:52 -04:00
|
|
|
const {
|
|
|
|
|
onSegmentationAdd,
|
|
|
|
|
data,
|
|
|
|
|
disableEditing,
|
|
|
|
|
mode,
|
|
|
|
|
disabled,
|
|
|
|
|
segmentationRepresentationType,
|
|
|
|
|
} = useSegmentationTableContext('AddSegmentationRow');
|
2024-11-06 07:15:27 -05:00
|
|
|
|
2025-10-29 14:15:52 -04:00
|
|
|
// Check if we have at least one segmentation of the representation type for the panel this component is contained in.
|
|
|
|
|
const hasRepresentationType =
|
|
|
|
|
(!segmentationRepresentationType && data.length > 0) ||
|
|
|
|
|
data.some(info => segmentationRepresentationType === info.representation?.type);
|
2024-11-06 07:15:27 -05:00
|
|
|
|
2025-10-29 14:15:52 -04:00
|
|
|
if (hasRepresentationType && mode === 'collapsed') {
|
2024-11-06 07:15:27 -05:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (disableEditing) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div
|
2025-07-15 20:09:23 -04:00
|
|
|
data-cy="addSegmentation"
|
2024-11-06 07:15:27 -05:00
|
|
|
className={`group ${disabled ? 'pointer-events-none cursor-not-allowed opacity-70' : ''}`}
|
2025-10-29 14:15:52 -04:00
|
|
|
onClick={() =>
|
|
|
|
|
!disabled && onSegmentationAdd({ segmentationId: '', segmentationRepresentationType })
|
|
|
|
|
}
|
2024-11-06 07:15:27 -05:00
|
|
|
>
|
|
|
|
|
{children}
|
2025-04-04 12:11:29 -04:00
|
|
|
<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]">
|
2025-10-29 14:15:52 -04:00
|
|
|
{t(disabled ? 'Segmentation not supported' : 'Add segmentation')}
|
2024-11-06 07:15:27 -05:00
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|