scottyaslan commented on code in PR #8354:
URL: https://github.com/apache/nifi/pull/8354#discussion_r1479111499


##########
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-frontend/src/main/nifi/src/app/pages/flow-designer/ui/canvas/items/flow/import-from-registry/import-from-registry.component.ts:
##########
@@ -0,0 +1,337 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { Component, Inject, Input, OnInit } from '@angular/core';
+import { MAT_DIALOG_DATA, MatDialogModule } from '@angular/material/dialog';
+import { ImportFromRegistryDialogRequest } from '../../../../../state/flow';
+import { Store } from '@ngrx/store';
+import { CanvasState } from '../../../../../state';
+import {
+    BucketEntity,
+    isDefinedAndNotNull,
+    RegistryClientEntity,
+    SelectOption,
+    TextTipInput,
+    VersionedFlow,
+    VersionedFlowEntity,
+    VersionedFlowSnapshotMetadata,
+    VersionedFlowSnapshotMetadataEntity
+} from '../../../../../../../state/shared';
+import { selectSaving } from '../../../../../state/flow/flow.selectors';
+import { AsyncPipe, JsonPipe, NgForOf, NgIf, NgTemplateOutlet } from 
'@angular/common';
+import { ErrorBanner } from 
'../../../../../../../ui/common/error-banner/error-banner.component';
+import { MatButtonModule } from '@angular/material/button';
+import { MatFormFieldModule } from '@angular/material/form-field';
+import { MatInputModule } from '@angular/material/input';
+import { MatOptionModule } from '@angular/material/core';
+import { MatSelectModule } from '@angular/material/select';
+import { NifiSpinnerDirective } from 
'../../../../../../../ui/common/spinner/nifi-spinner.directive';
+import { FormBuilder, FormControl, FormGroup, ReactiveFormsModule, Validators 
} from '@angular/forms';
+import { TextTip } from 
'../../../../../../../ui/common/tooltips/text-tip/text-tip.component';
+import { NifiTooltipDirective } from 
'../../../../../../../ui/common/tooltips/nifi-tooltip.directive';
+import { MatIconModule } from '@angular/material/icon';
+import { Observable, take } from 'rxjs';
+import { MatCheckboxModule } from '@angular/material/checkbox';
+import { MatTableDataSource, MatTableModule } from '@angular/material/table';
+import { MatSortModule, Sort } from '@angular/material/sort';
+import { NiFiCommon } from '../../../../../../../service/nifi-common.service';
+import { selectTimeOffset } from 
'../../../../../../../state/flow-configuration/flow-configuration.selectors';
+import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
+import { Client } from '../../../../../../../service/client.service';
+import { importFromRegistry } from '../../../../../state/flow/flow.actions';
+
+@Component({
+    selector: 'import-from-registry',
+    standalone: true,
+    imports: [
+        AsyncPipe,
+        ErrorBanner,
+        MatButtonModule,
+        MatDialogModule,
+        MatFormFieldModule,
+        MatInputModule,
+        NgIf,
+        NifiSpinnerDirective,
+        ReactiveFormsModule,
+        MatOptionModule,
+        MatSelectModule,
+        NgForOf,
+        NifiTooltipDirective,
+        MatIconModule,
+        NgTemplateOutlet,
+        JsonPipe,
+        MatCheckboxModule,
+        MatSortModule,
+        MatTableModule
+    ],
+    templateUrl: './import-from-registry.component.html',
+    styleUrls: ['./import-from-registry.component.scss']
+})
+export class ImportFromRegistry implements OnInit {
+    @Input() getBuckets!: (registryId: string) => Observable<BucketEntity[]>;
+    @Input() getFlows!: (registryId: string, bucketId: string) => 
Observable<VersionedFlowEntity[]>;
+    @Input() getFlowVersions!: (
+        registryId: string,
+        bucketId: string,
+        flowId: string
+    ) => Observable<VersionedFlowSnapshotMetadataEntity[]>;
+
+    saving$ = this.store.select(selectSaving);
+    timeOffset = 0;
+
+    protected readonly TextTip = TextTip;
+
+    importFromRegistryForm: FormGroup;
+    registryClientOptions: SelectOption[] = [];
+    bucketOptions: SelectOption[] = [];
+    flowOptions: SelectOption[] = [];
+
+    flowLookup: Map<string, VersionedFlow> = new Map<string, VersionedFlow>();
+    selectedFlowDescription: string | undefined;
+
+    sort: Sort = {
+        active: 'version',
+        direction: 'desc'
+    };
+    displayedColumns: string[] = ['version', 'created', 'comments'];
+    dataSource: MatTableDataSource<VersionedFlowSnapshotMetadata> =
+        new MatTableDataSource<VersionedFlowSnapshotMetadata>();
+    selectedFlowVersion: number | null = null;
+
+    constructor(
+        @Inject(MAT_DIALOG_DATA) private dialogRequest: 
ImportFromRegistryDialogRequest,
+        private formBuilder: FormBuilder,
+        private store: Store<CanvasState>,
+        private nifiCommon: NiFiCommon,
+        private client: Client
+    ) {
+        this.store
+            .select(selectTimeOffset)
+            .pipe(isDefinedAndNotNull(), takeUntilDestroyed())
+            .subscribe((timeOffset: number) => {
+                this.timeOffset = timeOffset;
+            });
+
+        const sortedRegistries = 
dialogRequest.registryClients.slice().sort((a, b) => {
+            return this.nifiCommon.compareString(a.component.name, 
b.component.name);
+        });
+
+        sortedRegistries.forEach((registryClient: RegistryClientEntity) => {
+            if (registryClient.permissions.canRead) {
+                this.registryClientOptions.push({
+                    text: registryClient.component.name,
+                    value: registryClient.id,
+                    description: registryClient.component.description
+                });
+            }
+        });
+
+        this.importFromRegistryForm = this.formBuilder.group({
+            registry: new FormControl(this.registryClientOptions[0].value, 
Validators.required),
+            bucket: new FormControl(null, Validators.required),
+            flow: new FormControl(null, Validators.required),
+            keepParameterContexts: new FormControl(true, Validators.required)
+        });
+    }
+
+    ngOnInit(): void {
+        const selectedRegistryId = 
this.importFromRegistryForm.get('registry')?.value;
+
+        if (selectedRegistryId) {

Review Comment:
   Could we just disable the ability to import from a registry if none are 
available?
   
   Also, the messaging in current NiFi when attempting to import from a 
registry when no registries are available looks like:
   
   ![Screenshot 2024-02-05 at 8 15 58 
PM](https://github.com/apache/nifi/assets/6797571/5086694a-24c8-4bc3-9095-eb11fdac559b)
   
   but here you have:
   ![Screenshot 2024-02-05 at 8 17 06 
PM](https://github.com/apache/nifi/assets/6797571/1c638a1a-7af8-4784-a5e2-791cf536df17)
   
   Also, In current NiFi the user can click to go configure a registry from 
this dialog.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@nifi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to