Skip to content

Commit

Permalink
Add feedback from Kaizen
Browse files Browse the repository at this point in the history
  • Loading branch information
msambol committed Sep 5, 2023
1 parent be8f01e commit 2f80151
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ const choice = new sfn.Choice(stack, 'choice', {

const success = new sfn.Succeed(stack, 'success');

choice.when(sfn.Condition.isPresent('$.success'), success, 'this is a comment for the when condition');
choice.when(sfn.Condition.isPresent('$.success'), success, {
comment: 'this is a comment for the when condition',
});
choice.when(sfn.Condition.isPresent('$.noComment'), shortWait);
choice.otherwise(success);
wait.next(choice);
Expand Down
4 changes: 3 additions & 1 deletion packages/aws-cdk-lib/aws-stepfunctions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,9 @@ const choice = new sfn.Choice(this, 'What color is it?', {
});
const handleBlueItem = new sfn.Pass(this, 'HandleBlueItem');
const handleOtherItemColor = new sfn.Pass(this, 'HanldeOtherItemColor');
choice.when(sfn.Condition.stringEquals('$.color', 'BLUE'), handleBlueItem, 'blue item comment');
choice.when(sfn.Condition.stringEquals('$.color', 'BLUE'), handleBlueItem, {
comment: 'blue item comment',
});
choice.otherwise(handleOtherItemColor);
```

Expand Down
6 changes: 3 additions & 3 deletions packages/aws-cdk-lib/aws-stepfunctions/lib/states/choice.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Construct } from 'constructs';
import { StateType } from './private/state-type';
import { State } from './state';
import { ChoiceTransitionOptions, State } from './state';
import { Chain } from '../chain';
import { Condition } from '../condition';
import { IChainable, INextable } from '../types';
Expand Down Expand Up @@ -53,8 +53,8 @@ export class Choice extends State {
/**
* If the given condition matches, continue execution with the given state
*/
public when(condition: Condition, next: IChainable, comment?: string): Choice {
super.addChoice(condition, next.startState, comment);
public when(condition: Condition, next: IChainable, options: ChoiceTransitionOptions = {}): Choice {
super.addChoice(condition, next.startState, options);
return this;
}

Expand Down
13 changes: 9 additions & 4 deletions packages/aws-cdk-lib/aws-stepfunctions/lib/states/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,8 @@ export abstract class State extends Construct implements IChainable {
/**
* Add a choice branch to this state
*/
protected addChoice(condition: Condition, next: State, comment?: string) {
this.choices.push({ condition, next, comment });
protected addChoice(condition: Condition, next: State, options: ChoiceTransitionOptions) {
this.choices.push({ condition, next, ...options });
next.startState.addIncoming(this);
if (this.containingGraph) {
next.startState.bindToGraph(this.containingGraph);
Expand Down Expand Up @@ -479,7 +479,7 @@ export interface FindStateOptions {
/**
* A Choice Transition
*/
interface ChoiceTransition {
interface ChoiceTransition extends ChoiceTransitionOptions {
/**
* State to transition to
*/
Expand All @@ -489,9 +489,14 @@ interface ChoiceTransition {
* Condition for this transition
*/
condition: Condition;
}

/**
* Options for Choice Transition
*/
export interface ChoiceTransitionOptions {
/**
* An optional description for this choice transition
* An optional description for the choice transition
*
* @default No comment
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,9 @@ describe('State Machine', () => {
comment: 'nebraska',
});
const success = new sfn.Succeed(stack, 'success');
choice.when(sfn.Condition.isPresent('$.success'), success, 'london');
choice.when(sfn.Condition.isPresent('$.success'), success, {
comment: 'london',
});
choice.otherwise(success);

// WHEN
Expand Down

0 comments on commit 2f80151

Please sign in to comment.