experiment showing only 1 device

This commit is contained in:
Proddy
2023-05-01 22:13:53 +02:00
parent 72f530b969
commit 8aa7cd166b

View File

@@ -7,6 +7,7 @@ import KeyboardArrowDownOutlinedIcon from '@mui/icons-material/KeyboardArrowDown
import KeyboardArrowUpOutlinedIcon from '@mui/icons-material/KeyboardArrowUpOutlined'; import KeyboardArrowUpOutlinedIcon from '@mui/icons-material/KeyboardArrowUpOutlined';
import PlayArrowIcon from '@mui/icons-material/PlayArrow'; import PlayArrowIcon from '@mui/icons-material/PlayArrow';
import RefreshIcon from '@mui/icons-material/Refresh'; import RefreshIcon from '@mui/icons-material/Refresh';
import SettingsBackupRestoreIcon from '@mui/icons-material/SettingsBackupRestore';
import StarIcon from '@mui/icons-material/Star'; import StarIcon from '@mui/icons-material/Star';
import UnfoldMoreOutlinedIcon from '@mui/icons-material/UnfoldMoreOutlined'; import UnfoldMoreOutlinedIcon from '@mui/icons-material/UnfoldMoreOutlined';
import { import {
@@ -193,8 +194,23 @@ const DashboardDevices: FC = () => {
} }
}; };
function onSelectChange(action: any, state: any) {
setSelectedDevice(state.id);
if (action.type === 'ADD_BY_ID_EXCLUSIVELY') {
void fetchDeviceData(state.id);
}
}
const device_select = useRowSelect(
{ nodes: coreData.devices },
{
onChange: onSelectChange
}
);
const fetchCoreData = useCallback(async () => { const fetchCoreData = useCallback(async () => {
try { try {
setSelectedDevice(undefined);
setCoreData((await EMSESP.readCoreData()).data); setCoreData((await EMSESP.readCoreData()).data);
} catch (error) { } catch (error) {
toast.error(extractErrorMessage(error, LL.PROBLEM_LOADING())); toast.error(extractErrorMessage(error, LL.PROBLEM_LOADING()));
@@ -216,20 +232,6 @@ const DashboardDevices: FC = () => {
} }
}; };
function onSelectChange(action: any, state: any) {
setSelectedDevice(state.id);
if (action.type === 'ADD_BY_ID_EXCLUSIVELY') {
void fetchDeviceData(state.id);
}
}
const device_select = useRowSelect(
{ nodes: coreData.devices },
{
onChange: onSelectChange
}
);
const escapeCsvCell = (cell: any) => { const escapeCsvCell = (cell: any) => {
if (cell == null) { if (cell == null) {
return ''; return '';
@@ -358,7 +360,12 @@ const DashboardDevices: FC = () => {
<MessageBox my={2} level="warning" message={LL.EMS_BUS_SCANNING()} /> <MessageBox my={2} level="warning" message={LL.EMS_BUS_SCANNING()} />
)} )}
<Table data={{ nodes: coreData.devices }} select={device_select} theme={device_theme} layout={{ custom: true }}> <Table
data={{ nodes: selectedDevice ? coreData.devices.filter((dv) => dv.id === selectedDevice) : coreData.devices }}
select={device_select}
theme={device_theme}
layout={{ custom: true }}
>
{(tableList: any) => ( {(tableList: any) => (
<> <>
<Header> <Header>
@@ -398,7 +405,7 @@ const DashboardDevices: FC = () => {
}; };
const renderDeviceData = () => { const renderDeviceData = () => {
if (!device_select.state.id) { if (!selectedDevice) {
return; return;
} }
@@ -521,6 +528,8 @@ const DashboardDevices: FC = () => {
/> />
)} )}
<Box display="flex" flexWrap="wrap">
<Box flexGrow={1}>
<ButtonRow> <ButtonRow>
<Button startIcon={<RefreshIcon />} variant="outlined" color="secondary" onClick={refreshData}> <Button startIcon={<RefreshIcon />} variant="outlined" color="secondary" onClick={refreshData}>
{LL.REFRESH()} {LL.REFRESH()}
@@ -531,6 +540,20 @@ const DashboardDevices: FC = () => {
</Button> </Button>
)} )}
</ButtonRow> </ButtonRow>
</Box>
<Box flexWrap="nowrap" whiteSpace="nowrap">
<ButtonRow>
<Button
startIcon={<SettingsBackupRestoreIcon />}
variant="outlined"
onClick={fetchCoreData}
color="warning"
>
{LL.RESET(0)}
</Button>
</ButtonRow>
</Box>
</Box>
</SectionContent> </SectionContent>
); );
}; };