-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Collections in the launch UI #30
Conversation
…n JSON.parse is used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good -- only had a few questions, possibly because I've never used the lossless-json
library before.
fullWidth={true} | ||
label={label} | ||
multiline={true} | ||
onChange={stringChangeHandler(onChange)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does the input value to stringChangeHandler
here get defined? Is it recursively referencing the onChange
handler of the TextField
? So, x = stringChangeHandler(x)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stringChangeHandler
generates an event handler that will forward the value received to its argument. So in this case, the prop value ends up looking like:
onChange = ({ target: { value } }) => props.onChange(value); // props here are the props to CollectionInput
function booleanToLiteral(value: string): Core.ILiteral { | ||
return { scalar: { primitive: { boolean: Boolean(value) } } }; | ||
function losslessReviver(key: string, value: any) { | ||
if (value && value.isLosslessNumber) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this handle a value of 0
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see why you're asking (0 is falsey). Your intuition is correct, but it should be fine in this case, as the behavior is just to return value
directly. That would result in a number
and is the desired behavior.
flyteorg/flyte#22
(This is being opened against a feature branch. I would like to add some more handling of errors and mapping to the fields in the form before merging this to master)
Collections are a list of Literal values which all have the same type. The inner type of a Collection may be another Collection, making nesting possible.
Our initial support for collections will require users to enter values as a valid string of JSON, which we will parse into native JS(ON) types (string, number, boolean) and then convert to the appropriate
Literal
type based on the type of the collection. It's a little clunky, but easy to validate and uses a well-known standard.Some important points:
lossless-json
for the parsing because it preserves integers that would otherwise overflow and gives us the ability to directly convert them toLong
s (which are used in our protobuf message classes to handle int64s).0, 1, '0', '1', true, false, 'true', 'false', 't', 'f'
)""
). This differs from entering single string values, which do not require quotes.I also made some changes to the input conversion functions:
InputValue
instead of being explicitlytoString
-ed beforehand. This puts the responsibility on the conversion function for converting to a string if necessaryAnd I also added a lot of test cases to cover all of the expected variations for values to be parsed, collections of those value types, and singly-nested collections of those value types.