fix(frontend): use getSelectedIds function

This commit is contained in:
yassinedorbozgithub 2025-02-17 17:15:22 +01:00
parent aabbfed851
commit af1c93f990

View File

@ -82,7 +82,6 @@ const Diagrams = () => {
const { searchPayload } = useSearch<IBlock>({ const { searchPayload } = useSearch<IBlock>({
$eq: [{ category: selectedCategoryId }], $eq: [{ category: selectedCategoryId }],
}); });
const selectedEntities = engine?.getModel()?.getSelectedEntities();
const { toast } = useToast(); const { toast } = useToast();
const { mutate: duplicateBlock, isLoading: isDuplicatingBlock } = useCreate( const { mutate: duplicateBlock, isLoading: isDuplicatingBlock } = useCreate(
EntityType.BLOCK, EntityType.BLOCK,
@ -92,10 +91,6 @@ const Diagrams = () => {
}, },
}, },
); );
const shouldDisableDuplicateButton =
selectedEntities?.length !== 1 ||
selectedEntities[0]?.getID()?.length !== 24 ||
isDuplicatingBlock;
const { data: categories } = useFind( const { data: categories } = useFind(
{ entity: EntityType.CATEGORY }, { entity: EntityType.CATEGORY },
{ {
@ -189,10 +184,7 @@ const Diagrams = () => {
}, },
); );
const handleDuplicateBlock = () => { const handleDuplicateBlock = () => {
if (!selectedEntities || selectedEntities.length !== 1) { const block = getBlockFromCache(selectedEntities[0]);
return;
}
const block = getBlockFromCache(selectedEntities[0].getID());
if (!block) { if (!block) {
return; return;
@ -558,6 +550,11 @@ const Diagrams = () => {
); );
} }
}; };
const selectedEntities = getSelectedIds();
const shouldDisableDuplicateButton =
selectedEntities.length !== 1 ||
selectedEntities[0]?.length !== 24 ||
isDuplicatingBlock;
return ( return (
<div <div