Skip to content

Commit 864bc25

Browse files
committed
Address review comments
- imageEvents: use `ImageType` directly - components/images: Simplify rows() - pages/images: Remove unnecessary (and incorrect) typing Signed-off-by: Mark Yen <mark.yen@suse.com>
1 parent 3c7958f commit 864bc25

File tree

8 files changed

+27
-39
lines changed

8 files changed

+27
-39
lines changed

pkg/rancher-desktop/backend/images/imageProcessor.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export interface childResultType {
2525
/**
2626
* The fields for display in the images table
2727
*/
28-
export interface imageType {
28+
export interface ImageType {
2929
imageName: string;
3030
tag: string;
3131
imageID: string;
@@ -77,7 +77,7 @@ export abstract class ImageProcessor extends EventEmitter {
7777
private sameErrorMessageCount = 0;
7878
protected showedStderr = false;
7979
private refreshInterval: ReturnType<typeof timers.setInterval> | null = null;
80-
protected images: imageType[] = [];
80+
protected images: ImageType[] = [];
8181
protected _isReady = false;
8282
protected isK8sReady = false;
8383
private hasImageListeners = false;
@@ -208,7 +208,7 @@ export abstract class ImageProcessor extends EventEmitter {
208208
/**
209209
* Returns the current list of cached images.
210210
*/
211-
listImages(): imageType[] {
211+
listImages(): ImageType[] {
212212
return this.images;
213213
}
214214

@@ -256,7 +256,7 @@ export abstract class ImageProcessor extends EventEmitter {
256256
}
257257
}
258258

259-
protected parse(data: string): imageType[] {
259+
protected parse(data: string): ImageType[] {
260260
const results = data
261261
.trimEnd()
262262
.split(/\r?\n/)

pkg/rancher-desktop/backend/images/mobyImageProcessor.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ export default class MobyImageProcessor extends imageProcessor.ImageProcessor {
9292
* ...
9393
*/
9494

95-
parse(data: string): imageProcessor.imageType[] {
96-
const images: imageProcessor.imageType[] = [];
95+
parse(data: string): imageProcessor.ImageType[] {
96+
const images: imageProcessor.ImageType[] = [];
9797
const records = data
9898
.split(/\r?\n/)
9999
.filter(line => line.trim().length > 0)
@@ -125,7 +125,7 @@ export default class MobyImageProcessor extends imageProcessor.ImageProcessor {
125125
}
126126
}
127127

128-
function imageComparator(a: imageProcessor.imageType, b: imageProcessor.imageType): number {
128+
function imageComparator(a: imageProcessor.ImageType, b: imageProcessor.ImageType): number {
129129
return a.imageName.localeCompare(b.imageName) ||
130130
a.tag.localeCompare(b.tag) ||
131131
a.imageID.localeCompare(b.imageID);

pkg/rancher-desktop/backend/images/nerdctlImageProcessor.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ export default class NerdctlImageProcessor extends imageProcessor.ImageProcessor
102102
* ...
103103
*/
104104

105-
parse(data: string): imageProcessor.imageType[] {
106-
const images: imageProcessor.imageType[] = [];
105+
parse(data: string): imageProcessor.ImageType[] {
106+
const images: imageProcessor.ImageType[] = [];
107107
const records = data.split(/\r?\n/)
108108
.filter(line => line.trim().length > 0)
109109
.map((line) => {
@@ -134,7 +134,7 @@ export default class NerdctlImageProcessor extends imageProcessor.ImageProcessor
134134
}
135135
}
136136

137-
function imageComparator(a: imageProcessor.imageType, b: imageProcessor.imageType): number {
137+
function imageComparator(a: imageProcessor.ImageType, b: imageProcessor.ImageType): number {
138138
return a.imageName.localeCompare(b.imageName) ||
139139
a.tag.localeCompare(b.tag) ||
140140
a.imageID.localeCompare(b.imageID);

pkg/rancher-desktop/components/Images.vue

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -226,15 +226,11 @@ export default {
226226
.map(this.getTaggedImage);
227227
},
228228
rows(): RowItem[] {
229-
const filteredImages = _.cloneDeep(this.filteredImages);
230-
231-
return filteredImages
232-
.map<RowItem>((image: Image & Partial<RowItem>) => ({
229+
return this.filteredImages
230+
.map(image => ({
233231
...image,
234232
// The `availableActions` property is used by the ActionMenu to fill
235-
// out the menu entries. Note that we need to modify the items
236-
// in-place, as SortableTable depends on object identity to manage its
237-
// selection state.
233+
// out the menu entries.
238234
availableActions: [
239235
{
240236
label: this.t('images.manager.table.action.push'),
@@ -259,10 +255,10 @@ export default {
259255
].filter(x => x.enabled),
260256
// ActionMenu callbacks - SortableTable assumes that these methods live
261257
// on the rows directly.
262-
doPush: image.doPush ?? this.doPush.bind(this, image),
263-
deleteImage: image.deleteImage ?? this.deleteImage.bind(this, image),
264-
deleteImages: image.deleteImages ?? this.deleteImages.bind(this),
265-
scanImage: image.scanImage ?? this.scanImage.bind(this, image),
258+
doPush: this.doPush.bind(this, image),
259+
deleteImage: this.deleteImage.bind(this, image),
260+
deleteImages: this.deleteImages.bind(this),
261+
scanImage: this.scanImage.bind(this, image),
266262
}));
267263
},
268264
showImageManagerOutput() {

pkg/rancher-desktop/entry/store.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export function mapTypedMutations
118118
>(namespace: N, mappings: G): {
119119
[key in keyof G]: (payload: Parameters<M[G[key]]>[1]) => ReturnType<M[G[key]]>;
120120
};
121-
// Actual implementation defers to mapState
121+
// Actual implementation defers to mapMutations
122122
export function mapTypedMutations(namespace: string, arg: any) {
123123
return mapMutations(namespace, arg);
124124
}

pkg/rancher-desktop/main/imageEvents.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import path from 'path';
66

77
import Electron from 'electron';
88

9-
import { ImageProcessor } from '@pkg/backend/images/imageProcessor';
9+
import { ImageProcessor, ImageType } from '@pkg/backend/images/imageProcessor';
1010
import { getIpcMainProxy } from '@pkg/main/ipcMain';
1111
import { isUnixError } from '@pkg/typings/unix.interface';
1212
import Logging from '@pkg/utils/logging';
@@ -15,14 +15,6 @@ import * as window from '@pkg/window';
1515
const console = Logging.images;
1616
const ipcMainProxy = getIpcMainProxy(console);
1717

18-
interface ImageContents {
19-
imageName: string;
20-
tag: string;
21-
imageID: string;
22-
size: string;
23-
digest: string;
24-
}
25-
2618
// Map image-related events to the associated image processor's methods
2719
// TODO: export the factory function to make this a singleton
2820
/**
@@ -42,7 +34,7 @@ export class ImageEventHandler {
4234
this.initEventHandlers();
4335
}
4436

45-
protected onImagesChanged(images: ImageContents[]) {
37+
protected onImagesChanged(images: ImageType[]) {
4638
window.send('images-changed', images);
4739
}
4840

pkg/rancher-desktop/pages/Images.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,15 @@ export default defineComponent({
116116
}
117117
});
118118
119-
ipcRenderer.on('images-check-state', (event, state: any) => {
119+
ipcRenderer.on('images-check-state', (event, state) => {
120120
this.setImageManagerState(state);
121121
});
122122
123-
ipcRenderer.invoke('images-check-state').then((state: any) => {
123+
ipcRenderer.invoke('images-check-state').then((state) => {
124124
this.setImageManagerState(state);
125125
});
126126
127-
ipcRenderer.on('settings-update', (event, settings: any) => {
127+
ipcRenderer.on('settings-update', (event, settings) => {
128128
// TODO: put in a status bar
129129
this.$data.settings = settings;
130130
this.checkSelectedNamespace();
@@ -134,14 +134,14 @@ export default defineComponent({
134134
this.images = await ipcRenderer.invoke('images-mounted', true);
135135
})();
136136
137-
ipcRenderer.on('images-namespaces', (event, namespaces: string[]) => {
137+
ipcRenderer.on('images-namespaces', (event, namespaces) => {
138138
// TODO: Use a specific message to indicate whether or not messages are supported.
139139
this.imageNamespaces = namespaces;
140140
this.supportsNamespaces = namespaces.length > 0;
141141
this.checkSelectedNamespace();
142142
});
143143
ipcRenderer.send('images-namespaces-read');
144-
ipcRenderer.on('settings-read', (event, settings: any) => {
144+
ipcRenderer.on('settings-read', (event, settings) => {
145145
this.settings = settings;
146146
});
147147
ipcRenderer.send('settings-read');

pkg/rancher-desktop/typings/electron-ipc.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export interface IpcMainInvokeEvents {
127127
'k8s-progress': () => Readonly<{ current: number, max: number, description?: string, transitionTime?: Date }>;
128128

129129
// #region main/imageEvents
130-
'images-mounted': (mounted: boolean) => (import('@pkg/backend/images/imageProcessor').imageType)[];
130+
'images-mounted': (mounted: boolean) => (import('@pkg/backend/images/imageProcessor').ImageType)[];
131131
'images-check-state': () => boolean;
132132
// #endregion
133133

@@ -202,7 +202,7 @@ export interface IpcRendererEvents {
202202
'images-process-output': (data: string, isStdErr: boolean) => void;
203203
'ok:images-process-output': (data: string) => void;
204204
'images-changed': (
205-
images: (import('@pkg/backend/images/imageProcessor').imageType)[]
205+
images: (import('@pkg/backend/images/imageProcessor').ImageType)[]
206206
) => void;
207207
'images-check-state': (state: boolean) => void;
208208
'images-namespaces': (namespaces: string[]) => void;

0 commit comments

Comments
 (0)