Skip to content

Commit dc9f7b5

Browse files
authored
feat: add onResourcesCount to API (#456)
Signed-off-by: Philippe Martin <[email protected]>
1 parent d78ac84 commit dc9f7b5

File tree

12 files changed

+35
-58
lines changed

12 files changed

+35
-58
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ export interface ContextsPermissionsInfo {
5858
permissions: ContextPermission[];
5959
}
6060

61+
export interface ResourceCount {
62+
contextName: string;
63+
resourceName: string;
64+
count: number;
65+
}
66+
67+
export interface ResourcesCountInfo {
68+
counts: ResourceCount[];
69+
}
70+
6171
/**
6272
* The subscriber for the events emitted by the Kubernetes Dashboard extension.
6373
*/
@@ -66,10 +76,17 @@ export interface KubernetesDashboardSubscriber {
6676
* Subscribes to the events emitted every time the health of the contexts changes.
6777
*/
6878
onContextsHealth(listener: (event: ContextsHealthsInfo) => void): Disposable;
79+
6980
/**
7081
* Subscribes to the events emitted every time the permissions of the contexts change.
7182
*/
7283
onContextsPermissions(listener: (event: ContextsPermissionsInfo) => void): Disposable;
84+
85+
/**
86+
* Subscribes to the events emitted every time the resources count changes.
87+
*/
88+
onResourcesCount(listener: (event: ResourcesCountInfo) => void): Disposable;
89+
7390
/**
7491
* Disposes the subscriber and unsubscribes from all the events emitted by the Kubernetes Dashboard extension.
7592
*/

packages/channels/src/channels.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,13 @@ import type { PodTerminalChunk } from './model/pod-terminal-chunk';
3333
import type { PortForwardsInfo } from './model/port-forward-info';
3434
import type { ResourceDetailsInfo } from './model/resource-details-info';
3535
import type { ResourceEventsInfo } from './model/resource-events-info';
36-
import type { ResourcesCountInfo } from './model/resources-count-info';
3736
import type { UpdateResourceInfo } from './model/update-resource-info';
3837
import { createRpcChannel } from '@kubernetes-dashboard/rpc';
39-
import type { ContextsHealthsInfo, ContextsPermissionsInfo } from '@podman-desktop/kubernetes-dashboard-extension-api';
38+
import type {
39+
ContextsHealthsInfo,
40+
ContextsPermissionsInfo,
41+
ResourcesCountInfo,
42+
} from '@podman-desktop/kubernetes-dashboard-extension-api';
4043

4144
// RPC channels (used by the webview to send requests to the extension)
4245
export const API_CONTEXTS = createRpcChannel<ContextsApi>('ContextsApi');

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
@@ -26,7 +26,6 @@ export * from './endpoint';
2626
export * from './endpoints-info';
2727
export * from './endpoints-options';
2828
export * from './kubernetes-providers-info';
29-
export * from './kubernetes-resource-count';
3029
export * from './kubernetes-troubleshooting';
3130
export * from './openshift-types';
3231
export * from './pod-logs-chunk';
@@ -37,7 +36,6 @@ export * from './resource-details-info';
3736
export * from './resource-details-options';
3837
export * from './resource-events-info';
3938
export * from './resource-events-options';
40-
export * from './resources-count-info';
4139
export * from './target-ref';
4240
export * from './update-resource-info';
4341
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
@@ -39,6 +39,7 @@ import {
3939
CONTEXTS_HEALTHS,
4040
CONTEXTS_PERMISSIONS,
4141
IDisposable,
42+
RESOURCES_COUNT,
4243
} from '@kubernetes-dashboard/channels';
4344
import { SystemApiImpl } from './manager/system-api';
4445
import { PortForwardApiImpl } from './manager/port-forward-api-impl';
@@ -53,6 +54,7 @@ import type {
5354
ContextsPermissionsInfo,
5455
KubernetesDashboardExtensionApi,
5556
KubernetesDashboardSubscriber,
57+
ResourcesCountInfo,
5658
} from '@podman-desktop/kubernetes-dashboard-extension-api';
5759
import { ApiSubscriber } from '/@/subscriber/api-subscriber';
5860

@@ -141,6 +143,9 @@ export class DashboardExtension {
141143
onContextsPermissions: (listener: (event: ContextsPermissionsInfo) => void): IDisposable => {
142144
return subscriber.subscribe(CONTEXTS_PERMISSIONS, undefined, listener);
143145
},
146+
onResourcesCount: (listener: (event: ResourcesCountInfo) => void): IDisposable => {
147+
return subscriber.subscribe(RESOURCES_COUNT, undefined, listener);
148+
},
144149
dispose: () => {
145150
subscriber.dispose();
146151
},

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ 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 { CurrentContextInfo, ActiveResourcesCountInfo, ResourcesCountInfo } from '@kubernetes-dashboard/channels';
27+
import type { CurrentContextInfo, 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 { ContextsPermissionsInfo } from '@podman-desktop/kubernetes-dashboard-extension-api';
31+
import type { ContextsPermissionsInfo, ResourcesCountInfo } from '@podman-desktop/kubernetes-dashboard-extension-api';
3232

3333
const statesMocks = new StatesMocks();
3434
const dependencyMocks = new DependencyMocks();

0 commit comments

Comments
 (0)