Skip to content

Commit

Permalink
fix: reset yeomanui panel state when closing window (#796)
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-gilin authored Jan 30, 2024
1 parent f759b4c commit eb3ba2f
Show file tree
Hide file tree
Showing 36 changed files with 4,578 additions and 4,425 deletions.
12 changes: 2 additions & 10 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,9 @@
"request": "launch",
"name": "backend unit tests",
"program": "${workspaceFolder}/node_modules/mocha/bin/mocha",
"args": [
"-r",
"ts-node/register",
"--timeout",
"999999",
"--colors",
"${workspaceFolder}/packages/backend/test/**/*.spec.ts"
],
"args": ["--timeout", "999999", "--colors", "${workspaceFolder}/packages/backend/dist/test/**/*.spec.js"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"protocol": "inspector"
"internalConsoleOptions": "neverOpen"
},
{
"name": "Run extension",
Expand Down
1 change: 0 additions & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"packages": ["packages/*"],
"useWorkspaces": true,
"npmClient": "yarn",
"command": {
"publish": {
Expand Down
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "root",
"version": "0.0.0",
"private": true,
"workspaces": {
"packages": [
Expand Down Expand Up @@ -68,35 +69,34 @@
}
},
"dependencies": {
"@sap-devx/webview-rpc": "0.4.1",
"lodash": "4.17.21"
},
"devDependencies": {
"@commitlint/cli": "11.0.0",
"@commitlint/config-conventional": "11.0.0",
"@commitlint/cli": "18.6.0",
"@commitlint/config-conventional": "18.6.0",
"@types/chai": "4.2.14",
"@types/mocha": "8.2.0",
"@types/rimraf": "3.0.0",
"@types/rimraf": "4.0.5",
"@typescript-eslint/eslint-plugin": "5.28.0",
"@typescript-eslint/parser": "5.28.0",
"chai": "4.2.0",
"coveralls": "2.11.16",
"cz-conventional-changelog": "3.3.0",
"eslint": "7.18.0",
"eslint-config-prettier": "7.2.0",
"eslint-plugin-eslint-comments": "3.2.0",
"eslint-plugin-vue": "^7.3.0",
"glob": "^7.1.6",
"husky": "4.3.6",
"lerna": "4.0.0",
"lint-staged": "10.5.3",
"make-dir": "^3.1.0",
"lerna": "8.0.1",
"lint-staged": "15.2.0",
"make-dir": "4.0.0",
"mocha": "8.2.1",
"npm-run-all": "4.1.5",
"nyc": "15.1.0",
"prettier": "2.2.1",
"rimraf": "3.0.2",
"shx": "0.3.3",
"prettier": "3.2.4",
"rimraf": "5.0.5",
"shx": "0.3.4",
"typescript": "~4.5.0"
},
"version": "0.0.0"
}
}
2 changes: 1 addition & 1 deletion packages/backend/.nycrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
"check-coverage": true,
"branches": 91,
"lines": 93,
"functions": 89,
"functions": 88,
"statements": 93
}
5 changes: 0 additions & 5 deletions packages/backend/nyc.config.js

This file was deleted.

12 changes: 6 additions & 6 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,13 @@
"coverage": "nyc mocha",
"coverage:copy": "shx mkdir -p ../../coverage && shx cp -u ./coverage/lcov.info ../../coverage/lcov_backend.info",
"frontend:copy": "npm-run-all clean:frontend && shx cp -r ../frontend/dist/. ./dist/media/",
"package": "vsce package --yarn",
"package": "vsce package --yarn --allow-star-activation --skip-license",
"test": "mocha",
"webpack": "webpack --mode development",
"webpack-dev:watch": "webpack --mode development --watch",
"ws:egRun": "node ./dist/src/webSocketServer/exploregens.js",
"ws:run": "node ./dist/src/webSocketServer/youi.js"
},
"extensionDependencies": [
"SAPOSS.app-studio-toolkit"
],
"contributes": {
"commands": [
{
Expand Down Expand Up @@ -189,7 +186,7 @@
}
},
"dependencies": {
"@sap-devx/webview-rpc": "0.3.1",
"@sap-devx/webview-rpc": "0.4.1",
"@sap-devx/yeoman-ui-types": "^1.14.1",
"@sap/bas-sdk": "3.2.1",
"@sap/swa-for-sapbas-vsx": "1.2.7",
Expand Down Expand Up @@ -218,17 +215,20 @@
"@types/webpack-env": "^1.16.2",
"@types/ws": "^7.4.5",
"@types/yeoman-environment": "^2.10.3",
"@vscode/vsce": "2.23.0",
"copy-webpack-plugin": "^9.0.0",
"lcov-result-merger": "3.1.0",
"sinon": "^11.1.1",
"string-replace-loader": "3.0.3",
"ts-loader": "^9.2.3",
"ts-node": "^9.1.1",
"vsce": "^1.100.1",
"webpack": "^5.72.0",
"webpack-cli": "^4.8.0",
"ws": "8.2.3"
},
"extensionDependencies": [
"SAPOSS.app-studio-toolkit"
],
"engines": {
"vscode": "^1.50.0"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/extCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class ExtCommands {

this.registerAndSubscribeCommand(
"yeomanUI._notifyGeneratorsChange",
this.yeomanUIPanel_notifyGeneratorsChange_Command.bind(this)
this.yeomanUIPanel_notifyGeneratorsChange_Command.bind(this),
);

this.registerAndSubscribeCommand("exploreGenerators", this.exploreGenerators_Command.bind(this));
Expand Down Expand Up @@ -68,7 +68,7 @@ export class ExtCommands {
(await window.showWarningMessage(
messages.warn_another_generator_running(this.yeomanUIPanel.yeomanui.generatorName.split(":")[0]),
btnContinue,
"Cancel"
"Cancel",
)) !== btnContinue
) {
return false;
Expand Down
5 changes: 4 additions & 1 deletion packages/backend/src/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,8 @@ export class GeneratorFilter {
return _.isEmpty(array1) || !_.isEmpty(_.intersection(array1, array2));
}

private constructor(public readonly types: string[], public readonly categories: string[]) {}
private constructor(
public readonly types: string[],
public readonly categories: string[],
) {}
}
4 changes: 2 additions & 2 deletions packages/backend/src/images/messageImages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export function getImage(state: Severity) {
return Constants.IS_IN_BAS
? errorTheiaDark
: _.get(vscode, "window.activeColorTheme.kind") === _.get(vscode, "ColorThemeKind.Light")
? errorVSCodeLight
: errorVSCodeDark;
? errorVSCodeLight
: errorVSCodeDark;
} else if (state === Severity.warning) {
return Constants.IS_IN_BAS ? warnTheia : warnVSCode;
} else {
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/logger/settings-changes-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function listenToLogSettingsChanges(context: vscode.ExtensionContext) {
getLogger().changeLevel(logLevel);
logLoggerDetails(context, logLevel);
}
})
}),
);

// Enable responding to changes in the sourceLocationTracking setting
Expand All @@ -33,7 +33,7 @@ export function listenToLogSettingsChanges(context: vscode.ExtensionContext) {

getLogger().changeSourceLocationTracking(newSourceLocationTracking);
}
})
}),
);
}

Expand Down
5 changes: 3 additions & 2 deletions packages/backend/src/panels/AbstractWebviewPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ export abstract class AbstractWebviewPanel {
protected flowPromise: FlowPromise<void>;
protected viewColumn: vscode.ViewColumn;

public loadWebviewPanel(uiOptions?: any): Promise<void> {
public loadWebviewPanel(uiOptions?: any, disposables: vscode.Disposable[] = []): Promise<void> {
this.disposeWebviewPanel();
if (uiOptions?.viewColumn in vscode.ViewColumn) {
this.viewColumn = uiOptions.viewColumn;
}
this.disposables = disposables;
const webViewPanel = this.createWebviewPanel();
this.setWebviewPanel(webViewPanel, uiOptions);

Expand Down Expand Up @@ -85,7 +86,7 @@ export abstract class AbstractWebviewPanel {
this.setFocused(this.webViewPanel.active);
},
null,
this.disposables
this.disposables,
);
}

Expand Down
15 changes: 10 additions & 5 deletions packages/backend/src/panels/YeomanUIPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,23 @@ export class YeomanUIPanel extends AbstractWebviewPanel {
this.installGens = !yeomanUi && isEmpty(args) ? undefined : args;
if (yeomanUi) {
if (!this.installGens) {
yeomanUi._notifyGeneratorsChange();
void yeomanUi._notifyGeneratorsChange();
} else {
yeomanUi._notifyGeneratorsInstall(this.installGens);
void yeomanUi._notifyGeneratorsInstall(this.installGens);
if (isEmpty(this.installGens)) {
Env.loadNpmPath(true); // force to reload the env existing npm paths
yeomanUi._notifyGeneratorsChange();
void yeomanUi._notifyGeneratorsChange();
this.installGens = undefined;
}
}
}
}

// clean up the current yeomanui instance on close panel
private reset() {
this.yeomanui = null;
}

public async loadWebviewPanel(uiOptions?: any): Promise<void> {
if (!Constants.IS_IN_BAS && (await NpmCommand.getNodeProcessVersions()).node === undefined) {
void vscode.window.showErrorMessage(messages.nodejs_install_not_found);
Expand All @@ -54,7 +59,7 @@ export class YeomanUIPanel extends AbstractWebviewPanel {
}
}

return super.loadWebviewPanel(uiOptions);
return super.loadWebviewPanel(uiOptions, [{ dispose: () => this.reset() }]);
}

private async tryToInstallGenerator(genNamespace: string) {
Expand Down Expand Up @@ -100,7 +105,7 @@ export class YeomanUIPanel extends AbstractWebviewPanel {
installGens: this.installGens,
data: get(uiOptions, "data"),
},
this.flowPromise.state
this.flowPromise.state,
);
this.yeomanui.registerCustomQuestionEventHandler("file-browser", "getFilePath", this.showOpenFileDialog.bind(this));
this.yeomanui.registerCustomQuestionEventHandler("folder-browser", "getPath", this.showOpenFolderDialog.bind(this));
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/swa-tracker/swa-tracker-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class SWA {
}
}
}
}
},
);

// Update the swa-tracker-wrapper with a reference to the swaTracker.
Expand Down Expand Up @@ -103,7 +103,7 @@ export class SWA {
generatorName: string,
isSucceeded: boolean,
logger?: IChildLogger,
errorMessage?: string
errorMessage?: string,
) {
try {
if (SWA.isInitialized()) {
Expand Down
6 changes: 3 additions & 3 deletions packages/backend/src/utils/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class EnvUtil {
private createEnvInstance(
args?: string | string[],
opts?: Environment.Options,
adapter?: TerminalAdapter
adapter?: TerminalAdapter,
): Environment<Environment.Options> {
return Environment.createEnv(args, opts, adapter);
}
Expand Down Expand Up @@ -155,11 +155,11 @@ class EnvUtil {
const env: Environment<Environment.Options> = this.createEnvInstance(
undefined,
{ sharedOptions: { forwardErrorToEnvironment: true } },
adapter
adapter,
);
// @types/yeoman-environment bug: generatorPath is still not exposed on LookupGeneratorMeta
env.register(_.get(meta, "generatorPath"), genNamespace, meta.packagePath);
const gen = env.create(genNamespace, { options });
const gen = env.create(genNamespace, [], { options });
return { env, gen };
}

Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/utils/npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class Command {
messages.no_write_access(globalPath),
{ modal: true },
messages.change_owner_for_global(globalPath),
this.SET_DEFAULT_LOCATION
this.SET_DEFAULT_LOCATION,
);
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/backend/src/vscode-youi-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class VSCodeYouiEvents implements YouiEvents {
message: string,
selectedWorkspace: string,
type: string,
targetFolderPath?: string
targetFolderPath?: string,
): void {
this.doClose();
void this.showDoneMessage(success, message, selectedWorkspace, type, targetFolderPath);
Expand Down Expand Up @@ -153,7 +153,7 @@ export class VSCodeYouiEvents implements YouiEvents {
await new Promise((resolve) => {
this.resolveFunc = resolve;
});
}
},
);
}

Expand All @@ -168,7 +168,7 @@ export class VSCodeYouiEvents implements YouiEvents {
errorMmessage: string,
selectedWorkspace: string,
type: string,
targetFolderPath?: string
targetFolderPath?: string,
): Thenable<any> {
this.resolveInstallingProgress();

Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/webSocketServer/youi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class YeomanUIWebSocketServer {
serverOutput,
childLogger,
{ filter: GeneratorFilter.create(), messages: backendMessages },
createFlowPromise<void>().state
createFlowPromise<void>().state,
);
this.yeomanui.registerCustomQuestionEventHandler("folder-browser", "getPath", this.mockFolderDialog.bind(this));
});
Expand Down
Loading

0 comments on commit eb3ba2f

Please sign in to comment.