mirror of
https://github.com/Kingsrook/qqq-frontend-material-dashboard.git
synced 2025-07-18 05:10:45 +00:00
CE-604 Make tab parents remember current selection; fix changing data passing through multiple levels of parents
This commit is contained in:
@ -26,7 +26,6 @@ import Tab from "@mui/material/Tab";
|
|||||||
import Tabs from "@mui/material/Tabs";
|
import Tabs from "@mui/material/Tabs";
|
||||||
import parse from "html-react-parser";
|
import parse from "html-react-parser";
|
||||||
import React, {useContext, useEffect, useReducer, useState} from "react";
|
import React, {useContext, useEffect, useReducer, useState} from "react";
|
||||||
import {useLocation} from "react-router-dom";
|
|
||||||
import QContext from "QContext";
|
import QContext from "QContext";
|
||||||
import MDTypography from "qqq/components/legacy/MDTypography";
|
import MDTypography from "qqq/components/legacy/MDTypography";
|
||||||
import TabPanel from "qqq/components/misc/TabPanel";
|
import TabPanel from "qqq/components/misc/TabPanel";
|
||||||
@ -80,7 +79,6 @@ DashboardWidgets.defaultProps = {
|
|||||||
|
|
||||||
function DashboardWidgets({widgetMetaDataList, tableName, entityPrimaryKey, omitWrappingGridContainer, areChildren, childUrlParams, parentWidgetMetaData, wrapWidgetsInTabPanels}: Props): JSX.Element
|
function DashboardWidgets({widgetMetaDataList, tableName, entityPrimaryKey, omitWrappingGridContainer, areChildren, childUrlParams, parentWidgetMetaData, wrapWidgetsInTabPanels}: Props): JSX.Element
|
||||||
{
|
{
|
||||||
const location = useLocation();
|
|
||||||
const [widgetData, setWidgetData] = useState([] as any[]);
|
const [widgetData, setWidgetData] = useState([] as any[]);
|
||||||
const [widgetCounter, setWidgetCounter] = useState(0);
|
const [widgetCounter, setWidgetCounter] = useState(0);
|
||||||
const [, forceUpdate] = useReducer((x) => x + 1, 0);
|
const [, forceUpdate] = useReducer((x) => x + 1, 0);
|
||||||
@ -89,11 +87,22 @@ function DashboardWidgets({widgetMetaDataList, tableName, entityPrimaryKey, omit
|
|||||||
const [haveLoadedParams, setHaveLoadedParams] = useState(false);
|
const [haveLoadedParams, setHaveLoadedParams] = useState(false);
|
||||||
const {accentColor} = useContext(QContext);
|
const {accentColor} = useContext(QContext);
|
||||||
|
|
||||||
const [selectedTab, setSelectedTab] = useState(0);
|
let initialSelectedTab = 0;
|
||||||
|
let selectedTabKey: string = null;
|
||||||
|
if(parentWidgetMetaData && wrapWidgetsInTabPanels)
|
||||||
|
{
|
||||||
|
selectedTabKey = `qqq.widgets.selectedTabs.${parentWidgetMetaData.name}`
|
||||||
|
if (localStorage.getItem(selectedTabKey))
|
||||||
|
{
|
||||||
|
initialSelectedTab = Number(localStorage.getItem(selectedTabKey));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const [selectedTab, setSelectedTab] = useState(initialSelectedTab);
|
||||||
|
|
||||||
const changeTab = (newValue: number) =>
|
const changeTab = (newValue: number) =>
|
||||||
{
|
{
|
||||||
setSelectedTab(newValue);
|
setSelectedTab(newValue);
|
||||||
|
localStorage.setItem(selectedTabKey, String(newValue));
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() =>
|
useEffect(() =>
|
||||||
@ -260,7 +269,7 @@ function DashboardWidgets({widgetMetaDataList, tableName, entityPrimaryKey, omit
|
|||||||
widgetIndex={i}
|
widgetIndex={i}
|
||||||
widgetMetaData={widgetMetaData}
|
widgetMetaData={widgetMetaData}
|
||||||
data={widgetData[i]}
|
data={widgetData[i]}
|
||||||
reloadWidgetCallback={reloadWidget}
|
reloadWidgetCallback={(data) => reloadWidget(i, data)}
|
||||||
storeDropdownSelections={widgetMetaData.storeDropdownSelections}
|
storeDropdownSelections={widgetMetaData.storeDropdownSelections}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
@ -56,7 +56,7 @@ interface Props
|
|||||||
widgetMetaData?: QWidgetMetaData;
|
widgetMetaData?: QWidgetMetaData;
|
||||||
widgetIndex: number;
|
widgetIndex: number;
|
||||||
data: ParentWidgetData;
|
data: ParentWidgetData;
|
||||||
reloadWidgetCallback?: (widgetIndex: number, params: string) => void;
|
reloadWidgetCallback?: (params: string) => void;
|
||||||
entityPrimaryKey?: string;
|
entityPrimaryKey?: string;
|
||||||
tableName?: string;
|
tableName?: string;
|
||||||
storeDropdownSelections?: boolean;
|
storeDropdownSelections?: boolean;
|
||||||
@ -92,10 +92,15 @@ function ParentWidget({urlParams, widgetMetaData, widgetIndex, data, reloadWidge
|
|||||||
}
|
}
|
||||||
}, [qInstance, data, childUrlParams]);
|
}, [qInstance, data, childUrlParams]);
|
||||||
|
|
||||||
|
useEffect(() =>
|
||||||
|
{
|
||||||
|
setChildUrlParams(urlParams)
|
||||||
|
}, [urlParams]);
|
||||||
|
|
||||||
const parentReloadWidgetCallback = (data: string) =>
|
const parentReloadWidgetCallback = (data: string) =>
|
||||||
{
|
{
|
||||||
setChildUrlParams(data);
|
setChildUrlParams(data);
|
||||||
reloadWidgetCallback(widgetIndex, data);
|
reloadWidgetCallback(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
Reference in New Issue
Block a user