mirror of
https://github.com/Kingsrook/qqq-frontend-material-dashboard.git
synced 2025-07-17 12:50:43 +00:00
Merge pull request #45 from Kingsrook/feature/CE-989-bug-performance-issue
CE-989 add option to (not) includeTableCountsOn(app)HomeScreen
This commit is contained in:
@ -22,7 +22,9 @@
|
||||
package com.kingsrook.qqq.frontend.materialdashboard.model.metadata;
|
||||
|
||||
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.layout.QAppMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.layout.QSupplementalAppMetaData;
|
||||
import com.kingsrook.qqq.backend.core.utils.CollectionUtils;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
@ -30,7 +32,39 @@ import com.kingsrook.qqq.backend.core.model.metadata.layout.QSupplementalAppMeta
|
||||
*******************************************************************************/
|
||||
public class MaterialDashboardAppMetaData extends QSupplementalAppMetaData
|
||||
{
|
||||
public static final String TYPE_NAME = "materialDashboard";
|
||||
|
||||
private Boolean showAppLabelOnHomeScreen = true;
|
||||
private Boolean includeTableCountsOnHomeScreen = true;
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
public static MaterialDashboardAppMetaData of(QAppMetaData app)
|
||||
{
|
||||
return ((MaterialDashboardAppMetaData) CollectionUtils.nonNullMap(app.getSupplementalMetaData()).get(TYPE_NAME));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** either get the supplemental meta dat attached to an app - or create a new one
|
||||
** and attach it to the app, and return that.
|
||||
*******************************************************************************/
|
||||
public static MaterialDashboardAppMetaData ofOrWithNew(QAppMetaData app)
|
||||
{
|
||||
MaterialDashboardAppMetaData materialDashboardAppMetaData = of(app);
|
||||
|
||||
if(materialDashboardAppMetaData == null)
|
||||
{
|
||||
materialDashboardAppMetaData = new MaterialDashboardAppMetaData();
|
||||
app.withSupplementalMetaData(materialDashboardAppMetaData);
|
||||
}
|
||||
|
||||
return (materialDashboardAppMetaData);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -51,7 +85,7 @@ public class MaterialDashboardAppMetaData extends QSupplementalAppMetaData
|
||||
@Override
|
||||
public String getType()
|
||||
{
|
||||
return ("materialDashboard");
|
||||
return TYPE_NAME;
|
||||
}
|
||||
|
||||
|
||||
@ -85,4 +119,35 @@ public class MaterialDashboardAppMetaData extends QSupplementalAppMetaData
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for includeTableCountsOnHomeScreen
|
||||
*******************************************************************************/
|
||||
public Boolean getIncludeTableCountsOnHomeScreen()
|
||||
{
|
||||
return (this.includeTableCountsOnHomeScreen);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for includeTableCountsOnHomeScreen
|
||||
*******************************************************************************/
|
||||
public void setIncludeTableCountsOnHomeScreen(Boolean includeTableCountsOnHomeScreen)
|
||||
{
|
||||
this.includeTableCountsOnHomeScreen = includeTableCountsOnHomeScreen;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Fluent setter for includeTableCountsOnHomeScreen
|
||||
*******************************************************************************/
|
||||
public MaterialDashboardAppMetaData withIncludeTableCountsOnHomeScreen(Boolean includeTableCountsOnHomeScreen)
|
||||
{
|
||||
this.includeTableCountsOnHomeScreen = includeTableCountsOnHomeScreen;
|
||||
return (this);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -77,9 +77,11 @@ function AppHome({app}: Props): JSX.Element
|
||||
|
||||
const mdbMetaData = app?.supplementalAppMetaData?.get("materialDashboard");
|
||||
let showAppLabelOnHomeScreen = true;
|
||||
let includeTableCountsOnHomeScreen = true;
|
||||
if(mdbMetaData)
|
||||
{
|
||||
showAppLabelOnHomeScreen = mdbMetaData.showAppLabelOnHomeScreen;
|
||||
includeTableCountsOnHomeScreen = mdbMetaData.includeTableCountsOnHomeScreen;
|
||||
}
|
||||
|
||||
useEffect(() =>
|
||||
@ -128,14 +130,15 @@ function AppHome({app}: Props): JSX.Element
|
||||
const tableCountNumbers = new Map<string, string>();
|
||||
const tableCountTexts = new Map<string, string>();
|
||||
newTables.forEach((table) =>
|
||||
{
|
||||
if(includeTableCountsOnHomeScreen)
|
||||
{
|
||||
tableCounts.set(table.name, {isLoading: true, value: null});
|
||||
|
||||
setTimeout(async () =>
|
||||
{
|
||||
const tableMetaData = await qController.loadTableMetaData(table.name);
|
||||
let countResult = null;
|
||||
if(tableMetaData.capabilities.has(Capability.TABLE_COUNT) && tableMetaData.readPermission)
|
||||
if (tableMetaData.capabilities.has(Capability.TABLE_COUNT) && tableMetaData.readPermission)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -152,7 +155,7 @@ function AppHome({app}: Props): JSX.Element
|
||||
tableCountTexts.set(table.name, " ");
|
||||
}
|
||||
}
|
||||
catch(e)
|
||||
catch (e)
|
||||
{
|
||||
console.log("Caught: " + e);
|
||||
tableCountNumbers.set(table.name, "–");
|
||||
@ -171,6 +174,17 @@ function AppHome({app}: Props): JSX.Element
|
||||
setTableCountTexts(tableCountTexts);
|
||||
setUpdatedTableCounts(new Date());
|
||||
}, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
tableCounts.set(table.name, {isLoading: false, value: null});
|
||||
tableCountNumbers.set(table.name, " ");
|
||||
tableCountTexts.set(table.name, " ");
|
||||
|
||||
setTableCounts(tableCounts);
|
||||
setTableCountNumbers(tableCountNumbers);
|
||||
setTableCountTexts(tableCountTexts);
|
||||
}
|
||||
});
|
||||
setTableCounts(tableCounts);
|
||||
|
||||
@ -299,7 +313,7 @@ function AppHome({app}: Props): JSX.Element
|
||||
</Box>
|
||||
{
|
||||
section.processes ? (
|
||||
<Box p={3} pl={5} pt={0} pb={1}>
|
||||
<Box p={3} pl={3} pt={0} pb={1}>
|
||||
<MDTypography variant="h6">Actions</MDTypography>
|
||||
</Box>
|
||||
) : null
|
||||
@ -340,7 +354,7 @@ function AppHome({app}: Props): JSX.Element
|
||||
}
|
||||
{
|
||||
section.reports ? (
|
||||
<Box p={3} pl={5} pt={0} pb={1}>
|
||||
<Box p={3} pl={3} pt={0} pb={1}>
|
||||
<MDTypography variant="h6">Reports</MDTypography>
|
||||
</Box>
|
||||
) : null
|
||||
@ -383,7 +397,7 @@ function AppHome({app}: Props): JSX.Element
|
||||
}
|
||||
{
|
||||
section.tables ? (
|
||||
<Box p={3} pl={5} pb={1} pt={0}>
|
||||
<Box p={3} pl={3} pb={1} pt={0}>
|
||||
<MDTypography variant="h6">Data</MDTypography>
|
||||
</Box>
|
||||
) : null
|
||||
@ -395,6 +409,13 @@ function AppHome({app}: Props): JSX.Element
|
||||
section.tables.map((tableName) =>
|
||||
{
|
||||
let table = app.childMap.get(tableName);
|
||||
let count = "";
|
||||
let percentage = "";
|
||||
if(includeTableCountsOnHomeScreen)
|
||||
{
|
||||
count = !tableCounts.has(table.name) || tableCounts.get(table.name).isLoading ? "..." : (tableCountNumbers.get(table.name));
|
||||
percentage = !tableCounts.has(table.name) || tableCounts.get(table.name).isLoading ? "" : (tableCountTexts.get(table.name));
|
||||
}
|
||||
return (
|
||||
<Grid key={table.name} item xs={12} md={12} lg={tileSizeLg}>
|
||||
{hasTablePermission(tableName) ?
|
||||
@ -402,8 +423,8 @@ function AppHome({app}: Props): JSX.Element
|
||||
<Box className="big-icon" mb={3}>
|
||||
<MiniStatisticsCard
|
||||
title={{fontWeight: "bold", text: table.label}}
|
||||
count={!tableCounts.has(table.name) || tableCounts.get(table.name).isLoading ? "..." : (tableCountNumbers.get(table.name))}
|
||||
percentage={{color: "info", text: (!tableCounts.has(table.name) || tableCounts.get(table.name).isLoading ? "" : (tableCountTexts.get(table.name)))}}
|
||||
count={count}
|
||||
percentage={{color: "info", text: percentage}}
|
||||
icon={{color: "info", component: <Icon>{table.iconName || app.iconName}</Icon>}}
|
||||
/>
|
||||
</Box>
|
||||
@ -411,8 +432,8 @@ function AppHome({app}: Props): JSX.Element
|
||||
<Box mb={3} title="You do not have permission to access this table">
|
||||
<MiniStatisticsCard
|
||||
title={{fontWeight: "bold", text: table.label}}
|
||||
count={!tableCounts.has(table.name) || tableCounts.get(table.name).isLoading ? "..." : (tableCountNumbers.get(table.name))}
|
||||
percentage={{color: "info", text: (!tableCounts.has(table.name) || tableCounts.get(table.name).isLoading ? "" : (tableCountTexts.get(table.name)))}}
|
||||
count={count}
|
||||
percentage={{color: "info", text: percentage}}
|
||||
icon={{color: "info", component: <Icon>{table.iconName || app.iconName}</Icon>}}
|
||||
isDisabled={true}
|
||||
/>
|
||||
|
Reference in New Issue
Block a user