Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const putComponentIntoState = (
state: State,
applicationName: string,
component: ApplicationComponentDetails,
isCreate: boolean,
): State => {
let components = state.components[applicationName];
let componentIndex = -1;
if (!components) {
state.components[applicationName] = [];
} else {
componentIndex = original(components)!.findIndex((c) => c.name === component.name);
}
if (componentIndex < 0) {
if (isCreate) {
state.components[applicationName].push(component);
}
} else {
state.components[applicationName][componentIndex] = component;
}
return state;
};
};
switch (action.payload.action) {
case RESOURCE_ACTION_UPDATE:
case RESOURCE_ACTION_ADD: {
const index = findIndex(original(state.protectedEndpoints)!);
if (index < 0) {
state.protectedEndpoints.unshift(endpoint);
} else {
state.protectedEndpoints[index] = endpoint;
}
return;
}
case RESOURCE_ACTION_DELETE: {
const index = findIndex(original(state.protectedEndpoints)!);
if (index >= 0) {
state.protectedEndpoints.splice(index, 1);
}
return;
}
}
} else {
return;
}
return;
}
}
return;
}, initialState);