[NIFI-13641] - Remove parameter value from parameter context update request 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
This commit is contained in:
Rob Fellows 2024-08-16 10:42:35 -04:00 committed by GitHub
parent 30e8df676e
commit 046d72d0dd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 35 additions and 5 deletions

View File

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

View File

@ -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(),
@ -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
}
};

View File

@ -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();
}
});
@ -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
}
};
}

View File

@ -312,6 +312,11 @@ export interface BulletinEntity {
};
}
export interface ReferencedAsset {
id: string;
name: string;
}
export interface ParameterEntity {
canWrite?: boolean;
parameter: Parameter;
@ -327,6 +332,7 @@ export interface Parameter {
referencingComponents?: AffectedComponentEntity[];
parameterContext?: ParameterContextReferenceEntity;
inherited?: boolean;
referencedAssets?: ReferencedAsset[];
}
export interface ParameterContextEntity {

View File

@ -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,
@ -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
@ -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) {
@ -162,6 +165,11 @@ 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: {
@ -169,7 +177,8 @@ export class EditParameterDialog extends CloseOnEscapeDialog {
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
}
});
}