Changes made to css and in process of adding delete feature

pull/33/head
Khwaja 3 months ago
parent 3291f0862f
commit d80f956a42

@ -250,6 +250,32 @@ const onAddCenterOutput = (centerName: string, productName: string) => {
}); });
}; };
const onRemovePlant = (plantName: string) => {
setCircularData(prev => {
const next = { ...prev };
delete next.plants[plantName];
return next;
});
};
const onRemoveProduct = (productName: string) => {
setCircularData(prev => {
const next = { ...prev };
delete next.products[productName];
return next;
});
};
const onRemoveCenter = (centerName: string) => {
setCircularData(prev => {
const next = { ...prev };
delete next.centers[centerName];
return next;
});
};
return ( return (
<div> <div>
<Header onClear={onClear} onSave={onSave} onLoad={onLoad} /> <Header onClear={onClear} onSave={onSave} onLoad={onLoad} />
@ -270,6 +296,9 @@ const onAddCenterOutput = (centerName: string, productName: string) => {
onAddCenterOutput={onAddCenterOutput} onAddCenterOutput={onAddCenterOutput}
onMoveCenter={onMoveCenter} onMoveCenter={onMoveCenter}
centers={circularData.centers} centers={circularData.centers}
onRemovePlant={onRemovePlant}
onRemoveProduct={onRemoveProduct}
onRemoveCenter={onRemoveCenter}
/> />
</div> </div>
</div> </div>

@ -5,33 +5,30 @@
margin-bottom: 12px !important; margin-bottom: 12px !important;
} }
.PlantNode, :global(.react-flow__node.PlantNode),
.ProductNode, :global(.react-flow__node.ProductNode),
.CenterNode { :global(.react-flow__node.CenterNode) {
border-color: rgba(0, 0, 0, 0.8) !important; border-color: rgba(0, 0, 0, 0.8) !important;
color: black !important; color: black !important;
font-size: 13px !important; font-size: 13px !important;
border-width: 1px !important; border-width: 1px !important;
border-radius: 6px !important; border-radius: 6px !important;
box-shadow: 0px 2px 4px -3px black !important; box-shadow: 0px 2px 4px -3px black !important;
width: 100%; width: 140px !important;
height: 100%; height: 40px !important;
} align-items: center;
justify-content: center;
box-sizing: border-box;
display: flex;
.PlantNode {
background-color: #8d8 !important;
} }
.ProductNode { :global(.react-flow__node.PlantNode) {
background-color: #e6e6e6 !important; --xy-node-background-color: #8d8 !important;
} }
:global(.react-flow__node.ProductNode) {
.CenterNode { --xy-node-background-color: #e6e6e6 !important;
background-color: #d3a610;
} }
:global(.react-flow__node.CenterNode) {
:global(.react-flow__node-default), --xy-node-background-color: #d3a610 !important;
:global(.react-flow__node-custom) {
width: 150px !important;
height: 60px !important;
} }

@ -1,10 +1,10 @@
import { CircularPlant, CircularProduct, CircularCenter } from "./CircularData"; import { CircularPlant, CircularProduct, CircularCenter } from "./CircularData";
import { Node, Edge } from "@xyflow/react"; import { Node, Edge } from "@xyflow/react";
import styles from "./PipelineBlock.module.css"; import styles from "./PipelineBlock.module.css";
import { ReactFlow, Background, Controls,MarkerType } from '@xyflow/react'; import { ReactFlow, Background, Controls, MarkerType } from '@xyflow/react';
import Section from '../Common/Section'; import Section from '../Common/Section';
import Card from '../Common/Card'; import Card from '../Common/Card';
import { useEffect } from "react"; import { useEffect, useCallback } from "react";
import { Connection } from '@xyflow/react'; import { Connection } from '@xyflow/react';
import CustomNode, { CustomNodeData }from "./NodesAndEdges"; import CustomNode, { CustomNodeData }from "./NodesAndEdges";
@ -21,6 +21,9 @@ interface PipelineBlockProps {
onAddPlantOutput: (plantName: string, productName: string) => void; onAddPlantOutput: (plantName: string, productName: string) => void;
onAddCenterInput: (plantName: string, productName: string) => void; onAddCenterInput: (plantName: string, productName: string) => void;
onAddCenterOutput: (plantName: string, productName: string) => void; onAddCenterOutput: (plantName: string, productName: string) => void;
onRemovePlant: (id:string) => void;
onRemoveProduct: (id: string) => void;
onRemoveCenter: (id: string) => void;
products: Record<string, CircularProduct>; products: Record<string, CircularProduct>;
plants: Record<string, CircularPlant>; plants: Record<string, CircularPlant>;
@ -74,6 +77,19 @@ const onNodeDragStop =(_:any, node: Node) => {
} }
}; };
const handleNodesDelete = useCallback((deleted: Node[]) => {
deleted.forEach((n) => {
const type = mapNameToType[n.id];
if (type === "plant") {
props.onRemovePlant(n.id);
} else if (type === "product") {
props.onRemoveProduct(n.id);
} else if (type === "center") {
props.onRemoveCenter!(n.id);
}
});
}, [props, mapNameToType]);
for (const [productName, product] of Object.entries(props.products) as [string, CircularProduct][]) { for (const [productName, product] of Object.entries(props.products) as [string, CircularProduct][]) {
if(!product.x || !product.y) hasNullPositions = true; if(!product.x || !product.y) hasNullPositions = true;
mapNameToType[productName] = "product"; mapNameToType[productName] = "product";
@ -81,10 +97,10 @@ const onNodeDragStop =(_:any, node: Node) => {
id: productName, id: productName,
type: "default", type: "default",
data: {label: productName, type: 'product'}, data: {label: productName, type: 'product'},
position: { x:product.x, y:product.y} position: { x:product.x, y:product.y},
className: 'ProductNode'
}); });
} }
console.log("ALL PLANTS:", props.plants);
for (const [plantName, plant] of Object.entries(props.plants) as [string, CircularPlant][]) { for (const [plantName, plant] of Object.entries(props.plants) as [string, CircularPlant][]) {
if(!plant.x || !plant.y) hasNullPositions = true; if(!plant.x || !plant.y) hasNullPositions = true;
mapNameToType[plantName] = "plant"; mapNameToType[plantName] = "plant";
@ -92,7 +108,8 @@ const onNodeDragStop =(_:any, node: Node) => {
id: plantName, id: plantName,
type: "default", type: "default",
data: {label: plantName, type: 'plant'}, data: {label: plantName, type: 'plant'},
position: { x:plant.x, y:plant.y} position: { x:plant.x, y:plant.y},
className: 'PlantNode'
}); });
if (plant) { if (plant) {
@ -130,12 +147,14 @@ const onNodeDragStop =(_:any, node: Node) => {
type: "default", type: "default",
data: { label: centerName, type: "center"}, data: { label: centerName, type: "center"},
position: {x: center.x, y: center.y}, position: {x: center.x, y: center.y},
className: 'CenterNode'
}); });
if (center.input) { if (center.input) {
edges.push({ edges.push({
id: `${center.input}-${centerName}`, id: `${center.input}-${centerName}`,
source: center.input, source: center.input,
target:centerName, target:centerName,
animated: true,
style: { stroke: "black"}, style: { stroke: "black"},
markerEnd: { type: MarkerType.ArrowClosed}, markerEnd: { type: MarkerType.ArrowClosed},
}); });
@ -145,6 +164,7 @@ const onNodeDragStop =(_:any, node: Node) => {
id: `${centerName}-${out}`, id: `${centerName}-${out}`,
source: centerName, source: centerName,
target:out, target:out,
animated: true,
style: { stroke: "black"}, style: { stroke: "black"},
markerEnd: { type: MarkerType.ArrowClosed}, markerEnd: { type: MarkerType.ArrowClosed},
}); });
@ -165,14 +185,14 @@ return (
<Card> <Card>
<div className={styles.PipelineBlock}> <div className={styles.PipelineBlock}>
<ReactFlow <ReactFlow
nodes={nodes} nodes={nodes}
edges={edges} edges={edges}
onNodeDoubleClick={onNodeDoubleClick} onNodeDoubleClick={onNodeDoubleClick}
onNodeDragStop={onNodeDragStop} onNodeDragStop={onNodeDragStop}
onConnect={onConnect} onConnect={onConnect}
onNodesDelete={handleNodesDelete} onNodesDelete={handleNodesDelete}
onEdgesDelete={handleEdgesDelete} deleteKeyCode="Delete"
deleteKeyCode={"Delete"}
maxZoom={1.25} maxZoom={1.25}
minZoom={0.5} minZoom={0.5}
snapToGrid={true} snapToGrid={true}

Loading…
Cancel
Save