fix(StatusPage): streamline active device selection and enhance device overlay integration

This commit is contained in:
Jaime Idolpx 2026-06-13 22:11:47 -04:00
parent 10c9a13340
commit 3088f1801c

View File

@ -27,20 +27,32 @@ export default function StatusPage({ config, setConfig, onOpenFileManager }: Sta
};
const [showDeviceOverlay, setShowDeviceOverlay] = useState(false);
// Find the first enabled device as the active device
const findActiveDevice = () => {
// Build a sorted list of all IEC devices for the overlay.
const allIecDevices = Object.entries(config.devices?.iec ?? {})
.sort(([a], [b]) => parseInt(a) - parseInt(b))
.map(([num, d]: [string, any]) => ({
id: `drive-${num}`,
number: num,
type: (d.type ?? 'drive') as any,
name: d.name,
enabled: d.enabled,
url: d.url,
mode: d.mode,
}));
// Find the first enabled drive as the active device.
const activeDevice = (() => {
if (config.devices?.iec) {
for (const [num, device] of Object.entries(config.devices.iec)) {
const d = device as any;
if (d.type === 'drive' && d.enabled) {
return { number: num, ...d };
}
if (d.type === 'drive' && d.enabled) return { number: num, ...d };
}
}
return null;
};
})();
const activeDevice = findActiveDevice();
const activeDeviceIndex = allIecDevices.findIndex(d => d.number === activeDevice?.number);
const activeDir = activeDevice
? (activeDevice.base_url || activeDevice.url || null)
: null;
@ -247,18 +259,10 @@ export default function StatusPage({ config, setConfig, onOpenFileManager }: Sta
</div>
{showDeviceOverlay && (
{showDeviceOverlay && allIecDevices.length > 0 && (
<DeviceDetailOverlay
devices={[{
id: `drive-${activeDevice.number}`,
number: activeDevice.number,
type: 'drive',
name: activeDevice.name,
enabled: activeDevice.enabled,
url: activeDevice.url,
mode: activeDevice.mode,
}]}
initialIndex={0}
devices={allIecDevices}
initialIndex={Math.max(0, activeDeviceIndex)}
config={config}
setConfig={setConfig}
onClose={() => setShowDeviceOverlay(false)}