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

fix: generate responses #5299

Merged
merged 4 commits into from
Dec 11, 2020
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
4 changes: 3 additions & 1 deletion Composer/packages/client/src/recoilModel/atoms/appState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,9 @@ export const formDialogGenerationProgressingState = atom({
default: false,
});

export const formDialogErrorState = atom<(Error & { kind: 'templateFetch' | 'generation' | 'deletion' }) | undefined>({
export const formDialogErrorState = atom<
(Error & { kind: 'templateFetch' | 'generation' | 'deletion'; logs?: string[] }) | undefined
>({
key: getFullyQualifiedKey('formDialogError'),
default: undefined,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export const formDialogsDispatcher = () => {
schemaId,
}),
kind: 'generation',
logs: ex.data?.logs,
});
} finally {
set(formDialogGenerationProgressingState, false);
Expand All @@ -113,8 +114,8 @@ export const formDialogsDispatcher = () => {
return;
}

await httpClient.delete(`/formDialogs/${projectId}/${dialogId}`);
await reloadProject(projectId);
const response = await httpClient.delete(`/formDialogs/${projectId}/${dialogId}`);
await reloadProject(response.data.id);
} catch (ex) {
set(formDialogErrorState, {
...ex,
Expand Down
14 changes: 9 additions & 5 deletions Composer/packages/server/src/controllers/formDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,14 @@ const generate = async (req: Request, res: Response) => {

const templatesDirs = await getTemplateDirs();

await currentProject.generateDialog(name, templatesDirs);
const updatedProject = await BotProjectService.getProjectById(projectId, user);
res.status(200).json({ id: projectId, ...updatedProject.getProject() });
const result = await currentProject.generateDialog(name, templatesDirs);

if (!result.success) {
res.status(500).json({ id: projectId, errors: result.errors });
GeoffCoxMSFT marked this conversation as resolved.
Show resolved Hide resolved
return;
}

res.status(200).json({ id: projectId });
} else {
res.status(404).json({
message: `Could not generate form dialog. Project ${projectId} not found.`,
Expand All @@ -91,8 +96,7 @@ const deleteDialog = async (req: Request, res: Response) => {
throw new Error('root dialog is not allowed to delete');
}
await currentProject.deleteFormDialog(dialogId);
const updatedProject = await BotProjectService.getProjectById(projectId, user);
res.status(200).json({ id: projectId, ...updatedProject.getProject() });
res.status(200).json({ id: projectId });
} catch (e) {
res.status(400).json({
message: e.message,
Expand Down
11 changes: 9 additions & 2 deletions Composer/packages/server/src/models/bot/botProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,15 +549,20 @@ export class BotProject implements IBotProject {
return qnaEndpointKey;
};

public async generateDialog(name: string, templateDirs?: string[]) {
public async generateDialog(name: string, templateDirs?: string[]): Promise<{ success: boolean; errors: string[] }> {
const defaultLocale = this.settings?.defaultLanguage || defaultLanguage;
const relativePath = defaultFilePath(this.name, defaultLocale, `${name}${FileExtensions.FormDialogSchema}`, {});
const schemaPath = Path.resolve(this.dir, relativePath);

const dialogPath = defaultFilePath(this.name, defaultLocale, `${name}${FileExtensions.Dialog}`, {});
const outDir = Path.dirname(Path.resolve(this.dir, dialogPath));

const errors: string[] = [];

const feedback = (type: FeedbackType, message: string): void => {
if (type == FeedbackType.error) {
errors.push(message);
}
// eslint-disable-next-line no-console
console.log(`${type} - ${message}`);
};
Expand Down Expand Up @@ -596,7 +601,7 @@ export class BotProject implements IBotProject {
// merge - if generated assets should be merged with any user customized assets
// singleton - if the generated assets should be merged into a single dialog
// feeback - a callback for status and progress and generation happens
await generate(
const success = await generate(
generateParams.schemaPath,
generateParams.prefix,
generateParams.outDir,
Expand All @@ -608,6 +613,8 @@ export class BotProject implements IBotProject {
generateParams.singleton,
generateParams.feedback
);

return { success, errors };
}

public async deleteFormDialog(dialogId: string) {
Expand Down