Skip to content

Commit 0d423bc

Browse files
authored
refactor(renderer): store PodInfoUI instead of PodInfo (podman-desktop#18319)
Signed-off-by: Simon Rey <51708585+simonrey1@users.noreply.github.com>
1 parent ffc1a5f commit 0d423bc

12 files changed

Lines changed: 77 additions & 60 deletions

packages/renderer/src/lib/kube/pods/terminal/KubernetesTerminalService.spec.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,24 @@
1818

1919
import '@testing-library/jest-dom/vitest';
2020

21-
import type { PodContainerInfo, PodInfo } from '@podman-desktop/api';
21+
import type { PodContainerInfo } from '@podman-desktop/api';
2222
import { beforeEach, expect, test } from 'vitest';
2323

2424
import { TerminalService } from '/@/lib/kube/pods/terminal/KubernetesTerminalService';
25+
import type { PodInfoUI } from '/@/lib/pod/PodInfoUI';
2526

2627
let terminalService: TestableKubernetesTerminalService;
2728

2829
class TestableKubernetesTerminalService extends TerminalService {
29-
public testInvalidateCacheRecordOnStatusUpdate(podsInfos: PodInfo[]): void {
30+
public testInvalidateCacheRecordOnStatusUpdate(podsInfos: PodInfoUI[]): void {
3031
return this.invalidateCacheRecordOnStatusUpdate(podsInfos);
3132
}
3233

3334
public testToKey(podName: string, containerName: string): string {
3435
return super.toKey(podName, containerName);
3536
}
3637

37-
public testInvalidateCacheRecordOnPodRemove(podsInfos: PodInfo[]): void {
38+
public testInvalidateCacheRecordOnPodRemove(podsInfos: PodInfoUI[]): void {
3839
return this.invalidateCacheRecordOnPodRemove(podsInfos);
3940
}
4041

@@ -69,11 +70,11 @@ test('should check if the terminal exists in the cache', () => {
6970

7071
test('should invalidate cache for non-running containers', () => {
7172
terminalService.testTerminalCache().set('pod1-container1', {});
72-
const podsInfosMock: PodInfo[] = [
73+
const podsInfosMock: PodInfoUI[] = [
7374
{
74-
Name: 'pod1',
75-
Containers: [{ Names: 'container1', Status: 'exited' } as PodContainerInfo],
76-
} as PodInfo,
75+
name: 'pod1',
76+
containers: [{ Names: 'container1', Status: 'exited' } as PodContainerInfo],
77+
} as PodInfoUI,
7778
];
7879

7980
terminalService.testInvalidateCacheRecordOnStatusUpdate(podsInfosMock);

packages/renderer/src/lib/kube/pods/terminal/KubernetesTerminalService.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
* SPDX-License-Identifier: Apache-2.0
1717
***********************************************************************/
1818

19-
import type { PodContainerInfo, PodInfo } from '@podman-desktop/api';
19+
import type { PodContainerInfo } from '@podman-desktop/api';
2020

2121
import KubernetesTerminal from '/@/lib/kube/pods/terminal/KubernetesTerminal.svelte';
22+
import type { PodInfoUI } from '/@/lib/pod/PodInfoUI';
2223
import { terminalStates } from '/@/stores/kubernetes-terminal-state-store';
2324
import { podsInfos } from '/@/stores/pods';
2425

@@ -32,20 +33,20 @@ export class TerminalService {
3233
});
3334
}
3435

35-
protected invalidateCacheRecordOnStatusUpdate(podsInfos: PodInfo[]): void {
36-
podsInfos.forEach((pod: PodInfo) => {
37-
pod.Containers.forEach((container: PodContainerInfo) => {
36+
protected invalidateCacheRecordOnStatusUpdate(podsInfos: PodInfoUI[]): void {
37+
podsInfos.forEach((pod: PodInfoUI) => {
38+
pod.containers.forEach((container: PodContainerInfo) => {
3839
if (container.Status !== 'running') {
39-
this.terminalCache.delete(this.toKey(pod.Name, container.Names));
40+
this.terminalCache.delete(this.toKey(pod.name, container.Names));
4041
}
4142
});
4243
});
4344
}
4445

45-
protected invalidateCacheRecordOnPodRemove(podsInfos: PodInfo[]): void {
46+
protected invalidateCacheRecordOnPodRemove(podsInfos: PodInfoUI[]): void {
4647
const activePods = new Set(
47-
podsInfos.flatMap((pod: PodInfo) =>
48-
pod.Containers.map((container: PodContainerInfo) => this.toKey(pod.Name, container.Names)),
48+
podsInfos.flatMap((pod: PodInfoUI) =>
49+
pod.containers.map((container: PodContainerInfo) => this.toKey(pod.name, container.Names)),
4950
),
5051
);
5152
for (const [key] of this.terminalCache) {

packages/renderer/src/lib/pod/PodDetails.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ test('Expect redirect to previous page if pod is deleted', async () => {
7070
// remove myPod from the store when we call 'removePod'
7171
// it will then refresh the store and update PodsDetails page
7272
vi.mocked(window.removePod).mockImplementation(async () => {
73-
podsInfos.update(pods => pods.filter(pod => pod.Id !== myPod.Id));
73+
podsInfos.update(pods => pods.filter(pod => pod.id !== myPod.Id));
7474
});
7575

7676
// defines a fake lastPage so we can check where we will be redirected

packages/renderer/src/lib/pod/PodDetails.svelte

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { getTabUrl, isTabSelected } from '/@/lib/ui/Util';
1010
import Route from '/@/Route.svelte';
1111
import { podsInfos } from '/@/stores/pods';
1212
13-
import { PodUtils } from './pod-utils';
1413
import PodActions from './PodActions.svelte';
1514
import PodDetailsInspect from './PodDetailsInspect.svelte';
1615
import PodDetailsKube from './PodDetailsKube.svelte';
@@ -28,18 +27,16 @@ let detailsPage: DetailsPage;
2827
let currentRouterPath: string;
2928
3029
onMount(() => {
31-
const podUtils = new PodUtils();
32-
3330
router.subscribe(route => {
3431
currentRouterPath = route.path;
3532
});
3633
3734
// loading pod info
3835
return podsInfos.subscribe(pods => {
39-
const matchingPod = pods.find(podInPods => podInPods.Name === podName && podInPods.engineId === engineId);
36+
const matchingPod = pods.find(podInPods => podInPods.name === podName && podInPods.engineId === engineId);
4037
if (matchingPod) {
4138
try {
42-
pod = podUtils.getPodInfoUI(matchingPod);
39+
pod = matchingPod;
4340
4441
if (currentRouterPath.endsWith('/')) {
4542
router.goto(`${currentRouterPath}logs`);

packages/renderer/src/lib/pod/PodsList.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ test('Expect the route to a pod details page is correctly encoded with an engine
343343
await vi.waitUntil(
344344
() => {
345345
const infos = get(podsInfos);
346-
return infos.length === 1 && infos[0].Name === ocppod.Name;
346+
return infos.length === 1 && infos[0].name === ocppod.Name;
347347
},
348348
{ timeout: 5000 },
349349
);
@@ -471,8 +471,8 @@ test('Expect All tab to show all pods running and stopped (not running)', async
471471

472472
expect(get(filtered)).toEqual(
473473
expect.arrayContaining([
474-
expect.objectContaining({ Status: 'Running' }),
475-
expect.objectContaining({ Status: 'Stopped' }),
474+
expect.objectContaining({ status: 'RUNNING' }),
475+
expect.objectContaining({ status: 'STOPPED' }),
476476
]),
477477
);
478478
});
@@ -496,7 +496,7 @@ test('Expect Running tab to show running pods only', async () => {
496496

497497
await vi.waitUntil(() => get(filtered).length === 1, { timeout: 5000 });
498498

499-
expect(get(filtered)).toEqual(expect.arrayContaining([expect.objectContaining({ Status: 'Running' })]));
499+
expect(get(filtered)).toEqual(expect.arrayContaining([expect.objectContaining({ status: 'RUNNING' })]));
500500
});
501501

502502
test('Expect Stopped tab to show stopped (not running) pods only', async () => {
@@ -518,7 +518,7 @@ test('Expect Stopped tab to show stopped (not running) pods only', async () => {
518518

519519
await vi.waitUntil(() => get(filtered).length === 1, { timeout: 5000 });
520520

521-
expect(get(filtered)).toEqual(expect.arrayContaining([expect.objectContaining({ Status: 'Stopped' })]));
521+
expect(get(filtered)).toEqual(expect.arrayContaining([expect.objectContaining({ status: 'STOPPED' })]));
522522
});
523523

524524
test('Expect tab filtering to not duplicate filter condition in the search bar', async () => {

packages/renderer/src/lib/pod/PodsList.svelte

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<script lang="ts">
22
import { faTrash } from '@fortawesome/free-solid-svg-icons';
3-
import type { PodInfo } from '@podman-desktop/core-api';
43
import {
54
Button,
65
FilteredEmptyScreen,
@@ -70,7 +69,7 @@ const podUtils = new PodUtils();
7069
7170
onMount(() => {
7271
return filtered.subscribe(value => {
73-
const computedPods = value.map((podInfo: PodInfo) => podUtils.getPodInfoUI(podInfo)).flat();
72+
const computedPods = value.map((podInfo: PodInfoUI) => podInfo).flat();
7473
7574
// Map engineName, engineId and engineType from currentContainers to EngineInfoUI[]
7675
const engines = computedPods.map(container => {

packages/renderer/src/lib/pod/pod-utils.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import type { PodInfo } from '@podman-desktop/core-api';
2222
import { expect, test } from 'vitest';
2323

2424
import { ensureRestrictedSecurityContext, PodUtils } from '/@/lib/pod/pod-utils';
25+
import type { PodInfoUI } from '/@/lib/pod/PodInfoUI';
2526

2627
function verifyPodSecurityContext(containers: any[], type = 'RuntimeDefault'): void {
2728
containers.forEach(container => {
@@ -91,21 +92,21 @@ test('Expect return a valid name for a new pod', () => {
9192

9293
test('Expect return a valid name for a new pod if there is a pod with the same name', () => {
9394
const podUtils = new PodUtils();
94-
const newPodName = podUtils.calculateNewPodName([{ Name: 'my-pod' } as PodInfo]);
95+
const newPodName = podUtils.calculateNewPodName([{ name: 'my-pod' } as PodInfoUI]);
9596

9697
expect(newPodName).toBe('my-pod-1');
9798
});
9899

99100
test('Expect return a valid name for a new pod if there is a pods with different names', () => {
100101
const podUtils = new PodUtils();
101-
const newPodName = podUtils.calculateNewPodName([{ Name: 'my-super-pod' } as PodInfo]);
102+
const newPodName = podUtils.calculateNewPodName([{ name: 'my-super-pod' } as PodInfoUI]);
102103

103104
expect(newPodName).toBe('my-pod');
104105
});
105106

106107
test('Expect return a valid name for a new pod if there are pods with the same name', () => {
107108
const podUtils = new PodUtils();
108-
const newPodName = podUtils.calculateNewPodName([{ Name: 'my-pod' } as PodInfo, { Name: 'my-pod-1' } as PodInfo]);
109+
const newPodName = podUtils.calculateNewPodName([{ name: 'my-pod' } as PodInfoUI, { name: 'my-pod-1' } as PodInfoUI]);
109110

110111
expect(newPodName).toBe('my-pod-2');
111112
});

packages/renderer/src/lib/pod/pod-utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@ export class PodUtils {
7474
};
7575
}
7676

77-
calculateNewPodName(existedPods?: PodInfo[]): string {
77+
calculateNewPodName(existedPods?: PodInfoUI[]): string {
7878
const proposedPodName = 'my-pod';
7979

8080
if (!existedPods) {
8181
return proposedPodName;
8282
}
8383

84-
const existedNames = existedPods.map(pod => pod.Name);
84+
const existedNames = existedPods.map(pod => pod.name);
8585

8686
if (!existedNames.includes(proposedPodName)) {
8787
return proposedPodName;

packages/renderer/src/stores/navigation/navigation-registry-pod.svelte.spec.ts

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
* SPDX-License-Identifier: Apache-2.0
1717
***********************************************************************/
1818

19-
import type { PodInfo } from '@podman-desktop/core-api';
2019
import { beforeEach, expect, test, vi } from 'vitest';
2120

21+
import type { PodInfoUI } from '/@/lib/pod/PodInfoUI';
2222
import { podsInfos } from '/@/stores/pods';
2323

2424
import { createNavigationPodEntry } from './navigation-registry-pod.svelte';
@@ -29,18 +29,33 @@ beforeEach(() => {
2929

3030
test('createNavigationPodEntry', async () => {
3131
const entry = createNavigationPodEntry();
32-
podsInfos.set([
33-
{
34-
Id: '1234',
35-
Name: 'pod-a',
36-
engineId: 'podman',
37-
} as unknown as PodInfo,
38-
{
39-
Id: '3456',
40-
Name: 'pod-b',
41-
engineId: 'podman',
42-
} as unknown as PodInfo,
43-
]);
32+
const podA: PodInfoUI = {
33+
id: '1234',
34+
shortId: '1234',
35+
name: 'pod-a',
36+
engineId: 'podman',
37+
engineName: 'Podman',
38+
status: 'RUNNING',
39+
age: '1 minute',
40+
created: '2026-01-01T00:00:00.000Z',
41+
selected: false,
42+
containers: [],
43+
namespace: '',
44+
};
45+
const podB: PodInfoUI = {
46+
id: '3456',
47+
shortId: '3456',
48+
name: 'pod-b',
49+
engineId: 'podman',
50+
engineName: 'Podman',
51+
status: 'RUNNING',
52+
age: '1 minute',
53+
created: '2026-01-01T00:00:00.000Z',
54+
selected: false,
55+
containers: [],
56+
namespace: '',
57+
};
58+
podsInfos.set([podA, podB]);
4459

4560
expect(entry).toBeDefined();
4661
expect(entry.name).toBe('Pods');

packages/renderer/src/stores/navigation/navigation-registry-pod.svelte.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ export function createNavigationPodEntry(): NavigationRegistryEntry {
3232
destinations = [
3333
...pods.map(pod => ({
3434
page: NavigationPage.PODMAN_POD_SUMMARY as const,
35-
parameters: { name: pod.Name, engineId: pod.engineId },
35+
parameters: { name: pod.name, engineId: pod.engineId },
3636
icon: { iconComponent: PodIcon },
37-
name: `Pod: ${pod.Name}`,
37+
name: `Pod: ${pod.name}`,
3838
})),
3939
{
4040
page: NavigationPage.PODMAN_PODS as const,

0 commit comments

Comments
 (0)