Merge pull request #7926 from engix-ltd/exclude_subtype

Exclude specified subtypes from autocomplete widget.
This commit is contained in:
Igor Kulikov 2023-03-28 19:24:40 +03:00 committed by GitHub
commit e7169d8419
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 7 deletions

View File

@ -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;

View File

@ -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

View File

@ -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()
);