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 ( } >