Merge branch 'main' into chore/rename-collection-context-name

This commit is contained in:
Mads Rasmussen
2024-05-01 08:51:42 +02:00
committed by GitHub
6 changed files with 46 additions and 12 deletions

View File

@@ -75,7 +75,11 @@ export class UmbEntityActionsBundleElement extends UmbLitElement {
#openContextMenu() {
if (!this.entityType) throw new Error('Entity type is not defined');
if (this.unique === undefined) throw new Error('Unique is not defined');
this.#sectionSidebarContext?.toggleContextMenu(this.entityType, this.unique, this.label);
this.#sectionSidebarContext?.toggleContextMenu(this, {
entityType: this.entityType,
unique: this.unique,
headline: this.label,
});
}
async #onFirstActionClick(event: PointerEvent) {

View File

@@ -4,6 +4,8 @@ import { UmbTextStyles } from '@umbraco-cms/backoffice/style';
import { css, html, nothing, customElement, state } from '@umbraco-cms/backoffice/external/lit';
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
import { observeMultiple } from '@umbraco-cms/backoffice/observable-api';
import type { UmbContextRequestEvent } from '@umbraco-cms/backoffice/context-api';
import { UMB_CONTENT_REQUEST_EVENT_TYPE } from '@umbraco-cms/backoffice/context-api';
@customElement('umb-section-sidebar-context-menu')
export class UmbSectionSidebarContextMenuElement extends UmbLitElement {
@@ -66,6 +68,17 @@ export class UmbSectionSidebarContextMenuElement extends UmbLitElement {
this.#closeContextMenu();
}
#proxyContextRequests(event: UmbContextRequestEvent) {
if (!this.#sectionSidebarContext) return;
// Note for this hack (The if-sentence): [NL]
// We do not currently have a good enough control to ensure that the proxy is last, meaning if another context is provided at this element, it might respond after the proxy event has been dispatched.
// To avoid such this hack just prevents proxying the event if its a request for its own context.
if (event.contextAlias !== UMB_SECTION_SIDEBAR_CONTEXT.contextAlias) {
event.stopImmediatePropagation();
this.#sectionSidebarContext.getContextElement()?.dispatchEvent(event.clone());
}
}
render() {
return html`
${this.#renderBackdrop()}
@@ -84,7 +97,7 @@ export class UmbSectionSidebarContextMenuElement extends UmbLitElement {
#renderModal() {
return this._isOpen && this._unique !== undefined && this._entityType
? html`<div id="action-modal">
? html`<div id="action-modal" @umb:context-request=${this.#proxyContextRequests}>
${this._headline ? html`<h3>${this.localize.string(this._headline)}</h3>` : nothing}
<umb-entity-action-list
@action-executed=${this.#onActionExecuted}

View File

@@ -1,3 +1,4 @@
import type { UmbOpenContextMenuArgs } from './types.js';
import { UmbContextToken } from '@umbraco-cms/backoffice/context-api';
import { UmbContextBase } from '@umbraco-cms/backoffice/class-api';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
@@ -16,21 +17,24 @@ export class UmbSectionSidebarContext extends UmbContextBase<UmbSectionSidebarCo
#headline = new UmbStringState<undefined>(undefined);
headline = this.#headline.asObservable();
#contextElement: Element | undefined = undefined;
constructor(host: UmbControllerHost) {
super(host, UMB_SECTION_SIDEBAR_CONTEXT);
}
toggleContextMenu(entityType: string, unique: string | null | undefined, headline: string | undefined) {
this.openContextMenu(entityType, unique, headline);
toggleContextMenu(host: Element, args: UmbOpenContextMenuArgs) {
this.openContextMenu(host, args);
}
// TODO: we wont get notified about tree item name changes because we don't have a subscription
// we need to figure out how we best can handle this when we only know the entity and unique id
openContextMenu(entityType: string, unique: string | null | undefined, headline: string | undefined) {
this.#entityType.setValue(entityType);
this.#unique.setValue(unique);
this.#headline.setValue(headline);
openContextMenu(host: Element, args: UmbOpenContextMenuArgs) {
this.#entityType.setValue(args.entityType);
this.#unique.setValue(args.unique);
this.#headline.setValue(args.headline);
this.#contextMenuIsOpen.setValue(true);
this.#contextElement = host;
}
closeContextMenu() {
@@ -38,6 +42,11 @@ export class UmbSectionSidebarContext extends UmbContextBase<UmbSectionSidebarCo
this.#entityType.setValue(undefined);
this.#unique.setValue(undefined);
this.#headline.setValue(undefined);
this.#contextElement = undefined;
}
getContextElement() {
return this.#contextElement;
}
}

View File

@@ -0,0 +1,5 @@
export interface UmbOpenContextMenuArgs {
entityType: string;
unique: string | null | undefined;
headline: string | undefined;
}

View File

@@ -180,7 +180,11 @@ export abstract class UmbTreeItemContextBase<TreeItemType extends UmbTreeItemMod
throw new Error('Could not request children, tree item is not set');
}
this.#sectionSidebarContext?.toggleContextMenu(this.entityType, this.unique, this.getTreeItem()?.name || '');
this.#sectionSidebarContext?.toggleContextMenu(this.getHostElement(), {
entityType: this.entityType,
unique: this.unique,
headline: this.getTreeItem()?.name || '',
});
}
public select() {

View File

@@ -30,14 +30,13 @@ export class UmbPropertyEditorUIPickerModalElement extends UmbModalBaseElement<
connectedCallback(): void {
super.connectedCallback();
this._submitLabel = this.data?.submitLabel ?? this._submitLabel;
// TODO: We never parse on a submit label, so this seem weird as we don't enable this of other places.
//this._submitLabel = this.data?.submitLabel ?? this._submitLabel;
this.#usePropertyEditorUIs();
}
#usePropertyEditorUIs() {
if (!this.data) return;
this.observe(umbExtensionsRegistry.byType('propertyEditorUi'), (propertyEditorUIs) => {
// Only include Property Editor UIs which has Property Editor Schema Alias
this._propertyEditorUIs = propertyEditorUIs.filter(