Skip to content
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

fix: allow role specification for single task executions #119

Merged
merged 5 commits into from
Nov 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -189,8 +190,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 @@ -222,6 +228,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