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

feat(App.vue): Adds support for command execution with object parameters #722

Merged
merged 5 commits into from
Oct 19, 2022
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
2 changes: 1 addition & 1 deletion packages/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
},
"dependencies": {
"@mdi/font": "5.9.55",
"@sap-devx/inquirer-gui": "0.2.1",
"@sap-devx/inquirer-gui": "0.3.0",
"@sap-devx/inquirer-gui-file-browser-plugin": "0.0.5",
"@sap-devx/inquirer-gui-folder-browser-plugin": "0.0.3",
"@sap-devx/inquirer-gui-label-plugin": "0.0.1",
Expand Down
11 changes: 7 additions & 4 deletions packages/frontend/src/youi/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,13 @@ export default {
this.showBusyIndicator = false;
}
},
executeCommand(event) {
const command = event.target.getAttribute("command");
const params = event.target.getAttribute("params");
this.rpc.invoke("executeCommand", [command, params]);
executeCommand(cmdOrEvent) {
let command = cmdOrEvent;
if (cmdOrEvent.target) {
command.id = cmdOrEvent.target.getAttribute("command");
command.params = cmdOrEvent.target.getAttribute("params");
}
this.rpc.invoke("executeCommand", [command.id, command.params]);
},
back() {
return this.gotoStep(1); // go 1 step back
Expand Down
28 changes: 27 additions & 1 deletion packages/frontend/test/App.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ describe("App.vue", () => {
expect(wrapper.vm.logText).toBe("test_test_log");
});

it("executeCommand - method", () => {
it("executeCommand:event - method", () => {
wrapper = initComponent(App, {}, true);
wrapper.vm.rpc = {
invoke: jest.fn(),
Expand All @@ -525,6 +525,32 @@ describe("App.vue", () => {
invokeSpy.mockRestore();
});

it("executeCommand:command - method", () => {
wrapper = initComponent(App, {}, true);
wrapper.vm.rpc = {
invoke: jest.fn(),
};

/**
* @see {IValidationLink.link.command}
*/
const command = {
id: "vscode.open",
params: {
a: {
b: 1,
},
c: ["2", "3"],
},
};
const invokeSpy = jest.spyOn(wrapper.vm.rpc, "invoke");
wrapper.vm.executeCommand(command);

expect(invokeSpy).toHaveBeenCalledWith("executeCommand", ["vscode.open", command.params]);

invokeSpy.mockRestore();
});

describe("next - method", () => {
it("resolve is null", () => {
wrapper = initComponent(App, {});
Expand Down
35 changes: 35 additions & 0 deletions packages/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,38 @@ export interface IPrompt {
name: string;
description: string;
}

/**
* Enhanced validation messages to support embedded help urls and commands
*/
export interface IValidationLink {
/**
* Validation message to be shown to the end user
*/
message: string;
link: {
/**
* The text associated with the help link
*/
text: string;
/**
* A string base64 encoded image
*/
icon?: string;
/**
* Command to be exectuted and parameters passed to the command
*/
command?: {
id: string;
params: Object | string;
};
/**
* A http url string
*/
url?: string;
};
/**
* Provide a stringified version of the link that will be used on the CLI
*/
toString(): string;
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2373,10 +2373,10 @@
dependencies:
vue "^2.6.10"

"@sap-devx/inquirer-gui@0.2.1":
version "0.2.1"
resolved "https://registry.yarnpkg.com/@sap-devx/inquirer-gui/-/inquirer-gui-0.2.1.tgz#d96ed170f386a59c9b0f6f98d40bd7ed0ce3c626"
integrity sha512-4Xvxq/G/up2pjyYQcqwgbmf3qDbHoGKEcTf9z5LMSxNtExSc1yvhN6VzLqpFqpRr6BDF1qmRRKswMmS2cLNa1A==
"@sap-devx/inquirer-gui@0.3.0":
version "0.3.0"
resolved "https://registry.yarnpkg.com/@sap-devx/inquirer-gui/-/inquirer-gui-0.3.0.tgz#aec200d40cc6d88381f73f773aecb5cf19229e08"
integrity sha512-kBNxug0cF6T/J8LrTTnh7oJ3wU1IQnZKkqmlTdoYLoYcWEXJ/ZVIKhcnzQCoR3mwE9T9XEMY4O0QEJBxDv9gTA==
dependencies:
strip-ansi "^6.0.0"
vue "2.6.12"
Expand Down