Refactor: Disable group button when its not possible to group (#1878)
This commit is contained in:
parent
06afef340e
commit
fdf1881f00
3 changed files with 30 additions and 3 deletions
|
|
@ -56,7 +56,11 @@ export const GradientGroup = (props) => {
|
||||||
</linearGradient>
|
</linearGradient>
|
||||||
</defs>
|
</defs>
|
||||||
</svg>
|
</svg>
|
||||||
<ForwardedIconComponent name="Combine" stroke="url(#grad3)" {...props} />
|
<ForwardedIconComponent
|
||||||
|
name="Combine"
|
||||||
|
stroke={`${props.disabled ? "#64748B" : "url(#grad3)"}`}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -483,6 +483,7 @@ export default function Page({
|
||||||
></Controls>
|
></Controls>
|
||||||
)}
|
)}
|
||||||
<SelectionMenu
|
<SelectionMenu
|
||||||
|
lastSelection={lastSelection}
|
||||||
isVisible={selectionMenuVisible}
|
isVisible={selectionMenuVisible}
|
||||||
nodes={lastSelection?.nodes}
|
nodes={lastSelection?.nodes}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,31 @@
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { NodeToolbar } from "reactflow";
|
import { NodeToolbar } from "reactflow";
|
||||||
import { GradientGroup } from "../../../../icons/GradientSparkles";
|
import { GradientGroup } from "../../../../icons/GradientSparkles";
|
||||||
export default function SelectionMenu({ onClick, nodes, isVisible }) {
|
import { validateSelection } from "../../../../utils/reactflowUtils";
|
||||||
|
import useFlowStore from "../../../../stores/flowStore";
|
||||||
|
export default function SelectionMenu({
|
||||||
|
onClick,
|
||||||
|
nodes,
|
||||||
|
isVisible,
|
||||||
|
lastSelection,
|
||||||
|
}) {
|
||||||
|
const edges = useFlowStore((state) => state.edges);
|
||||||
|
const [disable, setDisable] = useState<boolean>(
|
||||||
|
lastSelection && edges.length > 0
|
||||||
|
? validateSelection(lastSelection!, edges).length > 0
|
||||||
|
: false,
|
||||||
|
);
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
const [isTransitioning, setIsTransitioning] = useState(false);
|
const [isTransitioning, setIsTransitioning] = useState(false);
|
||||||
const [lastNodes, setLastNodes] = useState(nodes);
|
const [lastNodes, setLastNodes] = useState(nodes);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isOpen) {
|
||||||
|
return setDisable(validateSelection(lastSelection!, edges).length > 0);
|
||||||
|
}
|
||||||
|
setDisable(false);
|
||||||
|
}, [isOpen, setIsOpen]);
|
||||||
|
|
||||||
// nodes get saved to not be gone after the toolbar closes
|
// nodes get saved to not be gone after the toolbar closes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setLastNodes(nodes);
|
setLastNodes(nodes);
|
||||||
|
|
@ -42,13 +62,15 @@ export default function SelectionMenu({ onClick, nodes, isVisible }) {
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
className="flex h-full w-full items-center justify-between text-sm hover:text-indigo-500"
|
className={`${disable ? "flex h-full w-full cursor-not-allowed items-center justify-between text-sm text-muted-foreground" : "flex h-full w-full items-center justify-between text-sm hover:text-indigo-500"}`}
|
||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
|
disabled={disable}
|
||||||
>
|
>
|
||||||
<GradientGroup
|
<GradientGroup
|
||||||
strokeWidth={1.5}
|
strokeWidth={1.5}
|
||||||
size={22}
|
size={22}
|
||||||
className="text-primary"
|
className="text-primary"
|
||||||
|
disabled={disable}
|
||||||
/>
|
/>
|
||||||
Group
|
Group
|
||||||
</button>
|
</button>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue