Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NAS-133816 / 25.10 / YAML is not available during edit when app is created #11428

Merged
merged 2 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<ix-modal-header
[requiredRoles]="requiredRoles"
[title]="isNew() ? ('Install via YAML' | translate) : ('Edit App YAML' | translate)"
[title]="isNew ? ('Install via YAML' | translate) : ('Edit App YAML' | translate)"
[loading]="isLoading()"
></ix-modal-header>

Expand All @@ -15,7 +15,7 @@
formControlName="release_name"
[required]="true"
[label]="'Name' | translate"
[readonly]="!isNew()"
[readonly]="!isNew"
></ix-input>
<ix-code-editor
formControlName="custom_compose_config_string"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ describe('CustomAppFormComponent', () => {
getAllApps: jest.fn(() => {
return of([fakeApp]);
}),
getApp: jest.fn(() => of([fakeApp])),
}),
mockProvider(ErrorHandlerService),
mockProvider(DialogService, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Router } from '@angular/router';
import { FormBuilder } from '@ngneat/reactive-forms';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { map, of } from 'rxjs';
import { filter, map, of } from 'rxjs';
import { RequiresRolesDirective } from 'app/directives/requires-roles/requires-roles.directive';
import { CodeEditorLanguage } from 'app/enums/code-editor-language.enum';
import { Role } from 'app/enums/role.enum';
Expand Down Expand Up @@ -49,14 +49,17 @@ import { ErrorHandlerService } from 'app/services/error-handler.service';
],
})
export class CustomAppFormComponent implements OnInit {
protected isNew = signal(true);
protected requiredRoles = [Role.AppsWrite];
protected readonly CodeEditorLanguage = CodeEditorLanguage;
protected form = this.fb.group({
release_name: ['', Validators.required],
custom_compose_config_string: ['\n\n', Validators.required],
});

get isNew(): boolean {
return !this.existingApp;
}

protected existingApp: App | undefined;

protected isLoading = signal(false);
Expand All @@ -75,13 +78,16 @@ export class CustomAppFormComponent implements OnInit {
this.slideInRef.requireConfirmationWhen(() => {
return of(this.form.dirty);
});

this.existingApp = this.slideInRef.getData();

if (this.existingApp?.id) {
this.handleExistingApp();
}
}

ngOnInit(): void {
if (this.existingApp) {
this.setAppForEdit(this.existingApp);
} else {
if (!this.existingApp) {
this.setNewApp();
}
}
Expand All @@ -91,7 +97,6 @@ export class CustomAppFormComponent implements OnInit {
}

private setAppForEdit(app: App): void {
this.isNew.set(false);
this.form.patchValue({
release_name: app.id,
custom_compose_config_string: jsonToYaml(app.config),
Expand Down Expand Up @@ -121,14 +126,14 @@ export class CustomAppFormComponent implements OnInit {
{ custom_compose_config_string: data.custom_compose_config_string },
]);

const job$ = this.isNew() ? appCreate$ : appUpdate$;
const job$ = this.isNew ? appCreate$ : appUpdate$;

this.dialogService.jobDialog(
job$,
{
title: this.translate.instant('Custom App'),
canMinimize: false,
description: this.isNew()
description: this.isNew
? this.translate.instant('Creating custom app')
: this.translate.instant('Updating custom app'),
},
Expand All @@ -149,4 +154,25 @@ export class CustomAppFormComponent implements OnInit {
},
});
}

private handleExistingApp(): void {
this.isLoading.set(true);

this.appService.getApp(this.existingApp.id).pipe(
filter((apps) => apps.length > 0),
untilDestroyed(this),
).subscribe({
next: ([app]) => {
this.existingApp = app;
this.setAppForEdit(app);
},
error: (error: unknown) => {
this.errorHandler.showErrorModal(error);
this.slideInRef.close({ response: false, error });
},
complete: () => {
this.isLoading.set(false);
},
});
}
}
Loading