From 48f006d9f1f271ff90b79ff7bb7e9b8a178a0de5 Mon Sep 17 00:00:00 2001 From: Carina Ursu Date: Tue, 19 Sep 2023 10:24:30 -0700 Subject: [PATCH] fix: optional list arg is causing ui launch form to white screen (#817) Signed-off-by: Carina Ursu --- .../LaunchForm/inputHelpers/collection.ts | 26 +++++++++++-------- .../Launch/LaunchForm/inputHelpers/integer.ts | 12 +++++---- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/packages/console/src/components/Launch/LaunchForm/inputHelpers/collection.ts b/packages/console/src/components/Launch/LaunchForm/inputHelpers/collection.ts index 716c926b7..16ea3a40d 100644 --- a/packages/console/src/components/Launch/LaunchForm/inputHelpers/collection.ts +++ b/packages/console/src/components/Launch/LaunchForm/inputHelpers/collection.ts @@ -27,14 +27,9 @@ function fromLiteral( if (!literal.collection) { throw new Error('Collection literal missing `collection` property'); } - if (!literal.collection.literals) { - throw new Error( - 'Collection literal missing `collection.literals` property', - ); - } const subTypeHelper = getHelperForInput(subtype.type); - const values = literal.collection.literals.map(literal => { + const values = literal.collection?.literals?.map?.(literal => { let temp = subTypeHelper.fromLiteral(literal, subtype); try { // JSON.parse corrupts large numbers, so we must use lossless json parsing @@ -128,14 +123,23 @@ export const collectionHelper: InputHelper = { const subDefaultValue = subtypeHelper.typeDefinitionToDefaultValue( subtype!, ); - const subLiteral = subtypeHelper.toLiteral({ - value: subDefaultValue, - typeDefinition: subtype!, - }); + let literalArray: Core.ILiteral[] | undefined; + if ( + subDefaultValue !== undefined && + subDefaultValue !== null && + subDefaultValue !== '' + ) { + const subLiteral = subtypeHelper.toLiteral({ + value: subDefaultValue, + typeDefinition: subtype!, + }); + literalArray = [subLiteral]; + } + return fromLiteral( { collection: { - literals: [subLiteral], + literals: literalArray, }, }, { subtype: subtype! } as any, diff --git a/packages/console/src/components/Launch/LaunchForm/inputHelpers/integer.ts b/packages/console/src/components/Launch/LaunchForm/inputHelpers/integer.ts index 11812a030..ea35e93a0 100644 --- a/packages/console/src/components/Launch/LaunchForm/inputHelpers/integer.ts +++ b/packages/console/src/components/Launch/LaunchForm/inputHelpers/integer.ts @@ -11,14 +11,16 @@ function fromLiteral(literal: Core.ILiteral): InputValue { return extractLiteralWithCheck( literal, primitiveLiteralPaths.scalarInteger, - ).toString(); + )?.toString(); } function toLiteral({ value }: ConverterInput): Core.ILiteral { - const integer = - value instanceof Long ? value : Long.fromString(value.toString()); + const integerValue = + value === undefined || value instanceof Long + ? value + : Long.fromString(value.toString()); return { - scalar: { primitive: { integer } }, + scalar: { primitive: { integer: integerValue } }, }; } @@ -46,6 +48,6 @@ export const integerHelper: InputHelper = { toLiteral, validate, typeDefinitionToDefaultValue: typeDefinition => { - return ''; + return undefined as any; }, };