From 4266ed1690e835760f8d45356630796a7653c3b2 Mon Sep 17 00:00:00 2001 From: Darin Kelkhoff Date: Wed, 7 Sep 2022 11:19:15 -0500 Subject: [PATCH] Try to avoid errors formatting non-numbers --- .../components/QProcessSummaryResults.tsx | 3 ++- .../components/QValidationReview.tsx | 4 ++-- .../process-run/model/ProcessSummaryLine.tsx | 3 ++- src/qqq/utils/QValueUtils.tsx | 20 +++++++++++++++++++ 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/qqq/pages/process-run/components/QProcessSummaryResults.tsx b/src/qqq/pages/process-run/components/QProcessSummaryResults.tsx index 481b664..dc8df8e 100644 --- a/src/qqq/pages/process-run/components/QProcessSummaryResults.tsx +++ b/src/qqq/pages/process-run/components/QProcessSummaryResults.tsx @@ -32,6 +32,7 @@ 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"; +import QValueUtils from "qqq/utils/QValueUtils"; interface Props { @@ -66,7 +67,7 @@ function QProcessSummaryResults({ processValues?.recordCount !== undefined && sourceTableMetaData && ( - {processValues.recordCount.toLocaleString()} + {QValueUtils.getFormattedNumber(processValues.recordCount)} {" "} {sourceTableMetaData.label} {" "} diff --git a/src/qqq/pages/process-run/components/QValidationReview.tsx b/src/qqq/pages/process-run/components/QValidationReview.tsx index dd3ebc1..90c0c12 100644 --- a/src/qqq/pages/process-run/components/QValidationReview.tsx +++ b/src/qqq/pages/process-run/components/QValidationReview.tsx @@ -133,7 +133,7 @@ function QValidationReview({ processValues?.recordCount !== undefined && sourceTableMetaData && ( - {`Input: ${processValues.recordCount.toLocaleString()} ${sourceTableMetaData?.label} record${processValues.recordCount === 1 ? "" : "s"}.`} + {`Input: ${QValueUtils.getFormattedNumber(processValues.recordCount)} ${sourceTableMetaData?.label} record${processValues.recordCount === 1 ? "" : "s"}.`} ) @@ -189,7 +189,7 @@ function QValidationReview({ Validation complete on - {` ${processValues.recordCount.toLocaleString()} ${sourceTableMetaData?.label} `} + {` ${QValueUtils.getFormattedNumber(processValues.recordCount)} ${sourceTableMetaData?.label} `} records. diff --git a/src/qqq/pages/process-run/model/ProcessSummaryLine.tsx b/src/qqq/pages/process-run/model/ProcessSummaryLine.tsx index 79952c5..db3d15f 100644 --- a/src/qqq/pages/process-run/model/ProcessSummaryLine.tsx +++ b/src/qqq/pages/process-run/model/ProcessSummaryLine.tsx @@ -32,6 +32,7 @@ import Tooltip from "@mui/material/Tooltip"; import React from "react"; import {Link} from "react-router-dom"; import MDBox from "components/MDBox"; +import QValueUtils from "qqq/utils/QValueUtils"; /******************************************************************************* ** Entity that corresponds to qqq backend's ProcessSummaryLine - with methods @@ -89,7 +90,7 @@ export class ProcessSummaryLine {this.getIcon(isResultScreen)} {/* work hard to prevent the icon from falling down to the next line by itself... */} - {`${this.count.toLocaleString()} ${messageWords.join(" ")} `} + {`${QValueUtils.getFormattedNumber(this.count)} ${messageWords.join(" ")} `} { (linkTag) ? ( diff --git a/src/qqq/utils/QValueUtils.tsx b/src/qqq/utils/QValueUtils.tsx index be2262f..4a9169a 100644 --- a/src/qqq/utils/QValueUtils.tsx +++ b/src/qqq/utils/QValueUtils.tsx @@ -64,6 +64,26 @@ class QValueUtils return (displayValue); } + public static getFormattedNumber(n: number): string + { + try + { + if(n !== null && n !== undefined) + { + return (n.toLocaleString()); + } + else + { + return (""); + } + } + catch(e) + { + return (String(n)); + } + } + + public static breakTextIntoLines(value: string): JSX.Element {