From e376f4ae7204bc1d6f3164fa3f9028ef7ce20058 Mon Sep 17 00:00:00 2001 From: Darin Kelkhoff Date: Tue, 6 Sep 2022 11:16:08 -0500 Subject: [PATCH] QQQ-37 fixing links to source-table (need full table meta data for primary key) --- .../components/QProcessSummaryResults.tsx | 20 ++++-- .../components/QValidationReview.tsx | 22 +++++-- .../process-run/model/ProcessSummaryLine.tsx | 61 ++++++++++++++++--- 3 files changed, 82 insertions(+), 21 deletions(-) diff --git a/src/qqq/pages/process-run/components/QProcessSummaryResults.tsx b/src/qqq/pages/process-run/components/QProcessSummaryResults.tsx index 3b1bf4c..481b664 100644 --- a/src/qqq/pages/process-run/components/QProcessSummaryResults.tsx +++ b/src/qqq/pages/process-run/components/QProcessSummaryResults.tsx @@ -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 = ( { - processValues?.recordCount !== undefined && sourceTable && ( + processValues?.recordCount !== undefined && sourceTableMetaData && ( {processValues.recordCount.toLocaleString()} {" "} - {sourceTable.label} + {sourceTableMetaData.label} {" "} records were processed. @@ -67,7 +77,7 @@ function QProcessSummaryResults({ } { - 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))) } diff --git a/src/qqq/pages/process-run/components/QValidationReview.tsx b/src/qqq/pages/process-run/components/QValidationReview.tsx index 027e25b..dd3ebc1 100644 --- a/src/qqq/pages/process-run/components/QValidationReview.tsx +++ b/src/qqq/pages/process-run/components/QValidationReview.tsx @@ -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 = ( { - processValues?.recordCount !== undefined && sourceTable && ( + processValues?.recordCount !== undefined && sourceTableMetaData && ( - {`Input: ${processValues.recordCount.toLocaleString()} ${sourceTable?.label} record${processValues.recordCount === 1 ? "" : "s"}.`} + {`Input: ${processValues.recordCount.toLocaleString()} ${sourceTableMetaData?.label} record${processValues.recordCount === 1 ? "" : "s"}.`} ) @@ -175,11 +185,11 @@ function QValidationReview({ const postValidationList = ( { - processValues?.recordCount !== undefined && sourceTable && ( + processValues?.recordCount !== undefined && sourceTableMetaData && ( Validation complete on - {` ${processValues.recordCount.toLocaleString()} ${sourceTable?.label} `} + {` ${processValues.recordCount.toLocaleString()} ${sourceTableMetaData?.label} `} records. @@ -187,7 +197,7 @@ function QValidationReview({ } { - 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))) } diff --git a/src/qqq/pages/process-run/model/ProcessSummaryLine.tsx b/src/qqq/pages/process-run/model/ProcessSummaryLine.tsx index 92fafa9..79952c5 100644 --- a/src/qqq/pages/process-run/model/ProcessSummaryLine.tsx +++ b/src/qqq/pages/process-run/model/ProcessSummaryLine.tsx @@ -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 = + + open_in_new + + + } + return ( @@ -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) ? ( - {/* eslint-disable-next-line react/jsx-one-expression-per-line */} - {lastWord}  - - open_in_new - - {/* eslint-disable-next-line react/jsx-closing-tag-location */} - + {lastWord} {linkTag} ) : {lastWord} } @@ -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); } }