From 8398a1597f38ed766d0ad86cdd640fdb8b9dc01e Mon Sep 17 00:00:00 2001 From: James Date: Thu, 30 Jun 2022 13:15:19 -0400 Subject: [PATCH] fix: fix validation for duplicate and fix focus issue Signed-off-by: James --- .../components/Launch/LaunchForm/MapInput.tsx | 120 +----------------- 1 file changed, 4 insertions(+), 116 deletions(-) diff --git a/packages/zapp/console/src/components/Launch/LaunchForm/MapInput.tsx b/packages/zapp/console/src/components/Launch/LaunchForm/MapInput.tsx index f8f85cb28..a61a42b69 100644 --- a/packages/zapp/console/src/components/Launch/LaunchForm/MapInput.tsx +++ b/packages/zapp/console/src/components/Launch/LaunchForm/MapInput.tsx @@ -1,12 +1,12 @@ -import { Button, FormControl, FormHelperText, IconButton, TextField } from '@material-ui/core'; +import { Button, IconButton, TextField } from '@material-ui/core'; import { makeStyles, Theme } from '@material-ui/core/styles'; import * as React from 'react'; import RemoveIcon from '@material-ui/icons/Remove'; import Card from '@material-ui/core/Card'; import CardContent from '@material-ui/core/CardContent'; import { requiredInputSuffix } from './constants'; -import { InputProps, InputType, InputTypeDefinition, InputValue } from './types'; -import { formatType, getLaunchInputId, parseMappedTypeValue, toMappedTypeValue } from './utils'; +import { InputProps, InputType, InputTypeDefinition } from './types'; +import { formatType, toMappedTypeValue } from './utils'; const useStyles = makeStyles((theme: Theme) => ({ formControl: { @@ -17,7 +17,7 @@ const useStyles = makeStyles((theme: Theme) => ({ margin: theme.spacing(1), width: '100%', display: 'flex', - alignItems: 'center', + alignItems: 'flex-start', flexDirection: 'row', }, keyControl: { @@ -95,10 +95,7 @@ const MapSingleInputItem = (props: MapInputItemProps) => { export const MapInput = (props: InputProps) => { const { - error, - name, onChange, - value = '', typeDefinition: { subtype }, } = props; const classes = useStyles(); @@ -194,112 +191,3 @@ export const MapInput = (props: InputProps) => { ); }; - -// /** Handles rendering of the input component for any primitive-type input */ -// export const MapInput: React.FC = (props) => { -// const { -// error, -// name, -// onChange, -// value = '', -// typeDefinition: { subtype }, -// } = props; -// const hasError = !!error; -// const classes = useStyles(); -// const [keyRefs, setKeyRefs] = React.useState([]); - -// const [pairs, setPairs] = React.useState< -// { -// key: string; -// value: string; -// }[] -// >([]); -// const parsed = parseMappedTypeValue(value); -// React.useEffect(() => { -// setPairs(parsed); -// }, [value]); - -// const valueError = error?.startsWith("Value's value"); - -// const onAddItem = React.useCallback(() => { -// setKeyRefs((refs) => [...refs, null]); -// setPairs((pairs) => [...pairs, { key: '', value: '' }]); -// }, []); - -// const onDeleteItem = React.useCallback((index) => { -// setKeyRefs((refs) => [...refs.slice(0, index), ...refs.slice(index + 1)]); -// setPairs((pairs) => [...pairs.slice(0, index), ...pairs.slice(index + 1)]); -// }, []); - -// const onUpdate = (newPairs) => { -// const newValue = toMappedTypeValue(newPairs); -// setPairs(parseMappedTypeValue(newValue as InputValue)); -// onChange(newValue); -// }; - -// return ( -// -// -// {props.helperText} -// {pairs.map(({ key: itemKey, value: itemValue }, index) => { -// const keyControl = ( -// (keyRefs[index] = ref)} -// onBlur={() => { -// onUpdate([ -// ...pairs.slice(0, index), -// { key: keyRefs[index].value, value: itemValue }, -// ...pairs.slice(index + 1), -// ]); -// }} -// defaultValue={itemKey} -// variant="outlined" -// className={classes.keyControl} -// /> -// ); - -// const isOneLineType = -// subtype?.type === InputType.String || subtype?.type === InputType.Integer; -// const valueControl = ( -// ) => { -// onUpdate([ -// ...pairs.slice(0, index), -// { key: itemKey, value: e.target.value ?? '' }, -// ...pairs.slice(index + 1), -// ]); -// }} -// value={itemValue} -// variant="outlined" -// className={classes.valueControl} -// multiline={!isOneLineType} -// type={subtype?.type === InputType.Integer ? 'number' : 'text'} -// /> -// ); - -// return ( -// -//
-// {keyControl} -// {valueControl} -// onDeleteItem(index)}> -// -// -//
-//
-// ); -// })} -//
-// -//
-// {hasError && ( -// {error} -// )} -//
-//
-// ); -// };