From 847461f5339921e1a2f68512057a38d8a495a814 Mon Sep 17 00:00:00 2001 From: pianist <26953709+Pianist038801@users.noreply.github.com> Date: Wed, 4 Aug 2021 08:28:16 -0700 Subject: [PATCH] feat: add enum input type in launch form (#178) Signed-off-by: Pianist038801 Co-authored-by: Pianist038801 --- .../Launch/LaunchForm/SimpleInput.tsx | 34 ++++++++++++++++++- src/components/Launch/LaunchForm/constants.ts | 1 + .../inputHelpers/getHelperForInput.ts | 1 + .../Launch/LaunchForm/inputHelpers/utils.ts | 1 + src/components/Launch/LaunchForm/types.ts | 1 + src/components/Launch/LaunchForm/utils.ts | 2 ++ src/models/Common/types.ts | 3 ++ 7 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/components/Launch/LaunchForm/SimpleInput.tsx b/src/components/Launch/LaunchForm/SimpleInput.tsx index 2248c323e8..142b56dcaf 100644 --- a/src/components/Launch/LaunchForm/SimpleInput.tsx +++ b/src/components/Launch/LaunchForm/SimpleInput.tsx @@ -2,9 +2,12 @@ import { FormControl, FormControlLabel, FormHelperText, + MenuItem, + Select, Switch, TextField } from '@material-ui/core'; +import { makeStyles } from '@material-ui/core/styles'; import * as React from 'react'; import { DatetimeInput } from './DatetimeInput'; import { makeStringChangeHandler, makeSwitchChangeHandler } from './handlers'; @@ -12,6 +15,12 @@ import { InputProps, InputType } from './types'; import { UnsupportedInput } from './UnsupportedInput'; import { getLaunchInputId } from './utils'; +const useStyles = makeStyles(theme => ({ + formControl: { + minWidth: '100%' + } +})); + /** Handles rendering of the input component for any primitive-type input */ export const SimpleInput: React.FC = props => { const { @@ -19,11 +28,17 @@ export const SimpleInput: React.FC = props => { label, name, onChange, - typeDefinition: { type }, + typeDefinition: { type, literalType }, value = '' } = props; const hasError = !!error; const helperText = hasError ? error : props.helperText; + const classes = useStyles(); + + const handleEnumChange = (event: React.ChangeEvent<{ value: unknown }>) => { + onChange(event.target.value as string); + }; + switch (type) { case InputType.Boolean: return ( @@ -61,6 +76,23 @@ export const SimpleInput: React.FC = props => { variant="outlined" /> ); + case InputType.Enum: + return ( + + + {label} + + ); default: return ; } diff --git a/src/components/Launch/LaunchForm/constants.ts b/src/components/Launch/LaunchForm/constants.ts index 47b3ca6d3b..616aa1b1fc 100644 --- a/src/components/Launch/LaunchForm/constants.ts +++ b/src/components/Launch/LaunchForm/constants.ts @@ -37,6 +37,7 @@ export const typeLabels: { [k in InputType]: string } = { [InputType.Datetime]: 'datetime - UTC', [InputType.Duration]: 'duration - ms', [InputType.Error]: 'error', + [InputType.Enum]: 'enum', [InputType.Float]: 'float', [InputType.Integer]: 'integer', [InputType.Map]: '', diff --git a/src/components/Launch/LaunchForm/inputHelpers/getHelperForInput.ts b/src/components/Launch/LaunchForm/inputHelpers/getHelperForInput.ts index 76c06b203c..b5e7297145 100644 --- a/src/components/Launch/LaunchForm/inputHelpers/getHelperForInput.ts +++ b/src/components/Launch/LaunchForm/inputHelpers/getHelperForInput.ts @@ -22,6 +22,7 @@ const inputHelpers: Record = { [InputType.Collection]: collectionHelper, [InputType.Datetime]: datetimeHelper, [InputType.Duration]: durationHelper, + [InputType.Enum]: stringHelper, [InputType.Error]: unsupportedHelper, [InputType.Float]: floatHelper, [InputType.Integer]: integerHelper, diff --git a/src/components/Launch/LaunchForm/inputHelpers/utils.ts b/src/components/Launch/LaunchForm/inputHelpers/utils.ts index b4ae5c8742..ca7f299354 100644 --- a/src/components/Launch/LaunchForm/inputHelpers/utils.ts +++ b/src/components/Launch/LaunchForm/inputHelpers/utils.ts @@ -46,6 +46,7 @@ export function typeIsSupported(typeDefinition: InputTypeDefinition): boolean { case InputType.Blob: case InputType.Datetime: case InputType.Duration: + case InputType.Enum: case InputType.Float: case InputType.Integer: case InputType.Schema: diff --git a/src/components/Launch/LaunchForm/types.ts b/src/components/Launch/LaunchForm/types.ts index 175198671b..65a3193a91 100644 --- a/src/components/Launch/LaunchForm/types.ts +++ b/src/components/Launch/LaunchForm/types.ts @@ -147,6 +147,7 @@ export enum InputType { Datetime = 'DATETIME', Duration = 'DURATION', Error = 'ERROR', + Enum = 'ENUM', Float = 'FLOAT', Integer = 'INTEGER', Map = 'MAP', diff --git a/src/components/Launch/LaunchForm/utils.ts b/src/components/Launch/LaunchForm/utils.ts index 0a5523924a..d1f3358fde 100644 --- a/src/components/Launch/LaunchForm/utils.ts +++ b/src/components/Launch/LaunchForm/utils.ts @@ -168,6 +168,8 @@ export function getInputDefintionForLiteralType( result.type = InputType.Schema; } else if (literalType.simple) { result.type = simpleTypeToInputType[literalType.simple]; + } else if (literalType.enumType) { + result.type = InputType.Enum; } return result; } diff --git a/src/models/Common/types.ts b/src/models/Common/types.ts index fedef9ac3a..473561a565 100644 --- a/src/models/Common/types.ts +++ b/src/models/Common/types.ts @@ -141,10 +141,13 @@ export interface LiteralType extends Core.ILiteralType { metadata?: ProtobufStruct; schema?: SchemaType; simple?: SimpleType; + enumType?: EnumType; } export type SimpleType = Core.SimpleType; export const SimpleType = Core.SimpleType; +export type EnumType = Core.EnumType; +export const EnumType = Core.EnumType; export interface Variable extends Core.IVariable { type: LiteralType;