-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
030d7d7
Creating story for collection input types
schottra 6ae3d69
Adding collection input component
schottra c1519d7
Refactoring input converters to handle lists correctly
schottra 4142892
Adding story for nested collections and fixing collection parsing whe…
schottra 04619c4
Tests for input conversion and some bug fixes
schottra fafaa8d
Re-arranging tests
schottra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/components/Launch/LaunchWorkflowForm/CollectionInput.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { TextField } from '@material-ui/core'; | ||
import * as React from 'react'; | ||
import { InputChangeHandler, InputProps, InputType } from './types'; | ||
import { UnsupportedInput } from './UnsupportedInput'; | ||
|
||
function stringChangeHandler(onChange: InputChangeHandler) { | ||
return ({ target: { value } }: React.ChangeEvent<HTMLInputElement>) => { | ||
onChange(value); | ||
}; | ||
} | ||
|
||
/** Handles rendering of the input component for a Collection of SimpleType values*/ | ||
export const CollectionInput: React.FC<InputProps> = props => { | ||
const { | ||
label, | ||
helperText, | ||
onChange, | ||
typeDefinition: { subtype }, | ||
value = '' | ||
} = props; | ||
if (!subtype) { | ||
console.error( | ||
'Unexpected missing subtype for collection input', | ||
props.typeDefinition | ||
); | ||
return <UnsupportedInput {...props} />; | ||
} | ||
switch (subtype.type) { | ||
case InputType.Blob: | ||
case InputType.Boolean: | ||
case InputType.Collection: | ||
case InputType.Datetime: | ||
case InputType.Duration: | ||
case InputType.Error: | ||
case InputType.Float: | ||
case InputType.Integer: | ||
case InputType.Map: | ||
case InputType.String: | ||
case InputType.Struct: | ||
return ( | ||
<TextField | ||
helperText={helperText} | ||
fullWidth={true} | ||
label={label} | ||
multiline={true} | ||
onChange={stringChangeHandler(onChange)} | ||
rowsMax={8} | ||
value={value} | ||
variant="outlined" | ||
/> | ||
); | ||
default: | ||
return <UnsupportedInput {...props} />; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 68 additions & 35 deletions
103
src/components/Launch/LaunchWorkflowForm/__stories__/LaunchWorkflowForm.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,88 @@ | ||
import { action } from '@storybook/addon-actions'; | ||
import { storiesOf } from '@storybook/react'; | ||
import { resolveAfter } from 'common/promiseUtils'; | ||
import { mockAPIContextValue } from 'components/data/__mocks__/apiContext'; | ||
import { APIContext } from 'components/data/apiContext'; | ||
import { Workflow } from 'models'; | ||
import { Admin } from 'flyteidl'; | ||
import { mapValues } from 'lodash'; | ||
import { Variable, Workflow } from 'models'; | ||
import { createMockLaunchPlan } from 'models/__mocks__/launchPlanData'; | ||
import { | ||
createMockWorkflow, | ||
createMockWorkflowClosure, | ||
createMockWorkflowVersions | ||
} from 'models/__mocks__/workflowData'; | ||
import { mockExecution } from 'models/Execution/__mocks__/mockWorkflowExecutionsData'; | ||
import * as React from 'react'; | ||
import { LaunchWorkflowForm } from '../LaunchWorkflowForm'; | ||
import { mockParameterMap, mockWorkflowInputsInterface } from './mockInputs'; | ||
import { | ||
createMockWorkflowInputsInterface, | ||
mockCollectionVariables, | ||
mockNestedCollectionVariables, | ||
mockSimpleVariables | ||
} from './mockInputs'; | ||
|
||
const mockWorkflow = createMockWorkflow('MyWorkflow'); | ||
const mockLaunchPlan = createMockLaunchPlan( | ||
mockWorkflow.id.name, | ||
mockWorkflow.id.version | ||
); | ||
const submitAction = action('createWorkflowExecution'); | ||
|
||
const mockWorkflowVersions = createMockWorkflowVersions( | ||
mockWorkflow.id.name, | ||
10 | ||
); | ||
const renderForm = (variables: Record<string, Variable>) => { | ||
const mockWorkflow = createMockWorkflow('MyWorkflow'); | ||
const mockLaunchPlan = createMockLaunchPlan( | ||
mockWorkflow.id.name, | ||
mockWorkflow.id.version | ||
); | ||
|
||
const mockWorkflowVersions = createMockWorkflowVersions( | ||
mockWorkflow.id.name, | ||
10 | ||
); | ||
|
||
mockLaunchPlan.closure!.expectedInputs = mockParameterMap; | ||
const parameterMap = { | ||
parameters: mapValues(variables, v => ({ var: v })) | ||
}; | ||
|
||
const mockApi = mockAPIContextValue({ | ||
getLaunchPlan: () => resolveAfter(500, mockLaunchPlan), | ||
getWorkflow: id => { | ||
const workflow: Workflow = { | ||
id | ||
}; | ||
workflow.closure = createMockWorkflowClosure(); | ||
workflow.closure!.compiledWorkflow!.primary.template.interface = mockWorkflowInputsInterface; | ||
mockLaunchPlan.closure!.expectedInputs = parameterMap; | ||
|
||
return resolveAfter(500, workflow); | ||
}, | ||
listWorkflows: () => resolveAfter(500, { entities: mockWorkflowVersions }), | ||
listLaunchPlans: () => resolveAfter(500, { entities: [mockLaunchPlan] }) | ||
}); | ||
const mockApi = mockAPIContextValue({ | ||
createWorkflowExecution: input => { | ||
console.log(input); | ||
submitAction('See console for data'); | ||
return Promise.reject('Not implemented'); | ||
}, | ||
getLaunchPlan: () => resolveAfter(500, mockLaunchPlan), | ||
getWorkflow: id => { | ||
const workflow: Workflow = { | ||
id | ||
}; | ||
workflow.closure = createMockWorkflowClosure(); | ||
workflow.closure!.compiledWorkflow!.primary.template.interface = createMockWorkflowInputsInterface( | ||
variables | ||
); | ||
|
||
const onClose = () => console.log('Close'); | ||
return resolveAfter(500, workflow); | ||
}, | ||
listWorkflows: () => | ||
resolveAfter(500, { entities: mockWorkflowVersions }), | ||
listLaunchPlans: () => resolveAfter(500, { entities: [mockLaunchPlan] }) | ||
}); | ||
|
||
const onClose = () => console.log('Close'); | ||
|
||
return ( | ||
<APIContext.Provider value={mockApi}> | ||
<div style={{ width: 600, height: '95vh' }}> | ||
<LaunchWorkflowForm | ||
onClose={onClose} | ||
workflowId={mockWorkflow.id} | ||
/> | ||
</div> | ||
</APIContext.Provider> | ||
); | ||
}; | ||
|
||
const stories = storiesOf('Launch/LaunchWorkflowForm', module); | ||
stories.addDecorator(story => ( | ||
<APIContext.Provider value={mockApi}> | ||
<div style={{ width: 600, height: '95vh' }}>{story()}</div> | ||
</APIContext.Provider> | ||
)); | ||
|
||
stories.add('Basic', () => ( | ||
<LaunchWorkflowForm onClose={onClose} workflowId={mockWorkflow.id} /> | ||
)); | ||
|
||
stories.add('Simple', () => renderForm(mockSimpleVariables)); | ||
stories.add('Collections', () => renderForm(mockCollectionVariables)); | ||
stories.add('Nested Collections', () => | ||
renderForm(mockNestedCollectionVariables) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 theonChange
handler of theTextField
? 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: