From 917cf9e9ca5b25c9f98bf5b55ffb13a25c749584 Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Thu, 7 Nov 2024 10:35:47 +0100 Subject: [PATCH 1/7] [Fix partially #505] Refactor status message function and usage - remove translation function t from arguments --- .../menu/faultEvent/FaultEventMenu.tsx | 45 +++++++++---------- src/components/fta/FTAStatus.tsx | 14 +++--- src/components/table/FaultTreeTableBody.tsx | 9 ++-- 3 files changed, 33 insertions(+), 35 deletions(-) diff --git a/src/components/editor/faultTree/menu/faultEvent/FaultEventMenu.tsx b/src/components/editor/faultTree/menu/faultEvent/FaultEventMenu.tsx index 529db999..8b8339d3 100644 --- a/src/components/editor/faultTree/menu/faultEvent/FaultEventMenu.tsx +++ b/src/components/editor/faultTree/menu/faultEvent/FaultEventMenu.tsx @@ -30,7 +30,7 @@ import UnsavedChangesDialog from "./UnsavedChangesDialog"; import { useAppBar } from "@contexts/AppBarContext"; import { syncProblemIcon, warnIcon } from "@components/Icons"; import HintText from "@components/hintText/HintText"; -import { calculationStatusMessages } from "@components/fta/FTAStatus"; +import { statusMessages } from "@components/fta/FTAStatus"; import { FaultTreeStatus } from "@models/faultTreeModel"; interface Props { @@ -309,45 +309,40 @@ const FaultEventMenu = ({ return {value}}>{value.toExponential(2)}; }; - const requiredFailureRateComponent = (failureRate, requirementStatusColor, violates) => { + const requiredFailureRateComponent = (failureRate, violates) => { const cls = violates ? classes.violated : classes.notEditableValue; return ( {propertyLabelWithHint("eventDescription.requiredFailureRate")} {numberValue(failureRate)} - {violates && - warnIcon(calculationStatusMessages("faultEventMessage.requirementViolated", t), requirementStatusColor)} + {violates && warnIcon(statusMessages(t("faultEventMessage.requirementViolated")))} ); }; - const failureRateComponent = (failureRate, failureRateCode, statusCodes: string[] = []) => { - const isOutOfSync = statusCodes && statusCodes.length > 0; + const failureRateComponent = (failureRate, failureRateCode, statusMessages: string[] = []) => { + const _statusMessages = asArray(statusMessages); + const isOutOfSync = _statusMessages && _statusMessages.length > 0; const cls = isOutOfSync ? classes.outdated : classes.notEditableValue; return ( {propertyLabelWithHint(failureRateCode)} {numberValue(failureRate)} - {isOutOfSync && syncProblemIcon(calculationStatusMessages(statusCodes, t), statusCodes.length)} + {isOutOfSync && syncProblemIcon(statusMessages(_statusMessages), _statusMessages.length)} ); }; - const fhaFailureRateComponent = (failureRate, failureRateStatusColor, faultTreeStatus: FaultTreeStatus) => { - return failureRateComponent( - failureRate, - "eventDescription.fhaBasedFailureRate", - failureRateStatusColor, - faultTreeStatus, - ); + const fhaFailureRateComponent = (failureRate) => { + return failureRateComponent(failureRate, "eventDescription.fhaBasedFailureRate", null); }; - const calculatedFailureRateComponent = (failureRate, failureRateStatusColor, statusCodes: string[]) => { - return failureRateComponent(failureRate, "eventDescription.calculatedFailureRate", statusCodes); + const calculatedFailureRateComponent = (failureRate, failureRateStatusColor, statusMessages: string[]) => { + return failureRateComponent(failureRate, "eventDescription.calculatedFailureRate", statusMessages); }; const FailureRateBox = ({ value, failureRateKey, rate, selected, outdated }) => ( @@ -408,14 +403,13 @@ const FaultEventMenu = ({ {calculatedFailureRateComponent( shapeToolData.probability, calculatedFailureRateStatusColor, - faultTreeStatus.statusCodes, + asArray(faultTreeStatus.statusCodes).map((c) => t(c)), )} )} - {getRequiredFailureRate() && - requiredFailureRateComponent(getRequiredFailureRate(), requiredFailureRateStatusColor, violatesRequirement)} + {getRequiredFailureRate() && requiredFailureRateComponent(getRequiredFailureRate(), violatesRequirement)} {(frEstimate?.value || frEstimate?.value === 0) && ( - {fhaFailureRateComponent(frEstimate.value, null, null)} + {fhaFailureRateComponent(frEstimate.value)} )} )} @@ -428,12 +422,17 @@ const FaultEventMenu = ({ {calculatedFailureRateComponent( shapeToolData.probability, null, - isReferenceProbabilityOutdated(shapeToolData) ? ["faultEventMessage.referencedValueOutdated"] : [], + isReferenceProbabilityOutdated(shapeToolData) + ? [ + t("faultEventMessage.referencedValueOutdated", { + newValue: shapeToolData?.references?.probability, + }), + ] + : [], )} )} - {getRequiredFailureRate() && - requiredFailureRateComponent(getRequiredFailureRate(), requiredFailureRateStatusColor, violatesRequirement)} + {getRequiredFailureRate() && requiredFailureRateComponent(getRequiredFailureRate(), violatesRequirement)} {(frEstimate?.value || frEstimate?.value) && ( {fhaFailureRateComponent(frEstimate.value, null, null)} )} diff --git a/src/components/fta/FTAStatus.tsx b/src/components/fta/FTAStatus.tsx index 741bd993..53dbbeac 100644 --- a/src/components/fta/FTAStatus.tsx +++ b/src/components/fta/FTAStatus.tsx @@ -2,17 +2,17 @@ import * as React from "react"; import { asArray } from "@utils/utils"; import { Typography } from "@mui/material"; -export const calculationStatusMessages = (statusCodes: string[], t: any) => { - const _statusCodes = asArray(statusCodes); - return _statusCodes.length > 1 ? ( +export const statusMessages = (statusMessages: string | string[]) => { + const _statusMessages = asArray(statusMessages); + return _statusMessages.length > 1 ? ( - ) : _statusCodes.length == 1 ? ( + ) : _statusMessages.length == 1 ? ( - {t(_statusCodes[0])} + {_statusMessages[0]} ) : null; }; diff --git a/src/components/table/FaultTreeTableBody.tsx b/src/components/table/FaultTreeTableBody.tsx index e6f6ca8d..f7ffc1db 100644 --- a/src/components/table/FaultTreeTableBody.tsx +++ b/src/components/table/FaultTreeTableBody.tsx @@ -7,11 +7,11 @@ import useStyles from "./FaultTreeOverviewTable.styles"; import { FaultTree, getFaultTreeCalculationStatus } from "@models/faultTreeModel"; import { extractFragment } from "@services/utils/uriIdentifierUtils"; import { asArray, findByIri, formatDate } from "@utils/utils"; -import { ROUTES, Status } from "@utils/constants"; +import { ROUTES } from "@utils/constants"; import { useSelectedSystemSummaries } from "@hooks/useSelectedSystemSummaries"; import { useSystems } from "@hooks/useSystems"; import { syncProblemIcon, warnIcon } from "@components/Icons"; -import { calculationStatusMessages } from "@components/fta/FTAStatus"; +import { statusMessages } from "@components/fta/FTAStatus"; interface FaultTreeTableBodyProps { faultTrees: FaultTree[]; @@ -86,7 +86,7 @@ const FaultTreeTableBody: FC = ({ faultTrees, handleFau !calculationStatus.isOk && faultTree?.calculatedFailureRate && syncProblemIcon( - calculationStatusMessages(calculationStatus.statusCodes, t), + statusMessages(calculationStatus.statusCodes?.map((c) => t(c))), calculationStatus.statusCodes?.length, ), )} @@ -95,8 +95,7 @@ const FaultTreeTableBody: FC = ({ faultTrees, handleFau {failureRate( faultTree?.requiredFailureRate, - violatedRequirement && - warnIcon(calculationStatusMessages(["faultEventMessage.requirementViolated"], t)), + violatedRequirement && warnIcon(statusMessages(t("faultEventMessage.requirementViolated"))), )} {formatDate(faultTree?.modified)} From 9b16512967319129a35130ab968056119a1dc5f3 Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Thu, 7 Nov 2024 11:02:16 +0100 Subject: [PATCH 2/7] [Bug fix] ataNames could be null, use optional chaining to access its members --- .../editor/faultTree/menu/faultEvent/FaultEventMenu.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/editor/faultTree/menu/faultEvent/FaultEventMenu.tsx b/src/components/editor/faultTree/menu/faultEvent/FaultEventMenu.tsx index 8b8339d3..21ca242f 100644 --- a/src/components/editor/faultTree/menu/faultEvent/FaultEventMenu.tsx +++ b/src/components/editor/faultTree/menu/faultEvent/FaultEventMenu.tsx @@ -535,7 +535,7 @@ const FaultEventMenu = ({ - {ataNames.map((n) => { + {ataNames?.map((n) => { return
{n}
; })} From 4c8be01d214de704eecb04ee1d05211453e91d02 Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Thu, 7 Nov 2024 11:03:04 +0100 Subject: [PATCH 3/7] [Fix partially #505] Update localized messages for outdated failure rates --- public/locales/cs/translation.json | 3 ++- public/locales/en/translation.json | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/public/locales/cs/translation.json b/public/locales/cs/translation.json index 88e7732b..3d685b42 100644 --- a/public/locales/cs/translation.json +++ b/public/locales/cs/translation.json @@ -112,7 +112,8 @@ }, "faultEventMessage": { "outOfSyncValue": "Hodnota je zastaralá, intenzita poruch u některých listových uzlů byla aktualizována!", - "referencedValueOutdated": "Referenční hodnota byla změněna. Hodnota bude aktualizována při vyhodnocení stromu", + "referencedValueOutdated": "Referenční hodnota byla změněna. Nová hodnota je {{newValue}}. Hodnota bude aktualizována při vyhodnocení stromu", + "predictedFailureRateOutdated": "Referenční hodnota byla změněna. Nová hodnota je {{newValue}}.", "experimental": "Min. provozní hodiny (MOH) poruchoveho stromu se liší od MOH jeho systému", "requirementViolated": "Vypočtená intenzita poruch je větší, než je požadováno!" }, diff --git a/public/locales/en/translation.json b/public/locales/en/translation.json index 727775bd..6201ea3e 100644 --- a/public/locales/en/translation.json +++ b/public/locales/en/translation.json @@ -112,7 +112,8 @@ }, "faultEventMessage": { "outOfSyncValue": "The value is outdated, some of the leaf node failure rates were updated!", - "referencedValueOutdated": "The referenced value has changed. The value will be updated on tree evaluation.", + "referencedValueOutdated": "The referenced value has changed. New value is {{newValue}}. The value will be updated on tree evaluation.", + "predictedFailureRateOutdated": "The referenced value has changed. New value is {{newValue}}.", "experimental": "Fault tree's min. operational hours (MOH) is different from its system's MOH", "requirementViolated": "Calculated failure rate is bigger than required!" }, From 8d31a9afd158b7a6c7e1932f6843722d990e389a Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Thu, 7 Nov 2024 11:09:35 +0100 Subject: [PATCH 4/7] [Fix partially #505] Fix logic checking if failure rate is outdated --- .../editor/faultTree/menu/faultEvent/FaultEventMenu.tsx | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/components/editor/faultTree/menu/faultEvent/FaultEventMenu.tsx b/src/components/editor/faultTree/menu/faultEvent/FaultEventMenu.tsx index 21ca242f..7cabbcb8 100644 --- a/src/components/editor/faultTree/menu/faultEvent/FaultEventMenu.tsx +++ b/src/components/editor/faultTree/menu/faultEvent/FaultEventMenu.tsx @@ -362,12 +362,9 @@ const FaultEventMenu = ({ ); const renderFailureRateBox = (rateType, rateValue, iri, selectedRadioButton, failureRateKey) => { - const rate = - shapeToolData.probability !== rateValue && shapeToolData?.selectedEstimate?.iri === iri - ? shapeToolData.probability - : rateValue; const selected = selectedRadioButton === rateType; - const outdated = selected && shapeToolData.probability !== rateValue; + const outdated = shapeToolData.probability !== rateValue && shapeToolData?.selectedEstimate?.iri === iri; + const rate = outdated ? shapeToolData.probability : rateValue; return ( Date: Thu, 7 Nov 2024 11:14:12 +0100 Subject: [PATCH 5/7] [Fix partially #505] Add icon with status message for outdated predicted and operational failure rates in basic event --- .../menu/faultEvent/FaultEventMenu.tsx | 41 +++++++++++-------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/src/components/editor/faultTree/menu/faultEvent/FaultEventMenu.tsx b/src/components/editor/faultTree/menu/faultEvent/FaultEventMenu.tsx index 7cabbcb8..706898c5 100644 --- a/src/components/editor/faultTree/menu/faultEvent/FaultEventMenu.tsx +++ b/src/components/editor/faultTree/menu/faultEvent/FaultEventMenu.tsx @@ -345,23 +345,26 @@ const FaultEventMenu = ({ return failureRateComponent(failureRate, "eventDescription.calculatedFailureRate", statusMessages); }; - const FailureRateBox = ({ value, failureRateKey, rate, selected, outdated }) => ( - - } - label={propertyLabelWithHint(failureRateKey)} - className={selected ? classes.selected : classes.notSelected} - /> - {rate}}> - - {rate.toExponential(2)} - - - - ); + const FailureRateBox = ({ value, failureRateKey, rate, selected, outdated, messageCode, newValue }) => { + const cls = outdated ? classes.outdated : classes.notEditableValue; + + return ( + + } + label={propertyLabelWithHint(failureRateKey)} + className={selected ? classes.selected : classes.notSelected} + /> + + {numberValue(rate)} + {outdated && syncProblemIcon(statusMessages(t(messageCode, { newValue: newValue })), 1)} + + + ); + }; - const renderFailureRateBox = (rateType, rateValue, iri, selectedRadioButton, failureRateKey) => { + const renderFailureRateBox = (rateType, rateValue, iri, selectedRadioButton, failureRateKey, messageCode) => { const selected = selectedRadioButton === rateType; const outdated = shapeToolData.probability !== rateValue && shapeToolData?.selectedEstimate?.iri === iri; const rate = outdated ? shapeToolData.probability : rateValue; @@ -373,6 +376,8 @@ const FaultEventMenu = ({ rate={rate} selected={selected} outdated={outdated} + messageCode={messageCode} + newValue={outdated ? rateValue : undefined} /> ); }; @@ -380,8 +385,6 @@ const FaultEventMenu = ({ const violatesRequirement = shapeToolData?.probability && getRequiredFailureRate() && shapeToolData.probability > getRequiredFailureRate(); - const requiredFailureRateStatusColor = violatesRequirement ? theme.requirementViolation.color : theme.main.black; - const calculatedFailureRateStatusColor = faultTreeStatus.isOk ? theme.main.black : theme.notSynchronized.color; return ( @@ -459,6 +462,7 @@ const FaultEventMenu = ({ frPrediction?.iri, selectedRadioButton, "eventDescription.predictedFailureRate", + "faultEventMessage.referencedValueOutdated", )} {snsOperationalFailureRate && renderFailureRateBox( @@ -467,6 +471,7 @@ const FaultEventMenu = ({ frEstimate?.iri, selectedRadioButton, "eventDescription.operationalFailureRate", + "faultEventMessage.predictedFailureRateOutdated", )} Date: Thu, 7 Nov 2024 11:23:57 +0100 Subject: [PATCH 6/7] [Code fix] Remove unnecessary properties from components and functions - remove text property from HintText component - remove cls argument from numberValue in FaultEventMenu --- .../editor/faultTree/menu/faultEvent/FaultEventMenu.tsx | 2 +- src/components/hintText/HintText.tsx | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/editor/faultTree/menu/faultEvent/FaultEventMenu.tsx b/src/components/editor/faultTree/menu/faultEvent/FaultEventMenu.tsx index 706898c5..fc89150a 100644 --- a/src/components/editor/faultTree/menu/faultEvent/FaultEventMenu.tsx +++ b/src/components/editor/faultTree/menu/faultEvent/FaultEventMenu.tsx @@ -305,7 +305,7 @@ const FaultEventMenu = ({ ); }; - const numberValue = (value, cls = classes.notEditableValue) => { + const numberValue = (value) => { return {value}}>{value.toExponential(2)}; }; diff --git a/src/components/hintText/HintText.tsx b/src/components/hintText/HintText.tsx index 8b0e6e6f..554650b4 100644 --- a/src/components/hintText/HintText.tsx +++ b/src/components/hintText/HintText.tsx @@ -4,7 +4,6 @@ import useStyles from "./HintText.styles"; import { HelpOutline } from "@mui/icons-material"; interface HintTextProps { - text: string; hint: string; } From ea9aed4cf918c97bd374c937b8492fb01d6cf000 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bla=C5=A1ko?= Date: Mon, 11 Nov 2024 15:58:39 +0100 Subject: [PATCH 7/7] Revise comments related to outdated values --- public/locales/cs/translation.json | 4 ++-- public/locales/en/translation.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/public/locales/cs/translation.json b/public/locales/cs/translation.json index 3d685b42..8129e587 100644 --- a/public/locales/cs/translation.json +++ b/public/locales/cs/translation.json @@ -112,8 +112,8 @@ }, "faultEventMessage": { "outOfSyncValue": "Hodnota je zastaralá, intenzita poruch u některých listových uzlů byla aktualizována!", - "referencedValueOutdated": "Referenční hodnota byla změněna. Nová hodnota je {{newValue}}. Hodnota bude aktualizována při vyhodnocení stromu", - "predictedFailureRateOutdated": "Referenční hodnota byla změněna. Nová hodnota je {{newValue}}.", + "referencedValueOutdated": "Referencovaná hodnota byla změněna na {{newValue}}. Tuto hodnotu lze aktualizovat pomocí akce přepočítaní intenzity poruch.", + "predictedFailureRateOutdated": "Referencovaná hodnota byla změněna na {{newValue}}. Tuto hodnotu lze aktualizovat pomocí akce přepočítaní intenzity poruch.", "experimental": "Min. provozní hodiny (MOH) poruchoveho stromu se liší od MOH jeho systému", "requirementViolated": "Vypočtená intenzita poruch je větší, než je požadováno!" }, diff --git a/public/locales/en/translation.json b/public/locales/en/translation.json index 6201ea3e..fcb22c17 100644 --- a/public/locales/en/translation.json +++ b/public/locales/en/translation.json @@ -112,8 +112,8 @@ }, "faultEventMessage": { "outOfSyncValue": "The value is outdated, some of the leaf node failure rates were updated!", - "referencedValueOutdated": "The referenced value has changed. New value is {{newValue}}. The value will be updated on tree evaluation.", - "predictedFailureRateOutdated": "The referenced value has changed. New value is {{newValue}}.", + "referencedValueOutdated": "The referenced value has changed to {{newValue}}. The value can be updated with action to recalculate failure rate.", + "predictedFailureRateOutdated": "The referenced value has changed to {{newValue}}. The value can be updated with action to recalculate failure rate.", "experimental": "Fault tree's min. operational hours (MOH) is different from its system's MOH", "requirementViolated": "Calculated failure rate is bigger than required!" },