/* 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 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 TableCard from "qqq/pages/dashboards/Widgets/TableCard"; import QClient from "qqq/utils/QClient"; const qController = QClient.getInstance(); interface Props { widgetNameList: string[]; entityPrimaryKey?: string; } DashboardWidgets.defaultProps = { widgetNameList: null, entityPrimaryKey: null }; function DashboardWidgets({widgetNameList, entityPrimaryKey}: Props): JSX.Element { const location = useLocation(); const [qInstance, setQInstance] = useState(null as QInstance); const [widgets, setWidgets] = useState([] as any[]); const [widgetNames, setWidgetNames] = 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; } for (let i = 0; i < widgetNameList.length; i++) { widgets[i] = {}; (async () => { widgets[i] = await qController.widget(widgetNameList[i], `id=${entityPrimaryKey}`); setWidgetCounter(widgetCounter + 1); forceUpdate(); })(); } setWidgets(widgets); }, [qInstance, widgetNames]); useEffect(() => { setWidgets([] as any[]); setWidgetNames([] as any[]); }, [location]); const handleDropdownOnChange = (value: string, index: number) => { setTimeout(async () => { widgets[index] = await qController.widget(widgetNameList[index]); }, 1); }; const widgetCount = widgets ? widgets.length : 0; console.log(widgets); return ( widgetCount > 0 ? ( { widgets.map((widget, i) => ( { widget.type === "table" && ( ) } { widget.type === "html" && ( {widget.title} {parse(widget.html)} ) } { widget.type === "multiStatistics" && ( ) } )) } { widgets.map((widget, i) => ( { widget.type === "quickSightChart" && ( ) } { widget.type === "barChart" && ( ) } { widget.type === "lineChart" && ( { widget.lineChartData.datasets.map((dataSet: any) => ( )) } )} chart={widget.lineChartData as { labels: string[]; datasets: { label: string; color: "primary" | "secondary" | "info" | "success" | "warning" | "error" | "light" | "dark"; data: number[]; }[]; }} /> ) } )) } ) : null ); } export default DashboardWidgets;