-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add Task support to Launch form (#101)
* feat: add task support in launch components * test: updating launch form tests to handle task cases * fix: remaining broken tests
- Loading branch information
Showing
26 changed files
with
1,332 additions
and
101 deletions.
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
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
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,83 @@ | ||
import { DialogContent } from '@material-ui/core'; | ||
import { getCacheKey } from 'components/Cache/utils'; | ||
import * as React from 'react'; | ||
import { formStrings } from './constants'; | ||
import { LaunchFormActions } from './LaunchFormActions'; | ||
import { LaunchFormHeader } from './LaunchFormHeader'; | ||
import { LaunchFormInputs } from './LaunchFormInputs'; | ||
import { LaunchState } from './launchMachine'; | ||
import { SearchableSelector } from './SearchableSelector'; | ||
import { useStyles } from './styles'; | ||
import { | ||
BaseInterpretedLaunchState, | ||
BaseLaunchService, | ||
LaunchTaskFormProps | ||
} from './types'; | ||
import { useLaunchTaskFormState } from './useLaunchTaskFormState'; | ||
|
||
/** Renders the form for initiating a Launch request based on a Task */ | ||
export const LaunchTaskForm: React.FC<LaunchTaskFormProps> = props => { | ||
const { | ||
formInputsRef, | ||
state, | ||
service, | ||
taskSourceSelectorState | ||
} = useLaunchTaskFormState(props); | ||
const styles = useStyles(); | ||
const baseState = state as BaseInterpretedLaunchState; | ||
const baseService = service as BaseLaunchService; | ||
|
||
// Any time the inputs change (even if it's just re-ordering), we must | ||
// change the form key so that the inputs component will re-mount. | ||
const formKey = React.useMemo<string>(() => { | ||
return getCacheKey(state.context.parsedInputs); | ||
}, [state.context.parsedInputs]); | ||
|
||
const { | ||
fetchSearchResults, | ||
onSelectTaskVersion, | ||
selectedTask, | ||
taskSelectorOptions | ||
} = taskSourceSelectorState; | ||
|
||
const showTaskSelector = ![ | ||
LaunchState.LOADING_TASK_VERSIONS, | ||
LaunchState.FAILED_LOADING_TASK_VERSIONS | ||
].some(state.matches); | ||
|
||
// TODO: We removed all loading indicators here. Decide if we want skeletons | ||
// instead. | ||
return ( | ||
<> | ||
<LaunchFormHeader title={state.context.sourceId?.name} /> | ||
<DialogContent dividers={true} className={styles.inputsSection}> | ||
{showTaskSelector ? ( | ||
<section | ||
title={formStrings.taskVersion} | ||
className={styles.formControl} | ||
> | ||
<SearchableSelector | ||
id="launch-task-selector" | ||
label={formStrings.taskVersion} | ||
onSelectionChanged={onSelectTaskVersion} | ||
options={taskSelectorOptions} | ||
fetchSearchResults={fetchSearchResults} | ||
selectedItem={selectedTask} | ||
/> | ||
</section> | ||
) : null} | ||
<LaunchFormInputs | ||
key={formKey} | ||
ref={formInputsRef} | ||
state={baseState} | ||
variant="task" | ||
/> | ||
</DialogContent> | ||
<LaunchFormActions | ||
state={baseState} | ||
service={baseService} | ||
onClose={props.onClose} | ||
/> | ||
</> | ||
); | ||
}; |
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
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
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
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
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
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
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
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,18 @@ | ||
import { RefObject } from 'react'; | ||
import { WorkflowLaunchContext } from './launchMachine'; | ||
import { LaunchFormInputsRef } from './types'; | ||
|
||
export async function validate( | ||
formInputsRef: RefObject<LaunchFormInputsRef>, | ||
{}: WorkflowLaunchContext | ||
) { | ||
if (formInputsRef.current === null) { | ||
throw new Error('Unexpected empty form inputs ref'); | ||
} | ||
|
||
if (!formInputsRef.current.validate()) { | ||
throw new Error( | ||
'Some inputs have errors. Please correct them before submitting.' | ||
); | ||
} | ||
} |
Oops, something went wrong.