From 765362235e1764ab3033a993bd1f4633ddc7d4b0 Mon Sep 17 00:00:00 2001 From: amitjoshi Date: Mon, 25 Nov 2024 17:27:15 +0530 Subject: [PATCH] Refactor CreateSiteCommand and CreateSiteHelper to use structured options and improve readability; add CreateSiteTypes for better type management --- .../commands/create-site/CreateSiteCommand.ts | 14 +++---- .../commands/create-site/CreateSiteHelper.ts | 42 +++++++++++++------ .../commands/create-site/CreateSiteTypes.ts | 32 ++++++++++++++ 3 files changed, 68 insertions(+), 20 deletions(-) create mode 100644 src/common/chat-participants/powerpages/commands/create-site/CreateSiteTypes.ts diff --git a/src/common/chat-participants/powerpages/commands/create-site/CreateSiteCommand.ts b/src/common/chat-participants/powerpages/commands/create-site/CreateSiteCommand.ts index d49c6f34..f6212e79 100644 --- a/src/common/chat-participants/powerpages/commands/create-site/CreateSiteCommand.ts +++ b/src/common/chat-participants/powerpages/commands/create-site/CreateSiteCommand.ts @@ -18,18 +18,18 @@ export class CreateSiteCommand implements Command { stream.progress(NL2SITE_GENERATING_SITE); try { // eslint-disable-next-line @typescript-eslint/no-unused-vars - const result = await createSite( - intelligenceAPIEndpointInfo.intelligenceEndpoint, + const result = await createSite({ + intelligenceEndpoint: intelligenceAPIEndpointInfo.intelligenceEndpoint, intelligenceApiToken, - request.prompt, - powerPagesAgentSessionId, + userPrompt: request.prompt, + sessionId: powerPagesAgentSessionId, stream, telemetry, - orgID, - envID, + orgId: orgID, + envId: envID, userId, extensionContext - ); + }); // Process the result return { diff --git a/src/common/chat-participants/powerpages/commands/create-site/CreateSiteHelper.ts b/src/common/chat-participants/powerpages/commands/create-site/CreateSiteHelper.ts index 93f068d3..cebd6150 100644 --- a/src/common/chat-participants/powerpages/commands/create-site/CreateSiteHelper.ts +++ b/src/common/chat-participants/powerpages/commands/create-site/CreateSiteHelper.ts @@ -13,12 +13,26 @@ import { VSCODE_EXTENSION_NL2PAGE_REQUEST, VSCODE_EXTENSION_NL2SITE_REQUEST, VSC import { EditableFileSystemProvider } from '../../../../utilities/EditableFileSystemProvider'; import { HTML_FILE_EXTENSION, UTF8_ENCODING } from '../../../../constants'; import { EDITABLE_SCHEME } from './CreateSiteConstants'; - -export const createSite = async (intelligenceEndpoint: string, intelligenceApiToken: string, userPrompt: string, sessionId: string, stream: vscode.ChatResponseStream, telemetry: ITelemetry, orgId: string, envID: string, userId: string, extensionContext: vscode.ExtensionContext) => { - const { siteName, siteDescription, sitePages } = await fetchSiteAndPageData(intelligenceEndpoint, intelligenceApiToken, userPrompt, sessionId, telemetry, stream, orgId, envID, userId); +import { ICreateSiteOptions, IPreviewSitePagesContentOptions } from './CreateSiteTypes'; + +export const createSite = async (createSiteOptions: ICreateSiteOptions) => { + const { + intelligenceEndpoint, + intelligenceApiToken, + userPrompt, + sessionId, + stream, + telemetry, + orgId, + envId, + userId, + extensionContext + } = createSiteOptions; + + const { siteName, siteDescription, sitePages } = await fetchSiteAndPageData(intelligenceEndpoint, intelligenceApiToken, userPrompt, sessionId, telemetry, stream, orgId, envId, userId); // eslint-disable-next-line @typescript-eslint/no-unused-vars - const contentProvider = previewSitePagesContent(siteName, sitePages, stream, extensionContext, telemetry, sessionId, orgId, envID, userId); + const contentProvider = previewSitePagesContent({sitePages, stream, extensionContext, telemetry, sessionId, orgId, envId, userId}); // TODO: Implement the create site button click handler @@ -57,16 +71,18 @@ async function fetchSiteAndPageData(intelligenceEndpoint: string, intelligenceAp function previewSitePagesContent( - siteName: string, - sitePages: any[], - stream: vscode.ChatResponseStream, - extensionContext: vscode.ExtensionContext, - telemetry: ITelemetry, - sessionId: string, - orgId: string, - envId: string, - userId: string + options: IPreviewSitePagesContentOptions ): EditableFileSystemProvider { + const { + sitePages, + stream, + extensionContext, + telemetry, + sessionId, + orgId, + envId, + userId + } = options; const sitePagesContent: { name: string; content: string }[] = []; sitePages.forEach((page: any) => { sitePagesContent.push({ name: page.metadata.pageTitle, content: page.code }); diff --git a/src/common/chat-participants/powerpages/commands/create-site/CreateSiteTypes.ts b/src/common/chat-participants/powerpages/commands/create-site/CreateSiteTypes.ts new file mode 100644 index 00000000..505e5c5f --- /dev/null +++ b/src/common/chat-participants/powerpages/commands/create-site/CreateSiteTypes.ts @@ -0,0 +1,32 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + */ + +import { ITelemetry } from "../../../../OneDSLoggerTelemetry/telemetry/ITelemetry"; +import * as vscode from 'vscode'; + +export interface ICreateSiteOptions { + intelligenceEndpoint: string; + intelligenceApiToken: string; + userPrompt: string; + sessionId: string; + stream: vscode.ChatResponseStream; + telemetry: ITelemetry; + orgId: string; + envId: string; + userId: string; + extensionContext: vscode.ExtensionContext; +} + +export interface IPreviewSitePagesContentOptions { + // siteName: string; + sitePages: any[]; + stream: vscode.ChatResponseStream; + extensionContext: vscode.ExtensionContext; + telemetry: ITelemetry; + sessionId: string; + orgId: string; + envId: string; + userId: string; +}