From ecbd8ed9f62e18098518bc0b3f65ccb9f7ecc467 Mon Sep 17 00:00:00 2001 From: Tim Chamberlain Date: Thu, 18 May 2023 15:51:46 -0500 Subject: [PATCH 1/2] updated to show error if widgets dont load correctly, tried to make 'big icons' more specific and an 'opt in' --- .../components/widgets/DashboardWidgets.tsx | 32 +++++++++++++++---- src/qqq/components/widgets/Widget.tsx | 32 +++++++++++-------- src/qqq/pages/apps/Home.tsx | 5 +-- src/qqq/styles/qqq-override-styles.css | 9 +++--- 4 files changed, 51 insertions(+), 27 deletions(-) diff --git a/src/qqq/components/widgets/DashboardWidgets.tsx b/src/qqq/components/widgets/DashboardWidgets.tsx index 9929d40..b870b85 100644 --- a/src/qqq/components/widgets/DashboardWidgets.tsx +++ b/src/qqq/components/widgets/DashboardWidgets.tsx @@ -97,9 +97,19 @@ function DashboardWidgets({widgetMetaDataList, tableName, entityPrimaryKey, omit widgetData[i] = {}; (async () => { - widgetData[i] = await qController.widget(widgetMetaData.name, urlParams); - setWidgetData(widgetData); - setWidgetCounter(widgetCounter + 1); + try + { + widgetData[i] = await qController.widget(widgetMetaData.name, urlParams); + setWidgetData(widgetData); + setWidgetCounter(widgetCounter + 1); + widgetData[i]["errorLoading"] = false; + } + catch(e) + { + console.error(e); + widgetData[i]["errorLoading"] = true; + } + forceUpdate(); })(); } @@ -112,9 +122,19 @@ function DashboardWidgets({widgetMetaDataList, tableName, entityPrimaryKey, omit const urlParams = getQueryParams(widgetMetaDataList[index], data); setCurrentUrlParams(urlParams); - widgetData[index] = await qController.widget(widgetMetaDataList[index].name, urlParams); - setWidgetCounter(widgetCounter + 1); - setWidgetData(widgetData); + try + { + widgetData[index] = await qController.widget(widgetMetaDataList[index].name, urlParams); + setWidgetCounter(widgetCounter + 1); + setWidgetData(widgetData); + widgetData[index]["errorLoading"] = false; + } + catch(e) + { + console.error(e); + widgetData[index]["errorLoading"] = true; + } + forceUpdate(); })(); }; diff --git a/src/qqq/components/widgets/Widget.tsx b/src/qqq/components/widgets/Widget.tsx index 21f0582..5e5a4d3 100644 --- a/src/qqq/components/widgets/Widget.tsx +++ b/src/qqq/components/widgets/Widget.tsx @@ -43,6 +43,7 @@ export interface WidgetData }[][]; dropdownNeedsSelectedText?: string; hasPermission?: boolean; + errorLoading?: boolean; } @@ -297,6 +298,7 @@ function Widget(props: React.PropsWithChildren): JSX.Element } const hasPermission = props.widgetData?.hasPermission === undefined || props.widgetData?.hasPermission === true; + const errorLoading = props.widgetData?.errorLoading !== undefined && props.widgetData?.errorLoading === true; const widgetContent = @@ -360,11 +362,6 @@ function Widget(props: React.PropsWithChildren): JSX.Element ) ) } - {/* - - */} { hasPermission && ( props.labelAdditionalComponentsLeft.map((component, i) => @@ -386,22 +383,29 @@ function Widget(props: React.PropsWithChildren): JSX.Element { - hasPermission && props.widgetData?.dropdownNeedsSelectedText ? ( - - - {props.widgetData?.dropdownNeedsSelectedText} - + errorLoading ? ( + + error + An error occurred loading widget content. ) : ( - hasPermission ? ( - props.children + hasPermission && props.widgetData?.dropdownNeedsSelectedText ? ( + + + {props.widgetData?.dropdownNeedsSelectedText} + + ) : ( - You do not have permission to view this data. + hasPermission ? ( + props.children + ) : ( + You do not have permission to view this data. + ) ) ) } { - props?.footerHTML && ( + ! errorLoading && props?.footerHTML && ( {parse(props.footerHTML)} ) } diff --git a/src/qqq/pages/apps/Home.tsx b/src/qqq/pages/apps/Home.tsx index db4f326..58639d6 100644 --- a/src/qqq/pages/apps/Home.tsx +++ b/src/qqq/pages/apps/Home.tsx @@ -26,7 +26,8 @@ import {QProcessMetaData} from "@kingsrook/qqq-frontend-core/lib/model/metaData/ import {QReportMetaData} from "@kingsrook/qqq-frontend-core/lib/model/metaData/QReportMetaData"; import {QTableMetaData} from "@kingsrook/qqq-frontend-core/lib/model/metaData/QTableMetaData"; import {QWidgetMetaData} from "@kingsrook/qqq-frontend-core/lib/model/metaData/QWidgetMetaData"; -import {Box, Icon, Typography} from "@mui/material"; +import {Icon, Typography} from "@mui/material"; +import Box from "@mui/material/Box"; import Card from "@mui/material/Card"; import Divider from "@mui/material/Divider"; import Grid from "@mui/material/Grid"; @@ -316,7 +317,7 @@ function AppHome({app}: Props): JSX.Element {hasTablePermission(tableName) ? - + .MuiBox-root > .material-icons-round, -.MuiBox-root > .MuiBox-root > .material-icons-round +.big-icon .material-icons-round { font-size: 2rem !important; } .dashboard-schedule-icon { - font-size: 1rem !important; + font-size: 1.1rem !important; position: relative; - top: -13px; - margin-right: 3px; + top: -5px; + margin-right: 8px; } From 96bc57f5f9a18f749ae4a1c64897ed4bef88a023 Mon Sep 17 00:00:00 2001 From: Tim Chamberlain Date: Thu, 18 May 2023 19:36:16 -0500 Subject: [PATCH 2/2] fixed layout, null checks --- .../components/widgets/DashboardWidgets.tsx | 24 +++++++++++++++---- src/qqq/components/widgets/Widget.tsx | 2 +- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/qqq/components/widgets/DashboardWidgets.tsx b/src/qqq/components/widgets/DashboardWidgets.tsx index b870b85..831e735 100644 --- a/src/qqq/components/widgets/DashboardWidgets.tsx +++ b/src/qqq/components/widgets/DashboardWidgets.tsx @@ -102,12 +102,18 @@ function DashboardWidgets({widgetMetaDataList, tableName, entityPrimaryKey, omit widgetData[i] = await qController.widget(widgetMetaData.name, urlParams); setWidgetData(widgetData); setWidgetCounter(widgetCounter + 1); - widgetData[i]["errorLoading"] = false; + if(widgetData[i]) + { + widgetData[i]["errorLoading"] = false; + } } catch(e) { console.error(e); - widgetData[i]["errorLoading"] = true; + if(widgetData[i]) + { + widgetData[i]["errorLoading"] = true; + } } forceUpdate(); @@ -121,23 +127,31 @@ function DashboardWidgets({widgetMetaDataList, tableName, entityPrimaryKey, omit { const urlParams = getQueryParams(widgetMetaDataList[index], data); setCurrentUrlParams(urlParams); + widgetData[index] = {}; try { widgetData[index] = await qController.widget(widgetMetaDataList[index].name, urlParams); setWidgetCounter(widgetCounter + 1); setWidgetData(widgetData); - widgetData[index]["errorLoading"] = false; + + if (widgetData[index]) + { + widgetData[index]["errorLoading"] = false; + } } catch(e) { console.error(e); - widgetData[index]["errorLoading"] = true; + if (widgetData[index]) + { + widgetData[index]["errorLoading"] = true; + } } forceUpdate(); })(); - }; + } function getQueryParams(widgetMetaData: QWidgetMetaData, extraParams: string): string { diff --git a/src/qqq/components/widgets/Widget.tsx b/src/qqq/components/widgets/Widget.tsx index 5e5a4d3..447cfc9 100644 --- a/src/qqq/components/widgets/Widget.tsx +++ b/src/qqq/components/widgets/Widget.tsx @@ -384,7 +384,7 @@ function Widget(props: React.PropsWithChildren): JSX.Element { errorLoading ? ( - + error An error occurred loading widget content.