From 27804d6ec62bc26768d5b736b8542509d2251e23 Mon Sep 17 00:00:00 2001 From: Abhinav Jha Date: Tue, 14 Apr 2020 05:35:16 +0000 Subject: [PATCH 01/31] DRY property control creation. Generate ids for property pane config on the client. Add Multi switch control. Add Icon Widget (WIP). Enable blueprint based actions. --- .../cypress/locators/commonlocators.json | 2 +- .../designSystems/appsmith/IconComponent.tsx | 34 ++ .../designSystems/blueprint/CloseButton.tsx | 10 +- .../designSystems/blueprint/IconComponent.tsx | 24 -- .../blueprint/ModalComponent.tsx | 13 - .../ActionSelectorControl.tsx | 3 +- .../propertyControls/BaseControl.tsx | 2 - .../propertyControls/CodeEditorControl.tsx | 3 +- .../ColumnActionSelectorControl.tsx | 3 +- .../propertyControls/DatePickerControl.tsx | 3 +- .../propertyControls/DropDownControl.tsx | 3 +- .../propertyControls/InputTextControl.tsx | 3 +- .../propertyControls/MultiSelectControl.tsx | 3 +- .../propertyControls/MultiSwitchControl.tsx | 46 +++ .../propertyControls/OptionControl.tsx | 3 +- .../propertyControls/SwitchControl.tsx | 3 +- .../propertyControls/TimezoneControl.tsx | 3 +- .../components/propertyControls/index.test.ts | 10 + .../src/components/propertyControls/index.ts | 63 ++++ .../constants/PropertyControlConstants.tsx | 25 +- app/client/src/constants/WidgetConstants.tsx | 8 +- .../PropertyPaneConfigResponse.tsx | 348 +++++++++++++++--- .../mockResponses/WidgetConfigResponse.tsx | 58 ++- .../Editor/PropertyPane/PropertyControl.tsx | 4 +- .../src/pages/Editor/PropertyPane/index.tsx | 9 +- .../propertyPaneConfigReducer.tsx | 16 +- .../entityReducers/widgetConfigReducer.tsx | 6 +- app/client/src/sagas/ConfigsSagas.tsx | 23 +- app/client/src/sagas/WidgetBlueprintSagas.ts | 61 +++ app/client/src/sagas/WidgetOperationSagas.tsx | 23 +- .../src/utils/PropertyControlRegistry.tsx | 89 +---- app/client/src/utils/WidgetPropsUtils.tsx | 1 + app/client/src/utils/WidgetRegistry.tsx | 26 +- app/client/src/widgets/IconWidget.tsx | 65 ++++ app/client/src/widgets/InputWidget.tsx | 21 +- app/client/src/widgets/SpinnerWidget.tsx | 46 --- app/client/src/widgets/SwitchWidget.tsx | 33 +- 37 files changed, 755 insertions(+), 341 deletions(-) create mode 100644 app/client/src/components/designSystems/appsmith/IconComponent.tsx delete mode 100644 app/client/src/components/designSystems/blueprint/IconComponent.tsx create mode 100644 app/client/src/components/propertyControls/MultiSwitchControl.tsx create mode 100644 app/client/src/components/propertyControls/index.test.ts create mode 100644 app/client/src/components/propertyControls/index.ts create mode 100644 app/client/src/widgets/IconWidget.tsx delete mode 100644 app/client/src/widgets/SpinnerWidget.tsx diff --git a/app/client/cypress/locators/commonlocators.json b/app/client/cypress/locators/commonlocators.json index 766a9416be..4390b0e0c8 100644 --- a/app/client/cypress/locators/commonlocators.json +++ b/app/client/cypress/locators/commonlocators.json @@ -1,6 +1,6 @@ { "editIcon":".t--widget-propertypane-toggle", - "editPropCrossButton":"span[icon='cross']", + "editPropCrossButton":".t--property-pane-close-btn", "deleteWidgetIcon":".t--widget-delete-control", "dropdownSelectButton":".t--open-dropdown-Select" diff --git a/app/client/src/components/designSystems/appsmith/IconComponent.tsx b/app/client/src/components/designSystems/appsmith/IconComponent.tsx new file mode 100644 index 0000000000..14058919bf --- /dev/null +++ b/app/client/src/components/designSystems/appsmith/IconComponent.tsx @@ -0,0 +1,34 @@ +import React from "react"; +import { Icon, Intent } from "@blueprintjs/core"; +import { IconName } from "@blueprintjs/icons"; +import { noop } from "utils/AppsmithUtils"; +export type IconType = IconName | string; + +class IconComponent extends React.Component { + render() { + return ( + + ); + } +} + +export interface IconComponentProps { + iconSize?: number; + iconName?: IconType; + intent?: Intent; + disabled?: boolean; + onClick?: () => void; + color: string; +} + +export default IconComponent; diff --git a/app/client/src/components/designSystems/blueprint/CloseButton.tsx b/app/client/src/components/designSystems/blueprint/CloseButton.tsx index b683e08d57..3fc440c064 100644 --- a/app/client/src/components/designSystems/blueprint/CloseButton.tsx +++ b/app/client/src/components/designSystems/blueprint/CloseButton.tsx @@ -6,6 +6,7 @@ type CloseButtonProps = { color: Color; size: number; onClick: React.MouseEventHandler; + className?: string; }; const StyledButton = styled(Button)` @@ -22,5 +23,12 @@ const StyledButton = styled(Button)` `; export const CloseButton = (props: CloseButtonProps) => { - return ; + return ( + + ); }; diff --git a/app/client/src/components/designSystems/blueprint/IconComponent.tsx b/app/client/src/components/designSystems/blueprint/IconComponent.tsx deleted file mode 100644 index 493baecdcc..0000000000 --- a/app/client/src/components/designSystems/blueprint/IconComponent.tsx +++ /dev/null @@ -1,24 +0,0 @@ -import * as React from "react"; -import { ComponentProps } from "components/designSystems/appsmith/BaseComponent"; -import { Icon, Intent } from "@blueprintjs/core"; -import { IconName } from "@blueprintjs/icons"; -class IconComponent extends React.Component { - render() { - return ( - - ); - } -} - -export interface IconComponentProps extends ComponentProps { - iconSize?: number; - icon?: IconName; - intent?: Intent; - ellipsize?: boolean; -} - -export default IconComponent; diff --git a/app/client/src/components/designSystems/blueprint/ModalComponent.tsx b/app/client/src/components/designSystems/blueprint/ModalComponent.tsx index bf24be91c7..7c01d19147 100644 --- a/app/client/src/components/designSystems/blueprint/ModalComponent.tsx +++ b/app/client/src/components/designSystems/blueprint/ModalComponent.tsx @@ -1,9 +1,7 @@ import React, { ReactNode, RefObject, useRef, useEffect } from "react"; import { Overlay, Classes } from "@blueprintjs/core"; import styled from "styled-components"; -import { ControlIcons } from "icons/ControlIcons"; import { getCanvasClassName } from "utils/generators"; -const CloseModalControl = ControlIcons.CLOSE_CONTROL; const Container = styled.div<{ width: number; height: number; @@ -44,13 +42,6 @@ const Content = styled.div<{ height: ${props => props.height}px; `; -const CloseModalTrigger = styled(CloseModalControl)` - position: absolute; - right: -30px; - top: 0px; - cursor: pointer; -`; - export type ModalComponentProps = { isOpen: boolean; onClose: (e: any) => void; @@ -84,10 +75,6 @@ export const ModalComponent = (props: ModalComponentProps) => { enforceFocus={false} >
- { @@ -21,7 +20,7 @@ class ActionSelectorControl extends BaseControl { ); } - getControlType(): ControlType { + static getControlType() { return "ACTION_SELECTOR"; } } diff --git a/app/client/src/components/propertyControls/BaseControl.tsx b/app/client/src/components/propertyControls/BaseControl.tsx index 78dbef6dfd..d108a15cdf 100644 --- a/app/client/src/components/propertyControls/BaseControl.tsx +++ b/app/client/src/components/propertyControls/BaseControl.tsx @@ -14,8 +14,6 @@ abstract class BaseControl

extends Component< if (!_.isNil(this.props.onPropertyChange)) this.props.onPropertyChange(propertyName, propertyValue); } - - abstract getControlType(): ControlType; } export interface ControlBuilder { diff --git a/app/client/src/components/propertyControls/CodeEditorControl.tsx b/app/client/src/components/propertyControls/CodeEditorControl.tsx index 234fd0b33f..f7ee11926d 100644 --- a/app/client/src/components/propertyControls/CodeEditorControl.tsx +++ b/app/client/src/components/propertyControls/CodeEditorControl.tsx @@ -1,6 +1,5 @@ import React, { ChangeEvent } from "react"; import BaseControl, { ControlProps } from "./BaseControl"; -import { ControlType } from "constants/PropertyControlConstants"; import DynamicAutocompleteInput from "components/editorComponents/DynamicAutocompleteInput"; import { EventOrValueHandler } from "redux-form"; class CodeEditorControl extends BaseControl { @@ -25,7 +24,7 @@ class CodeEditorControl extends BaseControl { this.updateProperty(this.props.propertyName, value); }; - getControlType(): ControlType { + static getControlType() { return "CODE_EDITOR"; } } diff --git a/app/client/src/components/propertyControls/ColumnActionSelectorControl.tsx b/app/client/src/components/propertyControls/ColumnActionSelectorControl.tsx index ce6617e6be..d64df72cfe 100644 --- a/app/client/src/components/propertyControls/ColumnActionSelectorControl.tsx +++ b/app/client/src/components/propertyControls/ColumnActionSelectorControl.tsx @@ -2,7 +2,6 @@ import React from "react"; import BaseControl, { ControlProps } from "./BaseControl"; import { StyledPropertyPaneButton } from "./StyledControls"; -import { ControlType } from "constants/PropertyControlConstants"; import { generateReactKey } from "utils/generators"; import styled from "constants/DefaultTheme"; import { AnyStyledComponent } from "styled-components"; @@ -128,7 +127,7 @@ class ColumnActionSelectorControl extends BaseControl< this.updateProperty(this.props.propertyName, update); }; - getControlType(): ControlType { + static getControlType() { return "COLUMN_ACTION_SELECTOR"; } } diff --git a/app/client/src/components/propertyControls/DatePickerControl.tsx b/app/client/src/components/propertyControls/DatePickerControl.tsx index 79321bce7a..5f350be5d1 100644 --- a/app/client/src/components/propertyControls/DatePickerControl.tsx +++ b/app/client/src/components/propertyControls/DatePickerControl.tsx @@ -1,7 +1,6 @@ import React from "react"; import BaseControl, { ControlProps } from "./BaseControl"; import { StyledDatePicker } from "./StyledControls"; -import { ControlType } from "constants/PropertyControlConstants"; import moment from "moment-timezone"; class DatePickerControl extends BaseControl { @@ -35,7 +34,7 @@ class DatePickerControl extends BaseControl { this.updateProperty(this.props.propertyName, date); }; - getControlType(): ControlType { + static getControlType() { return "DATE_PICKER"; } } diff --git a/app/client/src/components/propertyControls/DropDownControl.tsx b/app/client/src/components/propertyControls/DropDownControl.tsx index 46ef56d48a..9aba458854 100644 --- a/app/client/src/components/propertyControls/DropDownControl.tsx +++ b/app/client/src/components/propertyControls/DropDownControl.tsx @@ -4,7 +4,6 @@ import { Button, MenuItem } from "@blueprintjs/core"; import { IItemRendererProps } from "@blueprintjs/select"; import { StyledDropDown, StyledDropDownContainer } from "./StyledControls"; import { DropdownOption } from "widgets/DropdownWidget"; -import { ControlType } from "constants/PropertyControlConstants"; class DropDownControl extends BaseControl { render() { @@ -57,7 +56,7 @@ class DropDownControl extends BaseControl { return selectedOption.value === this.props.propertyValue; }; - getControlType(): ControlType { + static getControlType() { return "DROP_DOWN"; } } diff --git a/app/client/src/components/propertyControls/InputTextControl.tsx b/app/client/src/components/propertyControls/InputTextControl.tsx index 208b0446c0..e87f9ac006 100644 --- a/app/client/src/components/propertyControls/InputTextControl.tsx +++ b/app/client/src/components/propertyControls/InputTextControl.tsx @@ -2,7 +2,6 @@ import React from "react"; import BaseControl, { ControlProps } from "./BaseControl"; import { StyledDynamicInput } from "./StyledControls"; import { InputType } from "widgets/InputWidget"; -import { ControlType } from "constants/PropertyControlConstants"; import DynamicAutocompleteInput from "components/editorComponents/DynamicAutocompleteInput"; export function InputText(props: { @@ -75,7 +74,7 @@ class InputTextControl extends BaseControl { this.updateProperty(this.props.propertyName, value); }; - getControlType(): ControlType { + static getControlType() { return "INPUT_TEXT"; } } diff --git a/app/client/src/components/propertyControls/MultiSelectControl.tsx b/app/client/src/components/propertyControls/MultiSelectControl.tsx index d0c54229d8..ba41b1236a 100644 --- a/app/client/src/components/propertyControls/MultiSelectControl.tsx +++ b/app/client/src/components/propertyControls/MultiSelectControl.tsx @@ -1,6 +1,5 @@ import React from "react"; import BaseControl, { ControlProps } from "./BaseControl"; -import { ControlType } from "constants/PropertyControlConstants"; import { MenuItem } from "@blueprintjs/core"; import { IItemRendererProps } from "@blueprintjs/select"; import { StyledMultiSelectDropDown } from "./StyledControls"; @@ -81,7 +80,7 @@ class MultiSelectControl extends BaseControl { ); }; - getControlType(): ControlType { + static getControlType() { return "MULTI_SELECT"; } } diff --git a/app/client/src/components/propertyControls/MultiSwitchControl.tsx b/app/client/src/components/propertyControls/MultiSwitchControl.tsx new file mode 100644 index 0000000000..0e67483212 --- /dev/null +++ b/app/client/src/components/propertyControls/MultiSwitchControl.tsx @@ -0,0 +1,46 @@ +import React from "react"; +import BaseControl, { ControlProps } from "./BaseControl"; +import { IconName, ButtonGroup, Button, Classes } from "@blueprintjs/core"; +import { IconNames } from "@blueprintjs/icons"; +const iconNames: string[] = Object.values({ ...IconNames }); + +class MultiSwitchControl extends BaseControl { + renderOption = (option: SwitchOption) => { + const isIcon: boolean = + !!option.icon && iconNames.indexOf(option.icon) > -1; + return ( +