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 outdated values #468

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -32,6 +32,12 @@ const useStyles = makeStyles()((theme: Theme) => ({
notEditableValue: {
color: theme.main.grey,
},
outdated: {
color: "red",
"&.Mui-checked": {
color: theme.main.red,
},
},
divider: {
marginTop: 8,
marginBottom: 8,
Expand Down
71 changes: 45 additions & 26 deletions src/components/editor/faultTree/menu/faultEvent/FaultEventMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ enum NodeTypeWithManualFailureRate {
External = "External",
}

const getFailureRateIris = (supertypes) => {
const value = asArray(supertypes);
return value.reduce(
(acc, item) => {
if (item?.hasFailureRate?.prediction?.iri) acc.predictionIri = item.hasFailureRate.prediction.iri;
if (item?.hasFailureRate?.estimate?.iri) acc.operationalIri = item.hasFailureRate.estimate.iri;
return acc;
},
{ predictionIri: "", operationalIri: "" },
);
};

const FaultEventMenu = ({ shapeToolData, onEventUpdated, refreshTree, rootIri }: Props) => {
const { t } = useTranslation();
const { classes } = useStyles();
Expand Down Expand Up @@ -179,14 +191,7 @@ const FaultEventMenu = ({ shapeToolData, onEventUpdated, refreshTree, rootIri }:
if (shapeToolData?.selectedEstimate) {
// SELECTED ESTIMATE => PREDICTED OR OPERATIONAL IS SELECTED
const iriOfSelectedValue = shapeToolData.selectedEstimate.iri;
const { predictionIri, operationalIri } = supertypes.reduce(
(acc, item) => {
if (item?.hasFailureRate?.prediction?.iri) acc.predictionIri = item.hasFailureRate.prediction.iri;
if (item?.hasFailureRate?.estimate?.iri) acc.operationalIri = item.hasFailureRate.estimate.iri;
return acc;
},
{ predictionIri: "", operationalIri: "" },
);
const { predictionIri, operationalIri } = getFailureRateIris(supertypes);

if (iriOfSelectedValue === predictionIri) {
setSelectedRadioButton(RadioButtonType.Predicted);
Expand Down Expand Up @@ -221,18 +226,31 @@ const FaultEventMenu = ({ shapeToolData, onEventUpdated, refreshTree, rootIri }:
const basedFailureRate = shapeToolData?.supertypes?.supertypes?.hasFailureRate?.estimate?.value;
const requiredFailureRate = shapeToolData?.supertypes?.hasFailureRate?.requirement?.upperBound;

const FailureRateBox = ({ value, label, rate, selected }) => (
const { predictionIri, operationalIri } = getFailureRateIris(shapeToolData?.supertypes?.supertypes);

const FailureRateBox = ({ value, label, rate, selected, outdated }) => (
<Box display="flex" flexDirection="row" alignItems="center">
<FormControlLabel
value={value}
control={<Radio style={{ color: theme.main.black }} />}
label={`${label}:`}
className={selected ? classes.selected : classes.notSelected}
/>
<Typography className={classes.notEditableValue}>{rate}</Typography>
<Typography className={outdated ? classes.outdated : classes.notEditableValue}>{rate}</Typography>
</Box>
);

const renderFailureRateBox = (rateType, rateValue, iri, selectedRadioButton, labelKey) => {
const rate =
shapeToolData.probability !== rateValue && shapeToolData?.selectedEstimate?.iri === iri
? shapeToolData.probability
: rateValue;
const selected = selectedRadioButton === rateType;
const outdated = selected && shapeToolData.probability !== rateValue;

return <FailureRateBox value={rateType} label={t(labelKey)} rate={rate} selected={selected} outdated={outdated} />;
};

return (
<Box paddingLeft={2} marginRight={2}>
{shapeToolData && shapeToolData.iri !== rootIri && (
Expand Down Expand Up @@ -320,22 +338,23 @@ const FaultEventMenu = ({ shapeToolData, onEventUpdated, refreshTree, rootIri }:
<Box className={classes.labelRow}>
<FormControl>
<RadioGroup value={selectedRadioButton} onChange={handleSnsBasicSelectedFailureRateChange}>
{snsPredictedFailureRate && (
<FailureRateBox
value={RadioButtonType.Predicted}
label={t("faultEventMenu.predictedFailureRate")}
rate={snsPredictedFailureRate}
selected={selectedRadioButton === RadioButtonType.Predicted}
/>
)}
{snsOperationalFailureRate && (
<FailureRateBox
value={RadioButtonType.Operational}
label={t("faultEventMenu.operationalFailureRate")}
rate={snsOperationalFailureRate}
selected={selectedRadioButton === RadioButtonType.Operational}
/>
)}
{snsPredictedFailureRate &&
renderFailureRateBox(
RadioButtonType.Predicted,
snsPredictedFailureRate,
predictionIri,
selectedRadioButton,
"faultEventMenu.predictedFailureRate",
)}

{snsOperationalFailureRate &&
renderFailureRateBox(
RadioButtonType.Operational,
snsOperationalFailureRate,
operationalIri,
selectedRadioButton,
"faultEventMenu.operationalFailureRate",
)}
<Box display={"flex"} flexDirection={"row"} alignItems="center">
<FormControlLabel
value={RadioButtonType.Manual}
Expand Down
1 change: 1 addition & 0 deletions src/styles/App.styles.declarations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ declare module "@mui/material/styles" {
main?: {
black: string;
grey: string;
red: string;
notSynchronized?: {
color: COLOR;
};
Expand Down
1 change: 1 addition & 0 deletions src/styles/App.styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const appTheme = createCustomMuiTheme({
main: {
black: "#000000",
grey: "#808080",
red: "#FF0000",
},
notSynchronized: {
color: "red",
Expand Down