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

refactor(fx-core): split scaffold question models #12852

Draft
wants to merge 12 commits into
base: dev
Choose a base branch
from
5 changes: 5 additions & 0 deletions packages/api/src/qm/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ export interface SingleSelectQuestion extends UserInputQuestion {
* whether to skip validation against allowed list in non-interactive mode, default false
*/
skipValidation?: boolean;

/**
* callback function which is triggered when the value is selected
*/
onDidSelection?: (itemOrId: string | OptionItem, inputs: Inputs) => Promise<void> | void;
}

/**
Expand Down
5 changes: 5 additions & 0 deletions packages/api/src/qm/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@ export interface InputResult<T> {
* answer value
*/
result?: T;

/**
* resolved option list
*/
options?: StaticOptions;
}

export type ConfirmResult = InputResult<boolean>;
Expand Down
14 changes: 9 additions & 5 deletions packages/cli/src/userInteraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,12 @@
if (config.options.length === 1 && config.skipSingleOption) {
const answer = (config.options as StaticOptions)[0];
if (config.returnObject) {
return ok({ type: "skip", result: answer });
return ok({ type: "skip", result: answer, options: config.options as StaticOptions });
} else {
if (typeof answer === "string") {
return ok({ type: "skip", result: answer });
return ok({ type: "skip", result: answer, options: config.options as StaticOptions });
} else {
return ok({ type: "skip", result: answer.id });
return ok({ type: "skip", result: answer.id, options: config.options as StaticOptions });
}
}
}
Expand Down Expand Up @@ -310,9 +310,13 @@
return ok({ type: "success", result: answer });
} else {
if (typeof answer === "string") {
return ok({ type: "success", result: answer });
return ok({ type: "success", result: answer, options: config.options as StaticOptions });

Check warning on line 313 in packages/cli/src/userInteraction.ts

View check run for this annotation

Codecov / codecov/patch

packages/cli/src/userInteraction.ts#L313

Added line #L313 was not covered by tests
} else {
return ok({ type: "success", result: answer.id });
return ok({
type: "success",
result: answer.id,
options: config.options as StaticOptions,
});
}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,27 @@
FxError,
GeneratorResult,
IGenerator,
IQTreeNode,
Inputs,
Result,
err,
ok,
} from "@microsoft/teamsfx-api";
import { merge } from "lodash";
import { getLocalizedString } from "../../../common/localizeUtils";
import { TelemetryEvent, TelemetryProperty } from "../../../common/telemetry";
import { CapabilityOptions, ProgrammingLanguage, QuestionNames } from "../../../question/constants";
import { botTriggerQuestion, meArchitectureQuestion } from "../../../question/create";
import { ProgressMessages, ProgressTitles } from "../../messages";
import { ActionContext, ActionExecutionMW } from "../../middleware/actionExecutionMW";
import { commonTemplateName, componentName } from "../constant";
import { ProgrammingLanguage, QuestionNames } from "../../../question/constants";
import { Generator, templateDefaultOnActionError } from "../generator";
import { convertToLangKey, renderTemplateFileData, renderTemplateFileName } from "../utils";
import { merge } from "lodash";
import { GeneratorContext, TemplateActionSeq } from "../generatorAction";
import { convertToLangKey, renderTemplateFileData, renderTemplateFileName } from "../utils";
import { TemplateInfo } from "./templateInfo";
import { getTemplateName, tryGetTemplateName } from "./templateNames";
import { getTemplateReplaceMap } from "./templateReplaceMap";
import { Templates } from "../../../question/templates";

export class DefaultTemplateGenerator implements IGenerator {
// override this property to send telemetry event with different component name
Expand Down Expand Up @@ -124,4 +128,49 @@
[TelemetryProperty.Fallback]: generatorContext.fallback ? "true" : "false", // Track fallback cases.
});
}

public getQuestionNode(): IQTreeNode {
return {

Check warning on line 133 in packages/fx-core/src/component/generator/templates/templateGenerator.ts

View check run for this annotation

Codecov / codecov/patch

packages/fx-core/src/component/generator/templates/templateGenerator.ts#L132-L133

Added lines #L132 - L133 were not covered by tests
data: {
type: "group",
},
children: [
{
// Notification bot trigger sub-tree
condition: (input: Inputs) =>
input[QuestionNames.Capabilities] === CapabilityOptions.notificationBot().id,

Check warning on line 141 in packages/fx-core/src/component/generator/templates/templateGenerator.ts

View check run for this annotation

Codecov / codecov/patch

packages/fx-core/src/component/generator/templates/templateGenerator.ts#L140-L141

Added lines #L140 - L141 were not covered by tests
data: botTriggerQuestion(),
},
{
// Search ME sub-tree
condition: (input: Inputs) =>
input[QuestionNames.Capabilities] === CapabilityOptions.m365SearchMe().id,

Check warning on line 147 in packages/fx-core/src/component/generator/templates/templateGenerator.ts

View check run for this annotation

Codecov / codecov/patch

packages/fx-core/src/component/generator/templates/templateGenerator.ts#L146-L147

Added lines #L146 - L147 were not covered by tests
data: meArchitectureQuestion(),
},
{
data: {
type: "singleSelect",
title: getLocalizedString("core.ProgrammingLanguageQuestion.title"),
name: QuestionNames.ProgrammingLanguage,
staticOptions: [
{ id: ProgrammingLanguage.JS, label: "JavaScript" },
{ id: ProgrammingLanguage.TS, label: "TypeScript" },
{ id: ProgrammingLanguage.CSharp, label: "C#" },
{ id: ProgrammingLanguage.PY, label: "Python" },
],
dynamicOptions: (inputs: Inputs) => {
const templateName = inputs[QuestionNames.TemplateName]; //inputs[QuestionNames.Capabilities];
const languages = Templates.filter((t) => t.name === templateName).map(
(t) => t.language

Check warning on line 164 in packages/fx-core/src/component/generator/templates/templateGenerator.ts

View check run for this annotation

Codecov / codecov/patch

packages/fx-core/src/component/generator/templates/templateGenerator.ts#L161-L164

Added lines #L161 - L164 were not covered by tests
);
return languages;

Check warning on line 166 in packages/fx-core/src/component/generator/templates/templateGenerator.ts

View check run for this annotation

Codecov / codecov/patch

packages/fx-core/src/component/generator/templates/templateGenerator.ts#L166

Added line #L166 was not covered by tests
},
skipSingleOption: true,
},
},
],
};
}
}

export const defaultGenerator = new DefaultTemplateGenerator();
6 changes: 4 additions & 2 deletions packages/fx-core/src/question/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ export enum QuestionNames {
ImportPlugin = "import-plugin",
PluginManifestFilePath = "plugin-manifest-path",
PluginOpenApiSpecFilePath = "plugin-opeanapi-spec-path",

TemplateName = "template-name",
}

export const AppNamePattern =
Expand Down Expand Up @@ -917,9 +919,9 @@ export const NotificationTriggers = {
TIMER: "timer",
} as const;

type NotificationTrigger = typeof NotificationTriggers[keyof typeof NotificationTriggers];
export type NotificationTrigger = typeof NotificationTriggers[keyof typeof NotificationTriggers];

interface HostTypeTriggerOptionItem extends OptionItem {
export interface HostTypeTriggerOptionItem extends OptionItem {
hostType: HostType;
triggers?: NotificationTrigger[];
}
Expand Down
2 changes: 1 addition & 1 deletion packages/fx-core/src/question/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ export function meArchitectureQuestion(): SingleSelectQuestion {
};
}

function botTriggerQuestion(): SingleSelectQuestion {
export function botTriggerQuestion(): SingleSelectQuestion {
return {
name: QuestionNames.BotTrigger,
title: getLocalizedString("plugins.bot.questionHostTypeTrigger.title"),
Expand Down
Loading
Loading