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

asArray replaced #270

Merged
merged 1 commit into from
May 5, 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 @@ -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];
};