Skip to content

Commit

Permalink
Merge pull request #270 from akaene/fix/asArray-new-location
Browse files Browse the repository at this point in the history
asArray replaced
  • Loading branch information
blcham authored May 5, 2024
2 parents f14c551 + 219daf7 commit bc4502b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Box, Typography, useTheme } from "@mui/material";
import { FaultEventScenario } from "../../../../models/faultEventScenario";
import { Table, TableBody, TableCell, TableContainer, TableHead, TableRow, Paper } from "@mui/material";
import useStyles from "./FaultEventScenariosTable.styles";
import { asArray } from "@utils/treeUtils";
import { asArray } from "@utils/utils";
import { useTranslation } from "react-i18next";

interface FaultEventScenariosTableProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import EventFailureModeList from "../failureMode/EventFailureModeList";
import { FailureMode } from "../../../../../models/failureModeModel";
import FailureModeShowDialog from "../../../../dialog/failureMode/show/FailureModeShowDialog";
import useStyles from "@components/editor/faultTree/menu/faultEvent/FaultEventMenu.styles";
import { asArray } from "@utils/treeUtils";
import { useTranslation } from "react-i18next";
import { asArray } from "@utils/utils";

interface Props {
shapeToolData?: FaultEvent;
Expand Down Expand Up @@ -45,7 +45,7 @@ const FaultEventMenu = ({ shapeToolData, onEventUpdated, refreshTree }: Props) =
setCriticality(undefined);
}

const types = asArray(shapeToolData?.supertypes?.supertypes)
const types = asArray(shapeToolData?.supertypes?.supertypes);

const filteredFailureRate = types.filter((type) => type.hasFailureRate);

Expand All @@ -55,7 +55,7 @@ const FaultEventMenu = ({ shapeToolData, onEventUpdated, refreshTree }: Props) =
setPredictedFailureRate(undefined);
}

const superTypes = asArray(shapeToolData?.supertypes?.behavior?.item?.supertypes)
const superTypes = asArray(shapeToolData?.supertypes?.behavior?.item?.supertypes);

const filteredAtaCode = superTypes.filter((sType) => sType?.ataCode);
const filteredPartNumber = superTypes.filter((sType) => sType?.partNumber);
Expand All @@ -82,7 +82,6 @@ const FaultEventMenu = ({ shapeToolData, onEventUpdated, refreshTree }: Props) =
}
}, [shapeToolData]);


return (
<Box paddingLeft={2} marginRight={2}>
<Typography variant="h5" gutterBottom>
Expand Down
10 changes: 0 additions & 10 deletions src/utils/treeUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,3 @@ export const getNodeWidthForText = (text, fontSize, containerHeight) => {
const finalWidth = Math.min(width, maxWidth);
return finalWidth;
};

export const asArray = (objectOrArray) => {
if (!objectOrArray) {
return [];
}
if (Array.isArray(objectOrArray)) {
return objectOrArray;
}
return [objectOrArray];
};
10 changes: 10 additions & 0 deletions src/utils/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,13 @@ const transformReferences = <Type extends AbstractModel>(b: Type, transformer: <
}
return bCopy;
};

export const asArray = (objectOrArray) => {
if (!objectOrArray) {
return [];
}
if (Array.isArray(objectOrArray)) {
return objectOrArray;
}
return [objectOrArray];
};

0 comments on commit bc4502b

Please sign in to comment.