/* QQQ - Low-code Application Framework for Engineers. * Copyright (C) 2021-2022. Kingsrook, LLC * 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States * contact@kingsrook.com * https://github.com/Kingsrook/ * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ import {QInstance} from "@kingsrook/qqq-frontend-core/lib/model/metaData/QInstance"; import {QWidgetMetaData} from "@kingsrook/qqq-frontend-core/lib/model/metaData/QWidgetMetaData"; import {Skeleton} from "@mui/material"; import Card from "@mui/material/Card"; import Grid from "@mui/material/Grid"; import parse from "html-react-parser"; import React, {useEffect, useReducer, useState} from "react"; import {useLocation} from "react-router-dom"; import MDBadgeDot from "qqq/components/Temporary/MDBadgeDot"; import MDBox from "qqq/components/Temporary/MDBox"; import MDTypography from "qqq/components/Temporary/MDTypography"; import BarChart from "qqq/pages/dashboards/Widgets/BarChart"; import LineChart from "qqq/pages/dashboards/Widgets/LineChart"; import MultiStatisticsCard from "qqq/pages/dashboards/Widgets/MultiStatisticsCard"; import QuickSightChart from "qqq/pages/dashboards/Widgets/QuickSightChart"; import StepperCard from "qqq/pages/dashboards/Widgets/StepperCard"; import TableCard from "qqq/pages/dashboards/Widgets/TableCard"; import QClient from "qqq/utils/QClient"; const qController = QClient.getInstance(); interface Props { widgetMetaDataList: QWidgetMetaData[]; entityPrimaryKey?: string; } DashboardWidgets.defaultProps = { widgetMetaDataList: null, entityPrimaryKey: null }; function DashboardWidgets({widgetMetaDataList, entityPrimaryKey}: Props): JSX.Element { const location = useLocation(); const [qInstance, setQInstance] = useState(null as QInstance); const [widgetData, setWidgetData] = useState([] as any[]); const [widgetCounter, setWidgetCounter] = useState(0); const [, forceUpdate] = useReducer((x) => x + 1, 0); useEffect(() => { (async () => { const newQInstance = await qController.loadMetaData(); setQInstance(newQInstance); })(); }, []); useEffect(() => { if (!qInstance) { return; } forceUpdate(); for (let i = 0; i < widgetMetaDataList.length; i++) { widgetData[i] = {}; (async () => { widgetData[i] = await qController.widget(widgetMetaDataList[i].name, `id=${entityPrimaryKey}`); setWidgetCounter(widgetCounter + 1); forceUpdate(); })(); } setWidgetData(widgetData); }, [qInstance, widgetMetaDataList]); useEffect(() => { setWidgetData([] as any[]); }, [location.pathname]); const handleDropdownOnChange = (value: string, index: number) => { setTimeout(async () => { widgetData[index] = await qController.widget(widgetMetaDataList[index].name); }, 1); }; const widgetCount = widgetMetaDataList ? widgetMetaDataList.length : 0; // console.log(JSON.stringify(widgetMetaDataList)); // console.log(widgetCount); return ( widgetCount > 0 ? ( { widgetMetaDataList.map((widgetMetaData, i) => ( { widgetMetaData.type === "table" && ( ) } { widgetMetaData.type === "stepper" && ( { widgetMetaData.label && ( {widgetMetaData.label} ) } ) } { widgetMetaData.type === "html" && ( {widgetMetaData.label} { widgetData && widgetData[i] && widgetData[i].html ? ( parse(widgetData[i].html) ) : } ) } { widgetMetaData.type === "multiStatistics" && ( ) } { widgetMetaData.type === "quickSightChart" && ( ) } { widgetMetaData.type === "barChart" && ( ) } { widgetMetaData.type === "lineChart" && ( widgetData && widgetData[i] ? ( { widgetData[i].lineChartData.datasets.map((dataSet: any) => ( )) } )} chart={widgetData[i].lineChartData as { labels: string[]; datasets: { label: string; color: "primary" | "secondary" | "info" | "success" | "warning" | "error" | "light" | "dark"; data: number[]; }[]; }} /> ) : null ) } )) } ) : null ); } export default DashboardWidgets;