fix: Update map with tables fixes
This commit is contained in:
@@ -18,6 +18,7 @@ import { observer } from "mobx-react-lite";
|
||||
import { Button, Checkbox, Typography } from "@mui/material";
|
||||
import { Vehicle } from "@shared";
|
||||
import { toast } from "react-toastify";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
|
||||
export type ConnectedDevice = string;
|
||||
|
||||
@@ -116,6 +117,7 @@ export const DevicesTable = observer(() => {
|
||||
const { snapshots, getSnapshots } = snapshotStore;
|
||||
const { getVehicles, vehicles } = vehicleStore; // Removed as devicesStore.devices should be the source of truth
|
||||
const { devices } = devicesStore;
|
||||
const navigate = useNavigate();
|
||||
const [selectedDeviceUuids, setSelectedDeviceUuids] = useState<string[]>([]);
|
||||
|
||||
// Transform the raw devices data into rows suitable for the table
|
||||
@@ -182,13 +184,25 @@ export const DevicesTable = observer(() => {
|
||||
const handleSendSnapshotAction = async (snapshotId: string) => {
|
||||
if (selectedDeviceUuids.length === 0) return;
|
||||
|
||||
const send = async (deviceUuid: string) => {
|
||||
try {
|
||||
await authInstance.post(
|
||||
`/devices/${deviceUuid}/force-snapshot-update`,
|
||||
{
|
||||
snapshot_id: snapshotId,
|
||||
}
|
||||
);
|
||||
toast.success(`Снапшот отправлен на устройство `);
|
||||
} catch (error) {
|
||||
console.error(`Error sending snapshot to device ${deviceUuid}:`, error);
|
||||
toast.error(`Не удалось отправить снапшот на устройство`);
|
||||
}
|
||||
};
|
||||
try {
|
||||
// Create an array of promises for all snapshot requests
|
||||
const snapshotPromises = selectedDeviceUuids.map((deviceUuid) => {
|
||||
console.log(`Sending snapshot ${snapshotId} to device ${deviceUuid}`);
|
||||
return authInstance.post(`/devices/${deviceUuid}/force-snapshot`, {
|
||||
snapshot_id: snapshotId,
|
||||
});
|
||||
return send(deviceUuid);
|
||||
});
|
||||
|
||||
// Wait for all promises to settle (either resolve or reject)
|
||||
@@ -209,6 +223,16 @@ export const DevicesTable = observer(() => {
|
||||
return (
|
||||
<>
|
||||
<TableContainer component={Paper} sx={{ mt: 2 }}>
|
||||
<div className="flex justify-end p-3 gap-2 ">
|
||||
<Button
|
||||
variant="contained"
|
||||
color="primary"
|
||||
size="small"
|
||||
onClick={() => navigate("/vehicle/create")}
|
||||
>
|
||||
Добавить устройство
|
||||
</Button>
|
||||
</div>
|
||||
<div className="flex justify-end p-3 gap-2">
|
||||
<Button
|
||||
variant="outlined" // Changed to outlined for distinction
|
||||
@@ -269,16 +293,34 @@ export const DevicesTable = observer(() => {
|
||||
'input[type="checkbox"]'
|
||||
) === null
|
||||
) {
|
||||
handleSelectDevice(
|
||||
{
|
||||
target: {
|
||||
checked: !selectedDeviceUuids.includes(
|
||||
row.device_uuid ?? ""
|
||||
),
|
||||
},
|
||||
} as React.ChangeEvent<HTMLInputElement>, // Simulate event
|
||||
row.device_uuid ?? ""
|
||||
);
|
||||
if (event.shiftKey) {
|
||||
if (row.device_uuid) {
|
||||
navigator.clipboard
|
||||
.writeText(row.device_uuid)
|
||||
.then(() => {
|
||||
toast.success(`UUID скопирован`);
|
||||
})
|
||||
.catch(() => {
|
||||
toast.error("Не удалось скопировать UUID");
|
||||
});
|
||||
} else {
|
||||
toast.warning("Устройство не имеет UUID");
|
||||
}
|
||||
}
|
||||
|
||||
// Only toggle checkbox if Shift key is not pressed
|
||||
if (!event.shiftKey) {
|
||||
handleSelectDevice(
|
||||
{
|
||||
target: {
|
||||
checked: !selectedDeviceUuids.includes(
|
||||
row.device_uuid ?? ""
|
||||
),
|
||||
},
|
||||
} as React.ChangeEvent<HTMLInputElement>, // Simulate event
|
||||
row.device_uuid ?? ""
|
||||
);
|
||||
}
|
||||
}
|
||||
}}
|
||||
sx={{
|
||||
|
||||
Reference in New Issue
Block a user