Skip to content

Commit

Permalink
[NIFI-13641] - Remove parameter value from parameter context update r…
Browse files Browse the repository at this point in the history
…equest if there are referenced assets (#9173)

* [NIFI-13641] - Remove parameter value from parameter context update request if there are referenced assets

* move parameter sanitization of referenced assets/value into the payload construction rather than in the effect

* rename variable

* remove optionality of id from ReferencedAsset interface

This closes #9173
  • Loading branch information
rfellows authored Aug 16, 2024
1 parent 30e8df6 commit 046d72d
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import { ErrorHelper } from '../../../../service/error-helper.service';
import { HttpErrorResponse } from '@angular/common/http';
import { isDefinedAndNotNull, MEDIUM_DIALOG, SMALL_DIALOG, XL_DIALOG } from 'libs/shared/src';
import { BackNavigation } from '../../../../state/navigation';
import { Storage, NiFiCommon } from '@nifi/shared';
import { NiFiCommon, Storage } from '@nifi/shared';

@Injectable()
export class ParameterContextListingEffects {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,16 @@ export class EditParameterContext extends TabbedDialog {
this.parameters = [];
}

// The backend api doesn't support providing both a parameter value and referenced assets
// even though it returns both from the GET api. We must strip the value out if there are
// referenced assets.
const updatedParameters: ParameterEntity[] = this.parameters.slice();
updatedParameters.forEach((parameter: ParameterEntity) => {
if ((parameter.parameter.referencedAssets || []).length > 0) {
parameter.parameter.value = null;
}
});

const payload: any = {
revision: this.client.getRevision(pc),
disconnectedNodeAcknowledged: this.clusterConnectionService.isDisconnectionAcknowledged(),
Expand All @@ -175,7 +185,7 @@ export class EditParameterContext extends TabbedDialog {
id: pc.id,
name: this.editParameterContextForm.get('name')?.value,
description: this.editParameterContextForm.get('description')?.value,
parameters: this.parameters,
parameters: updatedParameters,
inheritedParameterContexts: this.editParameterContextForm.get('inheritedParameterContexts')?.value
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,10 @@ export class ParameterTable implements AfterViewInit, ControlValueAccessor {
item.entity.parameter.valueRemoved = parameter.valueRemoved;
item.dirty = true;

if (valueChanged) {
item.entity.parameter.referencedAssets = undefined;
}

this.handleChanged();
}
});
Expand Down Expand Up @@ -368,7 +372,8 @@ export class ParameterTable implements AfterViewInit, ControlValueAccessor {
sensitive: item.entity.parameter.sensitive,
description: item.entity.parameter.description,
value: item.entity.parameter.value,
valueRemoved: item.entity.parameter.valueRemoved
valueRemoved: item.entity.parameter.valueRemoved,
referencedAssets: item.entity.parameter.referencedAssets
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,11 @@ export interface BulletinEntity {
};
}

export interface ReferencedAsset {
id: string;
name: string;
}

export interface ParameterEntity {
canWrite?: boolean;
parameter: Parameter;
Expand All @@ -327,6 +332,7 @@ export interface Parameter {
referencingComponents?: AffectedComponentEntity[];
parameterContext?: ParameterContextReferenceEntity;
inherited?: boolean;
referencedAssets?: ReferencedAsset[];
}

export interface ParameterContextEntity {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import { Component, EventEmitter, Inject, Input, Output } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogModule } from '@angular/material/dialog';
import { EditParameterRequest, EditParameterResponse, Parameter } from '../../../state/shared';
import { EditParameterRequest, EditParameterResponse, Parameter, ReferencedAsset } from '../../../state/shared';
import { MatButtonModule } from '@angular/material/button';
import {
AbstractControl,
Expand Down Expand Up @@ -68,6 +68,8 @@ export class EditParameterDialog extends CloseOnEscapeDialog {
editParameterForm: FormGroup;
isNew: boolean;

private originalParameter: Parameter | undefined = undefined;

constructor(
@Inject(MAT_DIALOG_DATA) public request: EditParameterRequest,
private formBuilder: FormBuilder
Expand All @@ -77,6 +79,7 @@ export class EditParameterDialog extends CloseOnEscapeDialog {
// seed the form for the new parameter. when existingParameters are not specified, this is the
// existing parameter that populates the form
const parameter: Parameter | undefined = request.parameter;
this.originalParameter = parameter;

const validators: any[] = [Validators.required];
if (request.existingParameters) {
Expand Down Expand Up @@ -162,14 +165,20 @@ export class EditParameterDialog extends CloseOnEscapeDialog {
okClicked(): void {
const value: string = this.editParameterForm.get('value')?.value;
const empty: boolean = this.editParameterForm.get('empty')?.value;
let referencedAssets: ReferencedAsset[] | undefined = undefined;

if (this.originalParameter) {
referencedAssets = this.originalParameter.referencedAssets;
}

this.editParameter.next({
parameter: {
name: this.editParameterForm.get('name')?.value,
value: value === '' && !empty ? null : value,
valueRemoved: value === '' && !empty,
sensitive: this.editParameterForm.get('sensitive')?.value,
description: this.editParameterForm.get('description')?.value
description: this.editParameterForm.get('description')?.value,
referencedAssets
}
});
}
Expand Down

0 comments on commit 046d72d

Please sign in to comment.