Skip to content

Commit

Permalink
Fix: Launch Form fixes (#798)
Browse files Browse the repository at this point in the history
* chore: launch form bug bash fixes

Signed-off-by: Carina Ursu <carina@union.ai>

* chore: pkg bump

Signed-off-by: Carina Ursu <carina@union.ai>

---------

Signed-off-by: Carina Ursu <carina@union.ai>
  • Loading branch information
ursucarina committed Jul 19, 2023
1 parent a7ba08a commit 3d3648e
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 40 deletions.
2 changes: 1 addition & 1 deletion packages/console/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
UnionValue,
InputValue,
} from '../types';
import { formatType } from '../utils';
import { formatType, getInputDefintionForLiteralType } from '../utils';

import { getHelperForInput } from '../inputHelpers/getHelperForInput';
import {
Expand All @@ -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<InputType> => {
Expand All @@ -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];
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ export const datetimeHelper: InputHelper = {
toLiteral,
validate,
typeDefinitionToDefaultValue: typeDefinition => {
return {};
return '';
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ export const floatHelper: InputHelper = {
toLiteral,
validate,
typeDefinitionToDefaultValue: typeDefinition => {
return {};
return '';
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ export const stringHelper: InputHelper = {
toLiteral,
validate,
typeDefinitionToDefaultValue: typeDefinition => {
return { scalar: { primitive: { stringValue: '' } } };
return '';
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function validate({ value, ...props }: InputValidatorParams) {
...(value as any),
});
} catch (error) {
throw new Error('Invalid value');
throw new Error(error.message);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function extractLiteralWithCheck<T>(
/** 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 '';
}
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 3d3648e

Please sign in to comment.