From 3533204cd5af6f4a06870a9f9f7818cec9ef231f Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Tue, 3 Sep 2024 19:24:27 +0200 Subject: [PATCH] [Side effect] Fix form reset based on data parameter - show message if event in the fault tree is selected --- public/locales/cs/translation.json | 3 +- public/locales/en/translation.json | 3 +- .../menu/faultEvent/FaultEventMenu.tsx | 9 +- .../FaultEventShapeToolPane.styles.tsx | 6 +- .../faultEvent/FaultEventShapeToolPane.tsx | 83 ++++++++++--------- 5 files changed, 55 insertions(+), 49 deletions(-) diff --git a/public/locales/cs/translation.json b/public/locales/cs/translation.json index beeb2c0a..62172eb1 100644 --- a/public/locales/cs/translation.json +++ b/public/locales/cs/translation.json @@ -109,7 +109,8 @@ "calculatedFailureRate": "Vypočtená intenzita poruch", "operationalFailureRate": "Provozní intenzita poruch", "manuallyDefinedFailureRate": "Manuálně definovaná intenzita poruch", - "unsavedChanges": "Máte neuložené změny. Chcete před pokračováním uložit změny?" + "unsavedChanges": "Máte neuložené změny. Chcete před pokračováním uložit změny?", + "notSelected": "Není vybrána žádná událost" }, "appBar": { "selectSystemPlaceholder": "Vyberte systém" diff --git a/public/locales/en/translation.json b/public/locales/en/translation.json index e081b266..b1029962 100644 --- a/public/locales/en/translation.json +++ b/public/locales/en/translation.json @@ -109,7 +109,8 @@ "calculatedFailureRate": "Calculated failure rate", "operationalFailureRate": "Operational failure rate", "manuallyDefinedFailureRate": "Manually defined failure rate", - "unsavedChanges": "You have unsaved changes. Do you want to save your changes before proceeding?" + "unsavedChanges": "You have unsaved changes. Do you want to save your changes before proceeding?", + "notSelected": "No Event selected" }, "appBar": { "selectSystemPlaceholder": "Select system" diff --git a/src/components/editor/faultTree/menu/faultEvent/FaultEventMenu.tsx b/src/components/editor/faultTree/menu/faultEvent/FaultEventMenu.tsx index 6516f3c4..dbcdd897 100644 --- a/src/components/editor/faultTree/menu/faultEvent/FaultEventMenu.tsx +++ b/src/components/editor/faultTree/menu/faultEvent/FaultEventMenu.tsx @@ -323,11 +323,10 @@ const FaultEventMenu = ({ selectedShapeToolData, onEventUpdated, refreshTree, ro return ( - {shapeToolData && ( - - - - )} + + + + {/* TODO: Finish for other nodes. Will be refactored. */} {/* ROOT NODE */} diff --git a/src/components/editor/faultTree/menu/faultEvent/FaultEventShapeToolPane.styles.tsx b/src/components/editor/faultTree/menu/faultEvent/FaultEventShapeToolPane.styles.tsx index 79e5686c..e6f8bc9e 100644 --- a/src/components/editor/faultTree/menu/faultEvent/FaultEventShapeToolPane.styles.tsx +++ b/src/components/editor/faultTree/menu/faultEvent/FaultEventShapeToolPane.styles.tsx @@ -3,7 +3,11 @@ import { makeStyles } from "tss-react/mui"; const useStyles = makeStyles()((theme: Theme) => ({ emptyTitle: { - padding: theme.spacing(0, 2), + textAlign: "center", + fontStyle: "italic", + fontWeight: "bold", + color: theme.main.grey, + padding: theme.spacing(10, 2), }, })); diff --git a/src/components/editor/faultTree/menu/faultEvent/FaultEventShapeToolPane.tsx b/src/components/editor/faultTree/menu/faultEvent/FaultEventShapeToolPane.tsx index 44982be0..13752393 100644 --- a/src/components/editor/faultTree/menu/faultEvent/FaultEventShapeToolPane.tsx +++ b/src/components/editor/faultTree/menu/faultEvent/FaultEventShapeToolPane.tsx @@ -8,6 +8,7 @@ import useStyles from "@components/editor/faultTree/menu/faultEvent/FaultEventSh import { ReusableFaultEventsProvider } from "@hooks/useReusableFaultEvents"; import { useCurrentFaultTree } from "@hooks/useCurrentFaultTree"; import { asArray } from "@utils/utils"; +import { useTranslation } from "react-i18next"; interface Props { data?: FaultEvent; @@ -18,55 +19,55 @@ interface Props { const FaultEventShapeToolPane = ({ data, refreshTree, formMethods }: Props) => { const { classes } = useStyles(); const [faultTree] = useCurrentFaultTree(); + const { t } = useTranslation(); - let editorPane; - let defaultValues; + const getFormValues = (data) => { + if (data) { + const safeSupertype = asArray(data.supertypes).map((t) => ({ name: t.name, iri: t.iri, types: t.types }))?.[0]; + return { + eventType: data.eventType, + name: data.name, + description: data.description, + probability: data.probability ? data.probability : 0.01, + gateType: data.gateType ? data.gateType : null, + sequenceProbability: data.sequenceProbability, + existingEvent: safeSupertype, + }; + } else { + return {}; + } + }; - if (data) { - const safeSupertype = asArray(data.supertypes).map((t) => ({ name: t.name, iri: t.iri, types: t.types }))?.[0]; - defaultValues = { - eventType: data.eventType, - name: data.name, - description: data.description, - probability: data.probability ? data.probability : 0.01, - gateType: data.gateType ? data.gateType : null, - sequenceProbability: data.sequenceProbability, - existingEvent: safeSupertype, - }; + useEffect(() => { + formMethods.reset(getFormValues(data)); + }, [data]); - useEffect(() => { - formMethods.reset(defaultValues); - }, [data]); + const isDisabled = + data && + ([EventType.INTERMEDIATE, EventType.BASIC, EventType.EXTERNAL].includes(data.eventType) || data.isReference); - const isDisabled = - data && - ([EventType.INTERMEDIATE, EventType.BASIC, EventType.EXTERNAL].includes(data.eventType) || data.isReference); + const editorPane = (isDisabled) => ( + + + + ); - editorPane = ( - - - - ); - } else { - defaultValues = {}; - formMethods.reset(defaultValues); - editorPane = ( - - No Event selected - - ); - } + const editorPaneNoSelection = () => ( + + {t("faultEventMenu.notSelected")} + + ); return ( - {editorPane} + {data ? editorPane(isDisabled) : editorPaneNoSelection()} {data?.gateType === GateType.PRIORITY_AND && (