Skip to content

Commit ce42a56

Browse files
committed
fix: engine selector issue
1 parent d8c2a04 commit ce42a56

File tree

1 file changed

+29
-27
lines changed

1 file changed

+29
-27
lines changed

src/app/cars/specifications-editor/engine/select/tree-item/tree-item.component.ts

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {AsyncPipe} from '@angular/common';
22
import {ChangeDetectionStrategy, Component, inject, input, output, signal} from '@angular/core';
3+
import {toObservable} from '@angular/core/rxjs-interop';
34
import {
45
ItemFields,
56
ItemListOptions,
@@ -13,7 +14,7 @@ import {
1314
import {ItemsClient} from '@grpc/spec.pbsc';
1415
import {LanguageService} from '@services/language';
1516
import {EMPTY, Observable} from 'rxjs';
16-
import {catchError, map, tap} from 'rxjs/operators';
17+
import {catchError, map, switchMap, tap} from 'rxjs/operators';
1718

1819
import {ToastsService} from '../../../../../toasts/toasts.service';
1920

@@ -34,36 +35,37 @@ export class CarsSelectEngineTreeItemComponent {
3435

3536
protected readonly open = signal(false);
3637
protected readonly loading = signal(false);
37-
protected readonly childs$: Observable<ItemParent[]> = this.#itemsClient
38-
.getItemParents(
39-
new ItemParentsRequest({
40-
fields: new ItemParentFields({
41-
item: new ItemFields({
42-
childsCount: true,
43-
nameHtml: true,
38+
protected readonly childs$: Observable<ItemParent[]> = toObservable(this.item).pipe(
39+
switchMap((item) =>
40+
this.#itemsClient.getItemParents(
41+
new ItemParentsRequest({
42+
fields: new ItemParentFields({
43+
item: new ItemFields({
44+
childsCount: true,
45+
nameHtml: true,
46+
}),
4447
}),
45-
}),
46-
language: this.#languageService.language,
47-
limit: 500,
48-
options: new ItemParentListOptions({
49-
item: new ItemListOptions({
50-
typeId: ItemType.ITEM_TYPE_ENGINE,
48+
language: this.#languageService.language,
49+
limit: 500,
50+
options: new ItemParentListOptions({
51+
item: new ItemListOptions({
52+
typeId: ItemType.ITEM_TYPE_ENGINE,
53+
}),
54+
parentId: item.itemId,
5155
}),
52-
parentId: this.item().itemId,
56+
order: ItemParentsRequest.Order.AUTO,
5357
}),
54-
order: ItemParentsRequest.Order.AUTO,
55-
}),
56-
)
57-
.pipe(
58-
catchError((error: unknown) => {
59-
this.#toastService.handleError(error);
60-
this.loading.set(false);
58+
),
59+
),
60+
catchError((error: unknown) => {
61+
this.#toastService.handleError(error);
62+
this.loading.set(false);
6163

62-
return EMPTY;
63-
}),
64-
tap(() => this.loading.set(false)),
65-
map((response) => response.items || []),
66-
);
64+
return EMPTY;
65+
}),
66+
tap(() => this.loading.set(false)),
67+
map((response) => response.items || []),
68+
);
6769

6870
protected selectEngine(engineId: string) {
6971
this.selected.emit(engineId);

0 commit comments

Comments
 (0)