feat(nodeToolbarComponent): add "Ungroup" button to the node toolbar when the node is a group

fix(styleUtils.ts): import the "Ungroup" icon from lucide-react to use it in the node toolbar component
This commit is contained in:
anovazzi1 2023-09-12 22:13:06 -03:00
commit 7de65ed709
2 changed files with 29 additions and 8 deletions

View file

@ -6,6 +6,7 @@ import { TabsContext } from "../../../../contexts/tabsContext";
import EditNodeModal from "../../../../modals/EditNodeModal"; import EditNodeModal from "../../../../modals/EditNodeModal";
import { nodeToolbarPropsType } from "../../../../types/components"; import { nodeToolbarPropsType } from "../../../../types/components";
import { classNames } from "../../../../utils/utils"; import { classNames } from "../../../../utils/utils";
import { ungroupNode } from "../../../../utils/reactflowUtils";
export default function NodeToolbarComponent({ export default function NodeToolbarComponent({
data, data,
@ -27,6 +28,7 @@ export default function NodeToolbarComponent({
data.node.template[templateField].type === "int") data.node.template[templateField].type === "int")
).length ).length
); );
const isGroup = data.node?.flow ? true : false;
const { paste } = useContext(TabsContext); const { paste } = useContext(TabsContext);
const reactFlowInstance = useReactFlow(); const reactFlowInstance = useReactFlow();
@ -79,9 +81,9 @@ export default function NodeToolbarComponent({
<a <a
className={classNames( className={classNames(
"relative -ml-px inline-flex items-center bg-background px-2 py-2 text-foreground shadow-md ring-1 ring-inset ring-ring transition-all duration-500 ease-in-out hover:bg-muted focus:z-10" + "relative -ml-px inline-flex items-center bg-background px-2 py-2 text-foreground shadow-md ring-1 ring-inset ring-ring transition-all duration-500 ease-in-out hover:bg-muted focus:z-10" +
(data.node?.documentation === "" (data.node?.documentation === ""
? " text-muted-foreground" ? " text-muted-foreground"
: " text-foreground") : " text-foreground")
)} )}
target="_blank" target="_blank"
rel="noopener noreferrer" rel="noopener noreferrer"
@ -106,10 +108,10 @@ export default function NodeToolbarComponent({
> >
<div <div
className={classNames( className={classNames(
"relative -ml-px inline-flex items-center rounded-r-md bg-background px-2 py-2 text-foreground shadow-md ring-1 ring-inset ring-ring transition-all duration-500 ease-in-out hover:bg-muted focus:z-10" + "relative -ml-px inline-flex items-center bg-background px-2 py-2 text-foreground shadow-md ring-1 ring-inset ring-ring transition-all duration-500 ease-in-out hover:bg-muted focus:z-10" +
(nodeLength == 0 (nodeLength == 0
? " text-muted-foreground" ? " text-muted-foreground"
: " text-foreground") : " text-foreground") +(isGroup?"":" rounded-r-md")
)} )}
> >
<IconComponent name="Settings2" className="h-4 w-4 " /> <IconComponent name="Settings2" className="h-4 w-4 " />
@ -117,6 +119,23 @@ export default function NodeToolbarComponent({
</EditNodeModal> </EditNodeModal>
</div> </div>
</ShadTooltip> </ShadTooltip>
{isGroup && (
<ShadTooltip content="Ungroup" side="top">
<button
className={classNames(
"relative -ml-px inline-flex items-center rounded-r-md bg-background px-2 py-2 text-foreground shadow-md ring-1 ring-inset ring-ring transition-all duration-500 ease-in-out hover:bg-muted focus:z-10"
)}
onClick={(event) => {
event.preventDefault();
ungroupNode(data, { edges: reactFlowInstance.getEdges(),
nodes: reactFlowInstance.getNodes(),
viewport: reactFlowInstance.getViewport() })
}}
>
<IconComponent name="Ungroup" className="h-4 w-4" />
</button>
</ShadTooltip>
)}
</span> </span>
</div> </div>
</> </>

View file

@ -75,7 +75,8 @@ import {
X, X,
XCircle, XCircle,
Zap, Zap,
Group Group,
Ungroup
} from "lucide-react"; } from "lucide-react";
import { FaApple, FaGithub } from "react-icons/fa"; import { FaApple, FaGithub } from "react-icons/fa";
import { AirbyteIcon } from "../icons/Airbyte"; import { AirbyteIcon } from "../icons/Airbyte";
@ -304,4 +305,5 @@ export const nodeIconsLucide: iconsType = {
Unplug, Unplug,
Group, Group,
ChevronUp, ChevronUp,
Ungroup
}; };