mcgilman commented on code in PR #8159:
URL: https://github.com/apache/nifi/pull/8159#discussion_r1430362779


##########
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-frontend/src/main/nifi/src/app/pages/flow-designer/state/controller-services/controller-services.effects.ts:
##########
@@ -234,18 +253,134 @@ export class ControllerServicesEffects {
                         );
                     };
 
-                    editDialogReference.componentInstance.getServiceLink = 
(serviceId: string) => {
-                        return 
this.controllerServiceService.getControllerService(serviceId).pipe(
-                            take(1),
-                            map((serviceEntity) => {
-                                return [
+                    const goTo = (commands: string[], destination: string): 
void => {
+                        if 
(editDialogReference.componentInstance.editControllerServiceForm.dirty) {
+                            const saveChangesDialogReference = 
this.dialog.open(YesNoDialog, {
+                                data: {
+                                    title: 'Controller Service Configuration',
+                                    message: `Save changes before going to 
this ${destination}?`
+                                },
+                                panelClass: 'small-dialog'
+                            });
+
+                            
saveChangesDialogReference.componentInstance.yes.pipe(take(1)).subscribe(() => {
+                                
editDialogReference.componentInstance.submitForm(commands);
+                            });
+
+                            
saveChangesDialogReference.componentInstance.no.pipe(take(1)).subscribe(() => {
+                                editDialogReference.close('ROUTED');
+                                this.router.navigate(commands);
+                            });
+                        } else {
+                            editDialogReference.close('ROUTED');
+                            this.router.navigate(commands);
+                        }
+                    };
+
+                    if (parameterContext != null) {
+                        editDialogReference.componentInstance.getParameters = 
(sensitive: boolean) => {
+                            return 
this.flowService.getParameterContext(parameterContext.id).pipe(
+                                take(1),
+                                map((response) => 
response.component.parameters),
+                                map((parameterEntities) => {
+                                    return parameterEntities
+                                        .map((parameterEntity: 
ParameterEntity) => parameterEntity.parameter)
+                                        .filter((parameter: Parameter) => 
parameter.sensitive == sensitive);
+                                })
+                            );
+                        };
+
+                        editDialogReference.componentInstance.parameterContext 
= parameterContext;
+                        editDialogReference.componentInstance.goToParameter = 
(parameter: string) => {
+                            const commands: string[] = ['/parameter-contexts', 
parameterContext.id];
+                            goTo(commands, 'Parameter');
+                        };
+
+                        
editDialogReference.componentInstance.convertToParameter = (
+                            name: string,
+                            sensitive: boolean,
+                            value: string | null
+                        ) => {
+                            return 
this.parameterService.getParameterContext(parameterContext.id, false).pipe(
+                                switchMap((parameterContextEntity) => {
+                                    const existingParameters: string[] =
+                                        
parameterContextEntity.component.parameters.map(
+                                            (parameterEntity: ParameterEntity) 
=> parameterEntity.parameter.name
+                                        );
+                                    const convertToParameterDialogRequest: 
EditParameterRequest = {
+                                        parameter: {
+                                            name,
+                                            value,
+                                            sensitive,
+                                            description: ''
+                                        },
+                                        existingParameters
+                                    };
+                                    const convertToParameterDialogReference = 
this.dialog.open(EditParameterDialog, {
+                                        data: convertToParameterDialogRequest,
+                                        panelClass: 'medium-dialog'
+                                    });
+
+                                    
convertToParameterDialogReference.componentInstance.saving$ =
+                                        
this.store.select(selectParameterSaving);
+
+                                    
convertToParameterDialogReference.componentInstance.cancel.pipe(
+                                        
takeUntil(convertToParameterDialogReference.afterClosed()),
+                                        tap(() => 
ParameterActions.stopPollingParameterContextUpdateRequest())
+                                    );
+
+                                    return 
convertToParameterDialogReference.componentInstance.editParameter.pipe(
+                                        
takeUntil(convertToParameterDialogReference.afterClosed()),
+                                        switchMap((dialogResponse: 
EditParameterResponse) => {
+                                            this.store.dispatch(
+                                                
ParameterActions.submitParameterContextUpdateRequest({
+                                                    request: {
+                                                        id: 
parameterContext.id,
+                                                        payload: {
+                                                            revision: 
this.client.getRevision(parameterContextEntity),
+                                                            component: {
+                                                                id: 
parameterContextEntity.id,
+                                                                parameters: [{ 
parameter: dialogResponse.parameter }]
+                                                            }
+                                                        }
+                                                    }
+                                                })
+                                            );
+
+                                            return 
this.store.select(selectParameterSaving).pipe(
+                                                
takeUntil(convertToParameterDialogReference.afterClosed()),
+                                                filter((parameterSaving) => 
parameterSaving === false),
+                                                map(() => {
+                                                    
convertToParameterDialogReference.close();
+                                                    return 
`#{${dialogResponse.parameter.name}}`;
+                                                })
+                                            );
+                                        })
+                                    );
+                                }),
+                                catchError((error) => {
+                                    // TODO handle error
+                                    return NEVER;
+                                })
+                            );
+                        };
+                    }

Review Comment:
   Thanks for calling this out. I agree that we should investigate ways to 
improve this. The block is identical but does reference a method that is 
different and the dialog instances that are different. From an offline 
discussion, we will investigate opportunities to pull some of this logic into 
separate services allowing the Effects to be more concise and helpful with some 
re-use in follow on efforts. 



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to