From a5f2881d02238d6a6de59f2ec6d6ccc69acd7490 Mon Sep 17 00:00:00 2001 From: Matt Gilman Date: Thu, 24 Oct 2024 12:52:53 -0400 Subject: [PATCH] NIFI-13926: Removed used of default branch name in favor of null in Import From Registry and Start Version Control. (#9443) - Reset form fields as necessary when queries to load buckets, branches, etc fail. This closes #9443 --- .../flow-designer/service/registry.service.ts | 6 +- .../flow-designer/state/flow/flow.effects.ts | 8 +- .../import-from-registry.component.ts | 22 ++-- .../save-version-dialog.component.ts | 107 ++++++++++-------- 4 files changed, 79 insertions(+), 64 deletions(-) diff --git a/nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/flow-designer/service/registry.service.ts b/nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/flow-designer/service/registry.service.ts index 1ca7566241..50bea55535 100644 --- a/nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/flow-designer/service/registry.service.ts +++ b/nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/flow-designer/service/registry.service.ts @@ -34,7 +34,7 @@ export class RegistryService { return this.httpClient.get(`${RegistryService.API}/flow/registries/${registryId}/branches`); } - getBuckets(registryId: string, branch?: string): Observable { + getBuckets(registryId: string, branch?: string | null): Observable { let params: HttpParams = new HttpParams(); if (branch) { params = params.set('branch', branch); @@ -42,7 +42,7 @@ export class RegistryService { return this.httpClient.get(`${RegistryService.API}/flow/registries/${registryId}/buckets`, { params }); } - getFlows(registryId: string, bucketId: string, branch?: string): Observable { + getFlows(registryId: string, bucketId: string, branch?: string | null): Observable { let params: HttpParams = new HttpParams(); if (branch) { params = params.set('branch', branch); @@ -52,7 +52,7 @@ export class RegistryService { }); } - getFlowVersions(registryId: string, bucketId: string, flowId: string, branch?: string): Observable { + getFlowVersions(registryId: string, bucketId: string, flowId: string, branch?: string | null): Observable { let params: HttpParams = new HttpParams(); if (branch) { params = params.set('branch', branch); diff --git a/nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/flow-designer/state/flow/flow.effects.ts b/nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/flow-designer/state/flow/flow.effects.ts index c996b9b56f..7513c14f1e 100644 --- a/nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/flow-designer/state/flow/flow.effects.ts +++ b/nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/flow-designer/state/flow/flow.effects.ts @@ -888,7 +888,7 @@ export class FlowEffects { dialogReference.componentInstance.getBuckets = ( registryId: string, - branch?: string + branch?: string | null ): Observable => { return this.registryService.getBuckets(registryId, branch).pipe( take(1), @@ -911,7 +911,7 @@ export class FlowEffects { dialogReference.componentInstance.getFlows = ( registryId: string, bucketId: string, - branch?: string + branch?: string | null ): Observable => { return this.registryService.getFlows(registryId, bucketId, branch).pipe( take(1), @@ -935,7 +935,7 @@ export class FlowEffects { registryId: string, bucketId: string, flowId: string, - branch?: string + branch?: string | null ): Observable => { return this.registryService.getFlowVersions(registryId, bucketId, flowId, branch).pipe( take(1), @@ -3500,7 +3500,7 @@ export class FlowEffects { dialogReference.componentInstance.getBuckets = ( registryId: string, - branch?: string + branch?: string | null ): Observable => { return this.registryService.getBuckets(registryId, branch).pipe( take(1), diff --git a/nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/flow-designer/ui/canvas/items/flow/import-from-registry/import-from-registry.component.ts b/nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/flow-designer/ui/canvas/items/flow/import-from-registry/import-from-registry.component.ts index 929d69eb94..ed9b47e2c3 100644 --- a/nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/flow-designer/ui/canvas/items/flow/import-from-registry/import-from-registry.component.ts +++ b/nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/flow-designer/ui/canvas/items/flow/import-from-registry/import-from-registry.component.ts @@ -84,13 +84,17 @@ import { ContextErrorBanner } from '../../../../../../../ui/common/context-error }) export class ImportFromRegistry extends CloseOnEscapeDialog implements OnInit { @Input() getBranches: (registryId: string) => Observable = () => of([]); - @Input() getBuckets!: (registryId: string, branch?: string) => Observable; - @Input() getFlows!: (registryId: string, bucketId: string, branch?: string) => Observable; + @Input() getBuckets!: (registryId: string, branch?: string | null) => Observable; + @Input() getFlows!: ( + registryId: string, + bucketId: string, + branch?: string | null + ) => Observable; @Input() getFlowVersions!: ( registryId: string, bucketId: string, flowId: string, - branch?: string + branch?: string | null ) => Observable; saving$ = this.store.select(selectSaving); @@ -151,7 +155,7 @@ export class ImportFromRegistry extends CloseOnEscapeDialog implements OnInit { this.importFromRegistryForm = this.formBuilder.group({ registry: new FormControl(this.registryClientOptions[0].value, Validators.required), - branch: new FormControl('default', Validators.required), + branch: new FormControl(null), bucket: new FormControl(null, Validators.required), flow: new FormControl(null, Validators.required), keepParameterContexts: new FormControl(true, Validators.required) @@ -184,7 +188,7 @@ export class ImportFromRegistry extends CloseOnEscapeDialog implements OnInit { private clearBranches(): void { this.branchOptions = []; - this.importFromRegistryForm.get('branch')?.setValue('default'); + this.importFromRegistryForm.get('branch')?.setValue(null); this.clearBuckets(); } @@ -211,6 +215,7 @@ export class ImportFromRegistry extends CloseOnEscapeDialog implements OnInit { this.importFromRegistryForm.get('flow')?.setValue(null); this.flowOptions = []; this.dataSource.data = []; + this.selectedFlowVersion = null; } flowChanged(flowId: string): void { @@ -245,7 +250,7 @@ export class ImportFromRegistry extends CloseOnEscapeDialog implements OnInit { } } - loadBuckets(registryId: string, branch?: string): void { + loadBuckets(registryId: string, branch?: string | null): void { this.bucketOptions = []; this.getBuckets(registryId, branch) @@ -271,7 +276,7 @@ export class ImportFromRegistry extends CloseOnEscapeDialog implements OnInit { }); } - loadFlows(registryId: string, bucketId: string, branch?: string): void { + loadFlows(registryId: string, bucketId: string, branch?: string | null): void { this.flowOptions = []; this.flowLookup.clear(); @@ -298,8 +303,9 @@ export class ImportFromRegistry extends CloseOnEscapeDialog implements OnInit { }); } - loadVersions(registryId: string, bucketId: string, flowId: string, branch?: string): void { + loadVersions(registryId: string, bucketId: string, flowId: string, branch?: string | null): void { this.dataSource.data = []; + this.selectedFlowVersion = null; this.selectedFlowDescription = this.flowLookup.get(flowId)?.description; this.getFlowVersions(registryId, bucketId, flowId, branch) diff --git a/nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/flow-designer/ui/canvas/items/flow/save-version-dialog/save-version-dialog.component.ts b/nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/flow-designer/ui/canvas/items/flow/save-version-dialog/save-version-dialog.component.ts index b0eaf16eee..7e6c305899 100644 --- a/nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/flow-designer/ui/canvas/items/flow/save-version-dialog/save-version-dialog.component.ts +++ b/nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/flow-designer/ui/canvas/items/flow/save-version-dialog/save-version-dialog.component.ts @@ -67,7 +67,7 @@ import { ContextErrorBanner } from '../../../../../../../ui/common/context-error }) export class SaveVersionDialog extends CloseOnEscapeDialog implements OnInit { @Input() getBranches: (registryId: string) => Observable = () => of([]); - @Input() getBuckets: (registryId: string, branch?: string) => Observable = () => of([]); + @Input() getBuckets: (registryId: string, branch?: string | null) => Observable = () => of([]); @Input({ required: true }) saving!: Signal; @Output() save: EventEmitter = new EventEmitter(); @@ -109,7 +109,7 @@ export class SaveVersionDialog extends CloseOnEscapeDialog implements OnInit { this.saveVersionForm = formBuilder.group({ registry: new FormControl(this.registryClientOptions[0].value, Validators.required), - branch: new FormControl('default', Validators.required), + branch: new FormControl(null), bucket: new FormControl(null, Validators.required), flowName: new FormControl(null, Validators.required), flowDescription: new FormControl(null), @@ -137,57 +137,64 @@ export class SaveVersionDialog extends CloseOnEscapeDialog implements OnInit { } } - loadBranches(registryId: string): void { - if (registryId) { - this.branchOptions = []; - - this.getBranches(registryId) - .pipe(take(1)) - .subscribe((branches: BranchEntity[]) => { - if (branches.length > 0) { - branches.forEach((entity: BranchEntity) => { - this.branchOptions.push({ - text: entity.branch.name, - value: entity.branch.name - }); - }); - - const branchId = this.branchOptions[0].value; - if (branchId) { - this.saveVersionForm.get('branch')?.setValue(branchId); - this.loadBuckets(registryId, branchId); - } - } - }); - } + private clearBranches(): void { + this.branchOptions = []; + this.saveVersionForm.get('branch')?.setValue(null); + this.clearBuckets(); } - loadBuckets(registryId: string, branch?: string): void { - if (registryId) { - this.bucketOptions = []; + loadBranches(registryId: string): void { + this.clearBranches(); - this.getBuckets(registryId, branch) - .pipe(take(1)) - .subscribe((buckets: BucketEntity[]) => { - if (buckets.length > 0) { - buckets.forEach((entity: BucketEntity) => { - // only allow buckets to be selectable if the user can read and write to them - if (entity.permissions.canRead && entity.permissions.canWrite) { - this.bucketOptions.push({ - text: entity.bucket.name, - value: entity.id, - description: entity.bucket.description - }); - } + this.getBranches(registryId) + .pipe(take(1)) + .subscribe((branches: BranchEntity[]) => { + if (branches.length > 0) { + branches.forEach((entity: BranchEntity) => { + this.branchOptions.push({ + text: entity.branch.name, + value: entity.branch.name }); + }); - const bucketId = this.bucketOptions[0].value; - if (bucketId) { - this.saveVersionForm.get('bucket')?.setValue(bucketId); - } + const branchId = this.branchOptions[0].value; + if (branchId) { + this.saveVersionForm.get('branch')?.setValue(branchId); + this.loadBuckets(registryId, branchId); } - }); - } + } + }); + } + + private clearBuckets(): void { + this.bucketOptions = []; + this.saveVersionForm.get('bucket')?.setValue(null); + } + + loadBuckets(registryId: string, branch?: string | null): void { + this.clearBuckets(); + + this.getBuckets(registryId, branch) + .pipe(take(1)) + .subscribe((buckets: BucketEntity[]) => { + if (buckets.length > 0) { + buckets.forEach((entity: BucketEntity) => { + // only allow buckets to be selectable if the user can read and write to them + if (entity.permissions.canRead && entity.permissions.canWrite) { + this.bucketOptions.push({ + text: entity.bucket.name, + value: entity.id, + description: entity.bucket.description + }); + } + }); + + const bucketId = this.bucketOptions[0].value; + if (bucketId) { + this.saveVersionForm.get('bucket')?.setValue(bucketId); + } + } + }); } registryChanged(registryId: string): void { @@ -200,8 +207,10 @@ export class SaveVersionDialog extends CloseOnEscapeDialog implements OnInit { } branchChanged(branch: string): void { - const registryId = this.saveVersionForm.get('registry')?.value; - this.loadBuckets(registryId, branch); + const selectedRegistryId: string | null = this.saveVersionForm.get('registry')?.value; + if (selectedRegistryId) { + this.loadBuckets(selectedRegistryId, branch); + } } submitForm() {