mirror of https://github.com/apache/nifi.git
NIFI-13110: (#8719)
- Auto-selecting the relationship when the source processor only offers a single relationship. This closes #8719
This commit is contained in:
parent
99d8433b7d
commit
5a5947d1b0
|
@ -20,6 +20,7 @@ import { ControlValueAccessor, FormsModule, NG_VALUE_ACCESSOR } from '@angular/f
|
||||||
import { MatCheckboxModule } from '@angular/material/checkbox';
|
import { MatCheckboxModule } from '@angular/material/checkbox';
|
||||||
|
|
||||||
import { Relationship } from '../../../../../../state/flow';
|
import { Relationship } from '../../../../../../state/flow';
|
||||||
|
import { NiFiCommon } from '../../../../../../../../service/nifi-common.service';
|
||||||
|
|
||||||
export interface RelationshipItem {
|
export interface RelationshipItem {
|
||||||
relationshipName: string;
|
relationshipName: string;
|
||||||
|
@ -53,8 +54,8 @@ export class SourceProcessor implements ControlValueAccessor {
|
||||||
|
|
||||||
isDisabled = false;
|
isDisabled = false;
|
||||||
isTouched = false;
|
isTouched = false;
|
||||||
onTouched!: () => void;
|
onTouched: (() => void) | null = null;
|
||||||
onChange!: (selectedRelationships: string[]) => void;
|
onChange: ((selectedRelationships: string[]) => void) | null = null;
|
||||||
|
|
||||||
name!: string;
|
name!: string;
|
||||||
relationships!: Relationship[];
|
relationships!: Relationship[];
|
||||||
|
@ -62,36 +63,62 @@ export class SourceProcessor implements ControlValueAccessor {
|
||||||
relationshipItems!: RelationshipItem[];
|
relationshipItems!: RelationshipItem[];
|
||||||
selectedRelationships!: string[];
|
selectedRelationships!: string[];
|
||||||
|
|
||||||
processRelationships(): void {
|
constructor(private nifiCommon: NiFiCommon) {}
|
||||||
if (this.relationships && this.selectedRelationships) {
|
|
||||||
this.relationshipItems = this.relationships.map((relationship) => {
|
|
||||||
return {
|
|
||||||
relationshipName: relationship.name,
|
|
||||||
selected: this.selectedRelationships.includes(relationship.name),
|
|
||||||
available: true
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
const unavailableRelationships: string[] = this.selectedRelationships.filter(
|
processRelationships(): void {
|
||||||
(selectedRelationship) =>
|
if (this.relationships) {
|
||||||
!this.relationships.some((relationship) => relationship.name == selectedRelationship)
|
if (this.nifiCommon.isEmpty(this.selectedRelationships)) {
|
||||||
);
|
this.relationshipItems = this.relationships.map((relationship) => {
|
||||||
unavailableRelationships.forEach((unavailableRelationship) => {
|
return {
|
||||||
this.relationshipItems.push({
|
relationshipName: relationship.name,
|
||||||
relationshipName: unavailableRelationship,
|
selected: this.relationships.length === 1,
|
||||||
selected: true,
|
available: true
|
||||||
available: false
|
};
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
this.considerDefaultSelection();
|
||||||
|
} else {
|
||||||
|
this.relationshipItems = this.relationships.map((relationship) => {
|
||||||
|
return {
|
||||||
|
relationshipName: relationship.name,
|
||||||
|
selected: this.selectedRelationships.includes(relationship.name),
|
||||||
|
available: true
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const unavailableRelationships: string[] = this.selectedRelationships.filter(
|
||||||
|
(selectedRelationship) =>
|
||||||
|
!this.relationships.some((relationship) => relationship.name == selectedRelationship)
|
||||||
|
);
|
||||||
|
unavailableRelationships.forEach((unavailableRelationship) => {
|
||||||
|
this.relationshipItems.push({
|
||||||
|
relationshipName: unavailableRelationship,
|
||||||
|
selected: true,
|
||||||
|
available: false
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
considerDefaultSelection(): void {
|
||||||
|
const callbacksConfigured: boolean = this.onChange != null && this.onTouched != null;
|
||||||
|
const autoSelected: boolean =
|
||||||
|
this.relationships?.length === 1 && this.nifiCommon.isEmpty(this.selectedRelationships);
|
||||||
|
|
||||||
|
if (callbacksConfigured && autoSelected) {
|
||||||
|
this.handleChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
registerOnChange(onChange: (selectedPrioritizers: string[]) => void): void {
|
registerOnChange(onChange: (selectedPrioritizers: string[]) => void): void {
|
||||||
this.onChange = onChange;
|
this.onChange = onChange;
|
||||||
|
this.considerDefaultSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
registerOnTouched(onTouch: () => void): void {
|
registerOnTouched(onTouch: () => void): void {
|
||||||
this.onTouched = onTouch;
|
this.onTouched = onTouch;
|
||||||
|
this.considerDefaultSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
setDisabledState(isDisabled: boolean): void {
|
setDisabledState(isDisabled: boolean): void {
|
||||||
|
@ -104,14 +131,16 @@ export class SourceProcessor implements ControlValueAccessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
handleChanged() {
|
handleChanged() {
|
||||||
// mark the component as touched if not already
|
if (this.onTouched && this.onChange) {
|
||||||
if (!this.isTouched) {
|
// mark the component as touched if not already
|
||||||
this.isTouched = true;
|
if (!this.isTouched) {
|
||||||
this.onTouched();
|
this.isTouched = true;
|
||||||
}
|
this.onTouched();
|
||||||
|
}
|
||||||
|
|
||||||
// emit the changes
|
// emit the changes
|
||||||
this.onChange(this.serializeSelectedRelationships());
|
this.onChange(this.serializeSelectedRelationships());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private serializeSelectedRelationships(): string[] {
|
private serializeSelectedRelationships(): string[] {
|
||||||
|
|
Loading…
Reference in New Issue