Skip to content

Commit

Permalink
fix: ui crash if copying component with no controls/threats
Browse files Browse the repository at this point in the history
  • Loading branch information
Tethik committed Nov 14, 2023
1 parent 8d6c988 commit 38e80f6
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions app/src/actions/model/copyNodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const copyNodes = (componentIds) => async (dispatch, getState) => {
//copy threats
const copyThreats = async () => {
await Promise.all(
threats?.threats[oldComponentId].map(async (oldThreatData) => {
(threats?.threats[oldComponentId] || []).map(async (oldThreatData) => {
const result = await dispatch(
api.endpoints.createThreat.initiate({
modelId: oldThreatData.modelId,
Expand All @@ -97,29 +97,31 @@ export const copyNodes = (componentIds) => async (dispatch, getState) => {

const copyControls = async () =>
await Promise.all(
controls?.controls[oldComponentId].map(async (oldControlData) => {
const result = await dispatch(
api.endpoints.createControl.initiate({
modelId: oldControlData.modelId,
control: {
componentId: newComponentId,
description: oldControlData.description,
title: oldControlData.title,
inPlace: oldControlData.inPlace,
},
})
);

if (result?.data?.control?.id) {
idMap.set(oldControlData.id, result.data.control.id);
(controls?.controls[oldComponentId] || []).map(
async (oldControlData) => {
const result = await dispatch(
api.endpoints.createControl.initiate({
modelId: oldControlData.modelId,
control: {
componentId: newComponentId,
description: oldControlData.description,
title: oldControlData.title,
inPlace: oldControlData.inPlace,
},
})
);

if (result?.data?.control?.id) {
idMap.set(oldControlData.id, result.data.control.id);
}
}
})
)
);

await Promise.all([copyThreats(), copyControls()]);

const oldThreats = new Set(
threats?.threats[oldComponentId].map((t) => t.id)
threats?.threats[oldComponentId]?.map((t) => t.id) || []
);

//link mitigations
Expand Down

0 comments on commit 38e80f6

Please sign in to comment.