mirror of
https://github.com/Kingsrook/qqq-frontend-material-dashboard.git
synced 2025-07-17 21:00:45 +00:00
QQQ-37 fixing links to source-table (need full table meta data for primary key)
This commit is contained in:
@ -28,9 +28,10 @@ import Grid from "@mui/material/Grid";
|
||||
import Icon from "@mui/material/Icon";
|
||||
import List from "@mui/material/List";
|
||||
import ListItemText from "@mui/material/ListItemText";
|
||||
import React from "react";
|
||||
import React, {useState} from "react";
|
||||
import MDBox from "components/MDBox";
|
||||
import {ProcessSummaryLine} from "qqq/pages/process-run/model/ProcessSummaryLine";
|
||||
import QClient from "qqq/utils/QClient";
|
||||
|
||||
interface Props
|
||||
{
|
||||
@ -48,17 +49,26 @@ function QProcessSummaryResults({
|
||||
qInstance, process, table = null, processValues, step,
|
||||
}: Props): JSX.Element
|
||||
{
|
||||
const sourceTable = qInstance.tables.get(processValues.sourceTable);
|
||||
const [sourceTableMetaData, setSourceTableMetaData] = useState(null as QTableMetaData);
|
||||
|
||||
if(processValues.sourceTable && !sourceTableMetaData)
|
||||
{
|
||||
(async () =>
|
||||
{
|
||||
const sourceTableMetaData = await QClient.getInstance().loadTableMetaData(processValues.sourceTable)
|
||||
setSourceTableMetaData(sourceTableMetaData);
|
||||
})();
|
||||
}
|
||||
|
||||
const resultValidationList = (
|
||||
<List sx={{mt: 2}}>
|
||||
{
|
||||
processValues?.recordCount !== undefined && sourceTable && (
|
||||
processValues?.recordCount !== undefined && sourceTableMetaData && (
|
||||
<ListItem sx={{my: 2}}>
|
||||
<ListItemText primaryTypographyProps={{fontSize: 16}}>
|
||||
{processValues.recordCount.toLocaleString()}
|
||||
{" "}
|
||||
{sourceTable.label}
|
||||
{sourceTableMetaData.label}
|
||||
{" "}
|
||||
records were processed.
|
||||
</ListItemText>
|
||||
@ -67,7 +77,7 @@ function QProcessSummaryResults({
|
||||
}
|
||||
<List>
|
||||
{
|
||||
processValues.processResults && processValues.processResults.map((processSummaryLine: ProcessSummaryLine, i: number) => (new ProcessSummaryLine(processSummaryLine).getProcessSummaryListItem(i, sourceTable, qInstance, true)))
|
||||
processValues.processResults && processValues.processResults.map((processSummaryLine: ProcessSummaryLine, i: number) => (new ProcessSummaryLine(processSummaryLine).getProcessSummaryListItem(i, sourceTableMetaData, qInstance, true)))
|
||||
}
|
||||
</List>
|
||||
</List>
|
||||
|
@ -36,6 +36,7 @@ import React, {useState} from "react";
|
||||
import MDBox from "components/MDBox";
|
||||
import MDTypography from "components/MDTypography";
|
||||
import {ProcessSummaryLine} from "qqq/pages/process-run/model/ProcessSummaryLine";
|
||||
import QClient from "qqq/utils/QClient";
|
||||
import QValueUtils from "qqq/utils/QValueUtils";
|
||||
|
||||
interface Props
|
||||
@ -60,7 +61,16 @@ function QValidationReview({
|
||||
}: Props): JSX.Element
|
||||
{
|
||||
const [previewRecordIndex, setPreviewRecordIndex] = useState(0);
|
||||
const sourceTable = qInstance.tables.get(processValues.sourceTable);
|
||||
const [sourceTableMetaData, setSourceTableMetaData] = useState(null as QTableMetaData);
|
||||
|
||||
if(processValues.sourceTable && !sourceTableMetaData)
|
||||
{
|
||||
(async () =>
|
||||
{
|
||||
const sourceTableMetaData = await QClient.getInstance().loadTableMetaData(processValues.sourceTable)
|
||||
setSourceTableMetaData(sourceTableMetaData);
|
||||
})();
|
||||
}
|
||||
|
||||
const updatePreviewRecordIndex = (offset: number) =>
|
||||
{
|
||||
@ -120,10 +130,10 @@ function QValidationReview({
|
||||
const preValidationList = (
|
||||
<List sx={{mt: 2}}>
|
||||
{
|
||||
processValues?.recordCount !== undefined && sourceTable && (
|
||||
processValues?.recordCount !== undefined && sourceTableMetaData && (
|
||||
<ListItem sx={{my: 2}}>
|
||||
<ListItemText primaryTypographyProps={{fontSize: 16}}>
|
||||
{`Input: ${processValues.recordCount.toLocaleString()} ${sourceTable?.label} record${processValues.recordCount === 1 ? "" : "s"}.`}
|
||||
{`Input: ${processValues.recordCount.toLocaleString()} ${sourceTableMetaData?.label} record${processValues.recordCount === 1 ? "" : "s"}.`}
|
||||
</ListItemText>
|
||||
</ListItem>
|
||||
)
|
||||
@ -175,11 +185,11 @@ function QValidationReview({
|
||||
const postValidationList = (
|
||||
<List sx={{mt: 2}}>
|
||||
{
|
||||
processValues?.recordCount !== undefined && sourceTable && (
|
||||
processValues?.recordCount !== undefined && sourceTableMetaData && (
|
||||
<ListItem sx={{my: 2}}>
|
||||
<ListItemText primaryTypographyProps={{fontSize: 16}}>
|
||||
Validation complete on
|
||||
{` ${processValues.recordCount.toLocaleString()} ${sourceTable?.label} `}
|
||||
{` ${processValues.recordCount.toLocaleString()} ${sourceTableMetaData?.label} `}
|
||||
records.
|
||||
</ListItemText>
|
||||
</ListItem>
|
||||
@ -187,7 +197,7 @@ function QValidationReview({
|
||||
}
|
||||
<List>
|
||||
{
|
||||
processValues.validationSummary && processValues.validationSummary.map((processSummaryLine: ProcessSummaryLine, i: number) => (new ProcessSummaryLine(processSummaryLine).getProcessSummaryListItem(i, sourceTable, qInstance)))
|
||||
processValues.validationSummary && processValues.validationSummary.map((processSummaryLine: ProcessSummaryLine, i: number) => (new ProcessSummaryLine(processSummaryLine).getProcessSummaryListItem(i, sourceTableMetaData, qInstance)))
|
||||
}
|
||||
</List>
|
||||
</List>
|
||||
|
@ -68,6 +68,21 @@ export class ProcessSummaryLine
|
||||
messageWords.splice(messageWords.length - 1, 1);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// try to get a link to the records - but note, it may come back null for various reasons - //
|
||||
// if it's null, then don't output a link tag. //
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
const linkToRecords = this.getLinkToRecords(table, qInstance);
|
||||
let linkTag = null;
|
||||
if(linkToRecords)
|
||||
{
|
||||
linkTag = <Link target="_blank" to={linkToRecords}>
|
||||
<Tooltip title="See these records in a new tab" sx={{py: 0}}>
|
||||
<IconButton sx={{py: 0}}><Icon fontSize="small">open_in_new</Icon></IconButton>
|
||||
</Tooltip>
|
||||
</Link>
|
||||
}
|
||||
|
||||
return (
|
||||
<ListItem key={i} sx={{pl: 4, my: 2}}>
|
||||
<MDBox display="flex" alignItems="top">
|
||||
@ -76,15 +91,9 @@ export class ProcessSummaryLine
|
||||
{/* work hard to prevent the icon from falling down to the next line by itself... */}
|
||||
{`${this.count.toLocaleString()} ${messageWords.join(" ")} `}
|
||||
{
|
||||
(table && this.primaryKeys) ? (
|
||||
(linkTag) ? (
|
||||
<span style={{whiteSpace: "nowrap"}}>
|
||||
{/* eslint-disable-next-line react/jsx-one-expression-per-line */}
|
||||
{lastWord} <Link target="_blank" to={this.getLinkToRecords(table, qInstance)}>
|
||||
<Tooltip title="See these records in a new tab" sx={{py: 0}}>
|
||||
<IconButton sx={{py: 0}}><Icon fontSize="small">open_in_new</Icon></IconButton>
|
||||
</Tooltip>
|
||||
{/* eslint-disable-next-line react/jsx-closing-tag-location */}
|
||||
</Link>
|
||||
{lastWord} {linkTag}
|
||||
</span>
|
||||
) : <span>{lastWord}</span>
|
||||
}
|
||||
@ -139,10 +148,42 @@ export class ProcessSummaryLine
|
||||
return "";
|
||||
}
|
||||
|
||||
private getLinkToRecords(table: QTableMetaData, qInstance: QInstance): string
|
||||
private getLinkToRecords(table: QTableMetaData, qInstance: QInstance): string | null
|
||||
{
|
||||
if(!table)
|
||||
{
|
||||
console.log("No table, so not returning a link to records");
|
||||
return (null);
|
||||
}
|
||||
|
||||
if(!table.primaryKeyField)
|
||||
{
|
||||
console.log("No table.primaryKeyField, so not returning a link to records");
|
||||
return (null);
|
||||
}
|
||||
|
||||
const tablePath = qInstance.getTablePath(table);
|
||||
if(!tablePath)
|
||||
{
|
||||
console.log("No tablePath, so not returning a link to records");
|
||||
return (null);
|
||||
}
|
||||
|
||||
if(!this.primaryKeys)
|
||||
{
|
||||
console.log("No primaryKeys, so not returning a link to records");
|
||||
return (null);
|
||||
}
|
||||
|
||||
const filter = new QQueryFilter([new QFilterCriteria(table.primaryKeyField, QCriteriaOperator.IN, this.primaryKeys)]);
|
||||
return (`${tablePath}?filter=${JSON.stringify(filter)}`);
|
||||
const path = `${tablePath}?filter=${JSON.stringify(filter)}`;
|
||||
|
||||
if(path.length > 2048)
|
||||
{
|
||||
console.log(`Path is too long [${path.length}], so not returning a link to records.`);
|
||||
return (null);
|
||||
}
|
||||
|
||||
return (path);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user