Skip to content

Commit

Permalink
feat: defaultlandscape introduction
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-gilin committed Oct 30, 2024
1 parent 9740787 commit 199c29b
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 105 deletions.
32 changes: 13 additions & 19 deletions packages/app-studio-toolkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,23 +121,17 @@
}
},
{
"command": "local-extension.landscape.default-on",
"title": "Make this the landscape as the default",
"icon": {
"light": "resources/common/joule.svg",
"dark": "resources/common/joule.svg"
}
"command": "app-studio-toolkit.devspace-manager.landscape.default-on",
"title": "Set as default landscape",
"icon": "$(vm-outline)"
},
{
"command": "local-extension.landscape.default-off",
"title": "Remove this landscape as the default",
"icon": {
"light": "resources/common/joule-full.svg",
"dark": "resources/common/joule-full.svg"
}
"command": "app-studio-toolkit.devspace-manager.landscape.default-off",
"title": "Deselect default landscape",
"icon": "$(vm-active)"
},
{
"command": "local-extension.landscape.get-default-landscape",
"command": "app-studio-toolkit.devspace-manager.get-default-landscape",
"title": "Returns the landscape marked as the default"
}
],
Expand Down Expand Up @@ -204,15 +198,15 @@
"commandPalette": [
{
"when": "false",
"command": "local-extension.landscape.get-default-landscape"
"command": "app-studio-toolkit.devspace-manager.get-default-landscape"
},
{
"when": "false",
"command": "local-extension.landscape.default-on"
"command": "app-studio-toolkit.devspace-manager.landscape.default-on"
},
{
"when": "false",
"command": "local-extension.landscape.default-off"
"command": "app-studio-toolkit.devspace-manager.landscape.default-off"
},
{
"when": "false",
Expand Down Expand Up @@ -338,12 +332,12 @@
"group": "inline@2"
},
{
"command": "local-extension.landscape.default-on",
"command": "app-studio-toolkit.devspace-manager.landscape.default-on",
"when": "view == dev-spaces && viewItem =~ /.*landscape-.*default-off.*/",
"group": "inline@1"
},
{
"command": "local-extension.landscape.default-off",
"command": "app-studio-toolkit.devspace-manager.landscape.default-off",
"when": "view == dev-spaces && viewItem =~ /.*landscape-.*default-on.*/",
"group": "inline@1"
}
Expand Down Expand Up @@ -379,7 +373,7 @@
],
"dependencies": {
"@sap/artifact-management": "1.39.0",
"@sap/bas-sdk": "^3.8.9",
"@sap/bas-sdk": "^3.9.0",
"@vscode-logging/wrapper": "2.0.0",
"axios": "^1.7.4",
"body-parser": "1.20.2",
Expand Down
14 changes: 0 additions & 14 deletions packages/app-studio-toolkit/resources/common/dark/land-ai.svg

This file was deleted.

3 changes: 0 additions & 3 deletions packages/app-studio-toolkit/resources/common/joule-full.svg

This file was deleted.

3 changes: 0 additions & 3 deletions packages/app-studio-toolkit/resources/common/joule.svg

This file was deleted.

14 changes: 0 additions & 14 deletions packages/app-studio-toolkit/resources/common/light/land-ai.svg

This file was deleted.

4 changes: 2 additions & 2 deletions packages/app-studio-toolkit/src/authentication/auth-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { createHttpTerminator, HttpTerminator } from "http-terminator";
import { platform } from "os";
import { getLogger } from "../logger/logger";
import { BasRemoteAuthenticationProvider } from "./authProvider";
import { core, helpers } from "@sap/bas-sdk";
import { core } from "@sap/bas-sdk";
import { messages } from "../../src/devspace-manager/common/messages";
import {
eventEmitter,
Expand Down Expand Up @@ -200,6 +200,6 @@ export async function getJwt(landscapeUrl: string): Promise<string> {

export async function hasJwt(landscapeUrl: string): Promise<boolean> {
return getJwt(landscapeUrl)
.then((jwt) => !helpers.isJwtExpired(jwt))
.then((jwt) => !core.isJwtExpired(jwt))
.catch((_) => false);
}
6 changes: 3 additions & 3 deletions packages/app-studio-toolkit/src/devspace-manager/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function initBasRemoteExplorer(context: ExtensionContext): void {
/* istanbul ignore next */
context.subscriptions.push(
commands.registerCommand(
"local-extension.landscape.default-on",
"app-studio-toolkit.devspace-manager.landscape.default-on",
async (node?: LandscapeNode): Promise<boolean> => {
return setDefaultLandscape(node?.url);
}
Expand All @@ -46,7 +46,7 @@ export function initBasRemoteExplorer(context: ExtensionContext): void {

context.subscriptions.push(
commands.registerCommand(
"local-extension.landscape.default-off",
"app-studio-toolkit.devspace-manager.landscape.default-off",
async (node: LandscapeNode): Promise<void> => {
await clearDefaultLandscape();
void commands.executeCommand("local-extension.tree.refresh");
Expand All @@ -56,7 +56,7 @@ export function initBasRemoteExplorer(context: ExtensionContext): void {

context.subscriptions.push(
commands.registerCommand(
"local-extension.landscape.get-default-landscape",
"app-studio-toolkit.devspace-manager.get-default-landscape",
() => {
return getDefaultLandscape();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
window,
workspace,
} from "vscode";
import { helpers } from "@sap/bas-sdk";
import { core } from "@sap/bas-sdk";
import { compact, isEmpty, size, trim, uniqBy } from "lodash";
import { hasJwt } from "../../authentication/auth-utils";
import { URL } from "node:url";
Expand Down Expand Up @@ -138,7 +138,7 @@ export async function cmdLoginToLandscape(node: LandscapeNode): Promise<void> {
);
if (session?.accessToken) {
// auto refresh util jwt expired
autoRefresh(30 * 1000, helpers.timeUntilJwtExpires(session.accessToken));
autoRefresh(30 * 1000, core.timeUntilJwtExpires(session.accessToken));
}
} finally {
void commands.executeCommand("local-extension.tree.refresh");
Expand Down Expand Up @@ -190,7 +190,7 @@ function selectLandscape(
items.push({ label: "", kind: QuickPickItemKind.Separator }); // action section separator
items.push({ label: LBL_ADD_LANDSCAPE });
return window.showQuickPick(items, {
placeHolder: "Select the landscape in which you want to use as default",
placeHolder: "Select a landscape for AI metering",
ignoreFocusOut: true,
}) as Promise<QuickPickLandscape | undefined>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@ export class DevSpaceDataProvider implements TreeDataProvider<TreeItem> {
this.extensionPath,
landscape.name,
TreeItemCollapsibleState.Expanded,
getSvgIconPath(
this.extensionPath,
`landscape${landscape.default ? "_ai" : ""}`
),
getSvgIconPath(this.extensionPath, `landscape`),
"",
landscape.default ? `${tooltip} ${messages.lbl_ai_enabled}` : tooltip,
landscape.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export function getSvgIconPath(
): IconPath {
const icons = {
landscape: { path: "common", name: "land.svg" },
landscape_ai: { path: "common", name: "land-ai.svg" },
basic_error: { path: "devspace", name: "basic_error.svg" },
basic_running: { path: "devspace", name: "basic_running.svg" },
basic_not_running: { path: "devspace", name: "basic_not_running.svg" },
Expand Down
28 changes: 16 additions & 12 deletions packages/app-studio-toolkit/test/devspace-manager/instance.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ describe("extension unit test", () => {
`local-extension.landscape.set`,
`local-extension.login`,
`local-extension.dev-space.open-in-code`,
`local-extension.landscape.default-on`,
`local-extension.landscape.default-off`,
`local-extension.landscape.get-default-landscape`,
`app-studio-toolkit.devspace-manager.landscape.default-on`,
`app-studio-toolkit.devspace-manager.landscape.default-off`,
`app-studio-toolkit.devspace-manager.get-default-landscape`,
]
)
).to.be.empty;
Expand All @@ -133,27 +133,31 @@ describe("extension unit test", () => {
instance.initBasRemoteExplorer(context);
});

it("command `local-extension.landscape.default-off`", async () => {
it("command `app-studio-toolkit.devspace-manager.landscape.default-off`", async () => {
commandsMock
.expects(`executeCommand`)
.withExactArgs(`local-extension.tree.refresh`)
.resolves();
instance.initBasRemoteExplorer(context);
// eslint-disable-next-line @typescript-eslint/await-thenable -- ignore
expect(await registry.get(`local-extension.landscape.default-off`)!()).be
.undefined;
expect(
// eslint-disable-next-line @typescript-eslint/await-thenable -- ignore
await registry.get(
`app-studio-toolkit.devspace-manager.landscape.default-off`
)!()
).be.undefined;
});

it("command `local-extension.landscape.get-default-landscape`", () => {
it("command `app-studio-toolkit.devspace-manager.get-default-landscape`", () => {
instance.initBasRemoteExplorer(context);
// eslint-disable-next-line @typescript-eslint/await-thenable -- ignore
expect(registry.get(`local-extension.landscape.get-default-landscape`)!())
.be.empty;
expect(
registry.get(
`app-studio-toolkit.devspace-manager.get-default-landscape`
)!()
).be.empty;
});

it("command `local-extension.tree.refresh`", () => {
instance.initBasRemoteExplorer(context);
// eslint-disable-next-line @typescript-eslint/await-thenable -- ignore
expect(registry.get(`local-extension.tree.refresh`)!()).be.undefined;
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ describe("Landscape Module Tests", function () {
});

describe("setDefaultLandscape", function () {
const placeHolderText = "Select a landscape for AI metering";
let mockCommands: SinonMock;
let mockWindow: SinonMock;

Expand Down Expand Up @@ -217,8 +218,7 @@ describe("Landscape Module Tests", function () {
mockWindow
.expects("showQuickPick")
.withExactArgs(items, {
placeHolder:
"Select the landscape in which you want to use as default",
placeHolder: placeHolderText,
ignoreFocusOut: true,
})
.resolves(items[1]);
Expand Down Expand Up @@ -269,8 +269,7 @@ describe("Landscape Module Tests", function () {
mockWindow
.expects("showQuickPick")
.withExactArgs(items, {
placeHolder:
"Select the landscape in which you want to use as default",
placeHolder: placeHolderText,
ignoreFocusOut: true,
})
.resolves(undefined);
Expand Down Expand Up @@ -336,8 +335,7 @@ describe("Landscape Module Tests", function () {
mockWindow
.expects("showQuickPick")
.withExactArgs(items, {
placeHolder:
"Select the landscape in which you want to use as default",
placeHolder: placeHolderText,
ignoreFocusOut: true,
})
.resolves(items[items.length - 1]);
Expand All @@ -362,8 +360,7 @@ describe("Landscape Module Tests", function () {
mockWindow
.expects("showQuickPick")
.withExactArgs(modifiedItems, {
placeHolder:
"Select the landscape in which you want to use as default",
placeHolder: placeHolderText,
ignoreFocusOut: true,
})
.resolves(modifiedItems[2]);
Expand Down
Loading

0 comments on commit 199c29b

Please sign in to comment.