INFRA-3416 | Saurabh | CR shouldn't be required on scale down of resources (#661)

* INFRA-3416 | Saurabh | Added valuesWithWeights in CR

* INFRA-3416 | Saurabh | Added valuesWithWeights in CR

* INFRA-3416 | Saurabh | Added interface
This commit is contained in:
Saurabh Bhagwan Sathe
2024-08-08 10:02:59 +05:30
committed by GitHub
parent 01e3841bf6
commit 7e47e46718

View File

@@ -1,6 +1,11 @@
import _ from 'lodash';
import { toast } from 'react-toastify';
interface ValueWithWeight {
type: string;
weight: number;
}
const isTarget = limitObject => {
return limitObject.hasOwnProperty('approvalFrom');
};
@@ -55,6 +60,27 @@ const findSingleValue = (limit, value) => {
return false;
};
const isWeightGreater = (
limit: { valuesWithWeights?: ValueWithWeight[] },
value: string,
previousValue: string,
): boolean => {
if (!limit.valuesWithWeights) return false;
const weightsMap = new Map<string, number>();
limit.valuesWithWeights.forEach(({ type, weight }) => {
weightsMap.set(type, weight);
});
const currentWeight = weightsMap.get(value);
const previousWeight = weightsMap.get(previousValue);
return (
currentWeight !== undefined && (previousWeight === undefined || currentWeight > previousWeight)
);
};
const isChangeRequestRequired = (limit, value, previousValue, manifestEnv) => {
if (value === undefined) return false;
const parsedValue = isString(value) ? parseValue(value) : value;
@@ -85,6 +111,9 @@ const isChangeRequestRequired = (limit, value, previousValue, manifestEnv) => {
if (findSingleValue(limit, value)) return true;
}
}
if (limit.hasOwnProperty('valuesWithWeights') && isWeightGreater(limit, value, previousValue)) {
return true;
}
if (limit.hasOwnProperty('object')) {
for (const json of limit.object) {
const jsonObj = JSON.parse(json);