PromucFlow_constructor/app/client/src/entities/Widget/utils.ts

238 lines
8.6 KiB
TypeScript
Raw Normal View History

import { WidgetProps } from "widgets/BaseWidget";
import {
PropertyPaneConfig,
ValidationConfig,
} from "constants/PropertyControlConstants";
Grouping widgets into container (#5704) * Cut copy paste first cut * removed different parent groups logic * mouseup on the outer canvas removes selections. * bug fix * remove unwanted dead code. * Adding tests * build fix * min height fixes * fixing specs. * fixing specs. * fix merge conflcits * fix border positioning * fix canvas widgets incorrect bouding box * fix bounding box position issue * fix bounding box position issue * fix * border issue fix * update test case * add colors in theme * use layers + use click capture on actions * add icon for grouping * fix overflow issue in contextmenu in containers * fix context menu display issue * update position of context menu * fix container box-shadow issue * fix container box-shadow issue * revert container box shadow * stop opening of property pane on shift clicking a widget * remove console.log * fix multiselect box issue * add container on copy * add analytics middleware * refactor paste widget saga * change flash element to accept array + revert refactor * add logic to create containers from selected widgets * update positions of grouped widgets * fix comments + remove console * update flashElementbyId to flashElementsById * remove analytics middleware + remove unecessary imports * add shorcut for grouping * fix position issue when pasting * allow grouping only when multi widgets are selected * fix ux issues with widget grouping * fix help text for grouping actions * filter out the modal widget when calculting next row * fix delete issue when grouping * persist positin when grouping if there is no collision * fix typo for new position * changes for review comments * changes for review comments * fix position issue when pasting * fix new container position issue * move utils function to utils * fix import issue * fix the composite widget grouping issue * fix table name bug * remove repeated code * move copied groups existence check; * fix copied group check Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com> Co-authored-by: root <root@DESKTOP-9GENCK0.localdomain> Co-authored-by: Pawan Kumar <pawankumar@Pawans-MacBook-Pro.local>
2021-08-25 05:00:31 +00:00
import { get, isObject, isUndefined, omitBy } from "lodash";
import { FlattenedWidgetProps } from "reducers/entityReducers/canvasWidgetsReducer";
import { EvaluationSubstitutionType } from "entities/DataTree/dataTreeFactory";
/**
* @typedef {Object} Paths
* @property {Object} configBindingPaths - The Binding Path
* @property {Object} configTriggerPaths - The Trigger Path
* @property {Object} configValidationPaths - The Validation Path
*/
/**
* This function gets the binding validation and trigger paths from a config
* @param config
* @param path
* @returns {Paths} Paths
*/
const checkPathsInConfig = (
config: any,
path: string,
): {
configBindingPaths: Record<string, EvaluationSubstitutionType>;
configTriggerPaths: Record<string, true>;
configValidationPaths: Record<string, ValidationConfig>;
} => {
const configBindingPaths: Record<string, EvaluationSubstitutionType> = {};
const configTriggerPaths: Record<string, true> = {};
const configValidationPaths: Record<any, ValidationConfig> = {};
// Purely a Binding Path
if (config.isBindProperty && !config.isTriggerProperty) {
configBindingPaths[path] =
config.evaluationSubstitutionType || EvaluationSubstitutionType.TEMPLATE;
if (config.validation) {
configValidationPaths[path] = config.validation;
}
} else if (config.isBindProperty && config.isTriggerProperty) {
configTriggerPaths[path] = true;
}
return { configBindingPaths, configTriggerPaths, configValidationPaths };
};
const childHasPanelConfig = (
config: any,
widget: WidgetProps,
basePath: string,
) => {
const panelPropertyPath = config.propertyName;
const widgetPanelPropertyValues = get(widget, panelPropertyPath);
let bindingPaths: Record<string, EvaluationSubstitutionType> = {};
let triggerPaths: Record<string, true> = {};
let validationPaths: Record<any, ValidationConfig> = {};
if (widgetPanelPropertyValues) {
Object.values(widgetPanelPropertyValues).forEach(
(widgetPanelPropertyValue: any) => {
config.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 panelPropertyConfigPath = `${basePath}.${widgetPanelPropertyValue.id}.${panelColumnControlConfig.propertyName}`;
let isControlHidden = false;
if ("hidden" in panelColumnControlConfig) {
isControlHidden = panelColumnControlConfig.hidden(
widget,
panelPropertyConfigPath,
);
}
if (!isControlHidden) {
const {
configBindingPaths,
configTriggerPaths,
configValidationPaths,
} = checkPathsInConfig(
panelColumnControlConfig,
panelPropertyConfigPath,
);
bindingPaths = { ...configBindingPaths, ...bindingPaths };
triggerPaths = { ...configTriggerPaths, ...triggerPaths };
validationPaths = {
...configValidationPaths,
...validationPaths,
};
// Has child Panel Config
if (panelColumnControlConfig.panelConfig) {
const {
bindingPaths: panelBindingPaths,
triggerPaths: panelTriggerPaths,
validationPaths: panelValidationPaths,
} = childHasPanelConfig(
panelColumnControlConfig,
widgetPanelPropertyValue,
panelPropertyConfigPath,
);
bindingPaths = { ...panelBindingPaths, ...bindingPaths };
triggerPaths = { ...panelTriggerPaths, ...triggerPaths };
validationPaths = {
...panelValidationPaths,
...validationPaths,
};
}
}
},
);
}
});
},
);
}
return { bindingPaths, triggerPaths, validationPaths };
};
export const getAllPathsFromPropertyConfig = (
widget: WidgetProps,
widgetConfig: readonly PropertyPaneConfig[],
defaultProperties: Record<string, any>,
): {
bindingPaths: Record<string, EvaluationSubstitutionType>;
triggerPaths: Record<string, true>;
validationPaths: Record<string, ValidationConfig>;
} => {
let bindingPaths: Record<string, EvaluationSubstitutionType> = {};
Object.keys(defaultProperties).forEach(
(property) =>
(bindingPaths[property] = EvaluationSubstitutionType.TEMPLATE),
);
let triggerPaths: Record<string, true> = {};
let validationPaths: Record<any, ValidationConfig> = {};
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);
}
if (!isHidden) {
const path = controlConfig.propertyName;
const {
configBindingPaths,
configTriggerPaths,
configValidationPaths,
} = checkPathsInConfig(controlConfig, path);
// Update default path configs with the ones in the property config
bindingPaths = { ...bindingPaths, ...configBindingPaths };
triggerPaths = { ...triggerPaths, ...configTriggerPaths };
validationPaths = { ...validationPaths, ...configValidationPaths };
}
// Has child Panel Config
if (controlConfig.panelConfig) {
const resultingPaths = childHasPanelConfig(
controlConfig,
widget,
basePath,
);
bindingPaths = { ...bindingPaths, ...resultingPaths.bindingPaths };
triggerPaths = { ...triggerPaths, ...resultingPaths.triggerPaths };
validationPaths = {
...validationPaths,
...resultingPaths.validationPaths,
};
}
if (controlConfig.children) {
const basePropertyPath = controlConfig.propertyName;
const widgetPropertyValue = get(widget, basePropertyPath, []);
// Property in object structure
if (
!isUndefined(widgetPropertyValue) &&
isObject(widgetPropertyValue)
) {
Object.keys(widgetPropertyValue).forEach((key: string) => {
const objectIndexPropertyPath = `${basePropertyPath}.${key}`;
controlConfig.children.forEach((childPropertyConfig: any) => {
const childArrayPropertyPath = `${objectIndexPropertyPath}.${childPropertyConfig.propertyName}`;
const {
configBindingPaths,
configTriggerPaths,
configValidationPaths,
} = checkPathsInConfig(
childPropertyConfig,
childArrayPropertyPath,
);
bindingPaths = { ...bindingPaths, ...configBindingPaths };
triggerPaths = { ...triggerPaths, ...configTriggerPaths };
validationPaths = {
...validationPaths,
...configValidationPaths,
};
});
});
}
}
});
}
});
return { bindingPaths, triggerPaths, validationPaths };
};
Grouping widgets into container (#5704) * Cut copy paste first cut * removed different parent groups logic * mouseup on the outer canvas removes selections. * bug fix * remove unwanted dead code. * Adding tests * build fix * min height fixes * fixing specs. * fixing specs. * fix merge conflcits * fix border positioning * fix canvas widgets incorrect bouding box * fix bounding box position issue * fix bounding box position issue * fix * border issue fix * update test case * add colors in theme * use layers + use click capture on actions * add icon for grouping * fix overflow issue in contextmenu in containers * fix context menu display issue * update position of context menu * fix container box-shadow issue * fix container box-shadow issue * revert container box shadow * stop opening of property pane on shift clicking a widget * remove console.log * fix multiselect box issue * add container on copy * add analytics middleware * refactor paste widget saga * change flash element to accept array + revert refactor * add logic to create containers from selected widgets * update positions of grouped widgets * fix comments + remove console * update flashElementbyId to flashElementsById * remove analytics middleware + remove unecessary imports * add shorcut for grouping * fix position issue when pasting * allow grouping only when multi widgets are selected * fix ux issues with widget grouping * fix help text for grouping actions * filter out the modal widget when calculting next row * fix delete issue when grouping * persist positin when grouping if there is no collision * fix typo for new position * changes for review comments * changes for review comments * fix position issue when pasting * fix new container position issue * move utils function to utils * fix import issue * fix the composite widget grouping issue * fix table name bug * remove repeated code * move copied groups existence check; * fix copied group check Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com> Co-authored-by: root <root@DESKTOP-9GENCK0.localdomain> Co-authored-by: Pawan Kumar <pawankumar@Pawans-MacBook-Pro.local>
2021-08-25 05:00:31 +00:00
/**
* this function gets the next available row for pasting widgets
* NOTE: this function excludes modal widget when calculating next available row
*
* @param parentContainerId
* @param canvasWidgets
* @returns
*/
export const nextAvailableRowInContainer = (
parentContainerId: string,
canvasWidgets: { [widgetId: string]: FlattenedWidgetProps },
) => {
Grouping widgets into container (#5704) * Cut copy paste first cut * removed different parent groups logic * mouseup on the outer canvas removes selections. * bug fix * remove unwanted dead code. * Adding tests * build fix * min height fixes * fixing specs. * fixing specs. * fix merge conflcits * fix border positioning * fix canvas widgets incorrect bouding box * fix bounding box position issue * fix bounding box position issue * fix * border issue fix * update test case * add colors in theme * use layers + use click capture on actions * add icon for grouping * fix overflow issue in contextmenu in containers * fix context menu display issue * update position of context menu * fix container box-shadow issue * fix container box-shadow issue * revert container box shadow * stop opening of property pane on shift clicking a widget * remove console.log * fix multiselect box issue * add container on copy * add analytics middleware * refactor paste widget saga * change flash element to accept array + revert refactor * add logic to create containers from selected widgets * update positions of grouped widgets * fix comments + remove console * update flashElementbyId to flashElementsById * remove analytics middleware + remove unecessary imports * add shorcut for grouping * fix position issue when pasting * allow grouping only when multi widgets are selected * fix ux issues with widget grouping * fix help text for grouping actions * filter out the modal widget when calculting next row * fix delete issue when grouping * persist positin when grouping if there is no collision * fix typo for new position * changes for review comments * changes for review comments * fix position issue when pasting * fix new container position issue * move utils function to utils * fix import issue * fix the composite widget grouping issue * fix table name bug * remove repeated code * move copied groups existence check; * fix copied group check Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com> Co-authored-by: root <root@DESKTOP-9GENCK0.localdomain> Co-authored-by: Pawan Kumar <pawankumar@Pawans-MacBook-Pro.local>
2021-08-25 05:00:31 +00:00
const filteredCanvasWidgets = omitBy(canvasWidgets, (widget) => {
return widget.type === "MODAL_WIDGET";
Grouping widgets into container (#5704) * Cut copy paste first cut * removed different parent groups logic * mouseup on the outer canvas removes selections. * bug fix * remove unwanted dead code. * Adding tests * build fix * min height fixes * fixing specs. * fixing specs. * fix merge conflcits * fix border positioning * fix canvas widgets incorrect bouding box * fix bounding box position issue * fix bounding box position issue * fix * border issue fix * update test case * add colors in theme * use layers + use click capture on actions * add icon for grouping * fix overflow issue in contextmenu in containers * fix context menu display issue * update position of context menu * fix container box-shadow issue * fix container box-shadow issue * revert container box shadow * stop opening of property pane on shift clicking a widget * remove console.log * fix multiselect box issue * add container on copy * add analytics middleware * refactor paste widget saga * change flash element to accept array + revert refactor * add logic to create containers from selected widgets * update positions of grouped widgets * fix comments + remove console * update flashElementbyId to flashElementsById * remove analytics middleware + remove unecessary imports * add shorcut for grouping * fix position issue when pasting * allow grouping only when multi widgets are selected * fix ux issues with widget grouping * fix help text for grouping actions * filter out the modal widget when calculting next row * fix delete issue when grouping * persist positin when grouping if there is no collision * fix typo for new position * changes for review comments * changes for review comments * fix position issue when pasting * fix new container position issue * move utils function to utils * fix import issue * fix the composite widget grouping issue * fix table name bug * remove repeated code * move copied groups existence check; * fix copied group check Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com> Co-authored-by: root <root@DESKTOP-9GENCK0.localdomain> Co-authored-by: Pawan Kumar <pawankumar@Pawans-MacBook-Pro.local>
2021-08-25 05:00:31 +00:00
});
return (
Grouping widgets into container (#5704) * Cut copy paste first cut * removed different parent groups logic * mouseup on the outer canvas removes selections. * bug fix * remove unwanted dead code. * Adding tests * build fix * min height fixes * fixing specs. * fixing specs. * fix merge conflcits * fix border positioning * fix canvas widgets incorrect bouding box * fix bounding box position issue * fix bounding box position issue * fix * border issue fix * update test case * add colors in theme * use layers + use click capture on actions * add icon for grouping * fix overflow issue in contextmenu in containers * fix context menu display issue * update position of context menu * fix container box-shadow issue * fix container box-shadow issue * revert container box shadow * stop opening of property pane on shift clicking a widget * remove console.log * fix multiselect box issue * add container on copy * add analytics middleware * refactor paste widget saga * change flash element to accept array + revert refactor * add logic to create containers from selected widgets * update positions of grouped widgets * fix comments + remove console * update flashElementbyId to flashElementsById * remove analytics middleware + remove unecessary imports * add shorcut for grouping * fix position issue when pasting * allow grouping only when multi widgets are selected * fix ux issues with widget grouping * fix help text for grouping actions * filter out the modal widget when calculting next row * fix delete issue when grouping * persist positin when grouping if there is no collision * fix typo for new position * changes for review comments * changes for review comments * fix position issue when pasting * fix new container position issue * move utils function to utils * fix import issue * fix the composite widget grouping issue * fix table name bug * remove repeated code * move copied groups existence check; * fix copied group check Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com> Co-authored-by: root <root@DESKTOP-9GENCK0.localdomain> Co-authored-by: Pawan Kumar <pawankumar@Pawans-MacBook-Pro.local>
2021-08-25 05:00:31 +00:00
Object.values(filteredCanvasWidgets).reduce(
(prev: number, next: any) =>
next?.parentId === parentContainerId && next.bottomRow > prev
? next.bottomRow
: prev,
0,
) + 1
);
};