in source/idea/idea-cluster-manager/webapp/src/common/utils.ts [320:396]
static canShowFormField(fieldRegistry: IdeaFormFieldRegistry, values: any, when?: SocaUserInputParamCondition) {
if (when == null) {
return true;
}
if (Utils.areAllEmpty(when.param, when.and, when.or)) {
return true;
}
const getParamMeta = (param: string): SocaUserInputParamMetadata | null => {
fieldRegistry.list().forEach((field) => {
if (field.getParamName() === param) {
return field.getParamMeta();
}
});
return null;
};
if (Utils.isNotEmpty(when.param)) {
const paramName = when.param!;
const paramValue = dot.pick(paramName, values);
if (Utils.isTrue(when.empty) && Utils.isEmpty(paramValue)) {
return true;
} else if (Utils.isTrue(when.not_empty) && Utils.isNotEmpty(paramValue)) {
return true;
} else if (Utils.isNotEmpty(when.eq) && paramValue === when.eq) {
return true;
} else if (Utils.isNotEmpty(when.not_eq) && paramValue !== when.not_eq) {
return true;
} else if (Utils.isNotEmpty(when.in) && when.in?.includes(paramValue)) {
return true;
} else if (Utils.isNotEmpty(when.not_in) && !when.not_in?.includes(paramValue)) {
return true;
} else if (when.starts_with && typeof paramValue === "string" && paramValue.startsWith(when.starts_with!)) {
return true;
}
const param = getParamMeta(paramName);
if (param != null && (param.data_type === "int" || param.data_type === "float")) {
const paramFloatVal = parseFloat(paramValue + "");
if (Utils.isNotEmpty(when.gt) && paramFloatVal > parseFloat(when.gt + "")) {
return true;
} else if (Utils.isNotEmpty(when.gte) && paramFloatVal >= parseFloat(when.gte + "")) {
return true;
} else if (Utils.isNotEmpty(when.lt) && paramFloatVal < parseFloat(when.lt + "")) {
return true;
} else if (Utils.isNotEmpty(when.lte) && paramFloatVal <= parseFloat(when.lte + "")) {
return true;
}
}
return false;
}
if (Utils.isNotEmpty(when.and)) {
const and = when.and!;
for (let i = 0; i < and.length; i++) {
const condition = and[i];
if (!Utils.canShowFormField(fieldRegistry, values, condition)) {
return false;
}
}
return true;
}
if (Utils.isNotEmpty(when.or)) {
const or = when.or!;
for (let i = 0; i < or.length; i++) {
const condition = or[i];
if (Utils.canShowFormField(fieldRegistry, values, condition)) {
return true;
}
}
return false;
}
return true;
}