Skip to content

Commit

Permalink
Rename steps to actions, rename rules to conditions (#1382)
Browse files Browse the repository at this point in the history
* Adaptive: rename rules to conditions

* Adaptive: rename steps to actions

* revert changes for componentDialog.ts, dialogContext.ts
  • Loading branch information
Qi Kang authored Nov 1, 2019
1 parent a92ab74 commit c876437
Show file tree
Hide file tree
Showing 98 changed files with 567 additions and 567 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@
import { DialogTurnResult, DialogCommand, DialogContext } from 'botbuilder-dialogs';
import { SequenceContext } from '../sequenceContext';

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

export class CodeStep<T extends DialogContext = SequenceContext> extends DialogCommand {
private handler: CodeStepHandler<T>;
export class CodeAction<T extends DialogContext = SequenceContext> extends DialogCommand {
private handler: CodeActionHandler<T>;

constructor(handler: CodeStepHandler<T>);
constructor(id: string, handler: CodeStepHandler<T>);
constructor(idOrHandler: string|CodeStepHandler<T>, handler?: CodeStepHandler<T>) {
constructor(handler: CodeActionHandler<T>);
constructor(id: string, handler: CodeActionHandler<T>);
constructor(idOrHandler: string|CodeActionHandler<T>, handler?: CodeActionHandler<T>) {
if (typeof idOrHandler === 'function') {
handler = idOrHandler;
idOrHandler = undefined;
}
super(idOrHandler as string);
this.handler = handler;
}

protected onComputeID(): string {
return `codeStep[${this.hashedLabel(this.handler.toString())}]`;
return `codeAction[${this.hashedLabel(this.handler.toString())}]`;
}

protected async onRunCommand(context: T, options: object): Promise<DialogTurnResult> {
return await this.handler(context, options);
}
Expand Down
89 changes: 89 additions & 0 deletions libraries/botbuilder-dialogs-adaptive/src/actions/editActions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/**
* @module botbuilder-planning
*/
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
import { DialogCommand, DialogTurnResult, Dialog, DialogConfiguration } from 'botbuilder-dialogs';
import { ActionChangeType, SequenceContext, ActionChangeList, ActionState } from '../sequenceContext';

export interface EditActionsConfiguration extends DialogConfiguration {
/**
* The type of change to make to the dialogs list of actions.
*/
changeType?: ActionChangeType;

/**
* The actions to update the dialog with.
*/
actions?: Dialog[];

/**
* Tags to insert actions before when [changeType](#changetype) is `ActionChangeType.insertActionsBeforeTags`.
*/
tags?: string[];
}

export class EditActions extends DialogCommand {
/**
* The type of change to make to the dialogs list of actions.
*/
public changeType: ActionChangeType;

/**
* The actions to update the dialog with.
*/
public actions: Dialog[];

/**
* Tags to insert actions before when [changeType](#changetype) is `PlanChangeType.doActionsBeforeTags`.
*/
public tags: string[];

/**
* Creates a new `EditActions` instance.
* @param changeType The type of change to make to the dialogs list of actions.
* @param actions The actions to update the dialog with.
*/
constructor();
constructor(changeType: ActionChangeType, actions: Dialog[], tags?: string[]);
constructor(changeType?: ActionChangeType, actions?: Dialog[], tags?: string[]) {
super();
if (changeType !== undefined) { this.changeType = changeType }
if (Array.isArray(actions)) { this.actions = actions }
if (Array.isArray(tags)) { this.tags = tags }
}

protected onComputeID(): string {
return `editActions[${this.hashedLabel(this.changeType)}]`;
}

public configure(config: EditActionsConfiguration): this {
return super.configure(config);
}

public getDependencies(): Dialog[] {
return this.actions;
}

protected async onRunCommand(sequence: SequenceContext, options: object): Promise<DialogTurnResult> {
// Ensure planning context and condition
if (!(sequence instanceof SequenceContext)) { throw new Error(`${this.id}: should only be used within a planning or sequence dialog.`) }
if (this.changeType == undefined) { throw new Error(`${this.id}: no 'changeType' specified.`) }

// Queue changes
const changes: ActionChangeList = {
changeType: this.changeType,
actions: this.actions.map((action) => {
return { dialogId: action.id, dialogStack: [] } as ActionState
})
};
if (this.changeType == ActionChangeType.insertActionsBeforeTags) {
changes.tags = this.tags;
}
sequence.queueChanges(changes);

return await sequence.endDialog();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
* Licensed under the MIT License.
*/
import { DialogCommand, DialogTurnResult, Dialog, DialogConfiguration } from 'botbuilder-dialogs';
import { SequenceContext, StepChangeList, StepChangeType } from '../sequenceContext';
import { SequenceContext, ActionChangeList, ActionChangeType } from '../sequenceContext';
import { ExpressionPropertyValue, ExpressionProperty } from '../expressionProperty';

/**
* Configuration info passed to a `ForEach` step.
* Configuration info passed to a `ForEach` action.
*/
export interface ForEachConfiguration extends DialogConfiguration {
/**
Expand All @@ -29,32 +29,32 @@ export interface ForEachConfiguration extends DialogConfiguration {
valueProperty?: string;

/**
* Steps to be run for each page of items.
* Actions to be run for each page of items.
*/
steps?: Dialog[];
actions?: Dialog[];
}

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

/**
* Creates a new `ForEach` instance.
* @param list Expression used to compute the list that should be enumerated.
* @param steps Steps to be run for each page of items.
* @param actions Actions to be run for each page of items.
*/
constructor();
constructor(list: ExpressionPropertyValue<any[]|object>, steps: Dialog[]);
constructor(list?: ExpressionPropertyValue<any[]|object>, steps?: Dialog[]) {
constructor(list: ExpressionPropertyValue<any[]|object>, actions: Dialog[]);
constructor(list?: ExpressionPropertyValue<any[]|object>, actions?: Dialog[]) {
super();
if (list) { this.list = new ExpressionProperty(list) }
if (steps) { this.steps = steps }
if (actions) { this.actions = actions }
}

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

/**
* Steps to be run for each page of items.
* Actions to be run for each page of items.
*/
public steps: Dialog[] = [];
public actions: Dialog[] = [];

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

public getDependencies(): Dialog[] {
return this.steps;
return this.actions;
}

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

// Add a call back into forEachPage() at the end of repeated steps.
// Add a call back into forEachPage() at the end of repeated actions.
// - A new offset is passed in which causes the next page of results to be returned.
changes.steps.push({
dialogStack: [],
dialogId: this.id,
options: {
changes.actions.push({
dialogStack: [],
dialogId: this.id,
options: {
list: list,
offset: offset + 1
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
* Licensed under the MIT License.
*/
import { DialogCommand, DialogTurnResult, Dialog, DialogConfiguration } from 'botbuilder-dialogs';
import { SequenceContext, StepChangeType, StepChangeList } from '../sequenceContext';
import { SequenceContext, ActionChangeType, ActionChangeList } from '../sequenceContext';
import { ExpressionPropertyValue, ExpressionProperty } from '../expressionProperty';

/**
* Configuration info passed to a `ForEachPage` step.
* Configuration info passed to a `ForEachPage` action.
*/
export interface ForEachPageConfiguration extends DialogConfiguration {
/**
Expand All @@ -29,40 +29,40 @@ export interface ForEachPageConfiguration extends DialogConfiguration {
valueProperty?: string;

/**
* Steps to be run for each page of items.
* Actions to be run for each page of items.
*/
steps?: Dialog[];
actions?: Dialog[];
}

/**
* Executes a set of steps once for each page of results in an in-memory list or collection.
*
* Executes a set of actions once for each page of results in an in-memory list or collection.
*
* @remarks
* The list or collection at [property](#property) will be broken up into pages and stored in
* `dialog.page` for each iteration of the loop. The size of each page is determined by [maxSize](#maxsize)
* and defaults to a size of 10. The loop can be exited early by including either a `EndDialog` or
* `GotoDialog` step.
* `GotoDialog` action.
*/
export class ForEachPage extends DialogCommand {

/**
* Creates a new `ForEachPage` instance.
* @param list Expression used to compute the list that should be enumerated.
* @param pageSize (Optional) number of items per page. Defaults to a value of 10.
* @param steps Steps to be run for each page of items.
* @param actions Actions to be run for each page of items.
*/
constructor();
constructor(list: ExpressionPropertyValue<any[]|object>, steps: Dialog[]);
constructor(list: ExpressionPropertyValue<any[]|object>, pageSize: ExpressionPropertyValue<number>, steps: Dialog[]);
constructor(list?: ExpressionPropertyValue<any[]|object>, pageSizeOrSteps?: ExpressionPropertyValue<number>|Dialog[], steps?: Dialog[]) {
constructor(list: ExpressionPropertyValue<any[]|object>, actions: Dialog[]);
constructor(list: ExpressionPropertyValue<any[]|object>, pageSize: ExpressionPropertyValue<number>, actions: Dialog[]);
constructor(list?: ExpressionPropertyValue<any[]|object>, pageSizeOrActions?: ExpressionPropertyValue<number>|Dialog[], actions?: Dialog[]) {
super();
if (Array.isArray(pageSizeOrSteps)) {
steps = pageSizeOrSteps;
pageSizeOrSteps = undefined;
if (Array.isArray(pageSizeOrActions)) {
actions = pageSizeOrActions;
pageSizeOrActions = undefined;
}
if (list) { this.list = new ExpressionProperty(list) }
if (pageSizeOrSteps) { this.pageSize = new ExpressionProperty(pageSizeOrSteps as any) }
if (steps) { this.steps = steps }
if (pageSizeOrActions) { this.pageSize = new ExpressionProperty(pageSizeOrActions as any) }
if (actions) { this.actions = actions }
}

protected onComputeID(): string {
Expand All @@ -86,9 +86,9 @@ export class ForEachPage extends DialogCommand {
public valueProperty: string = 'dialog.value';

/**
* Steps to be run for each page of items.
* Actions to be run for each page of items.
*/
public steps: Dialog[] = [];
public actions: Dialog[] = [];

public configure(config: ForEachPageConfiguration): this {
for (const key in config) {
Expand All @@ -109,7 +109,7 @@ export class ForEachPage extends DialogCommand {
}

public getDependencies(): Dialog[] {
return this.steps;
return this.actions;
}

protected async onRunCommand(sequence: SequenceContext, options: ForEachPageOptions): Promise<DialogTurnResult> {
Expand All @@ -131,17 +131,17 @@ export class ForEachPage extends DialogCommand {
// Update current plan
if (page.length > 0) {
sequence.state.setValue(this.valueProperty, page);
const changes: StepChangeList = {
changeType: StepChangeType.insertSteps,
steps: []
const changes: ActionChangeList = {
changeType: ActionChangeType.insertActions,
actions: []
};
this.steps.forEach((step) => changes.steps.push({ dialogStack: [], dialogId: step.id }));
this.actions.forEach((action) => changes.actions.push({ dialogStack: [], dialogId: action.id }));
if (page.length == pageSize) {
// Add a call back into forEachPage() at the end of repeated steps.
// Add a call back into forEachPage() at the end of repeated actions.
// - A new offset is passed in which causes the next page of results to be returned.
changes.steps.push({
dialogStack: [],
dialogId: this.id,
changes.actions.push({
dialogStack: [],
dialogId: this.id,
options: {
list: list,
offset: offset + pageSize,
Expand Down
Loading

0 comments on commit c876437

Please sign in to comment.