From e91c5e16ae89a1ba6b822d2607a91fd50173459d Mon Sep 17 00:00:00 2001 From: Kiryl Koniukh <49252228+Kasmadei@users.noreply.github.com> Date: Sun, 28 Apr 2024 16:23:03 +0200 Subject: [PATCH] [#226] Additional props for nodes --- public/locales/cs/translation.json | 10 ++ public/locales/en/translation.json | 9 ++ .../menu/faultEvent/FaultEventMenu.styles.tsx | 11 ++ .../menu/faultEvent/FaultEventMenu.tsx | 103 +++++++++++++++++- src/models/eventModel.tsx | 19 ++++ 5 files changed, 148 insertions(+), 4 deletions(-) create mode 100644 src/components/editor/faultTree/menu/faultEvent/FaultEventMenu.styles.tsx diff --git a/public/locales/cs/translation.json b/public/locales/cs/translation.json index f54265b6..c66030f4 100644 --- a/public/locales/cs/translation.json +++ b/public/locales/cs/translation.json @@ -80,5 +80,15 @@ "lastEditor": "Poslední editor", "status": "Stav", "edit": "Upravit" + }, + "faultEventMenu": { + "criticality": "Kritičnost", + "fhaBasedFailureRate": "Intenzita poruch založená na FHA", + "predictedFailureRate": "Predikovaná intenzita poruch", + "ataSystem": "ATA systém", + "partNumber": "Číslo součásti", + "stock": "Zásoba", + "quantity": "Množství" + } } diff --git a/public/locales/en/translation.json b/public/locales/en/translation.json index e882b83e..bf16ab9b 100644 --- a/public/locales/en/translation.json +++ b/public/locales/en/translation.json @@ -80,5 +80,14 @@ "lastEditor": "Last editor", "status": "Status", "edit": "Edit" + }, + "faultEventMenu": { + "criticality": "Criticality", + "fhaBasedFailureRate": "FHA based failure rate", + "predictedFailureRate": "Predicted failure rate", + "ataSystem": "ATA System", + "partNumber": "Part number", + "stock": "Stock", + "quantity": "Quantity" } } diff --git a/src/components/editor/faultTree/menu/faultEvent/FaultEventMenu.styles.tsx b/src/components/editor/faultTree/menu/faultEvent/FaultEventMenu.styles.tsx new file mode 100644 index 00000000..d4c03ae6 --- /dev/null +++ b/src/components/editor/faultTree/menu/faultEvent/FaultEventMenu.styles.tsx @@ -0,0 +1,11 @@ +import { Theme } from "@mui/material"; +import { makeStyles } from "tss-react/mui"; + +const useStyles = makeStyles()((theme: Theme) => ({ + label: { + fontWeight: "500", + color: "#00000080", + }, +})); + +export default useStyles; diff --git a/src/components/editor/faultTree/menu/faultEvent/FaultEventMenu.tsx b/src/components/editor/faultTree/menu/faultEvent/FaultEventMenu.tsx index 6b46d473..d6358172 100644 --- a/src/components/editor/faultTree/menu/faultEvent/FaultEventMenu.tsx +++ b/src/components/editor/faultTree/menu/faultEvent/FaultEventMenu.tsx @@ -1,14 +1,16 @@ -import { Button, Divider, Paper, Typography } from "@mui/material"; +import { Button, Divider, Paper, Typography, Box } from "@mui/material"; import FaultEventShapeToolPane from "./FaultEventShapeToolPane"; import { EventType, FaultEvent } from "../../../../../models/eventModel"; import * as React from "react"; import FailureModeDialog from "../../../../dialog/failureMode/create/FailureModeDialog"; -import { useState } from "react"; -import { EventFailureModeProvider, useEventFailureMode } from "../../../../../hooks/useEventFailureMode"; +import { useState, useEffect } from "react"; +import { EventFailureModeProvider } from "../../../../../hooks/useEventFailureMode"; import EventFailureModeList from "../failureMode/EventFailureModeList"; import { FailureMode } from "../../../../../models/failureModeModel"; import FailureModeShowDialog from "../../../../dialog/failureMode/show/FailureModeShowDialog"; -import { Box } from "@mui/material"; +import useStyles from "@components/editor/faultTree/menu/faultEvent/FaultEventMenu.styles"; +import { asArray } from "@utils/treeUtils"; +import { useTranslation } from "react-i18next"; interface Props { shapeToolData?: FaultEvent; @@ -17,16 +19,70 @@ interface Props { } const FaultEventMenu = ({ shapeToolData, onEventUpdated, refreshTree }: Props) => { + const { t } = useTranslation(); + const { classes } = useStyles(); const [failureModeDialogOpen, setFailureModeDialogOpen] = useState(false); const [failureModeOverviewDialogOpen, setFailureModeOverviewDialogOpen] = useState(false); const [failureModeOverview, setFailureModeOverview] = useState(null); + const [criticality, setCriticality] = useState(undefined); + const [predictedFailureRate, setPredictedFailureRate] = useState(undefined); + const [ataSystem, setAtaSystem] = useState(undefined); + const [partNumber, setPartNumber] = useState(undefined); + const [stock, setStock] = useState(undefined); + const [quantity, setQuantity] = useState(undefined); + const handleFailureModeClicked = (failureMode: FailureMode) => { setFailureModeOverview(failureMode); setFailureModeOverviewDialogOpen(true); }; + useEffect(() => { + if (shapeToolData?.supertypes?.criticality) { + setCriticality(shapeToolData.supertypes.criticality); + } else { + setCriticality(undefined); + } + + const types = asArray(shapeToolData?.supertypes?.supertypes) + + const filteredFailureRate = types.filter((type) => type.hasFailureRate); + + if (filteredFailureRate.length === 1 && filteredFailureRate[0].hasFailureRate?.prediction?.value) { + setPredictedFailureRate(filteredFailureRate[0].hasFailureRate?.prediction?.value); + } else { + setPredictedFailureRate(undefined); + } + + const superTypes = asArray(shapeToolData?.supertypes?.behavior?.item?.supertypes) + + const filteredAtaCode = superTypes.filter((sType) => sType?.ataCode); + const filteredPartNumber = superTypes.filter((sType) => sType?.partNumber); + + if (filteredAtaCode.length === 1 && filteredAtaCode[0].ataCode && filteredAtaCode[0].name) { + const ataSystemString = `${filteredAtaCode[0].ataCode} ${filteredAtaCode[0].name}`; + setAtaSystem(ataSystemString); + } else { + setAtaSystem(undefined); + } + + if (filteredPartNumber.length === 1 && filteredPartNumber[0].partNumber && filteredPartNumber[0].stock) { + setPartNumber(filteredPartNumber[0].partNumber); + setStock(filteredPartNumber[0].stock); + } else { + setPartNumber(undefined); + setStock(undefined); + } + + if (shapeToolData?.supertypes?.behavior?.item?.quantity) { + setQuantity(shapeToolData?.supertypes?.behavior?.item?.quantity); + } else { + setQuantity(undefined); + } + }, [shapeToolData]); + + return ( @@ -37,6 +93,45 @@ const FaultEventMenu = ({ shapeToolData, onEventUpdated, refreshTree }: Props) = {shapeToolData && ( + + {criticality && ( + + {t("faultEventMenu.criticality")}: {criticality} + + )} + + {predictedFailureRate && ( + + {shapeToolData.eventType === EventType.INTERMEDIATE ? ( + {t("faultEventMenu.fhaBasedFailureRate")}: + ) : ( + {t("faultEventMenu.predictedFailureRate")}: + )} + {` ${predictedFailureRate.toExponential(2)}`} + + )} + + {ataSystem && ( + + {t("faultEventMenu.ataSystem")}: {ataSystem} + + )} + {partNumber && ( + + {t("faultEventMenu.partNumber")}: {partNumber} + + )} + {stock && ( + + {t("faultEventMenu.stock")}: {stock} + + )} + {quantity && ( + + {t("faultEventMenu.quantity")}: {quantity} + + )} + Failure Mode diff --git a/src/models/eventModel.tsx b/src/models/eventModel.tsx index f07670e9..1f7fc69e 100644 --- a/src/models/eventModel.tsx +++ b/src/models/eventModel.tsx @@ -19,6 +19,15 @@ const ctx = { hasFailureRate: VocabularyUtils.PREFIX + "has-failure-rate", requirement: VocabularyUtils.PREFIX + "has-requirement", upperBound: VocabularyUtils.PREFIX + "to", + criticality: VocabularyUtils.PREFIX + "criticality", + prediction: VocabularyUtils.PREFIX + "has-prediction", + value: VocabularyUtils.PREFIX + "value", + ataCode: VocabularyUtils.PREFIX + "ata-code", + partNumber: VocabularyUtils.PREFIX + "part-number", + stock: VocabularyUtils.PREFIX + "stock", + behavior: VocabularyUtils.PREFIX + "is-manifestation-of", + item: VocabularyUtils.PREFIX + "has-component", + quantity: VocabularyUtils.PREFIX + "quantity", references: VocabularyUtils.PREFIX + "is-reference-to", isPartOf: VocabularyUtils.PREFIX + "is-part-of", isReference: VocabularyUtils.PREFIX + "is-reference", @@ -51,6 +60,16 @@ export interface FaultEvent extends AbstractModel { isPartOf?: string; }; supertypes?: { + criticality?: number; + superTypes?: any; + behavior?: { + item?: { + quantity?: number; + supertypes?: { + ataCode?: string; + }; + }; + }; hasFailureRate?: { iri?: string; requirement?: {