2021-03-30 05:29:03 +00:00
|
|
|
import { Action } from "entities/Action/index";
|
|
|
|
|
import _ from "lodash";
|
2021-04-26 05:41:32 +00:00
|
|
|
import { EvaluationSubstitutionType } from "entities/DataTree/dataTreeFactory";
|
|
|
|
|
import { isHidden } from "components/formControls/utils";
|
2021-03-30 05:29:03 +00:00
|
|
|
|
|
|
|
|
const dynamicFields = ["QUERY_DYNAMIC_TEXT", "QUERY_DYNAMIC_INPUT_TEXT"];
|
|
|
|
|
|
2021-04-26 05:41:32 +00:00
|
|
|
const getCorrectEvaluationSubstitutionType = (substitutionType?: string) => {
|
|
|
|
|
if (substitutionType) {
|
|
|
|
|
if (substitutionType === EvaluationSubstitutionType.SMART_SUBSTITUTE) {
|
|
|
|
|
return EvaluationSubstitutionType.SMART_SUBSTITUTE;
|
|
|
|
|
} else if (substitutionType === EvaluationSubstitutionType.PARAMETER) {
|
|
|
|
|
return EvaluationSubstitutionType.PARAMETER;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return EvaluationSubstitutionType.TEMPLATE;
|
|
|
|
|
};
|
|
|
|
|
|
2021-03-30 05:29:03 +00:00
|
|
|
export const getBindingPathsOfAction = (
|
|
|
|
|
action: Action,
|
|
|
|
|
formConfig?: any[],
|
2021-04-26 05:41:32 +00:00
|
|
|
): Record<string, EvaluationSubstitutionType> => {
|
|
|
|
|
const bindingPaths: Record<string, EvaluationSubstitutionType> = {
|
|
|
|
|
data: EvaluationSubstitutionType.TEMPLATE,
|
|
|
|
|
isLoading: EvaluationSubstitutionType.TEMPLATE,
|
2021-12-28 12:14:32 +00:00
|
|
|
datasourceUrl: EvaluationSubstitutionType.TEMPLATE,
|
2021-03-30 05:29:03 +00:00
|
|
|
};
|
|
|
|
|
if (!formConfig) {
|
|
|
|
|
return {
|
|
|
|
|
...bindingPaths,
|
2021-04-26 05:41:32 +00:00
|
|
|
config: EvaluationSubstitutionType.TEMPLATE,
|
2021-03-30 05:29:03 +00:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
const recursiveFindBindingPaths = (formConfig: any) => {
|
|
|
|
|
if (formConfig.children) {
|
|
|
|
|
formConfig.children.forEach(recursiveFindBindingPaths);
|
|
|
|
|
} else {
|
2021-04-26 05:41:32 +00:00
|
|
|
const configPath = getDataTreeActionConfigPath(formConfig.configProperty);
|
2021-03-30 05:29:03 +00:00
|
|
|
if (dynamicFields.includes(formConfig.controlType)) {
|
2021-04-26 05:41:32 +00:00
|
|
|
if (!isHidden(action, formConfig.hidden)) {
|
|
|
|
|
bindingPaths[configPath] = getCorrectEvaluationSubstitutionType(
|
|
|
|
|
formConfig.evaluationSubstitutionType,
|
|
|
|
|
);
|
|
|
|
|
}
|
2021-03-30 05:29:03 +00:00
|
|
|
}
|
|
|
|
|
if (formConfig.controlType === "ARRAY_FIELD") {
|
2021-10-04 09:41:25 +00:00
|
|
|
let actionValue = _.get(action, formConfig.configProperty);
|
2021-03-30 05:29:03 +00:00
|
|
|
if (Array.isArray(actionValue)) {
|
2021-10-04 09:41:25 +00:00
|
|
|
actionValue = actionValue.filter((val) => val);
|
2021-03-30 05:29:03 +00:00
|
|
|
for (let i = 0; i < actionValue.length; i++) {
|
|
|
|
|
formConfig.schema.forEach((schemaField: any) => {
|
|
|
|
|
if (
|
|
|
|
|
schemaField.key in actionValue[i] &&
|
|
|
|
|
dynamicFields.includes(schemaField.controlType)
|
|
|
|
|
) {
|
|
|
|
|
const arrayConfigPath = `${configPath}[${i}].${schemaField.key}`;
|
2021-04-26 05:41:32 +00:00
|
|
|
bindingPaths[
|
|
|
|
|
arrayConfigPath
|
|
|
|
|
] = getCorrectEvaluationSubstitutionType(
|
|
|
|
|
formConfig.evaluationSubstitutionType,
|
|
|
|
|
);
|
2021-03-30 05:29:03 +00:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
formConfig.forEach(recursiveFindBindingPaths);
|
|
|
|
|
|
|
|
|
|
return bindingPaths;
|
|
|
|
|
};
|
2021-04-26 05:41:32 +00:00
|
|
|
|
|
|
|
|
export const getDataTreeActionConfigPath = (propertyPath: string) =>
|
|
|
|
|
propertyPath.replace("actionConfiguration.", "config.");
|