mirror of
https://github.com/Kingsrook/qqq-frontend-material-dashboard.git
synced 2025-07-18 05:10:45 +00:00
Don't crash app home if count comes back null; don't crash table if no field named 'id'
This commit is contained in:
@ -55,6 +55,8 @@ function AppHome({app}: Props): JSX.Element
|
||||
const [reports, setReports] = useState([] as QReportMetaData[]);
|
||||
const [childApps, setChildApps] = useState([] as QAppMetaData[]);
|
||||
const [tableCounts, setTableCounts] = useState(new Map<string, { isLoading: boolean, value: number }>());
|
||||
const [tableCountNumbers, setTableCountNumbers] = useState(new Map<string, string>());
|
||||
const [tableCountTexts, setTableCountTexts] = useState(new Map<string, string>());
|
||||
const [updatedTableCounts, setUpdatedTableCounts] = useState(new Date());
|
||||
const [widgets, setWidgets] = useState([] as any[]);
|
||||
|
||||
@ -113,6 +115,8 @@ function AppHome({app}: Props): JSX.Element
|
||||
setChildApps(newChildApps);
|
||||
|
||||
const tableCounts = new Map<string, { isLoading: boolean, value: number }>();
|
||||
const tableCountNumbers = new Map<string, string>();
|
||||
const tableCountTexts = new Map<string, string>();
|
||||
newTables.forEach((table) =>
|
||||
{
|
||||
tableCounts.set(table.name, {isLoading: true, value: null});
|
||||
@ -122,6 +126,20 @@ function AppHome({app}: Props): JSX.Element
|
||||
const count = await qController.count(table.name);
|
||||
tableCounts.set(table.name, {isLoading: false, value: count});
|
||||
setTableCounts(tableCounts);
|
||||
|
||||
if(count !== null && count !== undefined)
|
||||
{
|
||||
tableCountNumbers.set(table.name, count.toLocaleString());
|
||||
tableCountTexts.set(table.name, count === 1 ? "total record" : "total records");
|
||||
}
|
||||
else
|
||||
{
|
||||
tableCountNumbers.set(table.name, "--");
|
||||
tableCountTexts.set(table.name, " ");
|
||||
}
|
||||
setTableCountNumbers(tableCountNumbers);
|
||||
setTableCountTexts(tableCountTexts);
|
||||
|
||||
setUpdatedTableCounts(new Date());
|
||||
}, 1);
|
||||
});
|
||||
@ -261,8 +279,8 @@ function AppHome({app}: Props): JSX.Element
|
||||
<MDBox mb={3}>
|
||||
<MiniStatisticsCard
|
||||
title={{fontWeight: "bold", text: table.label}}
|
||||
count={!tableCounts.has(table.name) || tableCounts.get(table.name).isLoading ? "..." : tableCounts.get(table.name).value.toLocaleString()}
|
||||
percentage={{color: "info", text: (!tableCounts.has(table.name) || tableCounts.get(table.name).isLoading ? "" : (tableCounts.get(table.name).value === 1 ? "total record" : "total records"))}}
|
||||
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)))}}
|
||||
icon={{color: "info", component: <Icon>{table.iconName || app.iconName}</Icon>}}
|
||||
direction="right"
|
||||
/>
|
||||
|
@ -592,9 +592,26 @@ function EntityList({table, launchProcess}: Props): JSX.Element
|
||||
row[field.name] = value;
|
||||
});
|
||||
|
||||
if(!row["id"])
|
||||
{
|
||||
row["id"] = row[tableMetaData.primaryKeyField];
|
||||
}
|
||||
|
||||
rows.push(row);
|
||||
});
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// do this secondary check for columnsToRender - in case we didn't have any rows above, and our check for string isn't enough. //
|
||||
// ... shouldn't this be just based on the field definition anyway... ? plus adornments? //
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
fields.forEach((field) =>
|
||||
{
|
||||
if(field.possibleValueSourceName)
|
||||
{
|
||||
columnsToRender[field.name] = true;
|
||||
}
|
||||
});
|
||||
|
||||
if(columnsModel.length == 0)
|
||||
{
|
||||
setupGridColumns(columnsToRender);
|
||||
@ -877,21 +894,6 @@ function EntityList({table, launchProcess}: Props): JSX.Element
|
||||
return "";
|
||||
}
|
||||
|
||||
function getRecordIdsForProcess(): string | QQueryFilter
|
||||
{
|
||||
if (selectFullFilterState === "filter")
|
||||
{
|
||||
return (buildQFilter(filterModel));
|
||||
}
|
||||
|
||||
if (selectedIds.length > 0)
|
||||
{
|
||||
return (selectedIds.join(","));
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
const openModalProcess = (process: QProcessMetaData = null) =>
|
||||
{
|
||||
if (selectFullFilterState === "filter")
|
||||
|
Reference in New Issue
Block a user