Skip to content

Commit 8fb9835

Browse files
committed
refactor: improve variable naming for better readability
- Rename currNamespace → currentNamespace - Rename nsSub → namespaceSubscription - Rename pollSub → pollingSubscription - Rename svc → inferenceService throughout codebase - Rename svcPrv → inferenceServicePrivate - Rename config → dialogConfig/snackConfig (context-specific) - Rename res → dialogResponse - Rename currLogs → currentLogs Updated 13 files including TypeScript components, HTML templates, and test specs to use more expressive and pronounceable variable names while maintaining all functionality.
1 parent a418683 commit 8fb9835

File tree

13 files changed

+213
-175
lines changed

13 files changed

+213
-175
lines changed

frontend/src/app/pages/index/config.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ import { getPredictorExtensionSpec } from 'src/app/shared/utils';
1515
import { parseRuntime } from 'src/app/shared/utils';
1616
import { InferenceServiceK8s } from 'src/app/types/kfserving/v1beta1';
1717

18-
export function generateDeleteConfig(svc: InferenceServiceK8s): DialogConfig {
18+
export function generateDeleteConfig(
19+
inferenceService: InferenceServiceK8s,
20+
): DialogConfig {
1921
return {
20-
title: $localize`Delete Endpoint ${svc.metadata.name}?`,
22+
title: $localize`Delete Endpoint ${inferenceService.metadata.name}?`,
2123
message: $localize`You cannot undo this action. Are you sure you want to delete this Endpoint?`,
2224
accept: $localize`DELETE`,
2325
applying: $localize`DELETING`,

frontend/src/app/pages/index/index.component.ts

Lines changed: 68 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ import {
3535
export class IndexComponent implements OnInit, OnDestroy {
3636
env = environment;
3737

38-
nsSub = new Subscription();
39-
pollSub = new Subscription();
38+
namespaceSubscription = new Subscription();
39+
pollingSubscription = new Subscription();
4040

41-
currNamespace: string | string[];
41+
currentNamespace: string | string[];
4242
config = defaultConfig;
4343
inferenceServices: InferenceServiceIR[] = [];
4444

@@ -67,100 +67,104 @@ export class IndexComponent implements OnInit, OnDestroy {
6767

6868
ngOnInit(): void {
6969
// Reset the poller whenever the selected namespace changes
70-
this.nsSub = this.ns.getSelectedNamespace2().subscribe(ns => {
71-
this.currNamespace = ns;
72-
this.poll(ns);
73-
this.newEndpointButton.namespaceChanged(ns, $localize`Endpoint`);
74-
});
70+
this.namespaceSubscription = this.ns
71+
.getSelectedNamespace2()
72+
.subscribe(ns => {
73+
this.currentNamespace = ns;
74+
this.poll(ns);
75+
this.newEndpointButton.namespaceChanged(ns, $localize`Endpoint`);
76+
});
7577
}
7678

7779
ngOnDestroy() {
78-
this.nsSub.unsubscribe();
79-
this.pollSub.unsubscribe();
80+
this.namespaceSubscription.unsubscribe();
81+
this.pollingSubscription.unsubscribe();
8082
}
8183

8284
public poll(ns: string | string[]) {
83-
this.pollSub.unsubscribe();
85+
this.pollingSubscription.unsubscribe();
8486
this.inferenceServices = [];
8587

8688
const request = this.backend.getInferenceServices(ns);
8789

88-
this.pollSub = this.poller.exponential(request).subscribe(svcs => {
89-
this.inferenceServices = this.processIncomingData(svcs);
90-
});
90+
this.pollingSubscription = this.poller
91+
.exponential(request)
92+
.subscribe(svcs => {
93+
this.inferenceServices = this.processIncomingData(svcs);
94+
});
9195
}
9296

9397
// action handling functions
9498
public reactToAction(a: ActionEvent) {
95-
const svc = a.data as InferenceServiceIR;
99+
const inferenceService = a.data as InferenceServiceIR;
96100

97101
switch (a.action) {
98102
case 'delete':
99-
this.deleteClicked(svc);
103+
this.deleteClicked(inferenceService);
100104
break;
101105
case 'copy-link':
102-
console.log(`Copied to clipboard: ${svc.status.url}`);
103-
this.clipboard.copy(svc.status.url);
104-
const config: SnackBarConfig = {
106+
console.log(`Copied to clipboard: ${inferenceService.status.url}`);
107+
this.clipboard.copy(inferenceService.status.url);
108+
const snackConfig: SnackBarConfig = {
105109
data: {
106-
msg: `Copied: ${svc.status.url}`,
110+
msg: `Copied: ${inferenceService.status.url}`,
107111
snackType: SnackType.Info,
108112
},
109113
};
110-
this.snack.open(config);
114+
this.snack.open(snackConfig);
111115
break;
112116
case 'name:link':
113117
/*
114118
* don't allow the user to navigate to the details page of a server
115119
* that is being deleted
116120
*/
117-
if (svc.ui.status.phase === STATUS_TYPE.TERMINATING) {
121+
if (inferenceService.ui.status.phase === STATUS_TYPE.TERMINATING) {
118122
a.event.stopPropagation();
119123
a.event.preventDefault();
120-
const config: SnackBarConfig = {
124+
const snackConfig: SnackBarConfig = {
121125
data: {
122126
msg: $localize`Endpoint is being deleted, cannot show details.`,
123127
snackType: SnackType.Info,
124128
},
125129
};
126-
this.snack.open(config);
130+
this.snack.open(snackConfig);
127131
return;
128132
}
129133
break;
130134
}
131135
}
132136

133-
private deleteClicked(svc: InferenceServiceIR) {
134-
const config = generateDeleteConfig(svc);
137+
private deleteClicked(inferenceService: InferenceServiceIR) {
138+
const dialogConfig = generateDeleteConfig(inferenceService);
135139

136-
const dialogRef = this.confirmDialog.open('Endpoint', config);
140+
const dialogRef = this.confirmDialog.open('Endpoint', dialogConfig);
137141
const applyingSub = dialogRef.componentInstance.applying$.subscribe(
138142
applying => {
139143
if (!applying) {
140144
return;
141145
}
142146

143-
this.backend.deleteInferenceService(svc).subscribe(
144-
res => {
147+
this.backend.deleteInferenceService(inferenceService).subscribe(
148+
dialogResponse => {
145149
dialogRef.close(DIALOG_RESP.ACCEPT);
146150
},
147151
err => {
148-
config.error = err;
152+
dialogConfig.error = err;
149153
dialogRef.componentInstance.applying$.next(false);
150154
},
151155
);
152156
},
153157
);
154158

155-
dialogRef.afterClosed().subscribe(res => {
159+
dialogRef.afterClosed().subscribe(dialogResponse => {
156160
applyingSub.unsubscribe();
157161

158-
if (res !== DIALOG_RESP.ACCEPT) {
162+
if (dialogResponse !== DIALOG_RESP.ACCEPT) {
159163
return;
160164
}
161165

162-
svc.ui.status.phase = STATUS_TYPE.TERMINATING;
163-
svc.ui.status.message = $localize`Preparing to delete Endpoint...`;
166+
inferenceService.ui.status.phase = STATUS_TYPE.TERMINATING;
167+
inferenceService.ui.status.message = $localize`Preparing to delete Endpoint...`;
164168
});
165169
}
166170

@@ -169,49 +173,56 @@ export class IndexComponent implements OnInit, OnDestroy {
169173
private processIncomingData(svcs: InferenceServiceK8s[]) {
170174
const svcsCopy: InferenceServiceIR[] = JSON.parse(JSON.stringify(svcs));
171175

172-
for (const svc of svcsCopy) {
173-
this.parseInferenceService(svc);
176+
for (const inferenceService of svcsCopy) {
177+
this.parseInferenceService(inferenceService);
174178
}
175179

176180
return svcsCopy;
177181
}
178182

179-
private parseInferenceService(svc: InferenceServiceIR) {
180-
svc.ui = { actions: {} };
181-
svc.ui.status = getK8sObjectUiStatus(svc);
182-
svc.ui.actions.copy = this.getCopyActionStatus(svc);
183-
svc.ui.actions.delete = this.getDeletionActionStatus(svc);
184-
185-
const predictorType = getPredictorType(svc.spec.predictor);
186-
const predictor = getPredictorExtensionSpec(svc.spec.predictor);
187-
svc.ui.predictorType = predictorType;
188-
svc.ui.runtimeVersion = predictor.runtimeVersion;
189-
svc.ui.storageUri = predictor.storageUri;
190-
svc.ui.protocolVersion = predictor.protocolVersion || 'v1';
191-
svc.ui.link = {
192-
text: svc.metadata.name,
193-
url: `/details/${svc.metadata.namespace}/${svc.metadata.name}`,
183+
private parseInferenceService(inferenceService: InferenceServiceIR) {
184+
inferenceService.ui = { actions: {} };
185+
inferenceService.ui.status = getK8sObjectUiStatus(inferenceService);
186+
inferenceService.ui.actions.copy =
187+
this.getCopyActionStatus(inferenceService);
188+
inferenceService.ui.actions.delete =
189+
this.getDeletionActionStatus(inferenceService);
190+
191+
const predictorType = getPredictorType(inferenceService.spec.predictor);
192+
const predictor = getPredictorExtensionSpec(
193+
inferenceService.spec.predictor,
194+
);
195+
inferenceService.ui.predictorType = predictorType;
196+
inferenceService.ui.runtimeVersion = predictor.runtimeVersion;
197+
inferenceService.ui.storageUri = predictor.storageUri;
198+
inferenceService.ui.protocolVersion = predictor.protocolVersion || 'v1';
199+
inferenceService.ui.link = {
200+
text: inferenceService.metadata.name,
201+
url: `/details/${inferenceService.metadata.namespace}/${inferenceService.metadata.name}`,
194202
};
195203
}
196204

197-
private getCopyActionStatus(svc: InferenceServiceIR) {
198-
if (svc.ui.status.phase !== STATUS_TYPE.READY) {
205+
private getCopyActionStatus(inferenceService: InferenceServiceIR) {
206+
if (inferenceService.ui.status.phase !== STATUS_TYPE.READY) {
199207
return STATUS_TYPE.UNAVAILABLE;
200208
}
201209

202210
return STATUS_TYPE.READY;
203211
}
204212

205-
private getDeletionActionStatus(svc: InferenceServiceIR) {
206-
if (svc.ui.status.phase !== STATUS_TYPE.TERMINATING) {
213+
private getDeletionActionStatus(inferenceService: InferenceServiceIR) {
214+
if (inferenceService.ui.status.phase !== STATUS_TYPE.TERMINATING) {
207215
return STATUS_TYPE.READY;
208216
}
209217

210218
return STATUS_TYPE.TERMINATING;
211219
}
212220

213221
// util functions
214-
public inferenceServiceTrackByFn(index: number, svc: InferenceServiceK8s) {
215-
return `${svc.metadata.name}/${svc.metadata.creationTimestamp}`;
222+
public inferenceServiceTrackByFn(
223+
index: number,
224+
inferenceService: InferenceServiceK8s,
225+
) {
226+
return `${inferenceService.metadata.name}/${inferenceService.metadata.creationTimestamp}`;
216227
}
217228
}

frontend/src/app/pages/server-info/details/details.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ describe('DetailsComponent', () => {
171171
beforeEach(() => {
172172
fixture = TestBed.createComponent(DetailsComponent);
173173
component = fixture.componentInstance;
174-
component.svc = mockISVC;
174+
component.inferenceService = mockISVC;
175175
fixture.detectChanges();
176176
});
177177

frontend/src/app/pages/server-info/details/details.component.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,26 @@ export class DetailsComponent {
1414

1515
@Input() namespace: string;
1616
@Input()
17-
set svc(s: InferenceServiceK8s) {
18-
this.svcPrv = s;
17+
set inferenceService(s: InferenceServiceK8s) {
18+
this.inferenceServicePrivate = s;
1919

2020
this.svcPropsList = this.generateSvcPropsList();
2121
}
22-
get svc(): InferenceServiceK8s {
23-
return this.svcPrv;
22+
get inferenceService(): InferenceServiceK8s {
23+
return this.inferenceServicePrivate;
2424
}
2525

2626
get externalUrl() {
27-
if (!this.svc.status) {
27+
if (!this.inferenceService.status) {
2828
return 'InferenceService is not ready to receive traffic yet.';
2929
}
3030

31-
return this.svc.status.url !== undefined
32-
? this.svc.status.url
31+
return this.inferenceService.status.url !== undefined
32+
? this.inferenceService.status.url
3333
: 'InferenceService is not ready to receive traffic yet.';
3434
}
3535

36-
private svcPrv: InferenceServiceK8s;
36+
private inferenceServicePrivate: InferenceServiceK8s;
3737

3838
private generateSvcPropsList(): ListEntry[] {
3939
const props: ListEntry[] = [];
@@ -47,16 +47,16 @@ export class DetailsComponent {
4747
private generateAnnotations() {
4848
const chips = [];
4949

50-
if (!this.svc.metadata.annotations) {
50+
if (!this.inferenceService.metadata.annotations) {
5151
return chips;
5252
}
5353

54-
for (const a in this.svc.metadata.annotations) {
55-
if (!this.svc.metadata.annotations.hasOwnProperty(a)) {
54+
for (const a in this.inferenceService.metadata.annotations) {
55+
if (!this.inferenceService.metadata.annotations.hasOwnProperty(a)) {
5656
continue;
5757
}
5858
const annotationKey = a;
59-
const annotationVal = this.svc.metadata.annotations[a];
59+
const annotationVal = this.inferenceService.metadata.annotations[a];
6060
if (annotationKey.includes('last-applied-configuration')) {
6161
continue;
6262
}
@@ -72,17 +72,17 @@ export class DetailsComponent {
7272

7373
private generateLabels() {
7474
const chips = [];
75-
if (!this.svc.metadata.labels) {
75+
if (!this.inferenceService.metadata.labels) {
7676
return chips;
7777
}
7878

79-
for (const l in this.svc.metadata.labels) {
80-
if (!this.svc.metadata.labels.hasOwnProperty(l)) {
79+
for (const l in this.inferenceService.metadata.labels) {
80+
if (!this.inferenceService.metadata.labels.hasOwnProperty(l)) {
8181
continue;
8282
}
8383

8484
const labelKey = l;
85-
const labelVal = this.svc.metadata.labels[l];
85+
const labelVal = this.inferenceService.metadata.labels[l];
8686

8787
const chip: ChipDescriptor = {
8888
value: `${labelKey}: ${labelVal}`,

frontend/src/app/pages/server-info/events/events.component.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ import { EventObject } from '../../../types/event';
1414
export class EventsComponent implements OnDestroy {
1515
public events: EventObject[] = [];
1616
public config = defaultConfig;
17-
private pollSub = new Subscription();
18-
private svcPrv: InferenceServiceK8s;
17+
private pollingSubscription = new Subscription();
18+
private inferenceServicePrivate: InferenceServiceK8s;
1919

2020
@Input()
21-
set svc(s: InferenceServiceK8s) {
22-
this.svcPrv = s;
21+
set inferenceService(s: InferenceServiceK8s) {
22+
this.inferenceServicePrivate = s;
2323
this.poll(s);
2424
}
25-
get svc(): InferenceServiceK8s {
26-
return this.svcPrv;
25+
get inferenceService(): InferenceServiceK8s {
26+
return this.inferenceServicePrivate;
2727
}
2828

2929
constructor(
@@ -32,18 +32,20 @@ export class EventsComponent implements OnDestroy {
3232
) {}
3333

3434
ngOnDestroy(): void {
35-
if (this.pollSub) {
36-
this.pollSub.unsubscribe();
35+
if (this.pollingSubscription) {
36+
this.pollingSubscription.unsubscribe();
3737
}
3838
}
3939

40-
private poll(svc: InferenceServiceK8s) {
41-
this.pollSub.unsubscribe();
40+
private poll(inferenceService: InferenceServiceK8s) {
41+
this.pollingSubscription.unsubscribe();
4242

43-
const request = this.backend.getInferenceServiceEvents(svc);
43+
const request = this.backend.getInferenceServiceEvents(inferenceService);
4444

45-
this.pollSub = this.poller.exponential(request).subscribe(events => {
46-
this.events = events;
47-
});
45+
this.pollingSubscription = this.poller
46+
.exponential(request)
47+
.subscribe(events => {
48+
this.events = events;
49+
});
4850
}
4951
}

0 commit comments

Comments
 (0)