2021-02-16 10:29:08 +00:00
|
|
|
import { WidgetProps } from "widgets/BaseWidget";
|
|
|
|
|
import { PropertyPaneConfig } from "constants/PropertyControlConstants";
|
2021-04-26 10:35:59 +00:00
|
|
|
import { get, isObject, isUndefined } from "lodash";
|
2021-03-16 05:01:37 +00:00
|
|
|
import { FlattenedWidgetProps } from "reducers/entityReducers/canvasWidgetsReducer";
|
2021-04-21 14:34:25 +00:00
|
|
|
import { VALIDATION_TYPES } from "constants/WidgetValidation";
|
2021-04-26 05:41:32 +00:00
|
|
|
import { EvaluationSubstitutionType } from "entities/DataTree/dataTreeFactory";
|
2021-02-16 10:29:08 +00:00
|
|
|
|
|
|
|
|
export const getAllPathsFromPropertyConfig = (
|
|
|
|
|
widget: WidgetProps,
|
|
|
|
|
widgetConfig: readonly PropertyPaneConfig[],
|
2021-04-26 05:41:32 +00:00
|
|
|
defaultProperties: Record<string, any>,
|
2021-02-16 10:29:08 +00:00
|
|
|
): {
|
2021-04-26 05:41:32 +00:00
|
|
|
bindingPaths: Record<string, EvaluationSubstitutionType>;
|
2021-02-16 10:29:08 +00:00
|
|
|
triggerPaths: Record<string, true>;
|
2021-04-21 14:34:25 +00:00
|
|
|
validationPaths: Record<string, VALIDATION_TYPES>;
|
2021-02-16 10:29:08 +00:00
|
|
|
} => {
|
2021-04-26 05:41:32 +00:00
|
|
|
const bindingPaths: Record<string, EvaluationSubstitutionType> = {};
|
|
|
|
|
Object.keys(defaultProperties).forEach(
|
|
|
|
|
(property) =>
|
|
|
|
|
(bindingPaths[property] = EvaluationSubstitutionType.TEMPLATE),
|
|
|
|
|
);
|
2021-02-16 10:29:08 +00:00
|
|
|
const triggerPaths: Record<string, true> = {};
|
2021-04-21 14:34:25 +00:00
|
|
|
const validationPaths: Record<any, VALIDATION_TYPES> = {};
|
2021-02-16 10:29:08 +00:00
|
|
|
widgetConfig.forEach((config) => {
|
|
|
|
|
if (config.children) {
|
|
|
|
|
config.children.forEach((controlConfig: any) => {
|
|
|
|
|
const basePath = controlConfig.propertyName;
|
|
|
|
|
let isHidden = false;
|
|
|
|
|
if ("hidden" in controlConfig) {
|
|
|
|
|
isHidden = controlConfig.hidden(widget, basePath);
|
|
|
|
|
}
|
2021-04-26 10:35:59 +00:00
|
|
|
|
2021-02-16 10:29:08 +00:00
|
|
|
if (!isHidden) {
|
|
|
|
|
if (
|
|
|
|
|
controlConfig.isBindProperty &&
|
|
|
|
|
!controlConfig.isTriggerProperty
|
|
|
|
|
) {
|
2021-04-26 05:41:32 +00:00
|
|
|
bindingPaths[controlConfig.propertyName] =
|
2021-06-01 04:59:45 +00:00
|
|
|
controlConfig.evaluationSubstitutionType ||
|
2021-04-26 05:41:32 +00:00
|
|
|
EvaluationSubstitutionType.TEMPLATE;
|
2021-04-21 14:34:25 +00:00
|
|
|
if (controlConfig.validation) {
|
|
|
|
|
validationPaths[controlConfig.propertyName] =
|
|
|
|
|
controlConfig.validation;
|
|
|
|
|
}
|
2021-02-16 10:29:08 +00:00
|
|
|
} else if (
|
|
|
|
|
controlConfig.isBindProperty &&
|
|
|
|
|
controlConfig.isTriggerProperty
|
|
|
|
|
) {
|
|
|
|
|
triggerPaths[controlConfig.propertyName] = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (controlConfig.panelConfig) {
|
|
|
|
|
const panelPropertyPath = controlConfig.propertyName;
|
|
|
|
|
const widgetPanelPropertyValues = get(widget, panelPropertyPath);
|
|
|
|
|
if (widgetPanelPropertyValues) {
|
|
|
|
|
Object.values(widgetPanelPropertyValues).forEach(
|
|
|
|
|
(widgetPanelPropertyValue: any) => {
|
|
|
|
|
controlConfig.panelConfig.children.forEach(
|
|
|
|
|
(panelColumnConfig: any) => {
|
|
|
|
|
let isSectionHidden = false;
|
|
|
|
|
if ("hidden" in panelColumnConfig) {
|
|
|
|
|
isSectionHidden = panelColumnConfig.hidden(
|
|
|
|
|
widget,
|
|
|
|
|
`${basePath}.${widgetPanelPropertyValue.id}`,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if (!isSectionHidden) {
|
|
|
|
|
panelColumnConfig.children.forEach(
|
|
|
|
|
(panelColumnControlConfig: any) => {
|
|
|
|
|
const panelPropertyPath = `${basePath}.${widgetPanelPropertyValue.id}.${panelColumnControlConfig.propertyName}`;
|
|
|
|
|
let isControlHidden = false;
|
|
|
|
|
if ("hidden" in panelColumnControlConfig) {
|
|
|
|
|
isControlHidden = panelColumnControlConfig.hidden(
|
|
|
|
|
widget,
|
|
|
|
|
panelPropertyPath,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if (!isControlHidden) {
|
|
|
|
|
if (
|
|
|
|
|
panelColumnControlConfig.isBindProperty &&
|
|
|
|
|
!panelColumnControlConfig.isTriggerProperty
|
|
|
|
|
) {
|
2021-04-26 05:41:32 +00:00
|
|
|
bindingPaths[panelPropertyPath] =
|
2021-06-01 04:59:45 +00:00
|
|
|
controlConfig.evaluationSubstitutionType ||
|
2021-04-26 05:41:32 +00:00
|
|
|
EvaluationSubstitutionType.TEMPLATE;
|
2021-04-21 14:34:25 +00:00
|
|
|
if (panelColumnControlConfig.validation) {
|
|
|
|
|
validationPaths[panelPropertyPath] =
|
|
|
|
|
panelColumnControlConfig.validation;
|
|
|
|
|
}
|
2021-02-16 10:29:08 +00:00
|
|
|
} else if (
|
|
|
|
|
panelColumnControlConfig.isBindProperty &&
|
|
|
|
|
panelColumnControlConfig.isTriggerProperty
|
|
|
|
|
) {
|
|
|
|
|
triggerPaths[panelPropertyPath] = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-03-04 05:24:47 +00:00
|
|
|
if (controlConfig.children) {
|
|
|
|
|
const basePropertyPath = controlConfig.propertyName;
|
2021-03-09 14:35:42 +00:00
|
|
|
const widgetPropertyValue = get(widget, basePropertyPath, []);
|
2021-04-26 10:35:59 +00:00
|
|
|
// Property in object structure
|
|
|
|
|
if (
|
|
|
|
|
!isUndefined(widgetPropertyValue) &&
|
|
|
|
|
isObject(widgetPropertyValue)
|
|
|
|
|
) {
|
|
|
|
|
Object.keys(widgetPropertyValue).map((key: string) => {
|
|
|
|
|
const objectIndexPropertyPath = `${basePropertyPath}.${key}`;
|
|
|
|
|
controlConfig.children.forEach((childPropertyConfig: any) => {
|
|
|
|
|
const childArrayPropertyPath = `${objectIndexPropertyPath}.${childPropertyConfig.propertyName}`;
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
childPropertyConfig.isBindProperty &&
|
|
|
|
|
!childPropertyConfig.isTriggerProperty
|
|
|
|
|
) {
|
|
|
|
|
bindingPaths[childArrayPropertyPath] =
|
2021-06-01 04:59:45 +00:00
|
|
|
childPropertyConfig.evaluationSubstitutionType ||
|
2021-04-26 10:35:59 +00:00
|
|
|
EvaluationSubstitutionType.TEMPLATE;
|
|
|
|
|
if (childPropertyConfig.validation) {
|
|
|
|
|
validationPaths[childArrayPropertyPath] =
|
|
|
|
|
childPropertyConfig.validation;
|
2021-03-09 14:35:42 +00:00
|
|
|
}
|
2021-04-26 10:35:59 +00:00
|
|
|
} else if (
|
|
|
|
|
childPropertyConfig.isBindProperty &&
|
|
|
|
|
childPropertyConfig.isTriggerProperty
|
|
|
|
|
) {
|
|
|
|
|
triggerPaths[childArrayPropertyPath] = true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
2021-03-09 14:35:42 +00:00
|
|
|
}
|
2021-03-04 05:24:47 +00:00
|
|
|
}
|
2021-02-16 10:29:08 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2021-04-21 14:34:25 +00:00
|
|
|
return { bindingPaths, triggerPaths, validationPaths };
|
2021-02-16 10:29:08 +00:00
|
|
|
};
|
2021-03-16 05:01:37 +00:00
|
|
|
|
|
|
|
|
export const nextAvailableRowInContainer = (
|
2021-04-26 05:41:32 +00:00
|
|
|
parentContainerId: string,
|
2021-03-16 05:01:37 +00:00
|
|
|
canvasWidgets: { [widgetId: string]: FlattenedWidgetProps },
|
|
|
|
|
) => {
|
|
|
|
|
return (
|
|
|
|
|
Object.values(canvasWidgets).reduce(
|
|
|
|
|
(prev: number, next: any) =>
|
2021-04-26 05:41:32 +00:00
|
|
|
next?.parentId === parentContainerId && next.bottomRow > prev
|
2021-03-16 05:01:37 +00:00
|
|
|
? next.bottomRow
|
|
|
|
|
: prev,
|
|
|
|
|
0,
|
|
|
|
|
) + 1
|
|
|
|
|
);
|
|
|
|
|
};
|