Skip to content

Commit 04e6c9f

Browse files
Mutugiiidogi
andauthored
manager: smoother ai services formatting (fixes #9265) (#9266)
Co-authored-by: dogi <[email protected]>
1 parent b4569d3 commit 04e6c9f

File tree

3 files changed

+44
-35
lines changed

3 files changed

+44
-35
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "planet",
33
"license": "AGPL-3.0",
4-
"version": "0.20.59",
4+
"version": "0.20.60",
55
"myplanet": {
6-
"latest": "v0.35.82",
7-
"min": "v0.34.82"
6+
"latest": "v0.36.9",
7+
"min": "v0.35.9"
88
},
99
"scripts": {
1010
"ng": "ng",

src/app/manager-dashboard/manager-aiservices.component.html

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,29 @@
22
<button mat-icon-button routerLink="/manager">
33
<mat-icon>arrow_back</mat-icon>
44
</button>
5-
<span i18n>AI API Configurations</span>
5+
<span i18n>AI Configurations</span>
66
</mat-toolbar>
77

88
<form class="container" [formGroup]="configForm">
99
<mat-card class="card">
1010
<mat-card-title i18n>API Keys</mat-card-title>
1111
<mat-card-content *ngIf="configuration.keys">
1212
<mat-list>
13-
<mat-list-item *ngFor="let key of objectKeys(configuration.keys)">
13+
<mat-list-item *ngFor="let apiKey of configuration.keys | keyvalue">
1414
<div class="list-item-content">
15-
<span>{{ key | titlecase }}</span>
15+
<span>{{ apiKey.key | titlecase }}</span>
1616
<mat-form-field>
1717
<input
1818
matInput
19-
[type]="hideKey[key] ? 'password' : 'text'"
20-
[formControlName]="'keys_' + key"
19+
[type]="hideKey[apiKey.key] ? 'password' : 'text'"
20+
[formControlName]="'keys_' + apiKey.key"
2121
placeholder="Enter API key"
2222
i18n-placeholder
2323
/>
24-
<button mat-icon-button matSuffix (click)="toggleHideKey(key)">
25-
<mat-icon>{{ hideKey[key] ? 'visibility_off' : 'visibility' }}</mat-icon>
24+
<button mat-icon-button matSuffix (click)="toggleHideKey(apiKey.key)">
25+
<mat-icon>{{ hideKey[apiKey.key] ? 'visibility_off' : 'visibility' }}</mat-icon>
2626
</button>
27-
<button mat-icon-button matSuffix (click)="copyKey(key)">
27+
<button mat-icon-button matSuffix (click)="copyKey(apiKey.key)">
2828
<mat-icon>content_copy</mat-icon>
2929
</button>
3030
</mat-form-field>
@@ -39,11 +39,11 @@
3939
<mat-card-title i18n>Models</mat-card-title>
4040
<mat-card-content *ngIf="configuration.models">
4141
<mat-list>
42-
<mat-list-item *ngFor="let model of objectKeys(configuration.models)">
42+
<mat-list-item *ngFor="let model of configuration.models | keyvalue">
4343
<div class="list-item-content">
44-
<span>{{ model | titlecase }}</span>
44+
<span>{{ model.key | titlecase }}</span>
4545
<mat-form-field>
46-
<input matInput [formControlName]="'models_' + model" placeholder="Enter model" i18n-placeholder />
46+
<input matInput [formControlName]="'models_' + model.key" placeholder="Enter model" i18n-placeholder />
4747
</mat-form-field>
4848
</div>
4949
</mat-list-item>

src/app/manager-dashboard/manager-aiservices.component.ts

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,34 @@
1-
import { Component, OnInit } from '@angular/core';
2-
import { UntypedFormBuilder, UntypedFormGroup } from '@angular/forms';
1+
import { Component, OnDestroy, OnInit } from '@angular/core';
2+
import { FormBuilder, FormGroup, FormControl, AbstractControl } from '@angular/forms';
33
import { Clipboard } from '@angular/cdk/clipboard';
44
import { Router } from '@angular/router';
5+
import { Subject } from 'rxjs';
56
import { finalize } from 'rxjs/operators';
6-
77
import { ConfigurationService } from '../configuration/configuration.service';
88
import { CouchService } from '../shared/couchdb.service';
99
import { PlanetMessageService } from '../shared/planet-message.service';
1010
import { StateService } from '../shared/state.service';
1111

12+
interface AIServiceConfigForm {
13+
streaming: FormControl<boolean>;
14+
assistantName: FormControl<string>;
15+
assistantInstructions: FormControl<string>;
16+
[key: string]: AbstractControl<any, any>;
17+
}
18+
1219
@Component({
1320
templateUrl: './manager-aiservices.component.html',
1421
styleUrls: [ './manager-settings.shared.scss' ],
1522
})
16-
export class ManagerAIServicesComponent implements OnInit {
23+
export class ManagerAIServicesComponent implements OnInit, OnDestroy {
1724
configuration: any = {};
18-
configForm: UntypedFormGroup;
25+
configForm: FormGroup<AIServiceConfigForm>;
1926
hideKey: { [key: string]: boolean } = {};
2027
spinnerOn = true;
28+
private unsubscribe$ = new Subject<void>();
2129

2230
constructor(
23-
private fb: UntypedFormBuilder,
31+
private fb: FormBuilder,
2432
private clipboard: Clipboard,
2533
private configurationService: ConfigurationService,
2634
private couchService: CouchService,
@@ -29,10 +37,10 @@ export class ManagerAIServicesComponent implements OnInit {
2937
private stateService: StateService,
3038
) {
3139
this.configForm = this.fb.group({
32-
streaming: [ false ],
33-
assistantName: [ '' ],
34-
assistantInstructions: [ '' ]
35-
});
40+
streaming: new FormControl(false, { nonNullable: true }),
41+
assistantName: new FormControl('', { nonNullable: true }),
42+
assistantInstructions: new FormControl('', { nonNullable: true })
43+
}) as FormGroup<AIServiceConfigForm>;
3644
}
3745

3846
ngOnInit() {
@@ -41,14 +49,19 @@ export class ManagerAIServicesComponent implements OnInit {
4149
this.initForm();
4250
}
4351

52+
ngOnDestroy() {
53+
this.unsubscribe$.next();
54+
this.unsubscribe$.complete();
55+
}
56+
4457
initForm() {
4558
this.configForm = this.fb.group({
46-
streaming: [ !!this.configuration.streaming ],
59+
streaming: new FormControl(!!this.configuration.streaming, { nonNullable: true }),
4760
...this.mapConfigToFormGroup(this.configuration.keys, 'keys_'),
4861
...this.mapConfigToFormGroup(this.configuration.models, 'models_'),
49-
assistantName: [ this.configuration.assistant?.name || '' ],
50-
assistantInstructions: [ this.configuration.assistant?.instructions || '' ]
51-
});
62+
assistantName: new FormControl(this.configuration.assistant?.name || '', { nonNullable: true }),
63+
assistantInstructions: new FormControl(this.configuration.assistant?.instructions || '', { nonNullable: true })
64+
}) as FormGroup<AIServiceConfigForm>;
5265

5366
if (this.configuration.keys) {
5467
for (const key of Object.keys(this.configuration.keys)) {
@@ -58,19 +71,15 @@ export class ManagerAIServicesComponent implements OnInit {
5871
}
5972

6073
mapConfigToFormGroup(configObject: any, prefix: string) {
61-
const formGroupObj = {};
74+
const formGroupObj: { [key: string]: FormControl<string> } = {};
6275
if (configObject) {
6376
for (const key of Object.keys(configObject)) {
64-
formGroupObj[prefix + key] = [ configObject[key] || '' ];
77+
formGroupObj[prefix + key] = new FormControl(configObject[key] || '', { nonNullable: true });
6578
}
6679
}
6780
return formGroupObj;
6881
}
6982

70-
objectKeys(obj: any): string[] {
71-
return Object.keys(obj);
72-
}
73-
7483
saveConfig() {
7584
const spinnerOff = () => this.spinnerOn = false;
7685
if (!this.configForm.valid) {
@@ -112,7 +121,7 @@ export class ManagerAIServicesComponent implements OnInit {
112121
}
113122

114123
copyKey(key: string) {
115-
const value = this.configForm.get('keys_' + key).value;
124+
const value = this.configForm.get('keys_' + key)?.value || '';
116125
this.clipboard.copy(value);
117126
}
118127

0 commit comments

Comments
 (0)