Skip to content

Commit

Permalink
fix(admin-ui): Allow collections to be moved to root
Browse files Browse the repository at this point in the history
Fixes #2236
  • Loading branch information
michaelbromley committed Jun 19, 2023
1 parent 1bbd6a2 commit 23b3f05
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
class="child-arrow"
[class.transparent]="depth === 0"
shape="child-arrow"
*ngIf="!collection.children?.length"
*ngIf="!collection.children?.length && collection.parentId !== '__'"
></clr-icon>
<button
class="icon-button folder-button"
Expand All @@ -38,8 +38,11 @@
<clr-icon shape="folder" *ngIf="!expandedIds.includes(collection.id)"></clr-icon>
<clr-icon shape="folder-open" *ngIf="expandedIds.includes(collection.id)"></clr-icon>
</button>
<button class="icon-button folder-button" *ngIf="collection.parentId === '__'" disabled>
<clr-icon shape="folder" class="is-solid"></clr-icon>
</button>
<button class="button-ghost" (click)="resolveWith(collection)">
<span>{{ 'catalog.move-collection-to' | translate : { name: collection.name } }}</span>
<span>{{ 'catalog.move-collection-to' | translate : {name: collection.name} }}</span>
</button>
</ng-template>
</vdr-dt2-column>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
import { FormControl } from '@angular/forms';
import { DataService, Dialog, GetCollectionListQuery, ItemOf } from '@vendure/admin-ui/core';
import { DataService, Dialog, GetCollectionListQuery, I18nService, ItemOf } from '@vendure/admin-ui/core';
import { BehaviorSubject, combineLatest, Observable, of, Subject } from 'rxjs';
import { debounceTime, distinctUntilChanged, startWith, switchMap, tap } from 'rxjs/operators';
import { debounceTime, distinctUntilChanged, map, startWith, switchMap, tap } from 'rxjs/operators';

@Component({
selector: 'vdr-move-collections-dialog',
Expand All @@ -23,7 +23,7 @@ export class MoveCollectionsDialogComponent
expandedIds: string[] = [];
subCollections$: Observable<Array<ItemOf<GetCollectionListQuery, 'collections'>>>;

constructor(private dataService: DataService) {}
constructor(private dataService: DataService, private i18nService: I18nService) {}

ngOnInit() {
const getCollectionsResult = this.dataService.collection.getCollections();
Expand Down Expand Up @@ -51,7 +51,38 @@ export class MoveCollectionsDialogComponent
},
);

this.items$ = getCollectionsResult.mapStream(data => data.collections.items);
const rootCollectionId$ = this.dataService.collection
.getCollections({
take: 1,
topLevelOnly: true,
})
.mapSingle(data => data.collections.items[0].parentId);

this.items$ = combineLatest(
getCollectionsResult.mapStream(({ collections }) => collections),
rootCollectionId$,
).pipe(
map(([collections, rootCollectionId]) => [
...(rootCollectionId
? [
{
id: rootCollectionId,
name: this.i18nService.translate('catalog.root-collection'),
slug: '',
parentId: '__',
position: 0,
featuredAsset: null,
children: [],
breadcrumbs: [],
isPrivate: false,
createdAt: '',
updatedAt: '',
} satisfies ItemOf<GetCollectionListQuery, 'collections'>,
]
: []),
...collections.items,
]),
);
this.totalItems$ = getCollectionsResult.mapStream(data => data.collections.totalItems);

this.subCollections$ = this.expandedIds$.pipe(
Expand Down

0 comments on commit 23b3f05

Please sign in to comment.