import { useEffect, useState } from "react"; import { useWidgetStore } from "../../../../../store/useWidgetStore"; import { AddIcon, RemoveIcon } from "../../../../icons/ExportCommonIcons"; import MultiLevelDropDown from "../../../../ui/inputs/MultiLevelDropDown"; import LineGrapInput from "../IotInputCards/LineGrapInput"; import RenameInput from "../../../../ui/inputs/RenameInput"; // Define the data structure for demonstration purposes const DATA_STRUCTURE = { furnace: { coolingRate: "coolingRate", furnaceTemperature: "furnaceTemperature", heatingRate: "heatingRate", machineId: "machineId", powerConsumption: "powerConsumption", status: "status", timestamp: "timestamp", vacuumLevel: "vacuumLevel", }, testDevice: { abrasiveLevel: { data1: "Data 1", data2: "Data 2", data3: "Data 3", }, airPressure: "airPressure", machineId: "machineId", powerConsumption: "powerConsumption", status: "status", temperature: { data1: "Data 1", data2: "Data 2", data3: "Data 3", }, timestamp: { data1: { Data01: "Data 01", Data02: "Data 02", Data03: "Data 03", }, data2: "Data 2", data3: "Data 3", }, }, }; interface Child { id: number; easing: string; } interface Group { id: number; easing: string; children: Child[]; } const Data = () => { const { selectedChartId } = useWidgetStore(); // State to store groups for all widgets (using Widget.id as keys) const [chartDataGroups, setChartDataGroups] = useState< Record >({}); useEffect(() => { // Initialize data groups for the newly selected widget if it doesn't exist if (selectedChartId && !chartDataGroups[selectedChartId.id]) { setChartDataGroups((prev) => ({ ...prev, [selectedChartId.id]: [ { id: Date.now(), easing: "Connecter 1", children: [{ id: Date.now(), easing: "Linear" }], }, ], })); } }, [selectedChartId]); // Handle adding a new child to the group const handleAddClick = (groupId: number) => { setChartDataGroups((prevGroups) => { const currentGroups = prevGroups[selectedChartId.id] || []; const group = currentGroups.find((g) => g.id === groupId); if (group && group.children.length < 7) { const newChild = { id: Date.now(), easing: "Linear" }; return { ...prevGroups, [selectedChartId.id]: currentGroups.map((g) => g.id === groupId ? { ...g, children: [...g.children, newChild] } : g ), }; } return prevGroups; }); }; // Remove a child from a group const removeChild = (groupId: number, childId: number) => { setChartDataGroups((currentGroups) => { const currentChartData = currentGroups[selectedChartId.id] || []; return { ...currentGroups, [selectedChartId.id]: currentChartData.map((group) => group.id === groupId ? { ...group, children: group.children.filter( (child) => child.id !== childId ), } : group ), }; }); }; // console.log("selectedChartId", selectedChartId); return (
{/* {selectedChartId?.title && (
{selectedChartId?.title}
)} */} {/* */} {/* Render groups dynamically */} { chartDataGroups[selectedChartId?.id] && <>
2D Widget Input
} {/* Info Box */}
i

By adding templates and widgets, you create a customizable and dynamic environment.

); }; export default Data; // {chartDataGroups[selectedChartId?.id]?.map((group) => ( //
// {group.children.map((child, index) => ( //
//
Input {index + 1}
//
// // {/* Add Icon */} // {group.children.length < 7 && ( //
handleAddClick(group.id)} // Pass groupId to handleAddClick // > // //
// )} // {/* Remove Icon */} // 1 ? "" : "disable" // }`} // onClick={(e) => { // e.stopPropagation(); // Prevent event bubbling // removeChild(group.id, child.id); // Pass groupId and childId to removeChild // }} // > // // //
//
// ))} //
// ))}