From cb478e8d1c31a093041bdfebc6f80e7dbf3416de Mon Sep 17 00:00:00 2001 From: Satbir Singh Date: Tue, 5 Nov 2019 12:08:41 +0000 Subject: [PATCH] Adding action selector control. --- .../propertyControls/ActionSelector.tsx | 136 ++++++++++++++++++ app/client/src/constants/ActionConstants.tsx | 16 +++ app/client/src/pages/Editor/Popper.tsx | 1 + .../src/utils/PropertyControlRegistry.tsx | 6 + 4 files changed, 159 insertions(+) create mode 100644 app/client/src/components/propertyControls/ActionSelector.tsx diff --git a/app/client/src/components/propertyControls/ActionSelector.tsx b/app/client/src/components/propertyControls/ActionSelector.tsx new file mode 100644 index 0000000000..6992664b1c --- /dev/null +++ b/app/client/src/components/propertyControls/ActionSelector.tsx @@ -0,0 +1,136 @@ +import React from "react"; +import BaseControl, { ControlProps } from "./BaseControl"; +import { ControlWrapper, StyledDropDown } from "./StyledControls"; +import { ControlType } from "../../constants/PropertyControlConstants"; +import { + ActionPayload, + ActionType, + PropertyPaneActionDropdownOptions, +} from "../../constants/ActionConstants"; +import { DropdownOption } from "../../widgets/DropdownWidget"; +import { MenuItem, Button } from "@blueprintjs/core"; +import { IItemRendererProps } from "@blueprintjs/select"; +import { connect } from "react-redux"; +import { AppState } from "../../reducers"; +import { ActionDataState } from "../../reducers/entityReducers/actionsReducer"; + +const DEFAULT_ACTION_TYPE = "Select Action Type"; + +class ActionSelectorControl extends BaseControl< + ControlProps & ActionDataState +> { + getSelectionActionType(): string { + const selectedActionTypeValue = + this.props.propertyValue && + this.props.propertyValue[0] && + this.props.propertyValue[0].actionType; + + const foundActionType = PropertyPaneActionDropdownOptions.find( + actionType => actionType.value === selectedActionTypeValue, + ); + + return foundActionType ? foundActionType.label : DEFAULT_ACTION_TYPE; + } + getSelectionActionLabel(allActions: DropdownOption[]): string { + const selectedActionId = + this.props.propertyValue && + this.props.propertyValue[0] && + this.props.propertyValue[0].actionId; + + const foundAction = allActions.find( + action => action.value === selectedActionId, + ); + + return foundAction ? foundAction.label : "Select Action"; + } + render() { + const actionTypeOptions: DropdownOption[] = PropertyPaneActionDropdownOptions; + const allActions = this.props.data.map(action => { + return { + label: action.name, + value: action.id, + }; + }); + const selectedActionType = this.getSelectionActionType(); + const selectedActionLabel = this.getSelectionActionLabel(allActions); + return ( + + + } + > +