Skip to content

Commit 84f95d9

Browse files
committed
feat: add onResourcesCount to api
Signed-off-by: Philippe Martin <[email protected]>
1 parent ce0cc36 commit 84f95d9

File tree

11 files changed

+28
-56
lines changed

11 files changed

+28
-56
lines changed

packages/api/src/kubernetes-dashboard-extension-api.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,22 @@ export interface CurrentContextInfo {
6767
namespace?: string;
6868
}
6969

70+
export interface ResourceCount {
71+
contextName: string;
72+
resourceName: string;
73+
count: number;
74+
}
75+
76+
export interface ResourcesCountInfo {
77+
counts: ResourceCount[];
78+
}
79+
7080
export interface KubernetesDashboardSubscriber {
7181
onContextsHealth(listener: (event: ContextsHealthsInfo) => void): Disposable;
7282
onContextsPermissions(listener: (event: ContextsPermissionsInfo) => void): Disposable;
7383
onAvailableContexts(listener: (event: AvailableContextsInfo) => void): Disposable;
7484
onCurrentContext(listener: (event: CurrentContextInfo) => void): Disposable;
85+
onResourcesCount(listener: (event: ResourcesCountInfo) => void): Disposable;
7586
dispose(): void;
7687
}
7788

packages/channels/src/channels.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ import type { PodTerminalChunk } from './model/pod-terminal-chunk';
3131
import type { PortForwardsInfo } from './model/port-forward-info';
3232
import type { ResourceDetailsInfo } from './model/resource-details-info';
3333
import type { ResourceEventsInfo } from './model/resource-events-info';
34-
import type { ResourcesCountInfo } from './model/resources-count-info';
3534
import type { UpdateResourceInfo } from './model/update-resource-info';
3635
import { createRpcChannel } from '@kubernetes-dashboard/rpc';
3736
import type {
3837
AvailableContextsInfo,
3938
ContextsHealthsInfo,
4039
ContextsPermissionsInfo,
4140
CurrentContextInfo,
41+
ResourcesCountInfo,
4242
} from '@podman-desktop/kubernetes-dashboard-extension-api';
4343

4444
// RPC channels (used by the webview to send requests to the extension)

packages/channels/src/model/active-resources-count-info.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* SPDX-License-Identifier: Apache-2.0
1717
***********************************************************************/
1818

19-
import type { ResourceCount } from './kubernetes-resource-count';
19+
import type { ResourceCount } from '@podman-desktop/kubernetes-dashboard-extension-api';
2020

2121
export interface ActiveResourcesCountInfo {
2222
counts: ResourceCount[];

packages/channels/src/model/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export * from './endpoint';
2424
export * from './endpoints-info';
2525
export * from './endpoints-options';
2626
export * from './kubernetes-providers-info';
27-
export * from './kubernetes-resource-count';
2827
export * from './kubernetes-troubleshooting';
2928
export * from './openshift-types';
3029
export * from './pod-logs-chunk';
@@ -35,7 +34,6 @@ export * from './resource-details-info';
3534
export * from './resource-details-options';
3635
export * from './resource-events-info';
3736
export * from './resource-events-options';
38-
export * from './resources-count-info';
3937
export * from './target-ref';
4038
export * from './update-resource-info';
4139
export * from './update-resource-options';

packages/channels/src/model/kubernetes-resource-count.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

packages/channels/src/model/resources-count-info.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

packages/extension/src/dashboard-extension.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import {
4141
CONTEXTS_PERMISSIONS,
4242
CURRENT_CONTEXT,
4343
IDisposable,
44+
RESOURCES_COUNT,
4445
} from '@kubernetes-dashboard/channels';
4546
import { SystemApiImpl } from './manager/system-api';
4647
import { PortForwardApiImpl } from './manager/port-forward-api-impl';
@@ -57,6 +58,7 @@ import type {
5758
CurrentContextInfo,
5859
KubernetesDashboardExtensionApi,
5960
KubernetesDashboardSubscriber,
61+
ResourcesCountInfo,
6062
} from '@podman-desktop/kubernetes-dashboard-extension-api';
6163
import { ApiSubscriber } from '/@/subscriber/api-subscriber';
6264

@@ -151,6 +153,9 @@ export class DashboardExtension {
151153
onCurrentContext: (listener: (event: CurrentContextInfo) => void): IDisposable => {
152154
return subscriber.subscribe(CURRENT_CONTEXT, undefined, listener);
153155
},
156+
onResourcesCount: (listener: (event: ResourcesCountInfo) => void): IDisposable => {
157+
return subscriber.subscribe(RESOURCES_COUNT, undefined, listener);
158+
},
154159
dispose: () => {
155160
subscriber.dispose();
156161
},

packages/extension/src/dispatcher/resources-count-dispatcher.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ import { inject, injectable } from 'inversify';
2020
import type { DispatcherObject } from './util/dispatcher-object';
2121
import { AbsDispatcherObjectImpl } from './util/dispatcher-object';
2222
import { ContextsManager } from '/@/manager/contexts-manager';
23-
import { RESOURCES_COUNT, type ResourcesCountInfo } from '@kubernetes-dashboard/channels';
23+
import { RESOURCES_COUNT } from '@kubernetes-dashboard/channels';
24+
import type { ResourcesCountInfo } from '@podman-desktop/kubernetes-dashboard-extension-api';
2425

2526
@injectable()
2627
export class ResourcesCountDispatcher

packages/extension/src/manager/contexts-manager.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import type {
3434
TargetRef,
3535
Endpoint,
3636
V1Route,
37-
ResourceCount,
3837
KubernetesTroubleshootingInformation,
3938
} from '@kubernetes-dashboard/channels';
4039
import { kubernetes, window } from '@podman-desktop/api';
@@ -75,7 +74,7 @@ import { NamespacesResourceFactory } from '/@/resources/namespaces-resource-fact
7574
import { EndpointSlicesResourceFactory } from '/@/resources/endpoint-slices-resource-factory.js';
7675
import { parseAllDocuments, stringify, type Tags } from 'yaml';
7776
import { writeFile } from 'node:fs/promises';
78-
import { ContextPermission } from '@podman-desktop/kubernetes-dashboard-extension-api';
77+
import { ContextPermission, ResourceCount } from '@podman-desktop/kubernetes-dashboard-extension-api';
7978

8079
const HEALTH_CHECK_TIMEOUT_MS = 5_000;
8180
const DEFAULT_NAMESPACE = 'default';

packages/webview/src/component/dashboard/DashboardResourceCard.spec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,15 @@ import { beforeEach, describe, expect, test, vi } from 'vitest';
2424

2525
import KubernetesDashboardResourceCard from './DashboardResourceCard.svelte';
2626
import { FakeStateObject } from '/@/state/util/fake-state-object.svelte';
27-
import type { ActiveResourcesCountInfo, ResourcesCountInfo } from '@kubernetes-dashboard/channels';
27+
import type { ActiveResourcesCountInfo } from '@kubernetes-dashboard/channels';
2828
import { StatesMocks } from '/@/tests/state-mocks';
2929
import { DependencyMocks } from '/@/tests/dependency-mocks';
3030
import { Navigator } from '/@/navigation/navigator';
31-
import type { CurrentContextInfo, ContextsPermissionsInfo } from '@podman-desktop/kubernetes-dashboard-extension-api';
31+
import type {
32+
CurrentContextInfo,
33+
ContextsPermissionsInfo,
34+
ResourcesCountInfo,
35+
} from '@podman-desktop/kubernetes-dashboard-extension-api';
3236

3337
const statesMocks = new StatesMocks();
3438
const dependencyMocks = new DependencyMocks();

0 commit comments

Comments
 (0)