Skip to content

Commit

Permalink
NIFI-14136: Fixing issue where a new Parameters value would be cleare…
Browse files Browse the repository at this point in the history
…d if it were edited prior to submission.
  • Loading branch information
mcgilman committed Jan 9, 2025
1 parent b80a673 commit cf7413a
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@

import { ComponentFixture, TestBed } from '@angular/core/testing';

import { ParameterTable } from './parameter-table.component';
import { ParameterItem, ParameterTable } from './parameter-table.component';
import { provideMockStore } from '@ngrx/store/testing';
import { initialState } from '../../../state/parameter-context-listing/parameter-context-listing.reducer';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { EditParameterResponse } from '../../../../../state/shared';
import { Observable, of } from 'rxjs';
import { Parameter } from '@nifi/shared';

describe('ParameterTable', () => {
let component: ParameterTable;
Expand All @@ -39,4 +42,73 @@ describe('ParameterTable', () => {
it('should create', () => {
expect(component).toBeTruthy();
});

it('should handle no parameters with no edits', () => {
component.writeValue([]);
expect(component.serializeParameters()).toEqual([]);
});

it('should handle no parameters with one added', () => {
component.writeValue([]);

const parameter: Parameter = {
name: 'param',
value: 'value',
description: 'asdf',
sensitive: false
};
component.createNewParameter = (): Observable<EditParameterResponse> => {
return of({
parameter,
valueChanged: true
});
};
component.newParameterClicked();

expect(component.serializeParameters()).toEqual([{ parameter }]);
});

it('should handle no parameters with one added and then edited', () => {
component.writeValue([]);

const parameter: Parameter = {
name: 'param',
value: 'value',
description: 'asdf',
sensitive: false
};
component.createNewParameter = (): Observable<EditParameterResponse> => {
return of({
parameter,
valueChanged: true
});
};
component.newParameterClicked();

const parameterItem: ParameterItem = component.dataSource.data[0];
expect(parameterItem.originalEntity.parameter).toEqual(parameter);

const description = 'updated description';
component.editParameter = (): Observable<EditParameterResponse> => {
return of({
parameter: {
name: 'param',
value: null,
sensitive: false,
description
},
valueChanged: false
});
};
component.editClicked(parameterItem);

expect(component.serializeParameters()).toEqual([
{
parameter: {
...parameter,
description
}
}
]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,19 @@ export class ParameterTable implements AfterViewInit, ControlValueAccessor {
if (!item.updatedEntity) {
item.updatedEntity = {
parameter: {
...item.originalEntity.parameter,
value: null
...item.originalEntity.parameter
}
};

// if this parameter is an existing parameter, we want to mark the value as null. a null value
// for existing parameters will indicate to the server that the value is unchanged. this is needed
// for sensitive parameters where the value isn't available client side. for new parameters which
// are not known on the server should not have their value cleared. this is relevant when the user
// created a new parameter and then subsequents edits it (e.g. to change the description) before
// submission.
if (!item.added) {
item.updatedEntity.parameter.value = null;
}
}

let hasChanged: boolean = response.valueChanged;
Expand Down Expand Up @@ -434,7 +443,10 @@ export class ParameterTable implements AfterViewInit, ControlValueAccessor {
this.onChange(this.serializeParameters());
}

private serializeParameters(): any[] {
/**
* Serializes the Parameters. Not private for testing purposes.
*/
serializeParameters(): any[] {
const parameters: ParameterItem[] = this.dataSource.data;

// only include dirty items
Expand Down

0 comments on commit cf7413a

Please sign in to comment.