- Added token management for various API calls in the factoryBuilder and visualization services. - Updated deleteLayerApi, deleteLineApi, deletePointApi, getLinesApi, setLineApi, updatePointApi, and version control APIs to handle new access tokens from response headers. - Introduced new API endpoints for 3D widget and floating widget data retrieval. - Enhanced error handling and logging for API responses. - Created new sessionValidity and input retrieval components for better session management and data handling.
110 lines
3.4 KiB
TypeScript
110 lines
3.4 KiB
TypeScript
import React, { useState, useEffect } from "react";
|
|
|
|
import useChartStore from "../../../../../store/visualization/useChartStore";
|
|
import { useWidgetStore } from "../../../../../store/useWidgetStore";
|
|
import axios from "axios";
|
|
import io from "socket.io-client";
|
|
import {CartIcon,DocumentIcon,GlobeIcon,WalletIcon,} from "../../../../../components/icons/3dChartIcons";
|
|
import { getUserData } from "../../../../../functions/getUserData";
|
|
import { useParams } from "react-router-dom";
|
|
import { getFloatingWidgetInput } from "../../../../../services/visulization/zone/getFloatingWidgetInput";
|
|
import { useVersionContext } from "../../../../builder/version/versionContext";
|
|
|
|
const TotalCardComponent = ({ object }: any) => {
|
|
const [progress, setProgress] = useState<any>(0);
|
|
const [measurements, setmeasurements] = useState<any>({});
|
|
const [duration, setDuration] = useState("1h");
|
|
const [name, setName] = useState(object.header ? object.header : "");
|
|
const { userName, userId, organization, email } = getUserData();
|
|
const { header, flotingDuration, flotingMeasurements } = useChartStore();
|
|
const { selectedChartId } = useWidgetStore();
|
|
const { projectId } = useParams()
|
|
const { selectedVersionStore } = useVersionContext();
|
|
const { selectedVersion } = selectedVersionStore();
|
|
|
|
const iotApiUrl = process.env.REACT_APP_IOT_SOCKET_SERVER_URL;
|
|
|
|
useEffect(() => {
|
|
if (!iotApiUrl || !measurements || Object.keys(measurements).length === 0)
|
|
return;
|
|
|
|
const socket = io(`http://${iotApiUrl}`);
|
|
|
|
const inputData = {
|
|
measurements,
|
|
duration,
|
|
interval: 1000,
|
|
};
|
|
|
|
const startStream = () => {
|
|
socket.emit("lastInput", inputData);
|
|
};
|
|
|
|
socket.on("connect", startStream);
|
|
|
|
socket.on("lastOutput", (response) => {
|
|
const responseData = response.input1;
|
|
|
|
if (typeof responseData === "number") {
|
|
setProgress(responseData);
|
|
}
|
|
});
|
|
|
|
return () => {
|
|
socket.off("lastOutput");
|
|
socket.emit("stop_stream"); // Stop streaming when component unmounts
|
|
socket.disconnect();
|
|
};
|
|
}, [measurements, duration, iotApiUrl]);
|
|
|
|
const fetchSavedInputes = async () => {
|
|
if (object?.id !== "") {
|
|
let response = await getFloatingWidgetInput(object?.id, organization,projectId,selectedVersion?.versionId||"")
|
|
if (response) {
|
|
setmeasurements(response.Data.Datastructure.measurements);
|
|
setDuration(response.Data.Datastructure.duration);
|
|
setName(response.Data.header);
|
|
}
|
|
}
|
|
};
|
|
|
|
useEffect(() => {
|
|
fetchSavedInputes();
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
if (selectedChartId?.id === object?.id) {
|
|
fetchSavedInputes();
|
|
}
|
|
}, [header, flotingDuration, flotingMeasurements]);
|
|
|
|
const mapIcon = (iconName: string) => {
|
|
switch (iconName) {
|
|
case "WalletIcon":
|
|
return <WalletIcon />;
|
|
case "GlobeIcon":
|
|
return <GlobeIcon />;
|
|
case "DocumentIcon":
|
|
return <DocumentIcon />;
|
|
case "CartIcon":
|
|
return <CartIcon />;
|
|
default:
|
|
return <WalletIcon />;
|
|
}
|
|
};
|
|
return (
|
|
<>
|
|
<div className="header-wrapper">
|
|
<div className="header">{name}</div>
|
|
<div className="data-values">
|
|
<div className="value">{progress}</div>
|
|
<div className="per">{object.per}</div>
|
|
</div>
|
|
</div>
|
|
<div className="icon">{mapIcon(object.iconName)}</div>
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default TotalCardComponent;
|