PromucFlow_constructor/app/client/src/WidgetProvider/factory/index.tsx

535 lines
14 KiB
TypeScript
Raw Normal View History

chore: Move the widget config to widget class (#26073) ## Description - Remove the config objects from widget and config maps from the widget factory. - Introduce methods in widget development API to dynamically fetch this items. - freeze the widget configuration. #### PR fixes following issue(s) Fixes https://github.com/appsmithorg/appsmith/issues/26008 > if no issue exists, please create an issue and ask the maintainers about this first > > #### Media > A video or a GIF is preferred. when using Loom, don’t embed because it looks like it’s a GIF. instead, just link to the video > > #### Type of change > Please delete options that are not relevant. - Bug fix (non-breaking change which fixes an issue) - New feature (non-breaking change which adds functionality) - Breaking change (fix or feature that would cause existing functionality to not work as expected) - Chore (housekeeping or task changes that don't impact user perception) - This change requires a documentation update > > > ## Testing > #### How Has This Been Tested? > Please describe the tests that you ran to verify your changes. Also list any relevant details for your test configuration. > Delete anything that is not relevant - [x] Manual - [ ] Jest - [ ] Cypress > > #### Test Plan > Add Testsmith test cases links that relate to this PR > > #### Issues raised during DP testing > Link issues raised during DP testing for better visiblity and tracking (copy link from comments dropped on this PR) > > > ## Checklist: #### Dev activity - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag #### QA activity: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-) have been covered - [x] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [x] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed
2023-09-06 12:15:04 +00:00
import type { PropertyPaneConfig } from "constants/PropertyControlConstants";
import type { WidgetProps } from "widgets/BaseWidget";
import type { RenderMode } from "constants/WidgetConstants";
import * as log from "loglevel";
import type {
chore: add highlight calculation logic for layouts. (#27980) ## Description 1. Add LayoutComponent functionality. 2. Create Basic LayoutComponents. 3. Create LayoutPresets needed for Container-like widgets. 4. Add highlight calculation logic for all basic Layout Components. 5. Create dragging sagas for Anvil. 6. Create DraggingArena associated functionality to handle DnD in Anvil. #### PR fixes following issue(s) Fixes #27004 #### Type of change > Please delete options that are not relevant. - New feature (non-breaking change which adds functionality) ## Testing #### How Has This Been Tested? - [ ] Manual - [ ] JUnit - [x] Jest - [ ] Cypress ## Checklist: #### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [x] PR is being merged under a feature flag #### QA activity: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [ ] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed --------- Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com> Co-authored-by: Aswath K <aswath.sana@gmail.com> Co-authored-by: rahulramesha <rahul@appsmith.com> Co-authored-by: rahulramesha <71900764+rahulramesha@users.noreply.github.com>
2023-10-19 20:27:40 +00:00
AnvilConfig,
chore: Move the widget config to widget class (#26073) ## Description - Remove the config objects from widget and config maps from the widget factory. - Introduce methods in widget development API to dynamically fetch this items. - freeze the widget configuration. #### PR fixes following issue(s) Fixes https://github.com/appsmithorg/appsmith/issues/26008 > if no issue exists, please create an issue and ask the maintainers about this first > > #### Media > A video or a GIF is preferred. when using Loom, don’t embed because it looks like it’s a GIF. instead, just link to the video > > #### Type of change > Please delete options that are not relevant. - Bug fix (non-breaking change which fixes an issue) - New feature (non-breaking change which adds functionality) - Breaking change (fix or feature that would cause existing functionality to not work as expected) - Chore (housekeeping or task changes that don't impact user perception) - This change requires a documentation update > > > ## Testing > #### How Has This Been Tested? > Please describe the tests that you ran to verify your changes. Also list any relevant details for your test configuration. > Delete anything that is not relevant - [x] Manual - [ ] Jest - [ ] Cypress > > #### Test Plan > Add Testsmith test cases links that relate to this PR > > #### Issues raised during DP testing > Link issues raised during DP testing for better visiblity and tracking (copy link from comments dropped on this PR) > > > ## Checklist: #### Dev activity - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag #### QA activity: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-) have been covered - [x] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [x] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed
2023-09-06 12:15:04 +00:00
AutocompletionDefinitions,
AutoLayoutConfig,
CanvasWidgetStructure,
WidgetConfigProps,
WidgetMethods,
} from "WidgetProvider/constants";
import {
addPropertyConfigIds,
addSearchConfigToPanelConfig,
convertFunctionsToString,
enhancePropertyPaneConfig,
generatePropertyPaneSearchConfig,
PropertyPaneConfigTypes,
} from "./helpers";
import { FILL_WIDGET_MIN_WIDTH } from "constants/minWidthConstants";
import type BaseWidget from "widgets/BaseWidget";
import { flow } from "lodash";
import { generateReactKey } from "utils/generators";
import {
WidgetFeaturePropertyEnhancements,
WidgetFeatureProps,
} from "../../utils/WidgetFeatures";
import type { RegisteredWidgetFeatures } from "../../utils/WidgetFeatures";
// import { WIDGETS_COUNT } from "widgets";
import type { SetterConfig } from "entities/AppTheming";
import { freeze, memoize } from "./decorators";
chore: add highlight calculation logic for layouts. (#27980) ## Description 1. Add LayoutComponent functionality. 2. Create Basic LayoutComponents. 3. Create LayoutPresets needed for Container-like widgets. 4. Add highlight calculation logic for all basic Layout Components. 5. Create dragging sagas for Anvil. 6. Create DraggingArena associated functionality to handle DnD in Anvil. #### PR fixes following issue(s) Fixes #27004 #### Type of change > Please delete options that are not relevant. - New feature (non-breaking change which adds functionality) ## Testing #### How Has This Been Tested? - [ ] Manual - [ ] JUnit - [x] Jest - [ ] Cypress ## Checklist: #### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [x] PR is being merged under a feature flag #### QA activity: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [ ] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed --------- Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com> Co-authored-by: Aswath K <aswath.sana@gmail.com> Co-authored-by: rahulramesha <rahul@appsmith.com> Co-authored-by: rahulramesha <71900764+rahulramesha@users.noreply.github.com>
2023-10-19 20:27:40 +00:00
import { defaultSizeConfig } from "layoutSystems/anvil/utils/widgetUtils";
chore: Move the widget config to widget class (#26073) ## Description - Remove the config objects from widget and config maps from the widget factory. - Introduce methods in widget development API to dynamically fetch this items. - freeze the widget configuration. #### PR fixes following issue(s) Fixes https://github.com/appsmithorg/appsmith/issues/26008 > if no issue exists, please create an issue and ask the maintainers about this first > > #### Media > A video or a GIF is preferred. when using Loom, don’t embed because it looks like it’s a GIF. instead, just link to the video > > #### Type of change > Please delete options that are not relevant. - Bug fix (non-breaking change which fixes an issue) - New feature (non-breaking change which adds functionality) - Breaking change (fix or feature that would cause existing functionality to not work as expected) - Chore (housekeeping or task changes that don't impact user perception) - This change requires a documentation update > > > ## Testing > #### How Has This Been Tested? > Please describe the tests that you ran to verify your changes. Also list any relevant details for your test configuration. > Delete anything that is not relevant - [x] Manual - [ ] Jest - [ ] Cypress > > #### Test Plan > Add Testsmith test cases links that relate to this PR > > #### Issues raised during DP testing > Link issues raised during DP testing for better visiblity and tracking (copy link from comments dropped on this PR) > > > ## Checklist: #### Dev activity - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag #### QA activity: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-) have been covered - [x] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [x] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed
2023-09-06 12:15:04 +00:00
type WidgetDerivedPropertyType = any;
export type DerivedPropertiesMap = Record<string, string>;
export type WidgetType = (typeof WidgetFactory.widgetTypes)[number];
class WidgetFactory {
static widgetTypes: Record<string, string> = {};
static widgetConfigMap: Map<
WidgetType,
Partial<WidgetProps> & WidgetConfigProps & { type: string }
> = new Map();
static widgetsMap: Map<WidgetType, typeof BaseWidget> = new Map();
static widgetBuilderMap: Map<WidgetType, any> = new Map();
static initialize(
widgets: [
typeof BaseWidget,
(widgetProps: CanvasWidgetStructure) => React.ReactNode,
][],
) {
const start = performance.now();
for (const [widget, builder] of widgets) {
WidgetFactory.widgetsMap.set(widget.type, widget);
WidgetFactory.widgetTypes[widget.type] = widget.type;
WidgetFactory.widgetBuilderMap.set(widget.type, builder);
WidgetFactory.configureWidget(widget);
WidgetFactory.preloadConfig(widget);
}
log.debug("Widget registration took: ", performance.now() - start, "ms");
}
private static preloadConfig(widget: typeof BaseWidget) {
if (widget.preloadConfig) {
// Call functions so we can store the configs in the memo cache
WidgetFactory.getWidgetPropertyPaneCombinedConfig(widget.type);
WidgetFactory.getWidgetPropertyPaneConfig(widget.type);
WidgetFactory.getWidgetPropertyPaneContentConfig(widget.type);
WidgetFactory.getWidgetPropertyPaneStyleConfig(widget.type);
WidgetFactory.getWidgetPropertyPaneSearchConfig(widget.type);
WidgetFactory.getWidgetAutoLayoutConfig(widget.type);
}
}
private static configureWidget(widget: typeof BaseWidget) {
const config = widget.getConfig();
const features = widget.getFeatures();
let enhancedFeatures: Record<string, unknown> = {};
if (features) {
Object.keys(features).forEach((registeredFeature: string) => {
enhancedFeatures = Object.assign(
{},
WidgetFeatureProps[registeredFeature as RegisteredWidgetFeatures],
WidgetFeaturePropertyEnhancements[
registeredFeature as RegisteredWidgetFeatures
](widget),
);
});
}
const _config = {
type: widget.type,
...widget.getDefaults(),
...enhancedFeatures,
searchTags: config.searchTags,
tags: config.tags,
hideCard: !!config.hideCard || !config.iconSVG,
isDeprecated: !!config.isDeprecated,
replacement: config.replacement,
displayName: config.name,
key: generateReactKey(),
iconSVG: config.iconSVG,
isCanvas: config.isCanvas,
needsHeightForContent: config.needsHeightForContent,
};
WidgetFactory.widgetConfigMap.set(widget.type, Object.freeze(_config));
}
static get(type: WidgetType) {
const widget = WidgetFactory.widgetsMap.get(type);
if (widget) {
return widget;
} else {
log.error(`Widget is not defined with type: ${type}`);
return;
}
}
static getConfig(type: WidgetType) {
const config = WidgetFactory.widgetConfigMap.get(type);
if (config) {
return config;
} else {
log.error(`Widget config is not registered for type: ${type}`);
return;
}
}
static getConfigs = () => {
return Object.fromEntries(WidgetFactory.widgetConfigMap);
};
static createWidget(
widgetData: CanvasWidgetStructure,
renderMode: RenderMode,
): React.ReactNode {
const { type } = widgetData;
const builder = WidgetFactory.widgetBuilderMap.get(type);
if (builder) {
const widgetProps = {
key: widgetData.widgetId,
isVisible: true,
...widgetData,
renderMode,
};
return builder(widgetProps);
} else {
const ex: WidgetCreationException = {
message:
"Widget Builder not registered for widget type" + widgetData.type,
};
log.error(ex);
return null;
}
}
@memoize
@freeze
static getWidgetTypes(): WidgetType[] {
return Array.from(WidgetFactory.widgetsMap.keys());
}
@memoize
@freeze
static getWidgetDerivedPropertiesMap(
widgetType: WidgetType,
): DerivedPropertiesMap {
const widget = WidgetFactory.widgetsMap.get(widgetType);
const derivedProperties = widget?.getDerivedPropertiesMap();
if (derivedProperties) {
return derivedProperties;
} else {
log.error(
`Derived properties are not defined for widget type: ${widgetType}`,
);
return {};
}
}
@memoize
@freeze
static getWidgetDefaultPropertiesMap(
widgetType: WidgetType,
): Record<string, string> {
const widget = WidgetFactory.widgetsMap.get(widgetType);
const defaultProperties = widget?.getDefaultPropertiesMap();
if (defaultProperties) {
return defaultProperties;
} else {
log.error(
`Default properties are not defined for widget type: ${widgetType}`,
);
return {};
}
}
fix: Validation issue in select widget on page reload (#28277) ## Description Fixes the regression in select widget validation caused by https://github.com/appsmithorg/appsmith/issues/27408 This PR remove most of the re-validation related logic written in evaluations code base. Going forward we'll maintain an internal dependencyMap for widgets. This can help avoid IIFE hacks to introduce dependency between fields. ###### Changes - Removes the concept of dependentPaths in validation config. - Remove validationDependencyMap from eval code base. - Added internal dependency map to base widget. - Added dependency map config for select, multi-select & Tabs widget. #### PR fixes following issue(s) Fixes #28368 Fixes #28224 #### Type of change - Bug fix (non-breaking change which fixes an issue) > > ## Testing > #### How Has This Been Tested? - [x] Manual - [ ] JUnit - [x] Jest - [x] Cypress > > #### Test Plan > Add Testsmith test cases links that relate to this PR > #### Issues raised during DP testing > Link issues raised during DP testing for better visiblity and tracking (copy link from comments dropped on this PR) > ## Checklist: #### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag #### QA activity: - [x] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-) have been covered - [x] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [x] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [x] Cypress test cases have been added and approved by SDET/manual QA - [x] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed
2023-10-27 12:48:42 +00:00
@memoize
@freeze
static getWidgetDependencyMap(
widgetType: WidgetType,
): Record<string, string[]> {
const widget = WidgetFactory.widgetsMap.get(widgetType);
const dependencyMap = widget?.getDependencyMap();
if (dependencyMap) {
return dependencyMap;
} else {
log.error(`Dependency map is defined for widget type: ${widgetType}`);
return {};
}
}
chore: Move the widget config to widget class (#26073) ## Description - Remove the config objects from widget and config maps from the widget factory. - Introduce methods in widget development API to dynamically fetch this items. - freeze the widget configuration. #### PR fixes following issue(s) Fixes https://github.com/appsmithorg/appsmith/issues/26008 > if no issue exists, please create an issue and ask the maintainers about this first > > #### Media > A video or a GIF is preferred. when using Loom, don’t embed because it looks like it’s a GIF. instead, just link to the video > > #### Type of change > Please delete options that are not relevant. - Bug fix (non-breaking change which fixes an issue) - New feature (non-breaking change which adds functionality) - Breaking change (fix or feature that would cause existing functionality to not work as expected) - Chore (housekeeping or task changes that don't impact user perception) - This change requires a documentation update > > > ## Testing > #### How Has This Been Tested? > Please describe the tests that you ran to verify your changes. Also list any relevant details for your test configuration. > Delete anything that is not relevant - [x] Manual - [ ] Jest - [ ] Cypress > > #### Test Plan > Add Testsmith test cases links that relate to this PR > > #### Issues raised during DP testing > Link issues raised during DP testing for better visiblity and tracking (copy link from comments dropped on this PR) > > > ## Checklist: #### Dev activity - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag #### QA activity: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-) have been covered - [x] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [x] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed
2023-09-06 12:15:04 +00:00
@memoize
@freeze
static getWidgetMetaPropertiesMap(
widgetType: WidgetType,
): Record<string, unknown> {
const widget = WidgetFactory.widgetsMap.get(widgetType);
const metaProperties = widget?.getMetaPropertiesMap();
if (metaProperties) {
return metaProperties;
} else {
log.error(
`Meta properties are not defined for widget type: ${widgetType}`,
);
return {};
}
}
@memoize
@freeze
static getWidgetPropertyPaneCombinedConfig(
type: WidgetType,
): readonly PropertyPaneConfig[] {
const contentConfig =
WidgetFactory.getWidgetPropertyPaneContentConfig(type);
const styleConfig = WidgetFactory.getWidgetPropertyPaneStyleConfig(type);
return [...contentConfig, ...styleConfig];
}
@memoize
@freeze
static getWidgetPropertyPaneConfig(
type: WidgetType,
): readonly PropertyPaneConfig[] {
const widget = WidgetFactory.widgetsMap.get(type);
const propertyPaneConfig = widget?.getPropertyPaneConfig();
const features = widget?.getFeatures();
if (Array.isArray(propertyPaneConfig) && propertyPaneConfig.length > 0) {
const enhance = flow([
enhancePropertyPaneConfig,
convertFunctionsToString,
addPropertyConfigIds,
Object.freeze,
]);
const enhancedPropertyPaneConfig = enhance(propertyPaneConfig, features);
return enhancedPropertyPaneConfig;
} else {
const config = WidgetFactory.getWidgetPropertyPaneCombinedConfig(type);
if (config === undefined) {
log.error("Widget property pane config not defined", type);
return [];
} else {
return config;
}
}
}
@memoize
@freeze
static getWidgetPropertyPaneContentConfig(
type: WidgetType,
): readonly PropertyPaneConfig[] {
const widget = WidgetFactory.widgetsMap.get(type);
const propertyPaneContentConfig = widget?.getPropertyPaneContentConfig();
const features = widget?.getFeatures();
if (propertyPaneContentConfig) {
const enhance = flow([
enhancePropertyPaneConfig,
convertFunctionsToString,
addPropertyConfigIds,
addSearchConfigToPanelConfig,
Object.freeze,
]);
const enhancedPropertyPaneContentConfig = enhance(
propertyPaneContentConfig,
features,
PropertyPaneConfigTypes.CONTENT,
type,
);
return enhancedPropertyPaneContentConfig;
} else {
return [];
}
}
@memoize
@freeze
static getWidgetPropertyPaneStyleConfig(
type: WidgetType,
): readonly PropertyPaneConfig[] {
const widget = WidgetFactory.widgetsMap.get(type);
const propertyPaneStyleConfig = widget?.getPropertyPaneStyleConfig();
const features = widget?.getFeatures();
if (propertyPaneStyleConfig) {
const enhance = flow([
enhancePropertyPaneConfig,
convertFunctionsToString,
addPropertyConfigIds,
addSearchConfigToPanelConfig,
Object.freeze,
]);
const enhancedPropertyPaneConfig = enhance(
propertyPaneStyleConfig,
features,
PropertyPaneConfigTypes.STYLE,
);
return enhancedPropertyPaneConfig;
} else {
return [];
}
}
@memoize
@freeze
static getWidgetPropertyPaneSearchConfig(
type: WidgetType,
): readonly PropertyPaneConfig[] {
const config = generatePropertyPaneSearchConfig(
WidgetFactory.getWidgetPropertyPaneContentConfig(type),
WidgetFactory.getWidgetPropertyPaneStyleConfig(type),
);
if (config) {
return config;
} else {
return [];
}
}
@memoize
@freeze
static getWidgetAutoLayoutConfig(type: WidgetType): AutoLayoutConfig {
const widget = WidgetFactory.widgetsMap.get(type);
const baseAutoLayoutConfig = widget?.getAutoLayoutConfig();
if (baseAutoLayoutConfig) {
return {
...baseAutoLayoutConfig,
widgetSize:
baseAutoLayoutConfig.widgetSize?.map((sizeConfig) => ({
...sizeConfig,
configuration: (props: WidgetProps) => {
if (!props)
return {
minWidth:
WidgetFactory.widgetConfigMap.get(type)?.minWidth ||
FILL_WIDGET_MIN_WIDTH,
minHeight:
WidgetFactory.widgetConfigMap.get(type)?.minHeight || 80,
};
return sizeConfig.configuration(props);
},
})) || [],
autoDimension: baseAutoLayoutConfig.autoDimension ?? {},
disabledPropsDefaults: baseAutoLayoutConfig.disabledPropsDefaults ?? {},
};
} else {
log.error(`Auto layout config is not defined for widget type: ${type}`);
return {
autoDimension: {},
widgetSize: [],
disableResizeHandles: {},
disabledPropsDefaults: {},
};
}
}
chore: add highlight calculation logic for layouts. (#27980) ## Description 1. Add LayoutComponent functionality. 2. Create Basic LayoutComponents. 3. Create LayoutPresets needed for Container-like widgets. 4. Add highlight calculation logic for all basic Layout Components. 5. Create dragging sagas for Anvil. 6. Create DraggingArena associated functionality to handle DnD in Anvil. #### PR fixes following issue(s) Fixes #27004 #### Type of change > Please delete options that are not relevant. - New feature (non-breaking change which adds functionality) ## Testing #### How Has This Been Tested? - [ ] Manual - [ ] JUnit - [x] Jest - [ ] Cypress ## Checklist: #### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [x] PR is being merged under a feature flag #### QA activity: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [ ] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed --------- Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com> Co-authored-by: Aswath K <aswath.sana@gmail.com> Co-authored-by: rahulramesha <rahul@appsmith.com> Co-authored-by: rahulramesha <71900764+rahulramesha@users.noreply.github.com>
2023-10-19 20:27:40 +00:00
@memoize
@freeze
static getWidgetAnvilConfig(type: WidgetType): AnvilConfig {
const widget = WidgetFactory.widgetsMap.get(type);
const baseAnvilConfig: AnvilConfig | null | undefined =
widget?.getAnvilConfig();
if (!baseAnvilConfig) {
log.error(`Anvil config is not defined for widget type: ${type}`);
return {
widgetSize: defaultSizeConfig,
};
}
return baseAnvilConfig;
}
chore: Move the widget config to widget class (#26073) ## Description - Remove the config objects from widget and config maps from the widget factory. - Introduce methods in widget development API to dynamically fetch this items. - freeze the widget configuration. #### PR fixes following issue(s) Fixes https://github.com/appsmithorg/appsmith/issues/26008 > if no issue exists, please create an issue and ask the maintainers about this first > > #### Media > A video or a GIF is preferred. when using Loom, don’t embed because it looks like it’s a GIF. instead, just link to the video > > #### Type of change > Please delete options that are not relevant. - Bug fix (non-breaking change which fixes an issue) - New feature (non-breaking change which adds functionality) - Breaking change (fix or feature that would cause existing functionality to not work as expected) - Chore (housekeeping or task changes that don't impact user perception) - This change requires a documentation update > > > ## Testing > #### How Has This Been Tested? > Please describe the tests that you ran to verify your changes. Also list any relevant details for your test configuration. > Delete anything that is not relevant - [x] Manual - [ ] Jest - [ ] Cypress > > #### Test Plan > Add Testsmith test cases links that relate to this PR > > #### Issues raised during DP testing > Link issues raised during DP testing for better visiblity and tracking (copy link from comments dropped on this PR) > > > ## Checklist: #### Dev activity - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag #### QA activity: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-) have been covered - [x] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [x] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed
2023-09-06 12:15:04 +00:00
@memoize
@freeze
static getWidgetTypeConfigMap(): WidgetTypeConfigMap {
const typeConfigMap: WidgetTypeConfigMap = {};
WidgetFactory.getWidgetTypes().forEach((type) => {
typeConfigMap[type] = {
defaultProperties: WidgetFactory.getWidgetDefaultPropertiesMap(type),
derivedProperties: WidgetFactory.getWidgetDerivedPropertiesMap(type),
metaProperties: WidgetFactory.getWidgetMetaPropertiesMap(type),
};
});
return typeConfigMap;
}
static getAutocompleteDefinitions(
type: WidgetType,
): AutocompletionDefinitions {
const widget = WidgetFactory.widgetsMap.get(type);
const autocompleteDefinition = widget?.getAutocompleteDefinitions();
if (autocompleteDefinition) {
return autocompleteDefinition;
} else {
log.error(
`Auto complete definitions are not defined for widget type: ${type}`,
);
return {};
}
}
@memoize
@freeze
static getWidgetSetterConfig(type: WidgetType): Partial<SetterConfig> {
const widget = WidgetFactory.widgetsMap.get(type);
const setterConfig = widget?.getSetterConfig() || {};
return setterConfig;
}
@memoize
@freeze
static getLoadingProperties(type: WidgetType): Array<RegExp> | undefined {
const widget = WidgetFactory.widgetsMap.get(type);
return widget?.getLoadingProperties();
}
@memoize
@freeze
static getWidgetStylesheetConfigMap(widgetType: WidgetType) {
const widget = WidgetFactory.widgetsMap.get(widgetType);
const stylesheet = widget?.getStylesheetConfig();
if (stylesheet) {
return stylesheet;
} else {
log.error(
`stylesheet config is not defined for widget type: ${widgetType}`,
);
return undefined;
}
}
@memoize
static getWidgetMethods(type: WidgetType): WidgetMethods {
const widget = WidgetFactory.widgetsMap.get(type);
const methods = widget?.getMethods();
if (methods) {
return methods;
} else {
return {};
}
}
}
export type WidgetTypeConfigMap = Record<
string,
{
defaultProperties: Record<string, string>;
metaProperties: Record<string, any>;
derivedProperties: WidgetDerivedPropertyType;
}
>;
export interface WidgetCreationException {
message: string;
}
export default WidgetFactory;