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

176 lines
6.9 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";
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 { WidgetTypes } from "constants/WidgetConstants";
export const getAllPathsFromPropertyConfig = (
widget: WidgetProps,
widgetConfig: readonly PropertyPaneConfig[],
defaultProperties: Record<string, any>,
): {
bindingPaths: Record<string, EvaluationSubstitutionType>;
triggerPaths: Record<string, true>;
validationPaths: Record<string, ValidationConfig>;
} => {
const bindingPaths: Record<string, EvaluationSubstitutionType> = {};
Object.keys(defaultProperties).forEach(
(property) =>
(bindingPaths[property] = EvaluationSubstitutionType.TEMPLATE),
);
const triggerPaths: Record<string, true> = {};
const 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) {
if (
controlConfig.isBindProperty &&
!controlConfig.isTriggerProperty
) {
bindingPaths[controlConfig.propertyName] =
controlConfig.evaluationSubstitutionType ||
EvaluationSubstitutionType.TEMPLATE;
if (controlConfig.validation) {
validationPaths[controlConfig.propertyName] =
controlConfig.validation;
}
} 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
) {
bindingPaths[panelPropertyPath] =
controlConfig.evaluationSubstitutionType ||
EvaluationSubstitutionType.TEMPLATE;
if (panelColumnControlConfig.validation) {
validationPaths[panelPropertyPath] =
panelColumnControlConfig.validation;
}
} else if (
panelColumnControlConfig.isBindProperty &&
panelColumnControlConfig.isTriggerProperty
) {
triggerPaths[panelPropertyPath] = true;
}
}
},
);
}
},
);
},
);
}
}
if (controlConfig.children) {
const basePropertyPath = controlConfig.propertyName;
const widgetPropertyValue = get(widget, basePropertyPath, []);
// 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] =
childPropertyConfig.evaluationSubstitutionType ||
EvaluationSubstitutionType.TEMPLATE;
if (childPropertyConfig.validation) {
validationPaths[childArrayPropertyPath] =
childPropertyConfig.validation;
}
} else if (
childPropertyConfig.isBindProperty &&
childPropertyConfig.isTriggerProperty
) {
triggerPaths[childArrayPropertyPath] = true;
}
});
});
}
}
});
}
});
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 === WidgetTypes.MODAL_WIDGET;
});
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
);
};