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";
|
2022-03-21 05:51:50 +00:00
|
|
|
import {
|
|
|
|
|
alternateViewTypeInputConfig,
|
|
|
|
|
isHidden,
|
|
|
|
|
ViewTypes,
|
|
|
|
|
} from "components/formControls/utils";
|
2022-02-26 03:52:06 +00:00
|
|
|
import {
|
|
|
|
|
PaginationSubComponent,
|
|
|
|
|
SortingSubComponent,
|
|
|
|
|
WhereClauseSubComponent,
|
|
|
|
|
allowedControlTypes,
|
|
|
|
|
} 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,
|
|
|
|
|
);
|
|
|
|
|
}
|
2022-03-21 05:51:50 +00:00
|
|
|
} else if (
|
|
|
|
|
"alternateViewTypes" in formConfig &&
|
|
|
|
|
Array.isArray(formConfig.alternateViewTypes) &&
|
|
|
|
|
formConfig.alternateViewTypes.length > 0 &&
|
|
|
|
|
formConfig.alternateViewTypes.includes(ViewTypes.JSON)
|
|
|
|
|
) {
|
|
|
|
|
bindingPaths[configPath] = getCorrectEvaluationSubstitutionType(
|
|
|
|
|
alternateViewTypeInputConfig.evaluationSubstitutionType,
|
|
|
|
|
);
|
2022-01-13 08:52:00 +00:00
|
|
|
} else 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
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-13 08:52:00 +00:00
|
|
|
} else if (formConfig.controlType === "WHERE_CLAUSE") {
|
|
|
|
|
const recursiveFindBindingPathsForWhereClause = (
|
|
|
|
|
newConfigPath: string,
|
|
|
|
|
actionValue: any,
|
|
|
|
|
) => {
|
|
|
|
|
if (
|
|
|
|
|
actionValue &&
|
|
|
|
|
actionValue.hasOwnProperty("children") &&
|
|
|
|
|
Array.isArray(actionValue.children)
|
|
|
|
|
) {
|
|
|
|
|
actionValue.children.forEach((value: any, index: number) => {
|
2022-02-26 03:52:06 +00:00
|
|
|
const childrenPath = getBindingOrConfigPathsForWhereClauseControl(
|
|
|
|
|
newConfigPath,
|
|
|
|
|
WhereClauseSubComponent.Children,
|
|
|
|
|
index,
|
2022-01-13 08:52:00 +00:00
|
|
|
);
|
2022-02-26 03:52:06 +00:00
|
|
|
recursiveFindBindingPathsForWhereClause(childrenPath, value);
|
2022-01-13 08:52:00 +00:00
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
if (actionValue.hasOwnProperty("key")) {
|
2022-02-26 03:52:06 +00:00
|
|
|
const keyPath = getBindingOrConfigPathsForWhereClauseControl(
|
|
|
|
|
newConfigPath,
|
|
|
|
|
WhereClauseSubComponent.Key,
|
|
|
|
|
undefined,
|
|
|
|
|
);
|
|
|
|
|
bindingPaths[keyPath] = getCorrectEvaluationSubstitutionType(
|
2022-01-13 08:52:00 +00:00
|
|
|
formConfig.evaluationSubstitutionType,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if (actionValue.hasOwnProperty("value")) {
|
2022-02-26 03:52:06 +00:00
|
|
|
const valuePath = getBindingOrConfigPathsForWhereClauseControl(
|
|
|
|
|
newConfigPath,
|
|
|
|
|
WhereClauseSubComponent.Value,
|
|
|
|
|
undefined,
|
|
|
|
|
);
|
|
|
|
|
bindingPaths[valuePath] = getCorrectEvaluationSubstitutionType(
|
2022-01-13 08:52:00 +00:00
|
|
|
formConfig.evaluationSubstitutionType,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const actionValue = _.get(action, formConfig.configProperty);
|
|
|
|
|
if (
|
|
|
|
|
actionValue &&
|
|
|
|
|
actionValue.hasOwnProperty("children") &&
|
|
|
|
|
Array.isArray(actionValue.children)
|
|
|
|
|
) {
|
|
|
|
|
actionValue.children.forEach((value: any, index: number) => {
|
2022-02-26 03:52:06 +00:00
|
|
|
const childrenPath = getBindingOrConfigPathsForWhereClauseControl(
|
|
|
|
|
configPath,
|
|
|
|
|
WhereClauseSubComponent.Children,
|
|
|
|
|
index,
|
2022-01-13 08:52:00 +00:00
|
|
|
);
|
2022-02-26 03:52:06 +00:00
|
|
|
recursiveFindBindingPathsForWhereClause(childrenPath, value);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} else if (formConfig.controlType === "PAGINATION") {
|
|
|
|
|
const limitPath = getBindingOrConfigPathsForPaginationControl(
|
|
|
|
|
PaginationSubComponent.Offset,
|
|
|
|
|
configPath,
|
|
|
|
|
);
|
|
|
|
|
const offsetPath = getBindingOrConfigPathsForPaginationControl(
|
|
|
|
|
PaginationSubComponent.Limit,
|
|
|
|
|
configPath,
|
|
|
|
|
);
|
|
|
|
|
bindingPaths[limitPath] = getCorrectEvaluationSubstitutionType(
|
|
|
|
|
formConfig.evaluationSubstitutionType,
|
|
|
|
|
);
|
|
|
|
|
bindingPaths[offsetPath] = getCorrectEvaluationSubstitutionType(
|
|
|
|
|
formConfig.evaluationSubstitutionType,
|
|
|
|
|
);
|
|
|
|
|
} else if (formConfig.controlType === "SORTING") {
|
|
|
|
|
const actionValue = _.get(action, formConfig.configProperty);
|
|
|
|
|
if (Array.isArray(actionValue)) {
|
|
|
|
|
actionValue.forEach((fieldConfig: any, index: number) => {
|
|
|
|
|
const columnPath = getBindingOrConfigPathsForSortingControl(
|
|
|
|
|
SortingSubComponent.Column,
|
|
|
|
|
configPath,
|
|
|
|
|
index,
|
|
|
|
|
);
|
|
|
|
|
bindingPaths[columnPath] = getCorrectEvaluationSubstitutionType(
|
|
|
|
|
formConfig.evaluationSubstitutionType,
|
|
|
|
|
);
|
|
|
|
|
const OrderPath = getBindingOrConfigPathsForSortingControl(
|
|
|
|
|
SortingSubComponent.Order,
|
|
|
|
|
configPath,
|
|
|
|
|
index,
|
|
|
|
|
);
|
|
|
|
|
bindingPaths[OrderPath] = getCorrectEvaluationSubstitutionType(
|
|
|
|
|
formConfig.evaluationSubstitutionType,
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} else if (formConfig.controlType === "ENTITY_SELECTOR") {
|
|
|
|
|
if (Array.isArray(formConfig.schema)) {
|
|
|
|
|
formConfig.schema.forEach((schemaField: any, index: number) => {
|
|
|
|
|
if (allowedControlTypes.includes(schemaField.controlType)) {
|
|
|
|
|
const columnPath = getBindingOrConfigPathsForEntitySelectorControl(
|
|
|
|
|
configPath,
|
|
|
|
|
index,
|
|
|
|
|
);
|
|
|
|
|
bindingPaths[columnPath] = getCorrectEvaluationSubstitutionType(
|
|
|
|
|
formConfig.evaluationSubstitutionType,
|
|
|
|
|
);
|
|
|
|
|
}
|
2022-01-13 08:52:00 +00:00
|
|
|
});
|
|
|
|
|
}
|
2021-03-30 05:29:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
formConfig.forEach(recursiveFindBindingPaths);
|
|
|
|
|
return bindingPaths;
|
|
|
|
|
};
|
2021-04-26 05:41:32 +00:00
|
|
|
|
2022-02-26 03:52:06 +00:00
|
|
|
export const getBindingOrConfigPathsForSortingControl = (
|
|
|
|
|
fieldName: SortingSubComponent.Order | SortingSubComponent.Column,
|
|
|
|
|
baseConfigProperty: string,
|
|
|
|
|
index?: number,
|
|
|
|
|
): string => {
|
|
|
|
|
if (_.isNumber(index)) {
|
|
|
|
|
return `${baseConfigProperty}[${index}].${fieldName}`;
|
|
|
|
|
} else {
|
|
|
|
|
return `${baseConfigProperty}.${fieldName}`;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const getBindingOrConfigPathsForPaginationControl = (
|
|
|
|
|
fieldName: PaginationSubComponent.Limit | PaginationSubComponent.Offset,
|
|
|
|
|
baseConfigProperty: string,
|
|
|
|
|
): string => {
|
|
|
|
|
return `${baseConfigProperty}.${fieldName}`;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const getBindingOrConfigPathsForWhereClauseControl = (
|
|
|
|
|
configPath: string,
|
|
|
|
|
fieldName:
|
|
|
|
|
| WhereClauseSubComponent.Children
|
|
|
|
|
| WhereClauseSubComponent.Condition
|
|
|
|
|
| WhereClauseSubComponent.Key
|
|
|
|
|
| WhereClauseSubComponent.Value,
|
|
|
|
|
index?: number,
|
|
|
|
|
): string => {
|
|
|
|
|
if (fieldName === "children" && _.isNumber(index)) {
|
|
|
|
|
return `${configPath}.${fieldName}[${index}]`;
|
|
|
|
|
} else if (configPath && fieldName) {
|
|
|
|
|
return `${configPath}.${fieldName}`;
|
|
|
|
|
}
|
|
|
|
|
return "";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const getBindingOrConfigPathsForEntitySelectorControl = (
|
|
|
|
|
baseConfigProperty: string,
|
|
|
|
|
index: number,
|
|
|
|
|
): string => {
|
|
|
|
|
return `${baseConfigProperty}.column_${index + 1}`;
|
|
|
|
|
};
|
|
|
|
|
|
2021-04-26 05:41:32 +00:00
|
|
|
export const getDataTreeActionConfigPath = (propertyPath: string) =>
|
|
|
|
|
propertyPath.replace("actionConfiguration.", "config.");
|