From e44a096e2cc5a5e198eeb5da756214b8267df24a Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Wed, 22 Nov 2023 13:22:08 +0100 Subject: [PATCH] temp "hack" to set the root path name --- .../core/collection/collection-default.context.ts | 13 +++++++++---- .../components/collection-view-bundle.element.ts | 14 ++++++++++++-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/collection/collection-default.context.ts b/src/Umbraco.Web.UI.Client/src/packages/core/collection/collection-default.context.ts index c64e88340f..de115e0fd2 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/collection/collection-default.context.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/collection/collection-default.context.ts @@ -2,7 +2,7 @@ import { UmbCollectionConfiguration, UmbCollectionContext } from './types.js'; import { UmbCollectionRepository } from '@umbraco-cms/backoffice/repository'; import { UmbBaseController, type UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api'; import { UmbContextToken } from '@umbraco-cms/backoffice/context-api'; -import { UmbArrayState, UmbNumberState, UmbObjectState } from '@umbraco-cms/backoffice/observable-api'; +import { UmbArrayState, UmbNumberState, UmbObjectState, UmbStringState } from '@umbraco-cms/backoffice/observable-api'; import { UmbApi, UmbExtensionApiInitializer, @@ -39,8 +39,10 @@ export class UmbDefaultCollectionContext(undefined); public readonly currentView = this.#currentView.asObservable(); + #rootPathname = new UmbStringState(''); + public readonly rootPathname = this.#rootPathname.asObservable(); + repository?: UmbCollectionRepository; - collectionRootPathname: string; #initResolver?: () => void; #initialized = false; @@ -58,8 +60,11 @@ export class UmbDefaultCollectionContext { + const currentUrl = new URL(window.location.href); + this.#rootPathname.next(currentUrl.pathname.substring(0, currentUrl.pathname.lastIndexOf('/'))); + }, 100); this.#configure(config); diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/collection/components/collection-view-bundle.element.ts b/src/Umbraco.Web.UI.Client/src/packages/core/collection/components/collection-view-bundle.element.ts index b6613609e2..94d44b99b0 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/collection/components/collection-view-bundle.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/collection/components/collection-view-bundle.element.ts @@ -13,7 +13,7 @@ export class UmbCollectionViewBundleElement extends UmbLitElement { _currentView?: ManifestCollectionView; @state() - private _collectionRootPathname = ''; + private _collectionRootPathname?: string; #collectionContext?: UmbDefaultCollectionContext; @@ -23,12 +23,22 @@ export class UmbCollectionViewBundleElement extends UmbLitElement { this.consumeContext(UMB_COLLECTION_CONTEXT, (context) => { this.#collectionContext = context; if (!this.#collectionContext) return; - this._collectionRootPathname = this.#collectionContext.collectionRootPathname; + this.#observeRootPathname(); this.#observeViews(); this.#observeCurrentView(); }); } + #observeRootPathname() { + this.observe( + this.#collectionContext!.rootPathname, + (rootPathname) => { + this._collectionRootPathname = rootPathname; + }, + 'umbCollectionRootPathnameObserver', + ); + } + #observeCurrentView() { this.observe( this.#collectionContext!.currentView,