Skip to content

Commit 0cad95e

Browse files
authored
feat: add navigation api (#375)
Signed-off-by: Philippe Martin <[email protected]>
1 parent 773daee commit 0cad95e

File tree

8 files changed

+75
-6
lines changed

8 files changed

+75
-6
lines changed

packages/channels/src/channels.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
***********************************************************************/
1818

1919
import type { ContextsApi } from './interface/contexts-api';
20+
import type { NavigationApi } from './interface/navigation-api';
2021
import type { PodLogsApi } from './interface/pod-logs-api';
2122
import type { PodTerminalsApi } from './interface/pod-terminals-api';
2223
import type { PortForwardApi } from './interface/port-forward-api';
@@ -42,6 +43,7 @@ export const API_CONTEXTS = createRpcChannel<ContextsApi>('ContextsApi');
4243
export const API_SUBSCRIBE = createRpcChannel<SubscribeApi>('SubscribeApi');
4344
export const API_SYSTEM = createRpcChannel<SystemApi>('SystemApi');
4445
export const API_PORT_FORWARD = createRpcChannel<PortForwardApi>('PortForwardApi');
46+
export const API_NAVIGATION = createRpcChannel<NavigationApi>('NavigationApi');
4547

4648
// Broadcast events (sent by extension and received by the webview)
4749
export const RESOURCES_COUNT = createRpcChannel<ResourcesCountInfo>('ResourcesCount');

packages/channels/src/interface/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { type PodTerminalsApi } from './pod-terminals-api';
2222
import { type DeletePortForwardOptions, type PortForwardApi } from './port-forward-api';
2323
import { type SubscribeApi } from './subscribe-api';
2424
import { type SystemApi } from './system-api';
25+
import { type NavigationApi } from './navigation-api';
2526

2627
export type {
2728
ContextsApi,
@@ -31,4 +32,5 @@ export type {
3132
SubscribeApi,
3233
SystemApi,
3334
DeletePortForwardOptions,
35+
NavigationApi,
3436
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**********************************************************************
2+
* Copyright (C) 2025 Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
***********************************************************************/
18+
19+
export const NavigationApi = Symbol.for('NavigationApi');
20+
21+
export interface NavigationApi {
22+
navigateToProviderNewConnection(id: string): Promise<void>;
23+
}

packages/extension/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"devDependencies": {
2424
"@kubernetes-dashboard/rpc": "workspace:*",
2525
"@kubernetes-dashboard/channels": "workspace:*",
26-
"@podman-desktop/api": "1.22.0",
26+
"@podman-desktop/api": "1.23.0-next.202510141447-e1ab0ef8faf",
2727
"@types/node": "^24",
2828
"@typescript-eslint/eslint-plugin": "^8.46.1",
2929
"@typescript-eslint/parser": "^8.30.1",

packages/extension/src/dashboard-extension.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { InversifyBinding } from '/@/inject/inversify-binding';
3030
import type { Container } from 'inversify';
3131
import {
3232
API_CONTEXTS,
33+
API_NAVIGATION,
3334
API_POD_LOGS,
3435
API_POD_TERMINALS,
3536
API_PORT_FORWARD,
@@ -42,6 +43,7 @@ import { PortForwardApiImpl } from './manager/port-forward-api-impl';
4243
import { PortForwardServiceProvider } from './port-forward/port-forward-service';
4344
import { PodLogsApiImpl } from './manager/pod-logs-api-impl';
4445
import { PodTerminalsApiImpl } from './manager/pod-terminals-api-impl';
46+
import { NavigationApiImpl } from '/@/manager/navigation-api';
4547

4648
export class DashboardExtension {
4749
#container: Container | undefined;
@@ -56,6 +58,7 @@ export class DashboardExtension {
5658
#portForwardServiceProvider: PortForwardServiceProvider;
5759
#podLogsApiImpl: PodLogsApiImpl;
5860
#podTerminalsApiImpl: PodTerminalsApiImpl;
61+
#navigationApiImpl: NavigationApiImpl;
5962

6063
constructor(readonly extensionContext: ExtensionContext) {
6164
this.#extensionContext = extensionContext;
@@ -82,6 +85,7 @@ export class DashboardExtension {
8285
this.#portForwardServiceProvider = await this.#container.getAsync(PortForwardServiceProvider);
8386
this.#podLogsApiImpl = await this.#container.getAsync(PodLogsApiImpl);
8487
this.#podTerminalsApiImpl = await this.#container.getAsync(PodTerminalsApiImpl);
88+
this.#navigationApiImpl = await this.#container.getAsync(NavigationApiImpl);
8589

8690
const afterFirst = performance.now();
8791

@@ -93,6 +97,7 @@ export class DashboardExtension {
9397
rpcExtension.registerInstance(API_PORT_FORWARD, this.#portForwardApiImpl);
9498
rpcExtension.registerInstance(API_POD_LOGS, this.#podLogsApiImpl);
9599
rpcExtension.registerInstance(API_POD_TERMINALS, this.#podTerminalsApiImpl);
100+
rpcExtension.registerInstance(API_NAVIGATION, this.#navigationApiImpl);
96101

97102
await this.listenMonitoring();
98103
await this.startMonitoring();

packages/extension/src/manager/_manager-module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { PortForwardApiImpl } from './port-forward-api-impl';
2525
import { PodLogsApiImpl } from './pod-logs-api-impl';
2626
import { IDisposable } from '@kubernetes-dashboard/channels';
2727
import { PodTerminalsApiImpl } from './pod-terminals-api-impl';
28+
import { NavigationApiImpl } from '/@/manager/navigation-api';
2829

2930
const managersModule = new ContainerModule(options => {
3031
options.bind<ContextsManager>(ContextsManager).toSelf().inSingletonScope();
@@ -33,6 +34,7 @@ const managersModule = new ContainerModule(options => {
3334
options.bind<PortForwardApiImpl>(PortForwardApiImpl).toSelf().inSingletonScope();
3435
options.bind<PodLogsApiImpl>(PodLogsApiImpl).toSelf().inSingletonScope();
3536
options.bind<PodTerminalsApiImpl>(PodTerminalsApiImpl).toSelf().inSingletonScope();
37+
options.bind<NavigationApiImpl>(NavigationApiImpl).toSelf().inSingletonScope();
3638

3739
// Bind IDisposable to services which need to clear data/stop connection/etc when the panel is left
3840
// (the onDestroy are not called from components when the panel is left, which may introduce memory leaks if not disposed here)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**********************************************************************
2+
* Copyright (C) 2025 Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
***********************************************************************/
18+
19+
import { injectable } from 'inversify';
20+
import * as podmanDesktopApi from '@podman-desktop/api';
21+
import { NavigationApi } from '@kubernetes-dashboard/channels/dist/interface/navigation-api';
22+
23+
@injectable()
24+
export class NavigationApiImpl implements NavigationApi {
25+
async navigateToProviderNewConnection(id: string): Promise<void> {
26+
// This test can be removed when the minimal version is set to 1.23
27+
if (!('navigateToCreateProviderConnection' in podmanDesktopApi.navigation)) {
28+
console.warn(
29+
'navigating to provider page is not supported in this version of Podman Desktop, please upgrade to the latest version',
30+
);
31+
return;
32+
}
33+
return podmanDesktopApi.navigation.navigateToCreateProviderConnection(id);
34+
}
35+
}

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)