From f8fb5cfe57bd73a6142f1c338c78251b30368524 Mon Sep 17 00:00:00 2001 From: Max Chopart Date: Wed, 5 Jun 2024 10:09:23 +0200 Subject: [PATCH 1/6] [Fix #346] Added default gate type to created fault tree --- .../faultEvent/FaultEventCreation.schema.tsx | 1 + .../dialog/faultEvent/FaultEventCreation.tsx | 65 +++++++++---------- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/components/dialog/faultEvent/FaultEventCreation.schema.tsx b/src/components/dialog/faultEvent/FaultEventCreation.schema.tsx index 3470d2e9..7c564f75 100644 --- a/src/components/dialog/faultEvent/FaultEventCreation.schema.tsx +++ b/src/components/dialog/faultEvent/FaultEventCreation.schema.tsx @@ -38,4 +38,5 @@ export const schema = Yup.object().shape({ export const rootEventSchema = Yup.object().shape({ name: Yup.string().min(1, "Must be at least 1 character long").required("Event is mandatory"), + gateType: Yup.string().nullable().default(GateType.OR), }); diff --git a/src/components/dialog/faultEvent/FaultEventCreation.tsx b/src/components/dialog/faultEvent/FaultEventCreation.tsx index 2ca5ffdb..a9870e36 100644 --- a/src/components/dialog/faultEvent/FaultEventCreation.tsx +++ b/src/components/dialog/faultEvent/FaultEventCreation.tsx @@ -80,6 +80,38 @@ const FaultEventCreation = ({ useFormMethods, isRootEvent }: Props) => { )} defaultValue={null} /> + + {(eventTypeWatch === EventType.INTERMEDIATE || !eventTypeWatch) && ( +
+ + {t("newFtaModal.gateType")} + ( + + )} + name="gateType" + control={control} + defaultValue={GateType.OR} + /> + +
+ )} ); } @@ -169,39 +201,6 @@ const FaultEventCreation = ({ useFormMethods, isRootEvent }: Props) => { {...register("sequenceProbability")} /> )} - - {(eventTypeWatch === EventType.INTERMEDIATE || !eventTypeWatch) && ( -
- - {t("newFtaModal.gateType")} - ( - - )} - name="gateType" - control={control} - defaultValue={GateType.OR} - /> - -
- )} )} From 48b76ca01a20d08e08bb05b720f2fba682e640df Mon Sep 17 00:00:00 2001 From: Max Chopart Date: Wed, 5 Jun 2024 14:37:57 +0200 Subject: [PATCH 2/6] [Fix #346] Removed unnecessary schema elements for creation of new event in FTA editor --- .../faultEvent/FaultEventCreation.schema.tsx | 2 +- .../dialog/faultEvent/FaultEventCreation.tsx | 60 +++++++++---------- .../dialog/faultEvent/FaultEventDialog.tsx | 8 +-- .../dialog/faultTree/FaultTreeDialog.tsx | 6 +- 4 files changed, 37 insertions(+), 39 deletions(-) diff --git a/src/components/dialog/faultEvent/FaultEventCreation.schema.tsx b/src/components/dialog/faultEvent/FaultEventCreation.schema.tsx index 7c564f75..a2febc8b 100644 --- a/src/components/dialog/faultEvent/FaultEventCreation.schema.tsx +++ b/src/components/dialog/faultEvent/FaultEventCreation.schema.tsx @@ -36,7 +36,7 @@ export const schema = Yup.object().shape({ .max(1, "Sequence probability cannot be greater than 1"), }); -export const rootEventSchema = Yup.object().shape({ +export const eventSchema = Yup.object().shape({ name: Yup.string().min(1, "Must be at least 1 character long").required("Event is mandatory"), gateType: Yup.string().nullable().default(GateType.OR), }); diff --git a/src/components/dialog/faultEvent/FaultEventCreation.tsx b/src/components/dialog/faultEvent/FaultEventCreation.tsx index a9870e36..73cd55a7 100644 --- a/src/components/dialog/faultEvent/FaultEventCreation.tsx +++ b/src/components/dialog/faultEvent/FaultEventCreation.tsx @@ -81,37 +81,35 @@ const FaultEventCreation = ({ useFormMethods, isRootEvent }: Props) => { defaultValue={null} /> - {(eventTypeWatch === EventType.INTERMEDIATE || !eventTypeWatch) && ( -
- - {t("newFtaModal.gateType")} - ( - - )} - name="gateType" - control={control} - defaultValue={GateType.OR} - /> - -
- )} +
+ + {t("newFtaModal.gateType")} + ( + + )} + name="gateType" + control={control} + defaultValue={GateType.OR} + /> + +
); } diff --git a/src/components/dialog/faultEvent/FaultEventDialog.tsx b/src/components/dialog/faultEvent/FaultEventDialog.tsx index 765a7f29..00fc4bec 100644 --- a/src/components/dialog/faultEvent/FaultEventDialog.tsx +++ b/src/components/dialog/faultEvent/FaultEventDialog.tsx @@ -8,12 +8,12 @@ import * as faultEventService from "@services/faultEventService"; import { SnackbarType, useSnackbar } from "@hooks/useSnackbar"; import FaultEventCreation from "./FaultEventCreation"; import { useForm } from "react-hook-form"; -import { schema } from "./FaultEventCreation.schema"; +import { eventSchema } from "./FaultEventCreation.schema"; import { yupResolver } from "@hookform/resolvers/yup"; import { eventFromHookFormValues } from "@services/faultEventService"; import { ReusableFaultEventsProvider } from "@hooks/useReusableFaultEvents"; import { FaultEvent } from "@models/eventModel"; -import {useSelectedSystem} from "@hooks/useSelectedSystem"; +import { useSelectedSystem } from "@hooks/useSelectedSystem"; interface Props { open: boolean; @@ -27,7 +27,7 @@ const FaultEventDialog = ({ open, eventIri, treeUri, onCreated, onClose }: Props const [showSnackbar] = useSnackbar(); const [selectedSystem] = useSelectedSystem(); - const useFormMethods = useForm({ resolver: yupResolver(schema) }); + const useFormMethods = useForm({ resolver: yupResolver(eventSchema) }); const { handleSubmit, formState } = useFormMethods; const { isSubmitting } = formState; @@ -51,7 +51,7 @@ const FaultEventDialog = ({ open, eventIri, treeUri, onCreated, onClose }: Props - + diff --git a/src/components/dialog/faultTree/FaultTreeDialog.tsx b/src/components/dialog/faultTree/FaultTreeDialog.tsx index a5879d91..e9f70f87 100644 --- a/src/components/dialog/faultTree/FaultTreeDialog.tsx +++ b/src/components/dialog/faultTree/FaultTreeDialog.tsx @@ -11,11 +11,11 @@ import FaultEventCreation from "@components/dialog/faultEvent/FaultEventCreation import { useFaultTrees } from "@hooks/useFaultTrees"; import { FaultTree } from "@models/faultTreeModel"; import { yupResolver } from "@hookform/resolvers/yup"; -import { rootEventSchema } from "@components/dialog/faultEvent/FaultEventCreation.schema"; +import { eventSchema } from "@components/dialog/faultEvent/FaultEventCreation.schema"; import { ReusableFaultEventsProvider } from "@hooks/useReusableFaultEvents"; import { useTranslation } from "react-i18next"; import useStyles from "@components/dialog/faultTree/FaultTreeDialog.styles"; -import {useSelectedSystem} from "@hooks/useSelectedSystem"; +import { useSelectedSystem } from "@hooks/useSelectedSystem"; const FaultTreeDialog = ({ open, handleCloseDialog }) => { const { t } = useTranslation(); @@ -25,7 +25,7 @@ const FaultTreeDialog = ({ open, handleCloseDialog }) => { const [processing, setIsProcessing] = useState(false); const [selectedSystem] = useSelectedSystem(); - const useFormMethods = useForm({ resolver: yupResolver(schema.concat(rootEventSchema)) }); + const useFormMethods = useForm({ resolver: yupResolver(schema.concat(eventSchema)) }); const { handleSubmit, register } = useFormMethods; const handleCreateFaultTree = async (values: any) => { From 1fdf9376818c15bf23572e969253275ddf403e84 Mon Sep 17 00:00:00 2001 From: Max Chopart Date: Wed, 5 Jun 2024 16:03:57 +0200 Subject: [PATCH 3/6] [Fix #346] Fixed missing probability field when creating new intermediate event. --- .../dialog/faultEvent/FaultEventCreation.tsx | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/components/dialog/faultEvent/FaultEventCreation.tsx b/src/components/dialog/faultEvent/FaultEventCreation.tsx index 73cd55a7..070c0f11 100644 --- a/src/components/dialog/faultEvent/FaultEventCreation.tsx +++ b/src/components/dialog/faultEvent/FaultEventCreation.tsx @@ -168,20 +168,18 @@ const FaultEventCreation = ({ useFormMethods, isRootEvent }: Props) => { /> {/* Probability field */} - {eventTypeWatch !== EventType.INTERMEDIATE && ( - - )} + {(gateTypeWatch === GateType.PRIORITY_AND || !gateTypeWatch) && eventTypeWatch === EventType.INTERMEDIATE && From b3c2f5891ff30353bd40e2c2777b12337a010339 Mon Sep 17 00:00:00 2001 From: Max Chopart Date: Thu, 6 Jun 2024 15:12:21 +0200 Subject: [PATCH 4/6] [Fix #352] Sidebar of fault tree editor now has context of selected system --- .../dialog/faultEvent/FaultEventCreation.tsx | 5 +++-- .../faultTree/menu/faultEvent/FaultEventMenu.tsx | 7 ++++++- .../menu/faultEvent/FaultEventShapeToolPane.tsx | 13 ++++--------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/components/dialog/faultEvent/FaultEventCreation.tsx b/src/components/dialog/faultEvent/FaultEventCreation.tsx index 070c0f11..a8a1036b 100644 --- a/src/components/dialog/faultEvent/FaultEventCreation.tsx +++ b/src/components/dialog/faultEvent/FaultEventCreation.tsx @@ -12,10 +12,11 @@ import { useTranslation } from "react-i18next"; interface Props { useFormMethods: any; isRootEvent: boolean; + eventValue?: FaultEvent; } // TODO: remove ts-ignores and migrate to higher version of react-hook-form -const FaultEventCreation = ({ useFormMethods, isRootEvent }: Props) => { +const FaultEventCreation = ({ useFormMethods, isRootEvent, eventValue }: Props) => { const { classes } = useStyles(); const { t } = useTranslation(); @@ -78,7 +79,7 @@ const FaultEventCreation = ({ useFormMethods, isRootEvent }: Props) => { renderInput={(params) => ( )} - defaultValue={null} + defaultValue={eventValue ? eventValue : null} />
diff --git a/src/components/editor/faultTree/menu/faultEvent/FaultEventMenu.tsx b/src/components/editor/faultTree/menu/faultEvent/FaultEventMenu.tsx index bff40c9e..20dd4bc9 100644 --- a/src/components/editor/faultTree/menu/faultEvent/FaultEventMenu.tsx +++ b/src/components/editor/faultTree/menu/faultEvent/FaultEventMenu.tsx @@ -11,6 +11,8 @@ import FailureModeShowDialog from "../../../../dialog/failureMode/show/FailureMo import useStyles from "@components/editor/faultTree/menu/faultEvent/FaultEventMenu.styles"; import { useTranslation } from "react-i18next"; import { asArray } from "@utils/utils"; +import { ReusableFaultEventsProvider } from "@hooks/useReusableFaultEvents"; +import { useSelectedSystem } from "@hooks/useSelectedSystem"; interface Props { shapeToolData?: FaultEvent; @@ -34,6 +36,7 @@ const FaultEventMenu = ({ shapeToolData, onEventUpdated, refreshTree, rootIri }: const [stock, setStock] = useState(undefined); const [quantity, setQuantity] = useState(undefined); const [schematicDesignation, setSchematicDesignation] = useState(undefined); + const [selectedSystem] = useSelectedSystem(); const handleFailureModeClicked = (failureMode: FailureMode) => { setFailureModeOverview(failureMode); @@ -103,7 +106,9 @@ const FaultEventMenu = ({ shapeToolData, onEventUpdated, refreshTree, rootIri }: return ( - + + + {/* TODO: Finish for other nodes. Will be refactored. */} diff --git a/src/components/editor/faultTree/menu/faultEvent/FaultEventShapeToolPane.tsx b/src/components/editor/faultTree/menu/faultEvent/FaultEventShapeToolPane.tsx index 64c923db..2429aca7 100644 --- a/src/components/editor/faultTree/menu/faultEvent/FaultEventShapeToolPane.tsx +++ b/src/components/editor/faultTree/menu/faultEvent/FaultEventShapeToolPane.tsx @@ -13,7 +13,6 @@ import { FaultEvent, GateType } from "@models/eventModel"; import FaultEventChildrenReorderList from "@components/editor/faultTree/menu/faultEvent/reorder/FaultEventChildrenReorderList"; import { SnackbarType, useSnackbar } from "@hooks/useSnackbar"; import useStyles from "@components/editor/faultTree/menu/faultEvent/FaultEventShapeToolPane.styles"; -import { ReusableFaultEventsProvider } from "@hooks/useReusableFaultEvents"; interface Props { data?: FaultEvent; @@ -26,7 +25,7 @@ const FaultEventShapeToolPane = ({ data, onEventUpdated, refreshTree }: Props) = const [showSnackbar] = useSnackbar(); let editorPane; - let updateFunction; + let updateEvent; let useFormMethods; let defaultValues; @@ -44,7 +43,7 @@ const FaultEventShapeToolPane = ({ data, onEventUpdated, refreshTree }: Props) = resolver: yupResolver(eventSchema), }); - updateFunction = async (values: any) => { + updateEvent = async (values: any) => { let dataClone = cloneDeep(data); const updatedFaultEvent = deepOmit(faultEventService.eventFromHookFormValues(values), "@type"); @@ -53,11 +52,7 @@ const FaultEventShapeToolPane = ({ data, onEventUpdated, refreshTree }: Props) = onEventUpdated(dataClone); }; - editorPane = ( - - - - ); + editorPane = ; } else { defaultValues = {}; useFormMethods = useForm(); @@ -93,7 +88,7 @@ const FaultEventShapeToolPane = ({ data, onEventUpdated, refreshTree }: Props) = {editorPane} {isDirty && ( - )} From 838cc47869c7c930729dd67acc6b12a785bcc596 Mon Sep 17 00:00:00 2001 From: Max Chopart Date: Thu, 6 Jun 2024 15:50:30 +0200 Subject: [PATCH 5/6] [Upd #352] Renamed schema for readability --- .../dialog/faultEvent/FaultEventCreation.schema.tsx | 2 +- src/components/dialog/faultEvent/FaultEventDialog.tsx | 4 ++-- src/components/dialog/faultTree/FaultTreeDialog.tsx | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/components/dialog/faultEvent/FaultEventCreation.schema.tsx b/src/components/dialog/faultEvent/FaultEventCreation.schema.tsx index a2febc8b..620a9978 100644 --- a/src/components/dialog/faultEvent/FaultEventCreation.schema.tsx +++ b/src/components/dialog/faultEvent/FaultEventCreation.schema.tsx @@ -36,7 +36,7 @@ export const schema = Yup.object().shape({ .max(1, "Sequence probability cannot be greater than 1"), }); -export const eventSchema = Yup.object().shape({ +export const faultEventSchema = Yup.object().shape({ name: Yup.string().min(1, "Must be at least 1 character long").required("Event is mandatory"), gateType: Yup.string().nullable().default(GateType.OR), }); diff --git a/src/components/dialog/faultEvent/FaultEventDialog.tsx b/src/components/dialog/faultEvent/FaultEventDialog.tsx index 00fc4bec..ef60b06d 100644 --- a/src/components/dialog/faultEvent/FaultEventDialog.tsx +++ b/src/components/dialog/faultEvent/FaultEventDialog.tsx @@ -8,7 +8,7 @@ import * as faultEventService from "@services/faultEventService"; import { SnackbarType, useSnackbar } from "@hooks/useSnackbar"; import FaultEventCreation from "./FaultEventCreation"; import { useForm } from "react-hook-form"; -import { eventSchema } from "./FaultEventCreation.schema"; +import { faultEventSchema } from "./FaultEventCreation.schema"; import { yupResolver } from "@hookform/resolvers/yup"; import { eventFromHookFormValues } from "@services/faultEventService"; import { ReusableFaultEventsProvider } from "@hooks/useReusableFaultEvents"; @@ -27,7 +27,7 @@ const FaultEventDialog = ({ open, eventIri, treeUri, onCreated, onClose }: Props const [showSnackbar] = useSnackbar(); const [selectedSystem] = useSelectedSystem(); - const useFormMethods = useForm({ resolver: yupResolver(eventSchema) }); + const useFormMethods = useForm({ resolver: yupResolver(faultEventSchema) }); const { handleSubmit, formState } = useFormMethods; const { isSubmitting } = formState; diff --git a/src/components/dialog/faultTree/FaultTreeDialog.tsx b/src/components/dialog/faultTree/FaultTreeDialog.tsx index e9f70f87..6ff81498 100644 --- a/src/components/dialog/faultTree/FaultTreeDialog.tsx +++ b/src/components/dialog/faultTree/FaultTreeDialog.tsx @@ -11,7 +11,7 @@ import FaultEventCreation from "@components/dialog/faultEvent/FaultEventCreation import { useFaultTrees } from "@hooks/useFaultTrees"; import { FaultTree } from "@models/faultTreeModel"; import { yupResolver } from "@hookform/resolvers/yup"; -import { eventSchema } from "@components/dialog/faultEvent/FaultEventCreation.schema"; +import { faultEventSchema } from "@components/dialog/faultEvent/FaultEventCreation.schema"; import { ReusableFaultEventsProvider } from "@hooks/useReusableFaultEvents"; import { useTranslation } from "react-i18next"; import useStyles from "@components/dialog/faultTree/FaultTreeDialog.styles"; @@ -25,7 +25,7 @@ const FaultTreeDialog = ({ open, handleCloseDialog }) => { const [processing, setIsProcessing] = useState(false); const [selectedSystem] = useSelectedSystem(); - const useFormMethods = useForm({ resolver: yupResolver(schema.concat(eventSchema)) }); + const useFormMethods = useForm({ resolver: yupResolver(schema.concat(faultEventSchema)) }); const { handleSubmit, register } = useFormMethods; const handleCreateFaultTree = async (values: any) => { From 87acec12f8b3b752ad142b0f9db5de6eb6063753 Mon Sep 17 00:00:00 2001 From: Max Chopart Date: Fri, 7 Jun 2024 17:02:25 +0200 Subject: [PATCH 6/6] [Upd #352] Removed probability attribution to intermediate events --- .../dialog/faultEvent/FaultEventCreation.tsx | 125 +++++++++--------- .../faultEvent/FaultEventShapeToolPane.tsx | 4 +- 2 files changed, 68 insertions(+), 61 deletions(-) diff --git a/src/components/dialog/faultEvent/FaultEventCreation.tsx b/src/components/dialog/faultEvent/FaultEventCreation.tsx index a8a1036b..3d99309f 100644 --- a/src/components/dialog/faultEvent/FaultEventCreation.tsx +++ b/src/components/dialog/faultEvent/FaultEventCreation.tsx @@ -13,10 +13,11 @@ interface Props { useFormMethods: any; isRootEvent: boolean; eventValue?: FaultEvent; + isEditedEvent?: boolean; } // TODO: remove ts-ignores and migrate to higher version of react-hook-form -const FaultEventCreation = ({ useFormMethods, isRootEvent, eventValue }: Props) => { +const FaultEventCreation = ({ useFormMethods, isRootEvent, eventValue, isEditedEvent = false }: Props) => { const { classes } = useStyles(); const { t } = useTranslation(); @@ -82,35 +83,72 @@ const FaultEventCreation = ({ useFormMethods, isRootEvent, eventValue }: Props) defaultValue={eventValue ? eventValue : null} /> -
- - {t("newFtaModal.gateType")} + {!selectedEvent && !isRootEvent && ( + + {t("newFtaModal.type")} ( - - )} - name="gateType" + render={({ field }) => { + const _onChange = field.onChange; + field.onChange = (e) => { + if (e.target.value !== EventType.INTERMEDIATE && e.target.value !== EventType.CONDITIONING) { + lastGateTypeRef.current = gateTypeWatch; + setValue("gateType", null); + } else setValue("gateType", lastGateTypeRef.current ? lastGateTypeRef.current : GateType.OR); + _onChange(e); + }; + return ( + + ); + }} + name="eventType" control={control} - defaultValue={GateType.OR} + defaultValue={EventType.INTERMEDIATE} /> -
+ )} + + {eventTypeWatch === EventType.INTERMEDIATE && ( +
+ + {t("newFtaModal.gateType")} + ( + + )} + name="gateType" + control={control} + defaultValue={GateType.OR} + /> + +
+ )} ); } @@ -121,41 +159,8 @@ const FaultEventCreation = ({ useFormMethods, isRootEvent, eventValue }: Props) } return ( <> - {!selectedEvent && filteredOptions.length === 0 && !isRootEvent && ( + {eventTypeWatch !== EventType.INTERMEDIATE && !isRootEvent && isEditedEvent && ( <> - - {t("newFtaModal.type")} - { - const _onChange = field.onChange; - field.onChange = (e) => { - if (e.target.value !== EventType.INTERMEDIATE && e.target.value !== EventType.CONDITIONING) { - lastGateTypeRef.current = gateTypeWatch; - setValue("gateType", null); - } else setValue("gateType", lastGateTypeRef.current ? lastGateTypeRef.current : GateType.OR); - _onChange(e); - }; - return ( - - ); - }} - name="eventType" - control={control} - defaultValue={EventType.INTERMEDIATE} - /> - - {/*TODO: sort out default value UI bug*/} ; + editorPane = ( + + ); } else { defaultValues = {}; useFormMethods = useForm();