get dynamic section alias for path

This commit is contained in:
Mads Rasmussen
2022-08-25 18:38:58 +02:00
parent 70249378e5
commit 56a6f3a633

View File

@@ -4,6 +4,8 @@ import { customElement, property, state } from 'lit/decorators.js';
import { UmbContextConsumerMixin } from '../../../core/context';
import { ITreeService } from '../tree.service';
import { UUIMenuItemEvent } from '@umbraco-ui/uui';
import { UmbSectionContext } from '../../sections/section.context';
import { Subscription } from 'rxjs';
@customElement('umb-tree-item')
export class UmbTreeItem extends UmbContextConsumerMixin(LitElement) {
@@ -30,8 +32,14 @@ export class UmbTreeItem extends UmbContextConsumerMixin(LitElement) {
@state()
private _pathName? = '';
@state()
private _sectionPathname?: string;
private _treeService?: ITreeService;
private _sectionContext?: UmbSectionContext;
private _sectionSubscription?: Subscription;
constructor() {
super();
@@ -39,11 +47,24 @@ export class UmbTreeItem extends UmbContextConsumerMixin(LitElement) {
this._treeService = treeService;
this._pathName = this._treeService?.tree?.meta?.pathname;
});
this.consumeContext('umbSectionContext', (sectionContext: UmbSectionContext) => {
this._sectionContext = sectionContext;
this._useSection();
});
}
private _useSection() {
this._sectionSubscription?.unsubscribe();
this._sectionSubscription = this._sectionContext?.data.subscribe((section) => {
this._sectionPathname = section.meta.pathname;
});
}
// TODO: how do we handle this?
private _constructPath(id: number) {
return `/section/members/${this._pathName}/${id}`;
return `/section/${this._sectionPathname}/${this._pathName}/${id}`;
}
private _onShowChildren(event: UUIMenuItemEvent) {
@@ -58,6 +79,11 @@ export class UmbTreeItem extends UmbContextConsumerMixin(LitElement) {
});
}
disconnectedCallback(): void {
super.disconnectedCallback();
this._sectionSubscription?.unsubscribe();
}
private _renderChildItems() {
return this.childItems.map((item) => {
return html`<umb-tree-item