Merge pull request #7926 from engix-ltd/exclude_subtype
Exclude specified subtypes from autocomplete widget.
This commit is contained in:
commit
e7169d8419
@ -342,12 +342,9 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit
|
||||
map((data) => {
|
||||
if (data) {
|
||||
if (this.excludeEntityIds && this.excludeEntityIds.length) {
|
||||
const excludeEntityIdsSet = new Set(this.excludeEntityIds);
|
||||
const entities: Array<BaseData<EntityId>> = [];
|
||||
data.forEach((entity) => {
|
||||
if (this.excludeEntityIds.indexOf(entity.id.id) === -1) {
|
||||
entities.push(entity);
|
||||
}
|
||||
});
|
||||
data.forEach(entity => !excludeEntityIdsSet.has(entity.id.id) && entities.push(entity));
|
||||
return entities;
|
||||
} else {
|
||||
return data;
|
||||
|
||||
@ -15,7 +15,7 @@
|
||||
limitations under the License.
|
||||
|
||||
-->
|
||||
<mat-form-field [formGroup]="subTypeFormGroup" class="mat-block">
|
||||
<mat-form-field [formGroup]="subTypeFormGroup" class="mat-block" [appearance]="appearance">
|
||||
<mat-label>{{ entitySubtypeText | translate }}</mat-label>
|
||||
<input matInput type="text" placeholder="{{ selectEntitySubtypeText | translate }}"
|
||||
#subTypeInput
|
||||
|
||||
@ -37,6 +37,7 @@ import { coerceBooleanProperty } from '@angular/cdk/coercion';
|
||||
import { AssetService } from '@core/http/asset.service';
|
||||
import { EntityViewService } from '@core/http/entity-view.service';
|
||||
import { EdgeService } from '@core/http/edge.service';
|
||||
import { MatFormFieldAppearance } from '@angular/material/form-field/form-field';
|
||||
|
||||
@Component({
|
||||
selector: 'tb-entity-subtype-autocomplete',
|
||||
@ -71,6 +72,12 @@ export class EntitySubTypeAutocompleteComponent implements ControlValueAccessor,
|
||||
@Input()
|
||||
disabled: boolean;
|
||||
|
||||
@Input()
|
||||
excludeSubTypes: Array<string>;
|
||||
|
||||
@Input()
|
||||
appearance: MatFormFieldAppearance = 'legacy';
|
||||
|
||||
@ViewChild('subTypeInput', {static: true}) subTypeInput: ElementRef;
|
||||
|
||||
selectEntitySubtypeText: string;
|
||||
@ -238,9 +245,14 @@ export class EntitySubTypeAutocompleteComponent implements ControlValueAccessor,
|
||||
break;
|
||||
}
|
||||
if (subTypesObservable) {
|
||||
const excludeSubTypesSet = new Set(this.excludeSubTypes);
|
||||
this.subTypes = subTypesObservable.pipe(
|
||||
catchError(() => of([] as Array<EntitySubtype>)),
|
||||
map(subTypes => subTypes.map(subType => subType.type)),
|
||||
map(subTypes => {
|
||||
const filteredSubTypes: Array<string> = [];
|
||||
subTypes.forEach(subType => !excludeSubTypesSet.has(subType.type) && filteredSubTypes.push(subType.type));
|
||||
return filteredSubTypes;
|
||||
}),
|
||||
publishReplay(1),
|
||||
refCount()
|
||||
);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user