Skip to content

Commit

Permalink
fix: optional list arg is causing ui launch form to white screen (#817)
Browse files Browse the repository at this point in the history
Signed-off-by: Carina Ursu <[email protected]>
  • Loading branch information
ursucarina authored Sep 19, 2023
1 parent a4348d8 commit 48f006d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ function fromLiteral(literal: Core.ILiteral): InputValue {
return extractLiteralWithCheck<Long>(
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 } },
};
}

Expand Down Expand Up @@ -46,6 +48,6 @@ export const integerHelper: InputHelper = {
toLiteral,
validate,
typeDefinitionToDefaultValue: typeDefinition => {
return '';
return undefined as any;
},
};

0 comments on commit 48f006d

Please sign in to comment.