2025-03-29 13:51:20 +00:00
|
|
|
import React, { useEffect } from "react";
|
2025-03-25 06:17:41 +00:00
|
|
|
import RenameInput from "../inputs/RenameInput";
|
|
|
|
import { EyeIcon, LockIcon, RmoveIcon } from "../../icons/ExportCommonIcons";
|
2025-03-26 13:00:33 +00:00
|
|
|
import { useSelectedZoneStore } from "../../../store/useZoneStore";
|
|
|
|
import { getZoneData } from "../../../services/realTimeVisulization/zoneData/getZones";
|
2025-03-29 13:51:20 +00:00
|
|
|
import useModuleStore, { useSubModuleStore } from "../../../store/useModuleStore";
|
2025-03-25 06:17:41 +00:00
|
|
|
|
|
|
|
interface ListProps {
|
|
|
|
items?: { id: string; name: string }[]; // Optional array of items to render
|
|
|
|
placeholder?: string; // Optional placeholder text
|
2025-03-27 03:36:26 +00:00
|
|
|
remove?: boolean;
|
2025-03-25 06:17:41 +00:00
|
|
|
}
|
|
|
|
|
2025-03-27 03:36:26 +00:00
|
|
|
const List: React.FC<ListProps> = ({ items = [], remove }) => {
|
2025-03-29 13:51:20 +00:00
|
|
|
const { activeModule, setActiveModule } = useModuleStore();
|
|
|
|
const { selectedZone, setSelectedZone } = useSelectedZoneStore();
|
2025-03-27 06:58:17 +00:00
|
|
|
const { setSubModule } = useSubModuleStore();
|
2025-03-29 13:51:20 +00:00
|
|
|
useEffect(() => {
|
|
|
|
useSelectedZoneStore.getState().setSelectedZone({
|
|
|
|
zoneName: "",
|
|
|
|
activeSides: [],
|
|
|
|
panelOrder: [],
|
|
|
|
lockedPanels: [],
|
|
|
|
zoneId: "",
|
|
|
|
zoneViewPortTarget: [],
|
|
|
|
zoneViewPortPosition: [],
|
|
|
|
widgets: [],
|
|
|
|
});
|
|
|
|
}, [activeModule]);
|
|
|
|
|
2025-03-26 13:00:33 +00:00
|
|
|
|
|
|
|
async function handleSelectZone(id: string) {
|
2025-03-29 13:51:20 +00:00
|
|
|
try {
|
|
|
|
// Avoid re-fetching if the same zone is already selected
|
|
|
|
if (selectedZone?.zoneId === id) {
|
|
|
|
console.log("Zone is already selected:", selectedZone.zoneName);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
setSubModule("zoneProperties");
|
|
|
|
|
|
|
|
const email = localStorage.getItem("email");
|
|
|
|
const organization = email?.split("@")[1]?.split(".")[0] || "";
|
2025-03-26 13:00:33 +00:00
|
|
|
|
2025-03-29 13:51:20 +00:00
|
|
|
let response = await getZoneData(id, organization);
|
|
|
|
|
|
|
|
setSelectedZone({
|
|
|
|
zoneName: response?.zoneName,
|
|
|
|
activeSides: response?.activeSides || [],
|
|
|
|
panelOrder: response?.panelOrder || [],
|
|
|
|
lockedPanels: response?.lockedPanels || [],
|
|
|
|
widgets: response?.widgets || [],
|
|
|
|
zoneId: response?.zoneId,
|
|
|
|
zoneViewPortTarget: response?.viewPortCenter || [],
|
|
|
|
zoneViewPortPosition: response?.viewPortposition || [],
|
|
|
|
});
|
|
|
|
|
|
|
|
console.log("Zone selected:", response?.zoneName);
|
|
|
|
} catch (error) {
|
|
|
|
console.error("Error selecting zone:", error);
|
|
|
|
}
|
2025-03-26 13:00:33 +00:00
|
|
|
}
|
2025-03-29 13:51:20 +00:00
|
|
|
|
2025-03-25 06:17:41 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{items.length > 0 ? (
|
|
|
|
<ul className="list-wrapper">
|
|
|
|
{items.map((item, index) => (
|
|
|
|
<li key={index} className="list-container">
|
|
|
|
<div className="list-item">
|
2025-03-26 13:00:33 +00:00
|
|
|
<div className="value" onClick={() => handleSelectZone(item.id)}>
|
2025-03-25 06:17:41 +00:00
|
|
|
<RenameInput value={item.name} />
|
|
|
|
</div>
|
|
|
|
<div className="options-container">
|
|
|
|
<div className="lock option">
|
|
|
|
<LockIcon isLocked />
|
|
|
|
</div>
|
|
|
|
<div className="visibe option">
|
|
|
|
<EyeIcon isClosed />
|
|
|
|
</div>
|
2025-03-27 03:36:26 +00:00
|
|
|
{remove && (
|
|
|
|
<div className="remove option">
|
|
|
|
<RmoveIcon />
|
|
|
|
</div>
|
|
|
|
)}
|
2025-03-25 06:17:41 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
) : (
|
|
|
|
<div className="list-wrapper">
|
|
|
|
<div className="no-item">No items to display</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default List;
|