Freedom9339 commented on code in PR #8965:
URL: https://github.com/apache/nifi/pull/8965#discussion_r1742282252


##########
nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/flow-designer/ui/move-controller-service/move-controller-service.component.ts:
##########
@@ -0,0 +1,232 @@
+/*
+ * 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 } from '@angular/core';
+import { MAT_DIALOG_DATA, MatDialogModule } from '@angular/material/dialog';
+import { FormBuilder, FormControl, FormGroup, ReactiveFormsModule, Validators 
} from '@angular/forms';
+import {
+    ControllerServiceEntity,
+    ControllerServiceReferencingComponent,
+    ControllerServiceReferencingComponentEntity
+} from '../../../../state/shared';
+import { MatInputModule } from '@angular/material/input';
+import { MatCheckboxModule } from '@angular/material/checkbox';
+import { MatButtonModule } from '@angular/material/button';
+import { AsyncPipe, NgTemplateOutlet } from '@angular/common';
+import { MatTabsModule } from '@angular/material/tabs';
+import { MatOptionModule } from '@angular/material/core';
+import { MatSelectModule } from '@angular/material/select';
+import { ControllerServiceApi } from 
'../../../../ui/common/controller-service/controller-service-api/controller-service-api.component';
+import { ControllerServiceReferences } from 
'../../../../ui/common/controller-service/controller-service-references/controller-service-references.component';
+import { NifiSpinnerDirective } from 
'../../../../ui/common/spinner/nifi-spinner.directive';
+import { TextTip, NifiTooltipDirective, SelectOption } from '@nifi/shared';
+import { Store } from '@ngrx/store';
+import { CloseOnEscapeDialog } from '@nifi/shared';
+import { moveControllerService } from 
'../../state/controller-services/controller-services.actions';
+import { NiFiState } from 'apps/nifi/src/app/state';
+import { MoveControllerServiceDialogRequest } from 
'../../state/controller-services';
+import { NgIf } from '@angular/common';
+import { BreadcrumbEntity } from '../../state/shared';
+
+@Component({
+    selector: 'move-controller-service',
+    standalone: true,
+    templateUrl: './move-controller-service.component.html',
+    imports: [
+        ReactiveFormsModule,
+        MatDialogModule,
+        MatInputModule,
+        MatCheckboxModule,
+        MatButtonModule,
+        MatTabsModule,
+        MatOptionModule,
+        MatSelectModule,
+        ControllerServiceApi,
+        ControllerServiceReferences,
+        AsyncPipe,
+        NifiSpinnerDirective,
+        NifiTooltipDirective,
+        NgTemplateOutlet,
+        NgIf
+    ],
+    styleUrls: ['./move-controller-service.component.scss']
+})
+export class MoveControllerService extends CloseOnEscapeDialog {
+    @Input() goToReferencingComponent!: (component: 
ControllerServiceReferencingComponent) => void;
+    protected readonly TextTip = TextTip;
+    protected controllerServiceActionProcessGroups: SelectOption[] = [];
+
+    controllerService: ControllerServiceEntity;
+
+    moveControllerServiceForm: FormGroup;
+
+    constructor(
+        @Inject(MAT_DIALOG_DATA) public request: 
MoveControllerServiceDialogRequest,
+        private store: Store<NiFiState>,
+        private formBuilder: FormBuilder
+    ) {
+        super();
+
+        this.controllerService = request.controllerService;
+
+        // build the form
+        this.moveControllerServiceForm = this.formBuilder.group({
+            processGroups: new FormControl('Process Group', 
Validators.required)
+        });
+
+        const parentControllerServices = 
request.parentControllerServices.filter(
+            (cs) => cs.parentGroupId != request.controllerService.parentGroupId
+        );
+
+        const processGroups: SelectOption[] = [];
+        if (request.breadcrumb != undefined) {
+            this.loadParentOption(request.breadcrumb, 
parentControllerServices, processGroups);
+        }
+        this.loadChildOptions(request.childProcessGroupOptions, 
request.processGroupEntity, processGroups);
+        this.controllerServiceActionProcessGroups = processGroups;
+
+        const firstEnabled = processGroups.findIndex((pg) => !pg.disabled);
+        if (firstEnabled != -1) {
+            
this.moveControllerServiceForm.controls['processGroups'].setValue(processGroups[firstEnabled].value);
+        }
+    }
+
+    loadParentOption(
+        breadcrumb: BreadcrumbEntity,
+        parentControllerServices: ControllerServiceEntity[],
+        processGroups: SelectOption[]
+    ) {
+        if (breadcrumb.parentBreadcrumb != undefined) {
+            const parentBreadcrumb = breadcrumb.parentBreadcrumb;
+            if (parentBreadcrumb.permissions.canRead && 
parentBreadcrumb.permissions.canWrite) {
+                const option: SelectOption = {
+                    text: parentBreadcrumb.breadcrumb.name + ' (Parent)',
+                    value: parentBreadcrumb.breadcrumb.id
+                };
+
+                let errorMsg = '';
+                const descriptors = 
this.controllerService.component.descriptors;
+                for (const descriptor in descriptors) {
+                    if (descriptors[descriptor].identifiesControllerService != 
undefined) {
+                        const controllerId = 
this.controllerService.component.properties[descriptors[descriptor].name];
+                        if (
+                            controllerId != null &&
+                            !parentControllerServices.some((service) => 
service.id == controllerId)
+                        ) {
+                            errorMsg += '[' + descriptors[descriptor].name + 
']';
+                        }
+                    }
+                }
+
+                if (errorMsg != '') {
+                    option.description =
+                        'The following properties reference controller 
services that would be out of scope for this ' +
+                        'process group: ' +
+                        errorMsg;
+                    option.disabled = true;
+                } else {
+                    option.disabled = false;
+                }
+
+                processGroups.push(option);
+            }
+        }
+    }
+
+    loadChildOptions(
+        childProcessGroupOptions: SelectOption[],
+        currentProcessGroupEntity: any,
+        processGroups: SelectOption[]
+    ) {
+        const referencingComponents: 
ControllerServiceReferencingComponentEntity[] =
+            this.controllerService.component.referencingComponents;
+        childProcessGroupOptions.forEach((child: SelectOption) => {
+            const option: SelectOption = {
+                text: child.text,
+                value: child.value
+            };
+
+            const root = 
this.getProcessGroupById(currentProcessGroupEntity.component, child.value ?? 
'');

Review Comment:
   I've fixed the recursion logic.



-- 
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