fix(StatusPage): streamline active device selection and enhance device overlay integration
This commit is contained in:
parent
10c9a13340
commit
3088f1801c
|
|
@ -27,20 +27,32 @@ export default function StatusPage({ config, setConfig, onOpenFileManager }: Sta
|
||||||
};
|
};
|
||||||
|
|
||||||
const [showDeviceOverlay, setShowDeviceOverlay] = useState(false);
|
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) {
|
if (config.devices?.iec) {
|
||||||
for (const [num, device] of Object.entries(config.devices.iec)) {
|
for (const [num, device] of Object.entries(config.devices.iec)) {
|
||||||
const d = device as any;
|
const d = device as any;
|
||||||
if (d.type === 'drive' && d.enabled) {
|
if (d.type === 'drive' && d.enabled) return { number: num, ...d };
|
||||||
return { number: num, ...d };
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
};
|
})();
|
||||||
|
|
||||||
const activeDevice = findActiveDevice();
|
const activeDeviceIndex = allIecDevices.findIndex(d => d.number === activeDevice?.number);
|
||||||
const activeDir = activeDevice
|
const activeDir = activeDevice
|
||||||
? (activeDevice.base_url || activeDevice.url || null)
|
? (activeDevice.base_url || activeDevice.url || null)
|
||||||
: null;
|
: null;
|
||||||
|
|
@ -247,18 +259,10 @@ export default function StatusPage({ config, setConfig, onOpenFileManager }: Sta
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{showDeviceOverlay && (
|
{showDeviceOverlay && allIecDevices.length > 0 && (
|
||||||
<DeviceDetailOverlay
|
<DeviceDetailOverlay
|
||||||
devices={[{
|
devices={allIecDevices}
|
||||||
id: `drive-${activeDevice.number}`,
|
initialIndex={Math.max(0, activeDeviceIndex)}
|
||||||
number: activeDevice.number,
|
|
||||||
type: 'drive',
|
|
||||||
name: activeDevice.name,
|
|
||||||
enabled: activeDevice.enabled,
|
|
||||||
url: activeDevice.url,
|
|
||||||
mode: activeDevice.mode,
|
|
||||||
}]}
|
|
||||||
initialIndex={0}
|
|
||||||
config={config}
|
config={config}
|
||||||
setConfig={setConfig}
|
setConfig={setConfig}
|
||||||
onClose={() => setShowDeviceOverlay(false)}
|
onClose={() => setShowDeviceOverlay(false)}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user