Merge branch 'feature/entity-actions' of https://github.com/umbraco/Umbraco.CMS.Backoffice into feature/entity-actions

This commit is contained in:
Niels Lyngsø
2023-02-03 15:15:40 +01:00
4 changed files with 29 additions and 48 deletions

View File

@@ -1,25 +0,0 @@
import { UmbContextToken } from '@umbraco-cms/context-api';
import { UmbControllerHostInterface } from '@umbraco-cms/controller';
import { BasicState } from 'libs/observable-api/basic-state';
export class UmbSectionSidebarContextMenuController {
#host: UmbControllerHostInterface;
#isOpen = new BasicState<boolean>(false);
isOpen = this.#isOpen.asObservable();
constructor(host: UmbControllerHostInterface) {
this.#host = host;
}
open() {
this.#isOpen.next(true);
}
close() {
this.#isOpen.next(false);
}
}
// TODO: that was a long name
export const UMB_SECTION_SIDEBAR_CONTEXT_MENU_CONTROLLER_CONTEXT_TOKEN =
new UmbContextToken<UmbSectionSidebarContextMenuController>(UmbSectionSidebarContextMenuController.name);

View File

@@ -63,17 +63,19 @@ export class UmbSectionSidebarContextMenu extends UmbLitElement {
@state()
private _unique?: string;
connectedCallback(): void {
super.connectedCallback();
@state()
private _headline?: string;
constructor() {
super();
this.consumeContext(UMB_SECTION_SIDEBAR_CONTEXT_TOKEN, (instance) => {
this.#sectionSidebarContext = instance;
this.observe(this.#sectionSidebarContext.contextMenuIsOpen, (isOpen) => {
this._isOpen = isOpen;
this._entityType = this.#sectionSidebarContext?.getEntityType();
this._unique = this.#sectionSidebarContext?.getUnique();
});
this.observe(this.#sectionSidebarContext.contextMenuIsOpen, (value) => (this._isOpen = value));
this.observe(this.#sectionSidebarContext.unique, (value) => (this._unique = value));
this.observe(this.#sectionSidebarContext.entityType, (value) => (this._entityType = value));
this.observe(this.#sectionSidebarContext.headline, (value) => (this._headline = value));
});
}
@@ -101,6 +103,7 @@ export class UmbSectionSidebarContextMenu extends UmbLitElement {
#renderModal() {
return this._isOpen
? html`<div id="action-modal">
<h3>${this._headline}</h3>
<umb-entity-action-list
entity-type=${ifDefined(this._entityType)}
unique=${ifDefined(this._unique)}></umb-entity-action-list>

View File

@@ -1,5 +1,6 @@
import { UmbContextToken } from '@umbraco-cms/context-api';
import { UmbControllerHostInterface } from '@umbraco-cms/controller';
import { StringState } from '@umbraco-cms/observable-api';
import { BasicState } from 'libs/observable-api/basic-state';
export class UmbSectionSidebarContext {
@@ -7,35 +8,37 @@ export class UmbSectionSidebarContext {
#contextMenuIsOpen = new BasicState<boolean>(false);
contextMenuIsOpen = this.#contextMenuIsOpen.asObservable();
#entityType?: string;
#unique?: string;
#entityType = new StringState<undefined>(undefined);
entityType = this.#entityType.asObservable();
getUnique() {
return this.#unique;
}
#unique = new StringState<undefined>(undefined);
unique = this.#unique.asObservable();
getEntityType() {
return this.#entityType;
}
#headline = new StringState<undefined>(undefined);
headline = this.#headline.asObservable();
constructor(host: UmbControllerHostInterface) {
this.#host = host;
}
toggleContextMenu(entityType: string, unique: string) {
this.#unique === unique ? this.closeContextMenu() : this.openContextMenu(entityType, unique);
toggleContextMenu(entityType: string, unique: string, headline: string) {
this.#unique.getValue() === unique ? this.closeContextMenu() : this.openContextMenu(entityType, unique, headline);
}
openContextMenu(entityType: string, unique: string) {
this.#entityType = entityType;
this.#unique = unique;
// 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, headline: string) {
this.#entityType.next(entityType);
this.#unique.next(unique);
this.#headline.next(headline);
this.#contextMenuIsOpen.next(true);
}
closeContextMenu() {
this.#contextMenuIsOpen.next(false);
this.#entityType = undefined;
this.#unique = undefined;
this.#entityType.next(undefined);
this.#unique.next(undefined);
this.#headline.next(undefined);
}
}

View File

@@ -208,7 +208,7 @@ export class UmbTreeItem extends UmbLitElement {
hasChildren: this.hasChildren,
parentKey: this.parentKey,
});
this._sectionSidebarContext?.toggleContextMenu(this.entityType, this.key);
this._sectionSidebarContext?.toggleContextMenu(this.entityType, this.key, this.label);
}
render() {