show message in Dashboard if no fav entities set

This commit is contained in:
proddy
2025-01-14 21:44:56 +01:00
parent 64a2f5eb11
commit 570678e3d3
13 changed files with 112 additions and 75 deletions

View File

@@ -1,9 +1,9 @@
import { useContext, useEffect, useState } from 'react'; import { useContext, useEffect, useState } from 'react';
import { IconContext } from 'react-icons/lib'; import { IconContext } from 'react-icons/lib';
import { Link } from 'react-router';
import { toast } from 'react-toastify'; import { toast } from 'react-toastify';
import ChevronRightIcon from '@mui/icons-material/ChevronRight'; import ChevronRightIcon from '@mui/icons-material/ChevronRight';
import ConstructionIcon from '@mui/icons-material/Construction';
import EditIcon from '@mui/icons-material/Edit'; import EditIcon from '@mui/icons-material/Edit';
import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
import UnfoldLessIcon from '@mui/icons-material/UnfoldLess'; import UnfoldLessIcon from '@mui/icons-material/UnfoldLess';
@@ -22,7 +22,7 @@ import { Body, Cell, Row, Table } from '@table-library/react-table-library/table
import { useTheme } from '@table-library/react-table-library/theme'; import { useTheme } from '@table-library/react-table-library/theme';
import { CellTree, useTree } from '@table-library/react-table-library/tree'; import { CellTree, useTree } from '@table-library/react-table-library/tree';
import { useRequest } from 'alova/client'; import { useRequest } from 'alova/client';
import { FormLoader, SectionContent, useLayoutTitle } from 'components'; import { FormLoader, MessageBox, SectionContent, useLayoutTitle } from 'components';
import { AuthenticatedContext } from 'contexts/authentication'; import { AuthenticatedContext } from 'contexts/authentication';
import { useI18nContext } from 'i18n/i18n-react'; import { useI18nContext } from 'i18n/i18n-react';
import { useInterval, usePersistState } from 'utils'; import { useInterval, usePersistState } from 'utils';
@@ -224,6 +224,10 @@ const Dashboard = () => {
return <FormLoader onRetry={fetchDashboard} errorMessage={error?.message} />; return <FormLoader onRetry={fetchDashboard} errorMessage={error?.message} />;
} }
const hasFavEntities = data.filter(
(item: DashboardItem) => item.id <= 90
).length;
return ( return (
<> <>
<Box <Box
@@ -236,10 +240,7 @@ const Dashboard = () => {
<Grid container spacing={0} justifyContent="flex-start"> <Grid container spacing={0} justifyContent="flex-start">
<Grid size={11}> <Grid size={11}>
<Typography mb={2} variant="body1" color="warning"> <Typography mb={2} variant="body1" color="warning">
{LL.DASHBOARD_1()}&nbsp; {LL.DASHBOARD_1()}
<ConstructionIcon
sx={{ color: '#9e9e9e', fontSize: 20, verticalAlign: 'middle' }}
/>
</Typography> </Typography>
</Grid> </Grid>
@@ -262,6 +263,24 @@ const Dashboard = () => {
</Grid> </Grid>
</Box> </Box>
{!loading && !hasFavEntities && (
<MessageBox my={1} level="info" message="">
<Typography>
{LL.NO_DATA_1()}&nbsp;
<Link to="/customizations" style={{ color: 'white' }}>
{LL.CUSTOMIZATIONS()}
</Link>
&nbsp;{LL.NO_DATA_2()}&nbsp;
{LL.NO_DATA_3()}&nbsp;
<Link to="/devices" style={{ color: 'white' }}>
{LL.DEVICES()}
</Link>
.
</Typography>
</MessageBox>
)}
{data.length > 0 && (
<Box <Box
padding={1} padding={1}
justifyContent="center" justifyContent="center"
@@ -278,11 +297,6 @@ const Dashboard = () => {
style: { verticalAlign: 'middle' } style: { verticalAlign: 'middle' }
}} }}
> >
{!loading && data.length === 0 ? (
<Typography variant="subtitle2" color="secondary">
{LL.NO_DATA()}
</Typography>
) : (
<Table <Table
data={{ nodes: data }} data={{ nodes: data }}
theme={dashboard_theme} theme={dashboard_theme}
@@ -338,9 +352,9 @@ const Dashboard = () => {
</Body> </Body>
)} )}
</Table> </Table>
)}
</IconContext.Provider> </IconContext.Provider>
</Box> </Box>
)}
</> </>
); );
}; };

View File

@@ -340,11 +340,12 @@ const cz: Translation = {
RESTARTING_POST: 'Příprava', RESTARTING_POST: 'Příprava',
AUTO_SCROLL: 'Automatické rolování', AUTO_SCROLL: 'Automatické rolování',
DASHBOARD: 'Dashboard', DASHBOARD: 'Dashboard',
NO_DATA: 'Žádná data nejsou k dispozici',
DASHBOARD_1: 'Přizpůsobte si dashboard označením EMS entit jako Oblíbené pomocí modulu Přizpůsobení', DASHBOARD_1: 'Přizpůsobte si dashboard označením EMS entit jako Oblíbené pomocí modulu Přizpůsobení',
DEVELOPER_MODE: 'Režim vývojáře', DEVELOPER_MODE: 'Režim vývojáře',
DUPLICATE: 'Duplicate', // TODO translate DUPLICATE: 'Duplicate', // TODO translate
UPGRADE: 'Upgrade' // TODO translate NO_DATA_1: 'No favourite EMS entities found. Use the', // TODO translate
NO_DATA_2: 'module to mark them.', // TODO translate
NO_DATA_3: 'To see all available entities go to' // TODO translate
}; };
export default cz; export default cz;

View File

@@ -340,11 +340,13 @@ const de: Translation = {
RESTARTING_POST: 'Vorbereitung', RESTARTING_POST: 'Vorbereitung',
AUTO_SCROLL: 'Automatisches Scrollen', AUTO_SCROLL: 'Automatisches Scrollen',
DASHBOARD: 'Dashboard', DASHBOARD: 'Dashboard',
NO_DATA: 'Keine Daten verfügbar',
DASHBOARD_1: 'Passen Sie Ihr Dashboard an, indem Sie EMS-Entitäten mithilfe des Moduls „Anpassungen“ als Favorit markieren', DASHBOARD_1: 'Passen Sie Ihr Dashboard an, indem Sie EMS-Entitäten mithilfe des Moduls „Anpassungen“ als Favorit markieren',
DEVELOPER_MODE: 'Entwicklermodus', DEVELOPER_MODE: 'Entwicklermodus',
DUPLICATE: 'Kopieren', DUPLICATE: 'Kopieren',
UPGRADE: 'Aktualisieren' UPGRADE: 'Aktualisieren',
NO_DATA_1: 'No favourite EMS entities found. Use the', // TODO translate
NO_DATA_2: 'module to mark them.', // TODO translate
NO_DATA_3: 'To see all available entities go to' // TODO translate
}; };
export default de; export default de;

View File

@@ -340,11 +340,13 @@ const en: Translation = {
RESTARTING_POST: 'Preparing', RESTARTING_POST: 'Preparing',
AUTO_SCROLL: 'Auto Scroll', AUTO_SCROLL: 'Auto Scroll',
DASHBOARD: 'Dashboard', DASHBOARD: 'Dashboard',
NO_DATA: 'No data available', DASHBOARD_1: 'The Dashboard shows all EMS entities that are active and marked as a Favorite, plus any Custom Entities, Schedules and external Sensors.',
DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module',
DEVELOPER_MODE: 'Developer Mode', DEVELOPER_MODE: 'Developer Mode',
DUPLICATE: 'Duplicate', DUPLICATE: 'Duplicate',
UPGRADE: 'Upgrade' UPGRADE: 'Upgrade',
NO_DATA_1: 'No favourite EMS entities found. Use the',
NO_DATA_2: 'module to mark them.',
NO_DATA_3: 'To see all available entities go to'
}; };
export default en; export default en;

View File

@@ -340,11 +340,13 @@ const fr: Translation = {
RESTARTING_POST: 'Preparing', // TODO translate RESTARTING_POST: 'Preparing', // TODO translate
AUTO_SCROLL: 'Auto Scroll', // TODO translate AUTO_SCROLL: 'Auto Scroll', // TODO translate
DASHBOARD: 'Dashboard', // TODO translate DASHBOARD: 'Dashboard', // TODO translate
NO_DATA: 'No data available', // TODO translate
DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module', // TODO translate DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module', // TODO translate
DEVELOPER_MODE: 'Developer Mode', // TODO translate DEVELOPER_MODE: 'Developer Mode', // TODO translate
DUPLICATE: 'Duplicate', // TODO translate DUPLICATE: 'Duplicate', // TODO translate
UPGRADE: 'Upgrade' // TODO translate UPGRADE: 'Upgrade', // TODO translate
NO_DATA_1: 'No favourite EMS entities found. Use the', // TODO translate
NO_DATA_2: 'module to mark them.', // TODO translate
NO_DATA_3: 'To see all available entities go to' // TODO translate
}; };
export default fr; export default fr;

View File

@@ -340,11 +340,13 @@ const it: Translation = {
RESTARTING_POST: 'Preparing', // TODO translate RESTARTING_POST: 'Preparing', // TODO translate
AUTO_SCROLL: 'Auto Scroll', // TODO translate AUTO_SCROLL: 'Auto Scroll', // TODO translate
DASHBOARD: 'Dashboard', // TODO translate DASHBOARD: 'Dashboard', // TODO translate
NO_DATA: 'No data available', // TODO translate
DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module', // TODO translate DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module', // TODO translate
DEVELOPER_MODE: 'Developer Mode', // TODO translate DEVELOPER_MODE: 'Developer Mode', // TODO translate
DUPLICATE: 'Duplicate', // TODO translate DUPLICATE: 'Duplicate', // TODO translate
UPGRADE: 'Upgrade' // TODO translate UPGRADE: 'Upgrade', // TODO translate
NO_DATA_1: 'No favourite EMS entities found. Use the', // TODO translate
NO_DATA_2: 'module to mark them.', // TODO translate
NO_DATA_3: 'To see all available entities go to' // TODO translate
}; };
export default it; export default it;

View File

@@ -340,11 +340,13 @@ const nl: Translation = {
RESTARTING_POST: 'Voorbereiding', RESTARTING_POST: 'Voorbereiding',
AUTO_SCROLL: 'Automatisch Scrollen', AUTO_SCROLL: 'Automatisch Scrollen',
DASHBOARD: 'Dashboard', DASHBOARD: 'Dashboard',
NO_DATA: 'Geen data beschikbaar',
DASHBOARD_1: 'Pas uw dashboard aan door EMS-entiteiten als favoriet te markeren met behulp van de module Aanpassingen', DASHBOARD_1: 'Pas uw dashboard aan door EMS-entiteiten als favoriet te markeren met behulp van de module Aanpassingen',
DEVELOPER_MODE: 'Ontwikkelaarsmodus', DEVELOPER_MODE: 'Ontwikkelaarsmodus',
DUPLICATE: 'Duplicaat', DUPLICATE: 'Duplicaat',
UPGRADE: 'Upgraden' UPGRADE: 'Upgraden',
NO_DATA_1: 'Geen favorite EMS entiteiten gevonden. Gebruik de',
NO_DATA_2: 'module om ze te markeren.',
NO_DATA_3: 'Om alle beschikbare entiteiten te bekijken ga naar'
}; };
export default nl; export default nl;

View File

@@ -340,11 +340,13 @@ const no: Translation = {
RESTARTING_POST: 'Preparing', // TODO translate RESTARTING_POST: 'Preparing', // TODO translate
AUTO_SCROLL: 'Auto Scroll', // TODO translate AUTO_SCROLL: 'Auto Scroll', // TODO translate
DASHBOARD: 'Dashboard', // TODO translate DASHBOARD: 'Dashboard', // TODO translate
NO_DATA: 'No data available', // TODO translate
DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module', // TODO translate DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module', // TODO translate
DEVELOPER_MODE: 'Developer Mode', // TODO translate DEVELOPER_MODE: 'Developer Mode', // TODO translate
DUPLICATE: 'Duplicate', // TODO translate DUPLICATE: 'Duplicate', // TODO translate
UPGRADE: 'Upgrade' // TODO translate UPGRADE: 'Upgrade', // TODO translate
NO_DATA_1: 'No favourite EMS entities found. Use the', // TODO translate
NO_DATA_2: 'module to mark them.', // TODO translate
NO_DATA_3: 'To see all available entities go to' // TODO translate
}; };
export default no; export default no;

View File

@@ -340,11 +340,13 @@ const pl: BaseTranslation = {
RESTARTING_POST: 'Preparing', // TODO translate RESTARTING_POST: 'Preparing', // TODO translate
AUTO_SCROLL: 'Auto Scroll', // TODO translate AUTO_SCROLL: 'Auto Scroll', // TODO translate
DASHBOARD: 'Dashboard', // TODO translate DASHBOARD: 'Dashboard', // TODO translate
NO_DATA: 'No data available', // TODO translate
DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module', // TODO translate DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module', // TODO translate
DEVELOPER_MODE: 'Developer Mode', // TODO translate DEVELOPER_MODE: 'Developer Mode', // TODO translate
DUPLICATE: 'Duplicate', // TODO translate DUPLICATE: 'Duplicate', // TODO translate
UPGRADE: 'Upgrade' // TODO translate UPGRADE: 'Upgrade', // TODO translate
NO_DATA_1: 'No favourite EMS entities found. Use the', // TODO translate
NO_DATA_2: 'module to mark them.', // TODO translate
NO_DATA_3: 'To see all available entities go to' // TODO translate
}; };
export default pl; export default pl;

View File

@@ -340,11 +340,13 @@ const sk: Translation = {
RESTARTING_POST: 'Príprava', RESTARTING_POST: 'Príprava',
AUTO_SCROLL: 'Automatické rolovanie', AUTO_SCROLL: 'Automatické rolovanie',
DASHBOARD: 'Panel', DASHBOARD: 'Panel',
NO_DATA: 'Nie sú k dispozícii žiadne údaje',
DASHBOARD_1: 'Prispôsobte si svoj informačný panel tak, že označíte entity EMS ako Obľúbené pomocou modulu Prispôsobenia', DASHBOARD_1: 'Prispôsobte si svoj informačný panel tak, že označíte entity EMS ako Obľúbené pomocou modulu Prispôsobenia',
DEVELOPER_MODE: 'Režim vývojára', DEVELOPER_MODE: 'Režim vývojára',
DUPLICATE: 'Duplicitné', DUPLICATE: 'Duplicitné',
UPGRADE: 'Inovovať' UPGRADE: 'Inovovať',
NO_DATA_1: 'No favourite EMS entities found. Use the', // TODO translate
NO_DATA_2: 'module to mark them.', // TODO translate
NO_DATA_3: 'To see all available entities go to' // TODO translate
}; };
export default sk; export default sk;

View File

@@ -340,11 +340,13 @@ const sv: Translation = {
RESTARTING_POST: 'Förbereder', RESTARTING_POST: 'Förbereder',
AUTO_SCROLL: 'Autoskrolla', AUTO_SCROLL: 'Autoskrolla',
DASHBOARD: 'Kontrollpanel', DASHBOARD: 'Kontrollpanel',
NO_DATA: 'Ingen data tillgänglig',
DASHBOARD_1: 'Anpassa din kontrollpanel genom att markera EMS enheter som Favorit i modulen Anpassningar', DASHBOARD_1: 'Anpassa din kontrollpanel genom att markera EMS enheter som Favorit i modulen Anpassningar',
DEVELOPER_MODE: 'Utvecklarläge', DEVELOPER_MODE: 'Utvecklarläge',
DUPLICATE: 'Dublett', DUPLICATE: 'Dublett',
UPGRADE: 'Uppgradera' UPGRADE: 'Uppgradera',
NO_DATA_1: 'Inga EMS entiteter har markeras som Favorit. Använd',
NO_DATA_2: 'modulen Anpassningar för att markera dem.',
NO_DATA_3: 'För att se alla tillgängliga entiteter gå till'
}; };
export default sv; export default sv;

View File

@@ -340,11 +340,13 @@ const tr: Translation = {
RESTARTING_POST: 'Preparing', // TODO translate RESTARTING_POST: 'Preparing', // TODO translate
AUTO_SCROLL: 'Auto Scroll', // TODO translate AUTO_SCROLL: 'Auto Scroll', // TODO translate
DASHBOARD: 'Dashboard', // TODO translate DASHBOARD: 'Dashboard', // TODO translate
NO_DATA: 'No data available', // TODO translate
DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module', // TODO translate DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module', // TODO translate
DEVELOPER_MODE: 'Developer Mode', // TODO translate DEVELOPER_MODE: 'Developer Mode', // TODO translate
DUPLICATE: 'Duplicate', // TODO translate DUPLICATE: 'Duplicate', // TODO translate
UPGRADE: 'Upgrade' // TODO translate UPGRADE: 'Upgrade', // TODO translate
NO_DATA_1: 'No favourite EMS entities found. Use the', // TODO translate
NO_DATA_2: 'module to mark them.', // TODO translate
NO_DATA_3: 'To see all available entities go to' // TODO translate
}; };
export default tr; export default tr;

View File

@@ -4507,7 +4507,7 @@ router
let fake = false; let fake = false;
// fake = true; // for testing // fake = true; // for testing, shows a subset of data
if (!fake) { if (!fake) {
// pick EMS devices from coredata // pick EMS devices from coredata
@@ -4603,35 +4603,37 @@ router
// for testing only // for testing only
// add the custom entity data // add the custom entity data
// dashboard_object = {
// id: DeviceTypeUniqueID.CUSTOM_UID, // unique ID for custom entities
// t: DeviceType.CUSTOM,
// nodes: getDashboardEntityData(99)
// };
// // only add to dashboard if we have values
// if ((dashboard_object.nodes ?? []).length > 0) {
// dashboard_data.push(dashboard_object);
// }
let scheduler_data = emsesp_schedule.schedule.filter((item) => item.name);
let scheduler_data2 = scheduler_data.map((item, index) => ({
id: DeviceTypeUniqueID.SCHEDULER_UID * 100 + index,
dv: {
id: '00' + item.name,
v: item.active ? 'on' : 'off',
c: item.name,
l: ['off', 'on']
}
}));
dashboard_object = { dashboard_object = {
id: DeviceTypeUniqueID.SCHEDULER_UID, id: DeviceTypeUniqueID.CUSTOM_UID, // unique ID for custom entities
t: DeviceType.SCHEDULER, t: DeviceType.CUSTOM,
nodes: scheduler_data2 nodes: getDashboardEntityData(DeviceTypeUniqueID.CUSTOM_UID)
}; };
// only add to dashboard if we have values // only add to dashboard if we have values
if ((dashboard_object.nodes ?? []).length > 0) { if ((dashboard_object.nodes ?? []).length > 0) {
dashboard_data.push(dashboard_object); dashboard_data.push(dashboard_object);
} }
// add the scheduler data
// let scheduler_data = emsesp_schedule.schedule.filter((item) => item.name);
// let scheduler_data2 = scheduler_data.map((item, index) => ({
// id: DeviceTypeUniqueID.SCHEDULER_UID * 100 + index,
// dv: {
// id: '00' + item.name,
// v: item.active ? 'on' : 'off',
// c: item.name,
// l: ['off', 'on']
// }
// }));
// dashboard_object = {
// id: DeviceTypeUniqueID.SCHEDULER_UID,
// t: DeviceType.SCHEDULER,
// nodes: scheduler_data2
// };
// only add to dashboard if we have values
// if ((dashboard_object.nodes ?? []).length > 0) {
// dashboard_data.push(dashboard_object);
// }
} }
// console.log('dashboard_data: ', dashboard_data); // console.log('dashboard_data: ', dashboard_data);