Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added default gate type to created fault tree #366

Merged
merged 6 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +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({
LaChope marked this conversation as resolved.
Show resolved Hide resolved
name: Yup.string().min(1, "Must be at least 1 character long").required("Event is mandatory"),
gateType: Yup.string().nullable().default(GateType.OR),
});
89 changes: 42 additions & 47 deletions src/components/dialog/faultEvent/FaultEventCreation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,36 @@ const FaultEventCreation = ({ useFormMethods, isRootEvent }: Props) => {
)}
defaultValue={null}
/>

<div className={classes.formControlDiv}>
<FormControl className={classes.formControl}>
<InputLabel id="gate-type-select-label">{t("newFtaModal.gateType")}</InputLabel>
<Controller
render={({ field }) => (
<Select
{...field}
labelId="gate-type-select-label"
label={t("newFtaModal.gateType")}
error={!!errors.gateType}
>
{gateTypeValues()
.filter((value) => value[0])
.map((value) => {
const [enabled, optionValue] = value;
return (
<MenuItem key={optionValue} value={optionValue} disabled={!enabled}>
{optionValue}
</MenuItem>
);
})}
</Select>
)}
name="gateType"
control={control}
defaultValue={GateType.OR}
/>
</FormControl>
</div>
</>
);
}
Expand Down Expand Up @@ -138,20 +168,18 @@ const FaultEventCreation = ({ useFormMethods, isRootEvent }: Props) => {
/>

{/* Probability field */}
{eventTypeWatch !== EventType.INTERMEDIATE && (
<TextField
label={t("newFtaModal.probability")}
type="number"
min={0}
max={1}
step={0.01}
error={!!errors.probability}
helperText={errors.probability?.message}
className={classes.probability}
defaultValue=""
{...register("probability")}
/>
)}
<TextField
blcham marked this conversation as resolved.
Show resolved Hide resolved
label={t("newFtaModal.probability")}
type="number"
min={0}
max={1}
step={0.01}
error={!!errors.probability}
helperText={errors.probability?.message}
className={classes.probability}
defaultValue=""
{...register("probability")}
/>

{(gateTypeWatch === GateType.PRIORITY_AND || !gateTypeWatch) &&
eventTypeWatch === EventType.INTERMEDIATE &&
Expand All @@ -169,39 +197,6 @@ const FaultEventCreation = ({ useFormMethods, isRootEvent }: Props) => {
{...register("sequenceProbability")}
/>
)}

{(eventTypeWatch === EventType.INTERMEDIATE || !eventTypeWatch) && (
<div className={classes.formControlDiv}>
<FormControl className={classes.formControl}>
<InputLabel id="gate-type-select-label">{t("newFtaModal.gateType")}</InputLabel>
<Controller
render={({ field }) => (
<Select
{...field}
disabled={existingEventSelected}
labelId="gate-type-select-label"
label={t("newFtaModal.gateType")}
error={!!errors.gateType}
>
{gateTypeValues()
.filter((value) => value[0])
.map((value) => {
const [enabled, optionValue] = value;
return (
<MenuItem key={optionValue} value={optionValue} disabled={!enabled}>
{optionValue}
</MenuItem>
);
})}
</Select>
)}
name="gateType"
control={control}
defaultValue={GateType.OR}
/>
</FormControl>
</div>
)}
</>
)}
</>
Expand Down
8 changes: 4 additions & 4 deletions src/components/dialog/faultEvent/FaultEventDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -51,7 +51,7 @@ const FaultEventDialog = ({ open, eventIri, treeUri, onCreated, onClose }: Props
</DialogTitle>
<DialogContent dividers>
<ReusableFaultEventsProvider treeUri={treeUri} systemUri={selectedSystem?.iri}>
<FaultEventCreation useFormMethods={useFormMethods} eventReusing={true} />
<FaultEventCreation useFormMethods={useFormMethods} isRootEvent={false} />
</ReusableFaultEventsProvider>
</DialogContent>
<DialogActions>
Expand Down
6 changes: 3 additions & 3 deletions src/components/dialog/faultTree/FaultTreeDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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) => {
Expand Down
Loading