Merge pull request #747 from navi-infra/INFRA-4059

INFRA-4059 | Saqib | Sends default value for existing manifests as well.
This commit is contained in:
Saqib Perwaiz
2025-01-08 14:27:23 +05:30
committed by GitHub
2 changed files with 19 additions and 7 deletions

View File

@@ -218,9 +218,9 @@ const Form = (props: any) => {
const pathKey = breached.limitPath;
if (Object.prototype.hasOwnProperty.call(defaultValues, pathKey)) {
setValueByPath(updatedManifest, path, defaultValues[pathKey]);
setValueByPath(updatedManifest, path, updatedManifest.id, defaultValues[pathKey]);
} else {
setValueByPath(updatedManifest, path);
setValueByPath(updatedManifest, path, updatedManifest.id);
}
});
}
@@ -331,6 +331,7 @@ const Form = (props: any) => {
return;
}
const currentManifest = _.cloneDeep(manifest);
try {
const isChangeRequestSuccessfullyCreatedIfAny = await sendChangeRequestIfAny(
manifest,
@@ -347,7 +348,15 @@ const Form = (props: any) => {
}
try {
const response = await post(manifest, API_TO_POST_MANIFEST);
const breachedValues = getBreachedValues(
initial.manifestLimits[`${currentManifest.environment}`],
currentManifest,
initial.preChangeManifest,
false,
);
const updatedManifest = JSON.parse(JSON.stringify(manifest));
unsetOrSetDefaultValues(updatedManifest, breachedValues, defaultValues);
const response = await post(updatedManifest, API_TO_POST_MANIFEST);
await handleManifestPostResponse(response, toastId, afterSubmitCallback);
} catch (postError) {
console.error(`Failed to post manifest. Error: ${postError}`);

View File

@@ -319,7 +319,7 @@ const getBreachedValues = (
return breaches;
};
function setValueByPath(obj, path, value = undefined): void {
function setValueByPath(obj, path, id, value = undefined): void {
if (!_.isArray(path) || path.length === 0) {
console.error('Invalid path');
return;
@@ -338,14 +338,17 @@ function setValueByPath(obj, path, value = undefined): void {
}
return acc[key];
}, obj);
if (_.isArray(target) && !isNaN(lastKey)) {
if (_.isArray(target) && !isNaN(lastKey) && (!target[parseInt(lastKey, 10)] || !id)) {
if (value === undefined) {
target.splice(parseInt(lastKey, 10), 1);
} else {
target[parseInt(lastKey, 10)] = value;
}
} else if (target !== undefined && !(_.isArray(target) && isNaN(lastKey))) {
} else if (
target !== undefined &&
!(_.isArray(target) && isNaN(lastKey)) &&
(!target[lastKey] || !id)
) {
target[lastKey] = value;
} else {
console.error('Property not found or cannot set value at path:', path);