deletepanel added

This commit is contained in:
Gomathi 2025-04-01 11:33:10 +05:30
parent 6f483baf8d
commit 695b066c81
21 changed files with 97 additions and 46 deletions

View File

@ -6,6 +6,7 @@ import {
} from "../../icons/RealTimeVisulationIcons"; } from "../../icons/RealTimeVisulationIcons";
import { panelData } from "../../../services/realTimeVisulization/zoneData/panel"; import { panelData } from "../../../services/realTimeVisulization/zoneData/panel";
import { AddIcon } from "../../icons/ExportCommonIcons"; import { AddIcon } from "../../icons/ExportCommonIcons";
import { deletePanelApi } from "../../../services/realTimeVisulization/zoneData/deletePanel";
// Define the type for `Side` // Define the type for `Side`
type Side = "top" | "bottom" | "left" | "right"; type Side = "top" | "bottom" | "left" | "right";
@ -34,7 +35,7 @@ interface ButtonsProps {
zoneName: string; zoneName: string;
activeSides: Side[]; activeSides: Side[];
panelOrder: Side[]; panelOrder: Side[];
lockedPanels: Side[]; lockedPanels: Side[];
zoneId: string; zoneId: string;
zoneViewPortTarget: number[]; zoneViewPortTarget: number[];
@ -103,8 +104,11 @@ const AddButtons: React.FC<ButtonsProps> = ({
}; };
// Function to handle "+" button click // Function to handle "+" button click
const handlePlusButtonClick = (side: Side) => { const handlePlusButtonClick = async (side: Side) => {
if (selectedZone.activeSides.includes(side)) { if (selectedZone.activeSides.includes(side)) {
const email = localStorage.getItem("email") || "";
const organization = email?.split("@")[1]?.split(".")[0]; // Fallback value
// If the panel is already active, remove all widgets and close the panel // If the panel is already active, remove all widgets and close the panel
const cleanedWidgets = selectedZone.widgets.filter( const cleanedWidgets = selectedZone.widgets.filter(
(widget) => widget.panel !== side (widget) => widget.panel !== side
@ -118,8 +122,14 @@ const AddButtons: React.FC<ButtonsProps> = ({
panelOrder: newActiveSides, panelOrder: newActiveSides,
}; };
let response = await deletePanelApi(selectedZone.zoneId, side, organization)
if (response.message === 'Panel deleted successfully') {
setSelectedZone(updatedZone);
}
// Delete the selectedZone state // Delete the selectedZone state
setSelectedZone(updatedZone);
} else { } else {
const updatePanelData = async () => { const updatePanelData = async () => {
try { try {
@ -140,13 +150,15 @@ const AddButtons: React.FC<ButtonsProps> = ({
// API call // API call
const response = await panelData(organization, selectedZone.zoneId, newActiveSides); const response = await panelData(organization, selectedZone.zoneId, newActiveSides);
if (response.message === 'Panels created successfully') {
setSelectedZone(updatedZone);
}
// Update state // Update state
setSelectedZone(updatedZone);
} catch (error) { } catch (error) {
} }
}; };

View File

@ -152,7 +152,6 @@ const DisplayZone: React.FC<DisplayZoneProps> = ({
async function handleSelect2dZoneData(zoneId: string, zoneName: string) { async function handleSelect2dZoneData(zoneId: string, zoneName: string) {
try { try {
if (selectedZone?.zoneId === zoneId) { if (selectedZone?.zoneId === zoneId) {
return; return;
} }
const email = localStorage.getItem("email") || ""; const email = localStorage.getItem("email") || "";
@ -161,6 +160,7 @@ const DisplayZone: React.FC<DisplayZoneProps> = ({
let response = await getSelect2dZoneData(zoneId, organization); let response = await getSelect2dZoneData(zoneId, organization);
console.log('response: ', response); console.log('response: ', response);
let res = await getFloatingZoneData(zoneId, organization); let res = await getFloatingZoneData(zoneId, organization);
console.log('res: ', res);
setFloatingWidget(res) setFloatingWidget(res)
// Set the selected zone in the store // Set the selected zone in the store
useDroppedObjectsStore.getState().setZone(zoneName, zoneId); useDroppedObjectsStore.getState().setZone(zoneName, zoneId);

View File

@ -96,7 +96,7 @@ const DroppedObjects: React.FC = () => {
console.log('res: ', res); console.log('res: ', res);
if (res.message === "FloatingWidget deleted successfully") { if (res.message === "FloatingWidget deleted successfully") {
deleteObject(zoneName, index); // Call the deleteObject method from the store deleteObject(zoneName,id, index); // Call the deleteObject method from the store
} }
} catch (error) { } catch (error) {
console.error("Error deleting floating widget:", error); console.error("Error deleting floating widget:", error);
@ -255,6 +255,7 @@ const DroppedObjects: React.FC = () => {
...zone.objects[draggingIndex.index], ...zone.objects[draggingIndex.index],
position: boundedPosition, position: boundedPosition,
}); });
console.log('response: ', response);
if (response.message === "Widget updated successfully") { if (response.message === "Widget updated successfully") {
updateObjectPosition(zoneName, draggingIndex.index, boundedPosition); updateObjectPosition(zoneName, draggingIndex.index, boundedPosition);
@ -386,10 +387,13 @@ const DroppedObjects: React.FC = () => {
<FleetEfficiencyComponent object={obj} /> <FleetEfficiencyComponent object={obj} />
</> </>
) : null} ) : null}
{renderObjectContent(obj)} {/* {renderObjectContent(obj)} */}
<div <div
className="icon kebab" className="icon kebab"
onClick={(event) => handleKebabClick(obj.id, event)} onClick={(event) => {
event.stopPropagation();
handleKebabClick(obj.id, event)
}}
> >
<KebabIcon /> <KebabIcon />
</div> </div>

View File

@ -1,5 +1,5 @@
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`; // let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
// let url_Backend_dwinzo = `http://192.168.0.102:5000`; let url_Backend_dwinzo = `http://192.168.0.102:5000`;
export const adding3dWidgets = async ( export const adding3dWidgets = async (
zoneId: string, zoneId: string,
organization: string, organization: string,

View File

@ -1,5 +1,5 @@
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`; // let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
// let url_Backend_dwinzo = `http://192.168.0.102:5000`; let url_Backend_dwinzo = `http://192.168.0.102:5000`;
export const addingFloatingWidgets = async ( export const addingFloatingWidgets = async (
zoneId: string, zoneId: string,

View File

@ -1,5 +1,5 @@
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`; // let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
// let url_Backend_dwinzo = `http://192.168.0.102:5000`; let url_Backend_dwinzo = `http://192.168.0.102:5000`;
export const addingWidgets = async ( export const addingWidgets = async (
zoneId: string, zoneId: string,
organization: string, organization: string,

View File

@ -1,5 +1,5 @@
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`; // let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
// let url_Backend_dwinzo = `http://192.168.0.102:5000`; let url_Backend_dwinzo = `http://192.168.0.102:5000`;
export const deleteFloatingWidgetApi = async ( export const deleteFloatingWidgetApi = async (
floatWidgetID: string, floatWidgetID: string,

View File

@ -0,0 +1,34 @@
// let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
let url_Backend_dwinzo = `http://192.168.0.102:5000`;
export const deletePanelApi = async (
zoneId: string,
panelName: string,
organization: string
) => {
console.log('panelName: ', panelName);
console.log('organization: ', organization);
console.log('zoneId: ', zoneId);
try {
const response = await fetch(`${url_Backend_dwinzo}/api/v2/panel/delete`, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ organization, zoneId, panelName }),
});
if (!response.ok) {
throw new Error("Failed to delete widget in the zone");
}
const result = await response.json();
return result;
} catch (error) {
if (error instanceof Error) {
throw new Error(error.message);
} else {
throw new Error("An unknown error occurred");
}
}
};

View File

@ -1,5 +1,5 @@
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`; // let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
// let url_Backend_dwinzo = `http://192.168.0.102:5000`; let url_Backend_dwinzo = `http://192.168.0.102:5000`;
export const deleteTemplateApi = async ( export const deleteTemplateApi = async (
templateID: string, templateID: string,

View File

@ -1,5 +1,5 @@
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`; // let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
// let url_Backend_dwinzo = `http://192.168.0.102:5000`; let url_Backend_dwinzo = `http://192.168.0.102:5000`;
export const deleteWidgetApi = async ( export const deleteWidgetApi = async (
widgetID: string, widgetID: string,

View File

@ -1,5 +1,5 @@
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`; // let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
// let url_Backend_dwinzo = `http://192.168.0.102:5000`; let url_Backend_dwinzo = `http://192.168.0.102:5000`;
export const duplicateWidgetApi = async ( export const duplicateWidgetApi = async (
zoneId: string, zoneId: string,
organization: string, organization: string,

View File

@ -1,5 +1,5 @@
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`; // let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
// let url_Backend_dwinzo = `http://192.168.0.102:5000`; let url_Backend_dwinzo = `http://192.168.0.102:5000`;
export const get3dWidgetZoneData = async ( export const get3dWidgetZoneData = async (
ZoneId?: string, ZoneId?: string,
organization?: string organization?: string

View File

@ -1,5 +1,5 @@
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`; // let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
// let url_Backend_dwinzo = `http://192.168.0.102:5000`; let url_Backend_dwinzo = `http://192.168.0.102:5000`;
export const getFloatingZoneData = async ( export const getFloatingZoneData = async (
ZoneId?: string, ZoneId?: string,
organization?: string organization?: string

View File

@ -1,5 +1,5 @@
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`; // let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
// let url_Backend_dwinzo = `http://192.168.0.102:5000`; let url_Backend_dwinzo = `http://192.168.0.102:5000`;
export const getSelect2dZoneData = async ( export const getSelect2dZoneData = async (
ZoneId?: string, ZoneId?: string,

View File

@ -1,5 +1,5 @@
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`; // let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
// let url_Backend_dwinzo = `http://192.168.0.102:5000`; let url_Backend_dwinzo = `http://192.168.0.102:5000`;
export const getTemplateData = async (organization?: string) => { export const getTemplateData = async (organization?: string) => {
try { try {
const response = await fetch( const response = await fetch(

View File

@ -1,5 +1,5 @@
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`; // let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
// let url_Backend_dwinzo = `http://192.168.0.102:5000`; let url_Backend_dwinzo = `http://192.168.0.102:5000`;
export const getZone2dData = async (organization?: string) => { export const getZone2dData = async (organization?: string) => {
try { try {
const response = await fetch( const response = await fetch(

View File

@ -1,5 +1,5 @@
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`; // let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
// let url_Backend_dwinzo = `http://192.168.0.102:5000`; let url_Backend_dwinzo = `http://192.168.0.102:5000`;
export const getZoneData = async (zoneId: string, organization: string) => { export const getZoneData = async (zoneId: string, organization: string) => {
console.log("organization: ", organization); console.log("organization: ", organization);

View File

@ -1,5 +1,5 @@
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`; // let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
// let url_Backend_dwinzo = `http://192.168.0.102:5000`; let url_Backend_dwinzo = `http://192.168.0.102:5000`;
export const loadTempleteApi = async ( export const loadTempleteApi = async (
templateID: string, templateID: string,
zoneId: string, zoneId: string,

View File

@ -1,5 +1,5 @@
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`; // let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
// let url_Backend_dwinzo = `http://192.168.0.102:5000`; let url_Backend_dwinzo = `http://192.168.0.102:5000`;
type Side = "top" | "bottom" | "left" | "right"; type Side = "top" | "bottom" | "left" | "right";
export const panelData = async ( export const panelData = async (

View File

@ -1,5 +1,5 @@
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`; // let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
// let url_Backend_dwinzo = `http://192.168.0.102:5000`; let url_Backend_dwinzo = `http://192.168.0.102:5000`;
export const saveTemplateApi = async (organization: string, template: {}) => { export const saveTemplateApi = async (organization: string, template: {}) => {
console.log('template: ', template); console.log('template: ', template);
try { try {

View File

@ -36,7 +36,7 @@ type DroppedObjectsState = {
bottom: number | "auto"; bottom: number | "auto";
} }
) => void; ) => void;
deleteObject: (zoneName: string, index: number) => void; // Add this line deleteObject: (zoneName: string, id: string, index: number) => void; // Add this line
duplicateObject: (zoneName: string, index: number) => void; // Add this line duplicateObject: (zoneName: string, index: number) => void; // Add this line
}; };
@ -77,15 +77,16 @@ export const useDroppedObjectsStore = create<DroppedObjectsState>((set) => ({
}; };
}), }),
deleteObject: (zoneName: string, index: number) => deleteObject: (zoneName: string, id: string, index: number) =>
set((state) => { set((state) => {
const zone = state.zones[zoneName]; const zone = state.zones[zoneName];
console.log("zone: ", zone);
if (!zone) return state; if (!zone) return state;
return { return {
zones: { zones: {
[zoneName]: { [zoneName]: {
...zone, ...zone,
objects: zone.objects.filter((_, i) => i !== index), // Remove object at the given index objects: zone.objects.filter((obj) => obj.id !== id), // Remove object at the given index
}, },
}, },
}; };