From b10afc975c6bc186126729bce3e9a8256d60976d Mon Sep 17 00:00:00 2001 From: Jerald-Golden-B Date: Sat, 20 Dec 2025 17:26:51 +0530 Subject: [PATCH] feat: implement UI for editing simulation block properties and element design. --- .../components/block/BlockEditor.tsx | 92 +++++++++++++------ .../components/element/ElementDesign.tsx | 65 +++++++------ .../components/element/ElementDropdown.tsx | 1 - app/src/types/simulationDashboard.d.ts | 2 +- 4 files changed, 100 insertions(+), 60 deletions(-) diff --git a/app/src/components/SimulationDashboard/components/block/BlockEditor.tsx b/app/src/components/SimulationDashboard/components/block/BlockEditor.tsx index 3d4e769..713aafd 100644 --- a/app/src/components/SimulationDashboard/components/block/BlockEditor.tsx +++ b/app/src/components/SimulationDashboard/components/block/BlockEditor.tsx @@ -26,7 +26,17 @@ interface BlockEditorProps { handleRemoveBlock: (blockId: string) => void; } -const BlockEditor: React.FC = ({ blockEditorRef, currentBlock, selectedBlock, updateBlockStyle, updateBlockSize, updateBlockPositionType, updateBlockZIndex, handleRemoveBlock }) => { +const BlockEditor: React.FC = ({ + blockEditorRef, + currentBlock, + selectedBlock, + updateBlockStyle, + updateBlockSize, + updateBlockPosition, + updateBlockPositionType, + updateBlockZIndex, + handleRemoveBlock, +}) => { const [color, setColor] = useState("#000000"); useEffect(() => { @@ -227,32 +237,6 @@ const BlockEditor: React.FC = ({ blockEditorRef, currentBlock,
-
-
Size
- { - updateBlockSize(selectedBlock, { - ...currentBlock.size!, - width: Number(newValue), // Make sure to convert the string back to a number here - }); - }} - /> - { - updateBlockSize(selectedBlock, { - ...currentBlock.size!, - height: Number(newValue), - }); - }} - /> -
-
Position
@@ -319,8 +303,58 @@ const BlockEditor: React.FC = ({ blockEditorRef, currentBlock,
-
-
Apperance
+
+
Appearance
+
+ {currentBlock.positionType === "absolute" && ( + <> + { + updateBlockPosition(selectedBlock, { + ...(currentBlock.position || { x: 0, y: 0 }), + x: Number(newValue), + }); + }} + /> + { + updateBlockPosition(selectedBlock, { + ...(currentBlock.position || { x: 0, y: 0 }), + y: Number(newValue), + }); + }} + /> + + )} + { + updateBlockSize(selectedBlock, { + ...currentBlock.size!, + width: Number(newValue), + }); + }} + /> + { + updateBlockSize(selectedBlock, { + ...currentBlock.size!, + height: Number(newValue), + }); + }} + /> +
= ({ setColor(rgbaToHex(getCurrentElementStyleValue(currentElement, "backgroundColor") || "#000000")); }, [currentElement]); + const graphOptions = [ + { id: "line", label: "Line Chart" }, + { id: "bar", label: "Bar Chart" }, + { id: "pie", label: "Pie Chart" }, + { id: "area", label: "Area Chart" }, + { id: "radar", label: "Radar Chart" }, + ]; + return (
{element?.type === "graph" && (
option.id === currentElement.graphType)?.label} onSelect={(newValue) => { updateGraphType(selectedBlock, selectedElement, newValue.id as GraphTypes); }} @@ -218,28 +221,32 @@ const ElementDesign: React.FC = ({
Appearance
- { - updateElementPosition(selectedBlock, selectedElement, { - ...(currentElement.position || { x: 0, y: 0 }), - x: Number(newValue), - }); - }} - /> - { - updateElementPosition(selectedBlock, selectedElement, { - ...(currentElement.position || { x: 0, y: 0 }), - y: Number(newValue), - }); - }} - /> + {currentElement.positionType === "absolute" && ( + <> + { + updateElementPosition(selectedBlock, selectedElement, { + ...(currentElement.position || { x: 0, y: 0 }), + x: Number(newValue), + }); + }} + /> + { + updateElementPosition(selectedBlock, selectedElement, { + ...(currentElement.position || { x: 0, y: 0 }), + y: Number(newValue), + }); + }} + /> + + )} = ({ showElementDropdown, key={elementType.label} onClick={() => { handleAddElement(showElementDropdown, elementType.type, elementType.graphType); - console.log('showElementDropdown: ', showElementDropdown); }} className="dropdown-button" > diff --git a/app/src/types/simulationDashboard.d.ts b/app/src/types/simulationDashboard.d.ts index 4cf1b4a..06533eb 100644 --- a/app/src/types/simulationDashboard.d.ts +++ b/app/src/types/simulationDashboard.d.ts @@ -11,7 +11,7 @@ type ElementDataBinding = { dataSource?: string | string[]; dataValue?: string | string[]; commonValue?: string; - dataType?: "single-machine" | "multiple-machine"; + dataType?: DataType; } type Position = {