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

Add REJECT support for ApprovedCondition for GateNodes #733

Merged
merged 3 commits into from
Mar 28, 2023
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 @@ -15,6 +15,7 @@ export interface LaunchFormActionsProps {
onClose(): void;
isError: boolean;
submitTitle: string;
rejectTitle?: string;
}
/** Renders the Submit/Cancel buttons for a LaunchForm */
export const LaunchFormActions: React.FC<LaunchFormActionsProps> = ({
Expand All @@ -23,6 +24,7 @@ export const LaunchFormActions: React.FC<LaunchFormActionsProps> = ({
onClose,
isError,
submitTitle,
rejectTitle,
}) => {
const styles = useStyles();
const submissionInFlight = state.matches(LaunchState.SUBMITTING);
Expand All @@ -35,6 +37,13 @@ export const LaunchFormActions: React.FC<LaunchFormActionsProps> = ({

const submit: React.FormEventHandler = event => {
event.preventDefault();
service.send({ type: 'SELECT_REJECT', value: false });
service.send({ type: 'SUBMIT' });
};

const reject: React.FormEventHandler = event => {
event.preventDefault();
service.send({ type: 'SELECT_REJECT', value: true });
service.send({ type: 'SUBMIT' });
};

Expand Down Expand Up @@ -99,6 +108,19 @@ export const LaunchFormActions: React.FC<LaunchFormActionsProps> = ({
>
{t('cancel')}
</Button>
{rejectTitle && (
<Button
color="primary"
disabled={!canSubmit || isError}
id="launch-workflow-reject"
onClick={reject}
type="submit"
variant="outlined"
>
{rejectTitle}
{submissionInFlight && <ButtonCircularProgress />}
</Button>
)}
<Button
color="primary"
disabled={!canSubmit || isError}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,16 @@ export const ResumeSignalForm: React.FC<ResumeSignalFormProps> = ({
service={baseService}
onClose={onClose}
isError={isError}
submitTitle={launchFormStrings('resume')}
submitTitle={
compiledNode.gateNode?.approve?.signalId
? launchFormStrings('approve')
: launchFormStrings('resume')
}
rejectTitle={
compiledNode.gateNode?.approve?.signalId
? launchFormStrings('reject')
: null
}
/>
</>
);
Expand Down
18 changes: 16 additions & 2 deletions packages/console/src/components/Launch/LaunchForm/launchMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export type SelectLaunchPlanEvent = {
type: 'SELECT_LAUNCH_PLAN';
launchPlan: LaunchPlan;
};
export type SelectRejectEvent = {
type: 'SELECT_REJECT';
value: boolean;
};
export type WorkflowVersionOptionsLoadedEvent = DoneInvokeEvent<Workflow[]>;
export type LaunchPlanOptionsLoadedEvent = DoneInvokeEvent<LaunchPlan[]>;
export type TaskVersionOptionsLoadedEvent = DoneInvokeEvent<Task[]>;
Expand All @@ -49,7 +53,8 @@ export type BaseLaunchEvent =
| SelectTaskVersionEvent
| SelectLaunchPlanEvent
| ExecutionCreatedEvent
| ErrorEvent;
| ErrorEvent
| SelectRejectEvent;

export type TaskLaunchEvent =
| BaseLaunchEvent
Expand All @@ -71,6 +76,7 @@ export interface BaseLaunchContext {
showErrors: boolean;
referenceExecutionId?: WorkflowExecutionIdentifier;
unsupportedRequiredInputs: ParsedInput[];
reject?: boolean;
}

export interface WorkflowLaunchContext extends BaseLaunchContext {
Expand Down Expand Up @@ -402,7 +408,12 @@ export const taskResumeMachineConfig: MachineConfig<
id: 'resumeTask',
initial: LaunchState.LOADING_INPUTS,
context: { ...defaultBaseContext },
on: defaultHandlers,
on: {
...defaultHandlers,
SELECT_REJECT: {
actions: ['selectReject'],
},
},
states: {
...(baseStateConfig as StatesConfig<
TaskResumeContext,
Expand Down Expand Up @@ -502,6 +513,9 @@ const baseActions: BaseMachineOptions['actions'] = {
error: (event as ErrorEvent).data,
})),
showErrors: assign(_ => ({ showErrors: true })),
selectReject: assign((_, event) => ({
reject: (event as SelectRejectEvent).value,
})),
};

const baseServices: BaseMachineOptions['services'] = {
Expand Down
2 changes: 2 additions & 0 deletions packages/console/src/components/Launch/LaunchForm/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const str = {
role: 'Role',
submit: 'Launch',
resume: 'Resume',
approve: 'Approve',
reject: 'Reject',
taskVersion: 'Task Version',
title: 'Create New Execution',
resumeTitle: 'Resume Paused Execution',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { useMachine } from '@xstate/react';
import { defaultStateMachineConfig } from 'components/common/constants';
import { APIContextValue, useAPIContext } from 'components/data/apiContext';
import { partial } from 'lodash';
import { SimpleType } from 'models/Common/types';
import { NodeExecutionIdentifier } from 'models/Execution/types';
import { CompiledNode } from 'models/Node/types';
import { RefObject, useMemo, useRef } from 'react';
Expand Down Expand Up @@ -72,7 +71,7 @@ async function validate(formInputsRef: RefObject<LaunchFormInputsRef>) {
async function submit(
{ resumeSignalNode }: APIContextValue,
formInputsRef: RefObject<LaunchFormInputsRef>,
{ compiledNode, nodeExecutionId }: TaskResumeContext,
{ compiledNode, nodeExecutionId, reject }: TaskResumeContext,
) {
const signalId =
compiledNode?.gateNode?.signal?.signalId ||
Expand All @@ -93,7 +92,7 @@ async function submit(
executionId: nodeExecutionId?.executionId,
},
value: isApprovedCondition
? { scalar: { primitive: { boolean: true } } }
? { scalar: { primitive: { boolean: !reject } } }
: literals['signal'],
});

Expand Down