Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NIFI-14105: Fixing issue in EditProcessGroup dialog when there is no … #9593

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { CanvasState } from '../../../../../state';
import { createProcessGroup, uploadProcessGroup } from '../../../../../state/flow/flow.actions';
import { selectSaving } from '../../../../../state/flow/flow.selectors';
import { AsyncPipe } from '@angular/common';
import { ErrorBanner } from '../../../../../../../ui/common/error-banner/error-banner.component';
import { MatButtonModule } from '@angular/material/button';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';
Expand All @@ -42,7 +41,6 @@ import { ContextErrorBanner } from '../../../../../../../ui/common/context-error
standalone: true,
imports: [
AsyncPipe,
ErrorBanner,
MatButtonModule,
MatDialogModule,
MatFormFieldModule,
Expand Down Expand Up @@ -84,7 +82,7 @@ export class CreateProcessGroup extends CloseOnEscapeDialog {
});

dialogRequest.parameterContexts.forEach((parameterContext) => {
if (parameterContext.permissions.canRead) {
if (parameterContext.permissions.canRead && parameterContext.component) {
this.parameterContextsOptions.push({
text: parameterContext.component.name,
value: parameterContext.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ <h2 mat-dialog-title>{{ readonly ? 'Process Group Details' : 'Edit Process Group
<mat-form-field>
<mat-label>Parameter Context</mat-label>
<mat-select formControlName="parameterContext">
@for (option of parameterContextsOptions; track option) {
@for (option of parameterContextsOptions; track option.value) {
@if (option.description) {
<mat-option
[value]="option.value"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ describe('EditProcessGroup', () => {
let component: EditProcessGroup;
let fixture: ComponentFixture<EditProcessGroup>;

const parameterContextId = '95d509b9-018b-1000-daff-b7957ea7934f';
const noPermissionsParameterContextId = '95d509b9-018b-1000-daff-b7957ea7935e';
const selectedParameterContextId = '95d509b9-018b-1000-daff-b7957ea7934f';
const data: any = {
type: 'ProcessGroup',
uri: 'https://localhost:4200/nifi-api/process-groups/162380af-018c-1000-a7eb-f5d06f77168b',
Expand Down Expand Up @@ -63,7 +64,7 @@ describe('EditProcessGroup', () => {
defaultBackPressureObjectThreshold: 10000,
defaultBackPressureDataSizeThreshold: '1 GB',
parameterContext: {
id: parameterContextId
id: selectedParameterContextId
},
executionEngine: 'INHERITED',
maxConcurrentTasks: 1,
Expand Down Expand Up @@ -106,6 +107,38 @@ describe('EditProcessGroup', () => {
outputPortCount: 0
}
};
const parameterContexts = [
{
revision: {
version: 0
},
id: selectedParameterContextId,
uri: '',
permissions: {
canRead: true,
canWrite: true
},
component: {
name: 'params 2',
description: '',
parameters: [],
boundProcessGroups: [],
inheritedParameterContexts: [],
id: '95d509b9-018b-1000-daff-b7957ea7934f'
}
},
{
revision: {
version: 0
},
id: noPermissionsParameterContextId,
uri: '',
permissions: {
canRead: false,
canWrite: false
}
}
];

beforeEach(() => {
TestBed.configureTestingModule({
Expand All @@ -124,27 +157,7 @@ describe('EditProcessGroup', () => {
});
fixture = TestBed.createComponent(EditProcessGroup);
component = fixture.componentInstance;
component.parameterContexts = [
{
revision: {
version: 0
},
id: parameterContextId,
uri: '',
permissions: {
canRead: true,
canWrite: true
},
component: {
name: 'params 2',
description: '',
parameters: [],
boundProcessGroups: [],
inheritedParameterContexts: [],
id: '95d509b9-018b-1000-daff-b7957ea7934f'
}
}
];
component.parameterContexts = parameterContexts;

fixture.detectChanges();
});
Expand All @@ -154,7 +167,78 @@ describe('EditProcessGroup', () => {
});

it('verify parameter context value', () => {
expect(component.parameterContextsOptions.length).toEqual(2);
expect(component.editProcessGroupForm.get('parameterContext')?.value).toEqual(parameterContextId);
expect(component.parameterContextsOptions.length).toEqual(3);
expect(component.editProcessGroupForm.get('parameterContext')?.value).toEqual(selectedParameterContextId);
});

describe('no permissions to available parameter context', () => {
it('verify selected parameter context with permissions', () => {
expect(component.parameterContextsOptions.length).toEqual(3);
component.parameterContextsOptions.forEach((parameterContextsOption) => {
if (parameterContextsOption.value === noPermissionsParameterContextId) {
expect(parameterContextsOption.disabled).toBeTruthy();
} else if (parameterContextsOption.value === selectedParameterContextId) {
expect(parameterContextsOption.disabled).toBeFalsy();
}
});
});

it('verify selected parameter context with no permissions', () => {
// change the selected parameter context to one with no permissions
component.request = {
...data,
entity: {
...data.entity,
component: {
...data.entity.component,
parameterContext: {
id: noPermissionsParameterContextId
}
}
}
};

// reset the parameter contexts to rebuild the options
component.parameterContexts = [...parameterContexts];

fixture.detectChanges();

expect(component.parameterContextsOptions.length).toEqual(3);
component.parameterContextsOptions.forEach((parameterContextsOption) => {
if (parameterContextsOption.value === noPermissionsParameterContextId) {
expect(parameterContextsOption.disabled).toBeFalsy();
} else if (parameterContextsOption.value === selectedParameterContextId) {
expect(parameterContextsOption.disabled).toBeFalsy();
}
});
});

it('verify no selected parameter context', () => {
// clear the selected parameter context
component.request = {
...data,
entity: {
...data.entity,
component: {
...data.entity.component,
parameterContext: undefined
}
}
};

// reset the parameter contexts to rebuild the options
component.parameterContexts = [...parameterContexts];

fixture.detectChanges();

expect(component.parameterContextsOptions.length).toEqual(3);
component.parameterContextsOptions.forEach((parameterContextsOption) => {
if (parameterContextsOption.value === noPermissionsParameterContextId) {
expect(parameterContextsOption.disabled).toBeTruthy();
} else if (parameterContextsOption.value === selectedParameterContextId) {
expect(parameterContextsOption.disabled).toBeFalsy();
}
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,27 @@ import { ContextErrorBanner } from '../../../../../../../ui/common/context-error
})
export class EditProcessGroup extends TabbedDialog {
@Input() set parameterContexts(parameterContexts: ParameterContextEntity[]) {
this.initializeParameterContextOptions();

parameterContexts.forEach((parameterContext) => {
if (parameterContext.permissions.canRead) {
if (parameterContext.permissions.canRead && parameterContext.component) {
this.parameterContextsOptions.push({
text: parameterContext.component.name,
value: parameterContext.id,
description: parameterContext.component.description
});
} else {
let disabled: boolean;
if (this.request.entity.component.parameterContext) {
disabled = this.request.entity.component.parameterContext.id !== parameterContext.id;
} else {
disabled = true;
}

this.parameterContextsOptions.push({
text: parameterContext.id,
value: parameterContext.id,
disabled: this.request.entity.component.parameterContext.id !== parameterContext.id
disabled
});
}
});
Expand Down Expand Up @@ -167,10 +176,7 @@ export class EditProcessGroup extends TabbedDialog {

this.readonly = !request.entity.permissions.canWrite;

this.parameterContextsOptions.push({
text: 'No parameter context',
value: null
});
this.initializeParameterContextOptions();

this.editProcessGroupForm = this.formBuilder.group({
name: new FormControl(request.entity.component.name, Validators.required),
Expand Down Expand Up @@ -203,6 +209,15 @@ export class EditProcessGroup extends TabbedDialog {
this.executionEngineChanged(request.entity.component.executionEngine);
}

private initializeParameterContextOptions(): void {
this.parameterContextsOptions = [
{
text: 'No parameter context',
value: null
}
];
}

executionEngineChanged(value: string): void {
if (value == this.STATELESS) {
this.editProcessGroupForm.addControl(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class GroupComponents {
});

dialogRequest.parameterContexts.forEach((parameterContext) => {
if (parameterContext.permissions.canRead) {
if (parameterContext.permissions.canRead && parameterContext.component) {
this.parameterContextsOptions.push({
text: parameterContext.component.name,
value: parameterContext.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,11 +534,14 @@ export class ParameterContextListingEffects {
ofType(ParameterContextListingActions.promptParameterContextDeletion),
map((action) => action.request),
tap((request) => {
// @ts-ignore - component will be defined since the user has permissions to delete the context, but it is optional as defined by the type
const name = request.parameterContext.component.name;

const dialogReference = this.dialog.open(YesNoDialog, {
...SMALL_DIALOG,
data: {
title: 'Delete Parameter Context',
message: `Delete parameter context ${request.parameterContext.component.name}?`
message: `Delete parameter context ${name}?`
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { Client } from '../../../../../service/client.service';
import { ParameterTable } from '../parameter-table/parameter-table.component';
import {
EditParameterResponse,
ParameterContext,
ParameterContextEntity,
ParameterContextUpdateRequestEntity,
ParameterEntity,
Expand Down Expand Up @@ -104,20 +105,23 @@ export class EditParameterContext extends TabbedDialog {
this.isNew = false;
this.readonly = !request.parameterContext.permissions.canWrite;

// @ts-ignore - component will be defined since the user has permissions to edit the context, but it is optional as defined by the type
const parameterContext: ParameterContext = request.parameterContext.component;

this.editParameterContextForm = this.formBuilder.group({
name: new FormControl(request.parameterContext.component.name, Validators.required),
description: new FormControl(request.parameterContext.component.description),
name: new FormControl(parameterContext.name, Validators.required),
description: new FormControl(parameterContext.description),
parameters: new FormControl({
value: request.parameterContext.component.parameters,
value: parameterContext.parameters,
disabled: this.readonly
}),
inheritedParameterContexts: new FormControl({
value: request.parameterContext.component.inheritedParameterContexts,
value: parameterContext.inheritedParameterContexts,
disabled: this.readonly
})
});
if (request.parameterContext.component.parameterProviderConfiguration) {
this.parameterProvider = request.parameterContext.component.parameterProviderConfiguration.component;
if (parameterContext.parameterProviderConfiguration) {
this.parameterProvider = parameterContext.parameterProviderConfiguration.component;
}
} else {
this.isNew = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export class ParameterContextInheritance implements ControlValueAccessor {
}

hasDescription(entity: ParameterContextEntity): boolean {
return !this.nifiCommon.isBlank(entity.component.description);
return !this.nifiCommon.isBlank(entity.component?.description);
}

removeSelected(entity: ParameterContextEntity, i: number): void {
Expand Down Expand Up @@ -172,12 +172,15 @@ export class ParameterContextInheritance implements ControlValueAccessor {

private serializeInheritedParameterContexts(): ParameterContextReferenceEntity[] {
return this.selectedParameterContexts.map((parameterContext) => {
// @ts-ignore - component will be defined since the user has permissions to inherit from the context, but it is optional as defined by the type
const name = parameterContext.component.name;

return {
permissions: parameterContext.permissions,
id: parameterContext.id,
component: {
id: parameterContext.component.id,
name: parameterContext.component.name
id: parameterContext.id,
name
}
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ export class ParameterContextTable {
}

formatName(entity: ParameterContextEntity): string {
return this.canRead(entity) ? entity.component.name : entity.id;
return this.canRead(entity) && entity.component ? entity.component.name : entity.id;
}

formatProvider(entity: ParameterContextEntity): string {
if (!this.canRead(entity)) {
if (!this.canRead(entity) || !entity.component) {
return '';
}
const paramProvider = entity.component.parameterProviderConfiguration;
Expand All @@ -78,7 +78,7 @@ export class ParameterContextTable {
}

formatDescription(entity: ParameterContextEntity): string {
return this.canRead(entity) ? entity.component.description : '';
return this.canRead(entity) && entity.component ? entity.component.description : '';
}

editClicked(entity: ParameterContextEntity): void {
Expand All @@ -105,14 +105,14 @@ export class ParameterContextTable {
}

canGoToParameterProvider(entity: ParameterContextEntity): boolean {
if (!this.canRead(entity)) {
if (!this.canRead(entity) || !entity.component) {
return false;
}
return !!entity.component.parameterProviderConfiguration;
}

getParameterProviderLink(entity: ParameterContextEntity): string[] {
if (!entity.component.parameterProviderConfiguration) {
if (!this.canRead(entity) || !entity.component || !entity.component.parameterProviderConfiguration) {
return [];
}
return ['/settings', 'parameter-providers', entity.component.parameterProviderConfiguration.id];
Expand Down
Loading
Loading