mirror of
https://github.com/Kingsrook/qqq-frontend-material-dashboard.git
synced 2025-07-18 05:10:45 +00:00
Better support for non-countable tables
This commit is contained in:
@ -18,6 +18,7 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import {Capability} from "@kingsrook/qqq-frontend-core/lib/model/metaData/Capability";
|
||||||
import {QAppMetaData} from "@kingsrook/qqq-frontend-core/lib/model/metaData/QAppMetaData";
|
import {QAppMetaData} from "@kingsrook/qqq-frontend-core/lib/model/metaData/QAppMetaData";
|
||||||
import {QAppNodeType} from "@kingsrook/qqq-frontend-core/lib/model/metaData/QAppNodeType";
|
import {QAppNodeType} from "@kingsrook/qqq-frontend-core/lib/model/metaData/QAppNodeType";
|
||||||
import {QInstance} from "@kingsrook/qqq-frontend-core/lib/model/metaData/QInstance";
|
import {QInstance} from "@kingsrook/qqq-frontend-core/lib/model/metaData/QInstance";
|
||||||
@ -123,23 +124,33 @@ function AppHome({app}: Props): JSX.Element
|
|||||||
|
|
||||||
setTimeout(async () =>
|
setTimeout(async () =>
|
||||||
{
|
{
|
||||||
const count = await qController.count(table.name);
|
const tableMetaData = await qController.loadTableMetaData(table.name);
|
||||||
tableCounts.set(table.name, {isLoading: false, value: count});
|
let countResult = null;
|
||||||
setTableCounts(tableCounts);
|
if(tableMetaData.capabilities.has(Capability.TABLE_COUNT))
|
||||||
|
|
||||||
if (count !== null && count !== undefined)
|
|
||||||
{
|
{
|
||||||
tableCountNumbers.set(table.name, count.toLocaleString());
|
countResult = await qController.count(table.name);
|
||||||
tableCountTexts.set(table.name, count === 1 ? "total record" : "total records");
|
|
||||||
|
if (countResult !== null && countResult !== undefined)
|
||||||
|
{
|
||||||
|
tableCountNumbers.set(table.name, countResult.toLocaleString());
|
||||||
|
tableCountTexts.set(table.name, countResult === 1 ? "total record" : "total records");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tableCountNumbers.set(table.name, "--");
|
||||||
|
tableCountTexts.set(table.name, " ");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
tableCountNumbers.set(table.name, "--");
|
tableCountNumbers.set(table.name, "–");
|
||||||
tableCountTexts.set(table.name, " ");
|
tableCountTexts.set(table.name, " ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tableCounts.set(table.name, {isLoading: false, value: countResult});
|
||||||
|
setTableCounts(tableCounts);
|
||||||
setTableCountNumbers(tableCountNumbers);
|
setTableCountNumbers(tableCountNumbers);
|
||||||
setTableCountTexts(tableCountTexts);
|
setTableCountTexts(tableCountTexts);
|
||||||
|
|
||||||
setUpdatedTableCounts(new Date());
|
setUpdatedTableCounts(new Date());
|
||||||
}, 1);
|
}, 1);
|
||||||
});
|
});
|
||||||
|
@ -220,7 +220,7 @@ function EntityList({table, launchProcess}: Props): JSX.Element
|
|||||||
const [tableProcesses, setTableProcesses] = useState([] as QProcessMetaData[]);
|
const [tableProcesses, setTableProcesses] = useState([] as QProcessMetaData[]);
|
||||||
const [allTableProcesses, setAllTableProcesses] = useState([] as QProcessMetaData[]);
|
const [allTableProcesses, setAllTableProcesses] = useState([] as QProcessMetaData[]);
|
||||||
const [pageNumber, setPageNumber] = useState(0);
|
const [pageNumber, setPageNumber] = useState(0);
|
||||||
const [totalRecords, setTotalRecords] = useState(0);
|
const [totalRecords, setTotalRecords] = useState(null);
|
||||||
const [selectedIds, setSelectedIds] = useState([] as string[]);
|
const [selectedIds, setSelectedIds] = useState([] as string[]);
|
||||||
const [selectFullFilterState, setSelectFullFilterState] = useState("n/a" as "n/a" | "checked" | "filter");
|
const [selectFullFilterState, setSelectFullFilterState] = useState("n/a" as "n/a" | "checked" | "filter");
|
||||||
const [columnsModel, setColumnsModel] = useState([] as GridColDef[]);
|
const [columnsModel, setColumnsModel] = useState([] as GridColDef[]);
|
||||||
@ -385,12 +385,15 @@ function EntityList({table, launchProcess}: Props): JSX.Element
|
|||||||
setLatestQueryId(thisQueryId);
|
setLatestQueryId(thisQueryId);
|
||||||
|
|
||||||
console.log(`Issuing query: ${thisQueryId}`);
|
console.log(`Issuing query: ${thisQueryId}`);
|
||||||
qController.count(tableName, qFilter).then((count) =>
|
if (tableMetaData.capabilities.has(Capability.TABLE_COUNT))
|
||||||
{
|
{
|
||||||
countResults[thisQueryId] = count;
|
qController.count(tableName, qFilter).then((count) =>
|
||||||
setCountResults(countResults);
|
{
|
||||||
setReceivedCountTimestamp(new Date());
|
countResults[thisQueryId] = count;
|
||||||
});
|
setCountResults(countResults);
|
||||||
|
setReceivedCountTimestamp(new Date());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
qController.query(tableName, qFilter, rowsPerPage, pageNumber * rowsPerPage).then((results) =>
|
qController.query(tableName, qFilter, rowsPerPage, pageNumber * rowsPerPage).then((results) =>
|
||||||
{
|
{
|
||||||
@ -588,7 +591,6 @@ function EntityList({table, launchProcess}: Props): JSX.Element
|
|||||||
const value = QValueUtils.getDisplayValue(field, record, "query");
|
const value = QValueUtils.getDisplayValue(field, record, "query");
|
||||||
if (typeof value !== "string")
|
if (typeof value !== "string")
|
||||||
{
|
{
|
||||||
console.log(`Need to render [${field.name}]`);
|
|
||||||
columnsToRender[field.name] = true;
|
columnsToRender[field.name] = true;
|
||||||
}
|
}
|
||||||
row[field.name] = value;
|
row[field.name] = value;
|
||||||
@ -983,7 +985,24 @@ function EntityList({table, launchProcess}: Props): JSX.Element
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const defaultLabelDisplayedRows = ({from, to, count}) =>
|
const defaultLabelDisplayedRows = ({from, to, count}) =>
|
||||||
{
|
{
|
||||||
if (count !== null && count !== undefined)
|
console.log(`In defaultLabelDisplayedRows with ${from} ${to} ${count}`);
|
||||||
|
if(tableMetaData && !tableMetaData.capabilities.has(Capability.TABLE_COUNT))
|
||||||
|
{
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// to avoid a non-countable table showing (this is what data-grid did) 91-100 even if there were only 95 records, //
|
||||||
|
// we'll do this... not quite good enough, but better than the original //
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
if(rows.length > 0 && rows.length < to - from)
|
||||||
|
{
|
||||||
|
to = from + rows.length;
|
||||||
|
}
|
||||||
|
return (`Showing ${from.toLocaleString()} to ${to.toLocaleString()}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// treat -1 as the sentinel that it's set as below -- remember, we did that so that 'to' would have a value in here when there's no count. //
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
if (count !== null && count !== undefined && count !== -1)
|
||||||
{
|
{
|
||||||
if (count === 0)
|
if (count === 0)
|
||||||
{
|
{
|
||||||
@ -1002,7 +1021,9 @@ function EntityList({table, launchProcess}: Props): JSX.Element
|
|||||||
return (
|
return (
|
||||||
<TablePagination
|
<TablePagination
|
||||||
component="div"
|
component="div"
|
||||||
count={totalRecords === null ? 0 : totalRecords}
|
// note - passing null here makes the 'to' param in the defaultLabelDisplayedRows also be null,
|
||||||
|
// so pass some sentinel value...
|
||||||
|
count={totalRecords === null ? -1 : totalRecords}
|
||||||
page={pageNumber}
|
page={pageNumber}
|
||||||
rowsPerPageOptions={[ 10, 25, 50, 100, 250 ]}
|
rowsPerPageOptions={[ 10, 25, 50, 100, 250 ]}
|
||||||
rowsPerPage={rowsPerPage}
|
rowsPerPage={rowsPerPage}
|
Reference in New Issue
Block a user