Skip to content

Commit c876437

Browse files
author
Qi Kang
authored
Rename steps to actions, rename rules to conditions (#1382)
* Adaptive: rename rules to conditions * Adaptive: rename steps to actions * revert changes for componentDialog.ts, dialogContext.ts
1 parent a92ab74 commit c876437

File tree

98 files changed

+567
-567
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+567
-567
lines changed

libraries/botbuilder-dialogs-adaptive/src/steps/beginDialog.ts renamed to libraries/botbuilder-dialogs-adaptive/src/actions/beginDialog.ts

File renamed without changes.

libraries/botbuilder-dialogs-adaptive/src/steps/cancelAllDialogs.ts renamed to libraries/botbuilder-dialogs-adaptive/src/actions/cancelAllDialogs.ts

File renamed without changes.

libraries/botbuilder-dialogs-adaptive/src/steps/codeStep.ts renamed to libraries/botbuilder-dialogs-adaptive/src/actions/codeAction.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,26 @@
88
import { DialogTurnResult, DialogCommand, DialogContext } from 'botbuilder-dialogs';
99
import { SequenceContext } from '../sequenceContext';
1010

11-
export type CodeStepHandler<T extends DialogContext = SequenceContext> = (context: T, options?: object) => Promise<DialogTurnResult>;
11+
export type CodeActionHandler<T extends DialogContext = SequenceContext> = (context: T, options?: object) => Promise<DialogTurnResult>;
1212

13-
export class CodeStep<T extends DialogContext = SequenceContext> extends DialogCommand {
14-
private handler: CodeStepHandler<T>;
13+
export class CodeAction<T extends DialogContext = SequenceContext> extends DialogCommand {
14+
private handler: CodeActionHandler<T>;
1515

16-
constructor(handler: CodeStepHandler<T>);
17-
constructor(id: string, handler: CodeStepHandler<T>);
18-
constructor(idOrHandler: string|CodeStepHandler<T>, handler?: CodeStepHandler<T>) {
16+
constructor(handler: CodeActionHandler<T>);
17+
constructor(id: string, handler: CodeActionHandler<T>);
18+
constructor(idOrHandler: string|CodeActionHandler<T>, handler?: CodeActionHandler<T>) {
1919
if (typeof idOrHandler === 'function') {
2020
handler = idOrHandler;
2121
idOrHandler = undefined;
2222
}
2323
super(idOrHandler as string);
2424
this.handler = handler;
2525
}
26-
26+
2727
protected onComputeID(): string {
28-
return `codeStep[${this.hashedLabel(this.handler.toString())}]`;
28+
return `codeAction[${this.hashedLabel(this.handler.toString())}]`;
2929
}
30-
30+
3131
protected async onRunCommand(context: T, options: object): Promise<DialogTurnResult> {
3232
return await this.handler(context, options);
3333
}

libraries/botbuilder-dialogs-adaptive/src/steps/deleteProperty.ts renamed to libraries/botbuilder-dialogs-adaptive/src/actions/deleteProperty.ts

File renamed without changes.
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/**
2+
* @module botbuilder-planning
3+
*/
4+
/**
5+
* Copyright (c) Microsoft Corporation. All rights reserved.
6+
* Licensed under the MIT License.
7+
*/
8+
import { DialogCommand, DialogTurnResult, Dialog, DialogConfiguration } from 'botbuilder-dialogs';
9+
import { ActionChangeType, SequenceContext, ActionChangeList, ActionState } from '../sequenceContext';
10+
11+
export interface EditActionsConfiguration extends DialogConfiguration {
12+
/**
13+
* The type of change to make to the dialogs list of actions.
14+
*/
15+
changeType?: ActionChangeType;
16+
17+
/**
18+
* The actions to update the dialog with.
19+
*/
20+
actions?: Dialog[];
21+
22+
/**
23+
* Tags to insert actions before when [changeType](#changetype) is `ActionChangeType.insertActionsBeforeTags`.
24+
*/
25+
tags?: string[];
26+
}
27+
28+
export class EditActions extends DialogCommand {
29+
/**
30+
* The type of change to make to the dialogs list of actions.
31+
*/
32+
public changeType: ActionChangeType;
33+
34+
/**
35+
* The actions to update the dialog with.
36+
*/
37+
public actions: Dialog[];
38+
39+
/**
40+
* Tags to insert actions before when [changeType](#changetype) is `PlanChangeType.doActionsBeforeTags`.
41+
*/
42+
public tags: string[];
43+
44+
/**
45+
* Creates a new `EditActions` instance.
46+
* @param changeType The type of change to make to the dialogs list of actions.
47+
* @param actions The actions to update the dialog with.
48+
*/
49+
constructor();
50+
constructor(changeType: ActionChangeType, actions: Dialog[], tags?: string[]);
51+
constructor(changeType?: ActionChangeType, actions?: Dialog[], tags?: string[]) {
52+
super();
53+
if (changeType !== undefined) { this.changeType = changeType }
54+
if (Array.isArray(actions)) { this.actions = actions }
55+
if (Array.isArray(tags)) { this.tags = tags }
56+
}
57+
58+
protected onComputeID(): string {
59+
return `editActions[${this.hashedLabel(this.changeType)}]`;
60+
}
61+
62+
public configure(config: EditActionsConfiguration): this {
63+
return super.configure(config);
64+
}
65+
66+
public getDependencies(): Dialog[] {
67+
return this.actions;
68+
}
69+
70+
protected async onRunCommand(sequence: SequenceContext, options: object): Promise<DialogTurnResult> {
71+
// Ensure planning context and condition
72+
if (!(sequence instanceof SequenceContext)) { throw new Error(`${this.id}: should only be used within a planning or sequence dialog.`) }
73+
if (this.changeType == undefined) { throw new Error(`${this.id}: no 'changeType' specified.`) }
74+
75+
// Queue changes
76+
const changes: ActionChangeList = {
77+
changeType: this.changeType,
78+
actions: this.actions.map((action) => {
79+
return { dialogId: action.id, dialogStack: [] } as ActionState
80+
})
81+
};
82+
if (this.changeType == ActionChangeType.insertActionsBeforeTags) {
83+
changes.tags = this.tags;
84+
}
85+
sequence.queueChanges(changes);
86+
87+
return await sequence.endDialog();
88+
}
89+
}

libraries/botbuilder-dialogs-adaptive/src/steps/editArray.ts renamed to libraries/botbuilder-dialogs-adaptive/src/actions/editArray.ts

File renamed without changes.

libraries/botbuilder-dialogs-adaptive/src/steps/emitEvent.ts renamed to libraries/botbuilder-dialogs-adaptive/src/actions/emitEvent.ts

File renamed without changes.

libraries/botbuilder-dialogs-adaptive/src/steps/endDialog.ts renamed to libraries/botbuilder-dialogs-adaptive/src/actions/endDialog.ts

File renamed without changes.

libraries/botbuilder-dialogs-adaptive/src/steps/endTurn.ts renamed to libraries/botbuilder-dialogs-adaptive/src/actions/endTurn.ts

File renamed without changes.

libraries/botbuilder-dialogs-adaptive/src/steps/forEach.ts renamed to libraries/botbuilder-dialogs-adaptive/src/actions/forEach.ts

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
* Licensed under the MIT License.
77
*/
88
import { DialogCommand, DialogTurnResult, Dialog, DialogConfiguration } from 'botbuilder-dialogs';
9-
import { SequenceContext, StepChangeList, StepChangeType } from '../sequenceContext';
9+
import { SequenceContext, ActionChangeList, ActionChangeType } from '../sequenceContext';
1010
import { ExpressionPropertyValue, ExpressionProperty } from '../expressionProperty';
1111

1212
/**
13-
* Configuration info passed to a `ForEach` step.
13+
* Configuration info passed to a `ForEach` action.
1414
*/
1515
export interface ForEachConfiguration extends DialogConfiguration {
1616
/**
@@ -29,32 +29,32 @@ export interface ForEachConfiguration extends DialogConfiguration {
2929
valueProperty?: string;
3030

3131
/**
32-
* Steps to be run for each page of items.
32+
* Actions to be run for each page of items.
3333
*/
34-
steps?: Dialog[];
34+
actions?: Dialog[];
3535
}
3636

3737
/**
38-
* Executes a set of steps once for each item in an in-memory list or collection.
39-
*
38+
* Executes a set of actions once for each item in an in-memory list or collection.
39+
*
4040
* @remarks
41-
* Each iteration of the loop will store an item from the list or collection at [property](#property)
42-
* to `dialog.item`. The loop can be exited early by including either a `EndDialog` or `GotoDialog`
43-
* step.
41+
* Each iteration of the loop will store an item from the list or collection at [property](#property)
42+
* to `dialog.item`. The loop can be exited early by including either a `EndDialog` or `GotoDialog`
43+
* action.
4444
*/
4545
export class ForEach extends DialogCommand {
4646

4747
/**
4848
* Creates a new `ForEach` instance.
4949
* @param list Expression used to compute the list that should be enumerated.
50-
* @param steps Steps to be run for each page of items.
50+
* @param actions Actions to be run for each page of items.
5151
*/
5252
constructor();
53-
constructor(list: ExpressionPropertyValue<any[]|object>, steps: Dialog[]);
54-
constructor(list?: ExpressionPropertyValue<any[]|object>, steps?: Dialog[]) {
53+
constructor(list: ExpressionPropertyValue<any[]|object>, actions: Dialog[]);
54+
constructor(list?: ExpressionPropertyValue<any[]|object>, actions?: Dialog[]) {
5555
super();
5656
if (list) { this.list = new ExpressionProperty(list) }
57-
if (steps) { this.steps = steps }
57+
if (actions) { this.actions = actions }
5858
}
5959

6060
protected onComputeID(): string {
@@ -78,9 +78,9 @@ export class ForEach extends DialogCommand {
7878
public valueProperty: string = 'dialog.value';
7979

8080
/**
81-
* Steps to be run for each page of items.
81+
* Actions to be run for each page of items.
8282
*/
83-
public steps: Dialog[] = [];
83+
public actions: Dialog[] = [];
8484

8585
public configure(config: ForEachConfiguration): this {
8686
for (const key in config) {
@@ -101,7 +101,7 @@ export class ForEach extends DialogCommand {
101101
}
102102

103103
public getDependencies(): Dialog[] {
104-
return this.steps;
104+
return this.actions;
105105
}
106106

107107
protected async onRunCommand(sequence: SequenceContext, options: ForEachOptions): Promise<DialogTurnResult> {
@@ -121,18 +121,18 @@ export class ForEach extends DialogCommand {
121121
if (item !== undefined) {
122122
sequence.state.setValue(this.valueProperty, item);
123123
sequence.state.setValue(this.indexProperty, offset);
124-
const changes: StepChangeList = {
125-
changeType: StepChangeType.insertSteps,
126-
steps: []
124+
const changes: ActionChangeList = {
125+
changeType: ActionChangeType.insertActions,
126+
actions: []
127127
};
128-
this.steps.forEach((step) => changes.steps.push({ dialogStack: [], dialogId: step.id }));
128+
this.actions.forEach((action) => changes.actions.push({ dialogStack: [], dialogId: action.id }));
129129

130-
// Add a call back into forEachPage() at the end of repeated steps.
130+
// Add a call back into forEachPage() at the end of repeated actions.
131131
// - A new offset is passed in which causes the next page of results to be returned.
132-
changes.steps.push({
133-
dialogStack: [],
134-
dialogId: this.id,
135-
options: {
132+
changes.actions.push({
133+
dialogStack: [],
134+
dialogId: this.id,
135+
options: {
136136
list: list,
137137
offset: offset + 1
138138
}

0 commit comments

Comments
 (0)