Skip to content

Commit

Permalink
fix: allow role specification for single task executions (#119)
Browse files Browse the repository at this point in the history
* feat: checkpoint for adding role input

* feat: adds role input for single task execution

* test: add tests for role inputs and no inputs case

* fix: pass authRole when relaunching single task executions

* chore: remove unused code
  • Loading branch information
schottra authored Nov 16, 2020
1 parent be2b257 commit 1ba0e01
Show file tree
Hide file tree
Showing 23 changed files with 746 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function useRelaunchTaskFormState({ execution }: RelaunchExecutionFormProps) {
defaultValue: {} as TaskInitialLaunchParameters,
doFetch: async execution => {
const {
spec: { launchPlan: taskId }
spec: { authRole, launchPlan: taskId }
} = execution;
const task = await apiContext.getTask(taskId);
const inputDefinitions = getTaskInputs(task);
Expand All @@ -73,7 +73,7 @@ function useRelaunchTaskFormState({ execution }: RelaunchExecutionFormProps) {
},
apiContext
);
return { values, taskId };
return { authRole, values, taskId };
}
},
execution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
createInputCacheKey,
getInputDefintionForLiteralType
} from 'components/Launch/LaunchForm/utils';
import { Admin } from 'flyteidl';
import {
Execution,
ExecutionData,
Expand Down Expand Up @@ -191,8 +192,13 @@ describe('RelaunchExecutionForm', () => {

describe('with single task execution', () => {
let values: LiteralValueMap;
let authRole: Admin.IAuthRole;
beforeEach(() => {
authRole = {
assumableIamRole: 'arn:aws:iam::12345678:role/defaultrole'
};
execution.spec.launchPlan.resourceType = ResourceType.TASK;
execution.spec.authRole = { ...authRole };
taskInputDefinitions = {
taskSimpleString: mockSimpleVariables.simpleString,
taskSimpleInteger: mockSimpleVariables.simpleInteger
Expand Down Expand Up @@ -224,6 +230,17 @@ describe('RelaunchExecutionForm', () => {
});
});

it('passes authRole from original execution', async () => {
const { getByText } = renderForm();
await waitFor(() => getByText(mockContentString));

checkLaunchFormProps({
initialParameters: expect.objectContaining({
authRole
})
});
});

it('maps execution input values to workflow inputs', async () => {
const { getByText } = renderForm();
await waitFor(() => getByText(mockContentString));
Expand Down
11 changes: 3 additions & 8 deletions src/components/Launch/LaunchForm/CollectionInput.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import { TextField } from '@material-ui/core';
import * as React from 'react';
import { InputChangeHandler, InputProps, InputType } from './types';
import { makeStringChangeHandler } from './handlers';
import { InputProps, InputType } from './types';
import { UnsupportedInput } from './UnsupportedInput';
import { getLaunchInputId } from './utils';

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 {
Expand Down Expand Up @@ -49,7 +44,7 @@ export const CollectionInput: React.FC<InputProps> = props => {
fullWidth={true}
label={label}
multiline={true}
onChange={stringChangeHandler(onChange)}
onChange={makeStringChangeHandler(onChange)}
rowsMax={8}
value={value}
variant="outlined"
Expand Down
54 changes: 33 additions & 21 deletions src/components/Launch/LaunchForm/LaunchFormInputs.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Typography } from '@material-ui/core';
import * as React from 'react';
import { BlobInput } from './BlobInput';
import { CollectionInput } from './CollectionInput';
import { formStrings } from './constants';
import { formStrings, inputsDescription } from './constants';
import { LaunchState } from './launchMachine';
import { NoInputsNeeded } from './NoInputsNeeded';
import { SimpleInput } from './SimpleInput';
import { StructInput } from './StructInput';
import { useStyles } from './styles';
Expand All @@ -15,6 +17,7 @@ import {
import { UnsupportedInput } from './UnsupportedInput';
import { UnsupportedRequiredInputsError } from './UnsupportedRequiredInputsError';
import { useFormInputsState } from './useFormInputsState';
import { isEnterInputsState } from './utils';

function getComponentForInput(input: InputProps, showErrors: boolean) {
const props = { ...input, error: showErrors ? input.error : undefined };
Expand All @@ -39,6 +42,29 @@ export interface LaunchFormInputsProps {
variant: 'workflow' | 'task';
}

const RenderFormInputs: React.FC<{
inputs: InputProps[];
showErrors: boolean;
variant: LaunchFormInputsProps['variant'];
}> = ({ inputs, showErrors, variant }) => {
const styles = useStyles();
return inputs.length === 0 ? (
<NoInputsNeeded variant={variant} />
) : (
<>
<header className={styles.sectionHeader}>
<Typography variant="h6">{formStrings.inputs}</Typography>
<Typography variant="body2">{inputsDescription}</Typography>
</header>
{inputs.map(input => (
<div key={input.label} className={styles.formControl}>
{getComponentForInput(input, showErrors)}
</div>
))}
</>
);
};

export const LaunchFormInputsImpl: React.RefForwardingComponent<
LaunchFormInputsRef,
LaunchFormInputsProps
Expand All @@ -49,38 +75,24 @@ export const LaunchFormInputsImpl: React.RefForwardingComponent<
showErrors
} = state.context;
const { getValues, inputs, validate } = useFormInputsState(parsedInputs);
const styles = useStyles();
React.useImperativeHandle(ref, () => ({
getValues,
validate
}));

const showInputs = [
LaunchState.UNSUPPORTED_INPUTS,
LaunchState.ENTER_INPUTS,
LaunchState.VALIDATING_INPUTS,
LaunchState.INVALID_INPUTS,
LaunchState.SUBMIT_VALIDATING,
LaunchState.SUBMITTING,
LaunchState.SUBMIT_FAILED,
LaunchState.SUBMIT_SUCCEEDED
].some(state.matches);

return showInputs ? (
return isEnterInputsState(state) ? (
<section title={formStrings.inputs}>
{state.matches(LaunchState.UNSUPPORTED_INPUTS) ? (
<UnsupportedRequiredInputsError
inputs={unsupportedRequiredInputs}
variant={variant}
/>
) : (
<>
{inputs.map(input => (
<div key={input.label} className={styles.formControl}>
{getComponentForInput(input, showErrors)}
</div>
))}
</>
<RenderFormInputs
inputs={inputs}
showErrors={showErrors}
variant={variant}
/>
)}
</section>
) : null;
Expand Down
Loading

0 comments on commit 1ba0e01

Please sign in to comment.