Skip to content

Commit

Permalink
NIFI-3785: Added protection against null root. Applied suggestions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Freedom9339 committed Oct 16, 2024
1 parent f83fe03 commit 275c18d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@ <h2 mat-dialog-title>Move Controller Service</h2>
<form class="controller-service-move-form" [formGroup]="moveControllerServiceForm">
<mat-dialog-content>
<div class="py-4 flex gap-x-3">
<div class="flex basis-2/3 flex-col gap-y-4 pr-4 overflow-hidden">
<div class="flex basis-1/2 flex-col gap-y-4 pr-4 overflow-hidden">
<div>
<div>Service</div>
<div
class="accent-color font-medium overflow-ellipsis overflow-hidden whitespace-nowrap"
[title]="controllerService.component.name">
<div class="tertiary-color font-medium truncate" [title]="controllerService.component.name">
{{ controllerService.component.name }}
</div>
</div>
Expand Down Expand Up @@ -56,7 +54,7 @@ <h2 mat-dialog-title>Move Controller Service</h2>
</mat-form-field>
</div>
</div>
<div class="flex basis-1/3 flex-col">
<div class="flex basis-1/2 flex-col">
<div>
Referencing Components
<i
Expand All @@ -77,6 +75,6 @@ <h2 mat-dialog-title>Move Controller Service</h2>
</mat-dialog-content>
<mat-dialog-actions align="end">
<button mat-button mat-dialog-close>Cancel</button>
<button type="button" color="primary" (click)="submitForm()" mat-button>Move</button>
<button type="button" color="primary" (click)="submitForm()" [disabled]="disableSubmit" mat-button>Move</button>
</mat-dialog-actions>
</form>
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export class MoveControllerService extends CloseOnEscapeDialog {
@Input() goToReferencingComponent!: (component: ControllerServiceReferencingComponent) => void;
protected readonly TextTip = TextTip;
protected controllerServiceActionProcessGroups: SelectOption[] = [];
protected disableSubmit: boolean = false;

controllerService: ControllerServiceEntity;

Expand Down Expand Up @@ -101,6 +102,11 @@ export class MoveControllerService extends CloseOnEscapeDialog {
const firstEnabled = processGroups.findIndex((pg) => !pg.disabled);
if (firstEnabled != -1) {
this.moveControllerServiceForm.controls['processGroups'].setValue(processGroups[firstEnabled].value);
} else {
if (processGroups.length > 0) {
this.moveControllerServiceForm.controls['processGroups'].setValue(processGroups[0].value);
}
this.disableSubmit = true;
}
}

Expand Down Expand Up @@ -161,21 +167,28 @@ export class MoveControllerService extends CloseOnEscapeDialog {

const root = this.getProcessGroupById(currentProcessGroupEntity.component, child.value ?? '');
let errorMsg = '';
for (const component of referencingComponents) {
if (!this.processGroupContainsComponent(root, component.component.groupId)) {
errorMsg += '[' + component.component.name + ']';
}
}

if (errorMsg != '') {
option.description =
'The following components would be out of scope for this ' + 'process group: ' + errorMsg;
if (root == null) {
option.description = 'Error loading process group root.';
option.disabled = true;
processGroups.push(option);
} else {
option.disabled = false;
}
for (const component of referencingComponents) {
if (!this.processGroupContainsComponent(root, component.component.groupId)) {
errorMsg += '[' + component.component.name + ']';
}
}

if (errorMsg != '') {
option.description =
'The following components would be out of scope for this process group: ' + errorMsg;
option.disabled = true;
} else {
option.disabled = false;
}

processGroups.push(option);
processGroups.push(option);
}
});
}

Expand All @@ -196,7 +209,6 @@ export class MoveControllerService extends CloseOnEscapeDialog {
}

getProcessGroupById(root: any, processGroupId: string): any {
console.log('a');
if (root != undefined) {
if (root.id == processGroupId) {
return root;
Expand All @@ -216,19 +228,17 @@ export class MoveControllerService extends CloseOnEscapeDialog {
}

submitForm() {
if (this.moveControllerServiceForm.get('processGroups')?.value != 'Process Group') {
this.store.dispatch(
moveControllerService({
request: {
controllerService: this.request.controllerService,
data: {
parentGroupId: this.moveControllerServiceForm.get('processGroups')?.value,
revision: this.request.controllerService.revision
}
this.store.dispatch(
moveControllerService({
request: {
controllerService: this.request.controllerService,
data: {
parentGroupId: this.moveControllerServiceForm.get('processGroups')?.value,
revision: this.request.controllerService.revision
}
})
);
}
}
})
);
}

override isDirty(): boolean {
Expand Down

0 comments on commit 275c18d

Please sign in to comment.