diff --git a/packages/console/package.json b/packages/console/package.json index 3c04fddc6..f26799a11 100644 --- a/packages/console/package.json +++ b/packages/console/package.json @@ -1,6 +1,6 @@ { "name": "@flyteorg/console", - "version": "0.0.41", + "version": "0.0.42", "description": "Flyteconsole main app module", "main": "./dist/index.js", "module": "./lib/index.js", diff --git a/packages/console/src/components/Launch/LaunchForm/LaunchFormComponents/UnionInput.tsx b/packages/console/src/components/Launch/LaunchForm/LaunchFormComponents/UnionInput.tsx index 486721954..fe4607275 100644 --- a/packages/console/src/components/Launch/LaunchForm/LaunchFormComponents/UnionInput.tsx +++ b/packages/console/src/components/Launch/LaunchForm/LaunchFormComponents/UnionInput.tsx @@ -6,7 +6,7 @@ import { UnionValue, InputValue, } from '../types'; -import { formatType } from '../utils'; +import { formatType, getInputDefintionForLiteralType } from '../utils'; import { getHelperForInput } from '../inputHelpers/getHelperForInput'; import { @@ -30,13 +30,58 @@ const generateInputTypeToValueMap = ( if (initialInputValue && subType.type === initialType.type) { map[subType.type] = initialInputValue; } else { - map[subType.type] = { value: undefined, typeDefinition: subType }; + const subtypeHelper = getHelperForInput(subType.type); + map[subType.type] = { + value: + subtypeHelper?.typeDefinitionToDefaultValue?.(subType) || undefined, + typeDefinition: subType, + }; } return map; }, {}); return final; }; +const getInitialInputValue = (props: InputProps): UnionValue => { + const collectionHelper = getHelperForInput(InputType.Collection); + const unionHelper = getHelperForInput(props.typeDefinition.type); + + if (props.hasCollectionParent && Array.isArray(props.initialValue)) { + const collectionValues = props.initialValue.map(literal => { + const unionValue = literal.scalar.union; + + return { + value: unionValue.value, + typeDefinition: getInputDefintionForLiteralType(unionValue.type as any), + }; + }); + + const subtype = collectionValues?.[0].typeDefinition; + const value = collectionHelper.fromLiteral( + { + collection: { + literals: collectionValues.map(v => v.value), + }, + } as any, + { + subtype, + } as any, + ) as any; + + return { + value, + typeDefinition: subtype, + }; + } + + return ( + props.initialValue && + (unionHelper.fromLiteral( + props.initialValue, + props.typeDefinition, + ) as UnionValue as any) + ); +}; const generateSearchableSelectorOption = ( inputTypeDefinition: InputTypeDefinition, ): SearchableSelectorOption => { @@ -56,26 +101,15 @@ const generateListOfSearchableSelectorOptions = ( }; export const UnionInput = (props: InputProps) => { - const { - initialValue, - label, - onChange, - typeDefinition, - error, - hasCollectionParent, - } = props; + const { label, onChange, typeDefinition, error, hasCollectionParent } = props; - const { listOfSubTypes, type } = typeDefinition; + const { listOfSubTypes } = typeDefinition; if (!listOfSubTypes?.length) { return <>; } - const helper = getHelperForInput(type); - - const initialInputValue = - initialValue && - (helper.fromLiteral(initialValue, typeDefinition) as UnionValue); + const initialInputValue = getInitialInputValue(props); const initialInputTypeDefinition = initialInputValue?.typeDefinition ?? listOfSubTypes[0]; diff --git a/packages/console/src/components/Launch/LaunchForm/inputHelpers/collection.ts b/packages/console/src/components/Launch/LaunchForm/inputHelpers/collection.ts index 91a14ad0c..716c926b7 100644 --- a/packages/console/src/components/Launch/LaunchForm/inputHelpers/collection.ts +++ b/packages/console/src/components/Launch/LaunchForm/inputHelpers/collection.ts @@ -1,5 +1,5 @@ import { Core } from '@flyteorg/flyteidl-types'; -import { InputType, InputTypeDefinition } from '../types'; +import { InputTypeDefinition } from '../types'; import { literalNone } from './constants'; import { getHelperForInput } from './getHelperForInput'; import { parseJSON } from './parseJson'; diff --git a/packages/console/src/components/Launch/LaunchForm/inputHelpers/datetime.ts b/packages/console/src/components/Launch/LaunchForm/inputHelpers/datetime.ts index c6ad98b83..3732dd28f 100644 --- a/packages/console/src/components/Launch/LaunchForm/inputHelpers/datetime.ts +++ b/packages/console/src/components/Launch/LaunchForm/inputHelpers/datetime.ts @@ -39,6 +39,6 @@ export const datetimeHelper: InputHelper = { toLiteral, validate, typeDefinitionToDefaultValue: typeDefinition => { - return {}; + return ''; }, }; diff --git a/packages/console/src/components/Launch/LaunchForm/inputHelpers/float.ts b/packages/console/src/components/Launch/LaunchForm/inputHelpers/float.ts index 4ce1caca6..5cfe4b79d 100644 --- a/packages/console/src/components/Launch/LaunchForm/inputHelpers/float.ts +++ b/packages/console/src/components/Launch/LaunchForm/inputHelpers/float.ts @@ -40,6 +40,6 @@ export const floatHelper: InputHelper = { toLiteral, validate, typeDefinitionToDefaultValue: typeDefinition => { - return {}; + return ''; }, }; diff --git a/packages/console/src/components/Launch/LaunchForm/inputHelpers/string.ts b/packages/console/src/components/Launch/LaunchForm/inputHelpers/string.ts index aed0c1191..832b82e67 100644 --- a/packages/console/src/components/Launch/LaunchForm/inputHelpers/string.ts +++ b/packages/console/src/components/Launch/LaunchForm/inputHelpers/string.ts @@ -38,6 +38,6 @@ export const stringHelper: InputHelper = { toLiteral, validate, typeDefinitionToDefaultValue: typeDefinition => { - return { scalar: { primitive: { stringValue: '' } } }; + return ''; }, }; diff --git a/packages/console/src/components/Launch/LaunchForm/inputHelpers/test/inputHelpers.test.ts b/packages/console/src/components/Launch/LaunchForm/inputHelpers/test/inputHelpers.test.ts index 21cf91798..ce76aeb03 100644 --- a/packages/console/src/components/Launch/LaunchForm/inputHelpers/test/inputHelpers.test.ts +++ b/packages/console/src/components/Launch/LaunchForm/inputHelpers/test/inputHelpers.test.ts @@ -96,12 +96,12 @@ describe('literalToInputValue', () => { )}`, () => { const result = literalToInputValue(typeDefinition, input); let expectedString = output; - if ( - typeDefinition.type === InputType.Integer || - typeDefinition.type === InputType.Struct - ) { + if (typeDefinition.type === InputType.Struct) { expectedString = formatParameterValues(typeDefinition.type, output); } + if (typeDefinition.type === InputType.Integer) { + expectedString = `${output}`; + } expect(expectedString).toEqual(result); }), ); diff --git a/packages/console/src/components/Launch/LaunchForm/inputHelpers/union.ts b/packages/console/src/components/Launch/LaunchForm/inputHelpers/union.ts index db4c48a64..0d874e69a 100644 --- a/packages/console/src/components/Launch/LaunchForm/inputHelpers/union.ts +++ b/packages/console/src/components/Launch/LaunchForm/inputHelpers/union.ts @@ -93,7 +93,7 @@ function validate({ value, ...props }: InputValidatorParams) { ...(value as any), }); } catch (error) { - throw new Error('Invalid value'); + throw new Error(error.message); } } diff --git a/packages/console/src/components/Launch/LaunchForm/inputHelpers/utils.ts b/packages/console/src/components/Launch/LaunchForm/inputHelpers/utils.ts index 05101cfd1..1323a721b 100644 --- a/packages/console/src/components/Launch/LaunchForm/inputHelpers/utils.ts +++ b/packages/console/src/components/Launch/LaunchForm/inputHelpers/utils.ts @@ -20,7 +20,7 @@ export function extractLiteralWithCheck( /** Converts a value within a collection to the appropriate string * representation. Some values require additional quotes. */ -export function collectionChildToStringOld(type: InputType, value: any) { +export function collectionChildToString(type: InputType, value: any) { if (value === undefined) { return ''; } @@ -34,14 +34,9 @@ export function formatParameterValues(type: InputType, value: any) { return ''; } - return type === InputType.Integer - ? `${value}` - : JSON.stringify(value, null, type === InputType.Struct ? 2 : 0) - .split(',') - .join(', '); - // return type === (InputType.Integer || InputType.Struct) - // ? `${value}` - // : stringifyValue(value); + return JSON.stringify(value, null, type === InputType.Struct ? 2 : 0) + .split(',') + .join(', '); } /** Determines if a given input type, including all levels of nested types, is @@ -101,7 +96,7 @@ export function typeIsSupported(typeDefinition: InputTypeDefinition): boolean { } export function isKeyOfBlobDimensionality( - value: string, + value: string | number | symbol, ): value is keyof typeof BlobDimensionality { - return Object.keys(BlobDimensionality).indexOf(value) >= 0; + return Object.keys(BlobDimensionality).indexOf(value as any) >= 0; } diff --git a/website/package.json b/website/package.json index 077334bd3..4ab77cba4 100644 --- a/website/package.json +++ b/website/package.json @@ -37,7 +37,7 @@ }, "dependencies": { "@flyteorg/common": "^0.0.4", - "@flyteorg/console": "^0.0.41", + "@flyteorg/console": "^0.0.42", "long": "^4.0.0", "protobufjs": "~6.11.3", "react-ga4": "^1.4.1", diff --git a/yarn.lock b/yarn.lock index a8c134318..f719b4a77 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2020,7 +2020,7 @@ __metadata: resolution: "@flyteconsole/client-app@workspace:website" dependencies: "@flyteorg/common": ^0.0.4 - "@flyteorg/console": ^0.0.41 + "@flyteorg/console": ^0.0.42 "@types/long": ^3.0.32 long: ^4.0.0 protobufjs: ~6.11.3 @@ -2059,7 +2059,7 @@ __metadata: languageName: unknown linkType: soft -"@flyteorg/console@^0.0.41, @flyteorg/console@workspace:packages/console": +"@flyteorg/console@^0.0.42, @flyteorg/console@workspace:packages/console": version: 0.0.0-use.local resolution: "@flyteorg/console@workspace:packages/console" dependencies: