Skip to content

Commit

Permalink
Merge pull request #5826 from microsoft/task/extension/notification-a…
Browse files Browse the repository at this point in the history
…fter-loading-api

Task: Show notification after loading api
  • Loading branch information
baywet authored Nov 28, 2024
2 parents 046b490 + 4e1e979 commit 81c0e7b
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 18 deletions.
30 changes: 25 additions & 5 deletions vscode/microsoft-kiota/src/commands/editPathsCommand.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as vscode from "vscode";
import * as vscode from 'vscode';

import { extensionId, treeViewId } from "../constants";
import { extensionId, SHOW_MESSAGE_AFTER_API_LOAD, treeViewId } from "../constants";
import { ClientOrPluginProperties } from "../kiotaInterop";
import { OpenApiTreeProvider } from "../providers/openApiTreeProvider";
import { WorkspaceGenerationContext } from "../types/WorkspaceGenerationContext";
Expand All @@ -10,7 +10,10 @@ import { Command } from "./Command";

export class EditPathsCommand extends Command {

public constructor(private _openApiTreeProvider: OpenApiTreeProvider) {
constructor(
private openApiTreeProvider: OpenApiTreeProvider,
private context: vscode.ExtensionContext
) {
super();
}

Expand All @@ -20,12 +23,29 @@ export class EditPathsCommand extends Command {

public async execute({ clientOrPluginKey, clientOrPluginObject }: Partial<WorkspaceGenerationContext>): Promise<void> {
await this.loadEditPaths(clientOrPluginKey!, clientOrPluginObject!);
this._openApiTreeProvider.resetInitialState();
this.openApiTreeProvider.resetInitialState();
await updateTreeViewIcons(treeViewId, false, true);
await vscode.commands.executeCommand('kiota.workspace.refresh');
}

private async loadEditPaths(clientOrPluginKey: string, clientOrPluginObject: ClientOrPluginProperties) {
await openTreeViewWithProgress(() => this._openApiTreeProvider.loadEditPaths(clientOrPluginKey, clientOrPluginObject));
await openTreeViewWithProgress(() => this.openApiTreeProvider.loadEditPaths(clientOrPluginKey, clientOrPluginObject));

const regenerateAnswer = vscode.l10n.t("Regenerate");
const showGenerateMessage = this.context.globalState.get<boolean>(SHOW_MESSAGE_AFTER_API_LOAD, true);

if (showGenerateMessage) {
const doNotShowAgainOption = vscode.l10n.t("Do not show this again");
const response = await vscode.window.showInformationMessage(
vscode.l10n.t('Click on Regenerate after selecting the paths in the API Explorer'),
regenerateAnswer,
doNotShowAgainOption
);
if (response === regenerateAnswer) {
await vscode.commands.executeCommand(`kiota.regenerate`);
} else if (response === doNotShowAgainOption) {
await this.context.globalState.update(SHOW_MESSAGE_AFTER_API_LOAD, false);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import TelemetryReporter from "@vscode/extension-telemetry";
import * as vscode from "vscode";

import { extensionId, treeViewId } from "../../constants";
import { extensionId, SHOW_MESSAGE_AFTER_API_LOAD, treeViewId } from "../../constants";
import { setDeepLinkParams } from "../../handlers/deepLinkParamsHandler";
import { searchSteps } from "../../modules/steps/searchSteps";
import { OpenApiTreeProvider } from "../../providers/openApiTreeProvider";
Expand All @@ -13,13 +13,11 @@ import { searchDescription } from "./searchDescription";

export class SearchOrOpenApiDescriptionCommand extends Command {

private _openApiTreeProvider: OpenApiTreeProvider;
private _context: vscode.ExtensionContext;

constructor(openApiTreeProvider: OpenApiTreeProvider, context: vscode.ExtensionContext) {
constructor(
private openApiTreeProvider: OpenApiTreeProvider,
private context: vscode.ExtensionContext
) {
super();
this._openApiTreeProvider = openApiTreeProvider;
this._context = context;
}

public getName(): string {
Expand All @@ -31,7 +29,7 @@ export class SearchOrOpenApiDescriptionCommand extends Command {
if (Object.keys(searchParams).length > 0) {
let [params, errorsArray] = validateDeepLinkQueryParams(searchParams);
setDeepLinkParams(params);
const reporter = new TelemetryReporter(this._context.extension.packageJSON.telemetryInstrumentationKey);
const reporter = new TelemetryReporter(this.context.extension.packageJSON.telemetryInstrumentationKey);
reporter.sendTelemetryEvent("DeepLinked searchOrOpenApiDescription", {
"searchParameters": JSON.stringify(searchParams),
"validationErrors": errorsArray.join(", ")
Expand All @@ -40,7 +38,7 @@ export class SearchOrOpenApiDescriptionCommand extends Command {

// proceed to enable loading of openapi description
const yesAnswer = vscode.l10n.t("Yes, override it");
if (this._openApiTreeProvider.hasChanges()) {
if (this.openApiTreeProvider.hasChanges()) {
const response = await vscode.window.showWarningMessage(
vscode.l10n.t(
"Before adding a new API description, consider that your changes and current selection will be lost."),
Expand All @@ -58,12 +56,29 @@ export class SearchOrOpenApiDescriptionCommand extends Command {
title: vscode.l10n.t("Searching...")
}, (progress, _) => {
const settings = getExtensionSettings(extensionId);
return searchDescription(this._context, x, settings.clearCache);
return searchDescription(this.context, x, settings.clearCache);
}));

if (config.descriptionPath) {
await openTreeViewWithProgress(() => this._openApiTreeProvider.setDescriptionUrl(config.descriptionPath!));
await openTreeViewWithProgress(() => this.openApiTreeProvider.setDescriptionUrl(config.descriptionPath!));

const generateAnswer = vscode.l10n.t("Generate");
const showGenerateMessage = this.context.globalState.get<boolean>(SHOW_MESSAGE_AFTER_API_LOAD, true);

if (showGenerateMessage) {
const doNotShowAgainOption = vscode.l10n.t("Do not show this again");
const response = await vscode.window.showInformationMessage(
vscode.l10n.t('Click on Generate after selecting the paths in the API Explorer'),
generateAnswer,
doNotShowAgainOption
);

if (response === generateAnswer) {
await vscode.commands.executeCommand(`${treeViewId}.generateClient`);
} else if (response === doNotShowAgainOption) {
await this.context.globalState.update(SHOW_MESSAGE_AFTER_API_LOAD, false);
}
}
}
await vscode.window.showInformationMessage(vscode.l10n.t('You can now select the required endpoints from {0}', this._openApiTreeProvider.apiTitle!));
}
}
1 change: 1 addition & 0 deletions vscode/microsoft-kiota/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ export const APIMANIFEST = "apimanifest";
export const REMIND_ME_LATER_FLAG = 'remindMeLater';
export const API_MANIFEST_FILE = "apimanifest.json";
export const MANIFEST_KIOTA_VERSION_KEY = "x-ms-kiota-version";
export const SHOW_MESSAGE_AFTER_API_LOAD = "show-message-after-api-load";
2 changes: 1 addition & 1 deletion vscode/microsoft-kiota/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export async function activate(
const removeFromSelectedEndpointsCommand = new RemoveFromSelectedEndpointsCommand(openApiTreeProvider);
const filterDescriptionCommand = new FilterDescriptionCommand(openApiTreeProvider);
const openDocumentationPageCommand = new OpenDocumentationPageCommand();
const editPathsCommand = new EditPathsCommand(openApiTreeProvider);
const editPathsCommand = new EditPathsCommand(openApiTreeProvider, context);
const searchOrOpenApiDescriptionCommand = new SearchOrOpenApiDescriptionCommand(openApiTreeProvider, context);
const generateClientCommand = new GenerateClientCommand(openApiTreeProvider, context, dependenciesInfoProvider, setWorkspaceGenerationContext, kiotaOutputChannel);
const regenerateCommand = new RegenerateCommand(context, openApiTreeProvider, kiotaOutputChannel);
Expand Down

0 comments on commit 81c0e7b

Please sign in to comment.