Skip to content

Commit

Permalink
Additioanl props for nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kasmadei committed Apr 28, 2024
1 parent a060d1a commit b42e847
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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;
105 changes: 101 additions & 4 deletions src/components/editor/faultTree/menu/faultEvent/FaultEventMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
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";

interface Props {
shapeToolData?: FaultEvent;
Expand All @@ -17,16 +17,74 @@ interface Props {
}

const FaultEventMenu = ({ shapeToolData, onEventUpdated, refreshTree }: Props) => {
const { classes } = useStyles();
const [failureModeDialogOpen, setFailureModeDialogOpen] = useState(false);

const [failureModeOverviewDialogOpen, setFailureModeOverviewDialogOpen] = useState(false);
const [failureModeOverview, setFailureModeOverview] = useState<FailureMode | null>(null);

const [criticality, setCriticality] = useState<number | undefined>(undefined);
const [predictedFailureRate, setPredictedFailureRate] = useState<number | undefined>(undefined);
const [ataSystem, setAtaSystem] = useState<string | undefined>(undefined);
const [partNumber, setPartNumber] = useState<string | undefined>(undefined);
const [stock, setStock] = useState<string | undefined>(undefined);
const [quantity, setQuantity] = useState<number | undefined>(undefined);

const handleFailureModeClicked = (failureMode: FailureMode) => {
setFailureModeOverview(failureMode);
setFailureModeOverviewDialogOpen(true);
};

useEffect(() => {
if (shapeToolData?.supertypes?.criticality) {
setCriticality(shapeToolData.supertypes.criticality);
} else {
setCriticality(undefined);
}

const types = Array.isArray(shapeToolData?.supertypes?.supertypes)
? shapeToolData?.supertypes?.supertypes
: shapeToolData?.supertypes?.supertypes
? [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 = Array.isArray(shapeToolData?.supertypes?.behavior?.item?.supertypes)
? shapeToolData?.supertypes?.behavior?.item?.supertypes
: [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 (
<Box paddingLeft={2} marginRight={2}>
<Typography variant="h5" gutterBottom>
Expand All @@ -37,6 +95,45 @@ const FaultEventMenu = ({ shapeToolData, onEventUpdated, refreshTree }: Props) =

{shapeToolData && (
<EventFailureModeProvider eventIri={shapeToolData?.iri}>
<Box style={{ marginTop: 16, marginBottom: 16 }}>
{criticality && (
<Typography>
<span className={classes.label}>Criticality:</span> {criticality}
</Typography>
)}

{predictedFailureRate && (
<Typography>
{shapeToolData.eventType === EventType.INTERMEDIATE ? (
<span className={classes.label}>FHA based failure rate:</span>
) : (
<span className={classes.label}>Predicted failure rate:</span>
)}
{` ${predictedFailureRate.toExponential(2)}`}
</Typography>
)}

{ataSystem && (
<Typography>
<span className={classes.label}>ATA System:</span> {ataSystem}
</Typography>
)}
{partNumber && (
<Typography>
<span className={classes.label}>Part number:</span> {partNumber}
</Typography>
)}
{stock && (
<Typography>
<span className={classes.label}>Stock:</span> {stock}
</Typography>
)}
{quantity && (
<Typography>
<span className={classes.label}>Quantity:</span> {quantity}
</Typography>
)}
</Box>
<Typography variant="h5" gutterBottom>
Failure Mode
</Typography>
Expand Down
19 changes: 19 additions & 0 deletions src/models/eventModel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
};

export const CONTEXT = Object.assign({}, ctx, ABSTRACT_CONTEXT, FAILURE_MODE_CONTEXT, RECTANGLE_CONTEXT);
Expand All @@ -45,6 +54,16 @@ export interface FaultEvent extends AbstractModel {
probabilityRequirement?: number;
iri?: string;
supertypes?: {
criticality?: number;
superTypes?: any;
behavior?: {
item?: {
quantity?: number;
supertypes?: {
ataCode?: string;
};
};
};
hasFailureRate?: {
iri?: string;
requirement?: {
Expand Down

0 comments on commit b42e847

Please sign in to comment.