mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
experiment showing only 1 device
This commit is contained in:
@@ -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,16 +528,32 @@ const DashboardDevices: FC = () => {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<ButtonRow>
|
<Box display="flex" flexWrap="wrap">
|
||||||
<Button startIcon={<RefreshIcon />} variant="outlined" color="secondary" onClick={refreshData}>
|
<Box flexGrow={1}>
|
||||||
{LL.REFRESH()}
|
<ButtonRow>
|
||||||
</Button>
|
<Button startIcon={<RefreshIcon />} variant="outlined" color="secondary" onClick={refreshData}>
|
||||||
{device_select.state.id && device_select.state.id !== 'sensor' && (
|
{LL.REFRESH()}
|
||||||
<Button startIcon={<DownloadIcon />} variant="outlined" onClick={handleDownloadCsv}>
|
</Button>
|
||||||
{LL.EXPORT()}
|
{device_select.state.id && device_select.state.id !== 'sensor' && (
|
||||||
</Button>
|
<Button startIcon={<DownloadIcon />} variant="outlined" onClick={handleDownloadCsv}>
|
||||||
)}
|
{LL.EXPORT()}
|
||||||
</ButtonRow>
|
</Button>
|
||||||
|
)}
|
||||||
|
</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>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user