-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1311 from umbraco/feature/workspace-action-menu
Feature/workspace action menu
- Loading branch information
Showing
15 changed files
with
367 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/packages/core/extension-registry/models/workspace-action-menu-item.model.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type { ConditionTypes } from '../conditions/types.js'; | ||
import type { MetaEntityAction } from './entity-action.model.js'; | ||
import type { ManifestElementAndApi, ManifestWithDynamicConditions } from '@umbraco-cms/backoffice/extension-api'; | ||
import type { UmbWorkspaceAction } from '@umbraco-cms/backoffice/workspace'; | ||
|
||
export interface ManifestWorkspaceActionMenuItem | ||
extends ManifestElementAndApi<HTMLElement, UmbWorkspaceAction>, | ||
ManifestWithDynamicConditions<ConditionTypes> { | ||
type: 'workspaceActionMenuItem'; | ||
meta: MetaWorkspaceActionMenuItem; | ||
} | ||
|
||
export interface MetaWorkspaceActionMenuItem extends MetaEntityAction { | ||
/** | ||
* Define which workspace actions this menu item should be shown for. | ||
* @examples [ | ||
* ['Umb.WorkspaceAction.Document.Save', 'Umb.WorkspaceAction.Document.SaveAndPublish'], | ||
* "Umb.WorkspaceAction.Document.Save" | ||
* ] | ||
* @required | ||
*/ | ||
workspaceActions: string | string[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/packages/core/workspace/components/workspace-action/common/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './save/index.js'; | ||
export * from './workspace-action-base.js'; |
2 changes: 1 addition & 1 deletion
2
src/packages/core/workspace/components/workspace-action/common/save/save.action.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...workspace-action/workspace-action-base.ts → ...ce-action/common/workspace-action-base.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
src/packages/core/workspace/components/workspace-action/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
export * from './workspace-action-base.js'; | ||
export * from './workspace-action.element.js'; | ||
export * from './shared/index.js'; | ||
export * from './common/index.js'; |
2 changes: 2 additions & 0 deletions
2
src/packages/core/workspace/components/workspace-action/shared/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './workspace-action/index.js'; | ||
export * from './workspace-action-menu/index.js'; |
1 change: 1 addition & 0 deletions
1
...packages/core/workspace/components/workspace-action/shared/workspace-action-menu/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './workspace-action-menu.element.js'; |
144 changes: 144 additions & 0 deletions
144
...components/workspace-action/shared/workspace-action-menu/workspace-action-menu.element.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
import type { CSSResultGroup } from '@umbraco-cms/backoffice/external/lit'; | ||
import { css, html, customElement, property, state, repeat, nothing } from '@umbraco-cms/backoffice/external/lit'; | ||
import { UmbTextStyles } from '@umbraco-cms/backoffice/style'; | ||
import type { ManifestTypes, ManifestWorkspaceActionMenuItem } from '@umbraco-cms/backoffice/extension-registry'; | ||
import { umbExtensionsRegistry } from '@umbraco-cms/backoffice/extension-registry'; | ||
import type { UmbExtensionElementInitializer } from '@umbraco-cms/backoffice/extension-api'; | ||
import { UmbExtensionsElementInitializer } from '@umbraco-cms/backoffice/extension-api'; | ||
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'; | ||
import { UMB_WORKSPACE_CONTEXT } from '@umbraco-cms/backoffice/workspace'; | ||
import type { UUIInterfaceColor, UUIInterfaceLook } from '@umbraco-cms/backoffice/external/uui'; | ||
|
||
@customElement('umb-workspace-action-menu') | ||
export class UmbWorkspaceActionMenuElement extends UmbLitElement { | ||
#workspaceContext?: typeof UMB_WORKSPACE_CONTEXT.TYPE; | ||
#actionsInitializer?: UmbExtensionsElementInitializer<ManifestTypes, 'workspaceActionMenuItem'>; | ||
|
||
/** | ||
* The workspace actions to filter the available actions by. | ||
* @example ['Umb.WorkspaceAction.Document.Save', 'Umb.WorkspaceAction.Document.SaveAndPublishNew'] | ||
*/ | ||
@property({ type: Array }) | ||
workspaceActions: Array<string> = []; | ||
|
||
@property() | ||
look: UUIInterfaceLook = 'secondary'; | ||
|
||
@property() | ||
color: UUIInterfaceColor = 'default'; | ||
|
||
@state() | ||
private _actions: Array<UmbExtensionElementInitializer<ManifestWorkspaceActionMenuItem, never>> = []; | ||
|
||
@state() | ||
_popoverOpen = false; | ||
|
||
constructor() { | ||
super(); | ||
|
||
this.consumeContext(UMB_WORKSPACE_CONTEXT, (context) => { | ||
this.#workspaceContext = context; | ||
this.#initialise(); | ||
}); | ||
} | ||
|
||
#initialise() { | ||
if (!this.#workspaceContext) throw new Error('No workspace context'); | ||
|
||
// If there are no workspace action aliases, then there is no need to initialize the actions. | ||
if (!this.workspaceActions.length) return; | ||
|
||
const unique = this.#workspaceContext.getUnique(); | ||
const entityType = this.#workspaceContext.getEntityType(); | ||
|
||
this.#actionsInitializer = new UmbExtensionsElementInitializer( | ||
this, | ||
umbExtensionsRegistry, | ||
'workspaceActionMenuItem', // TODO: Stop using string for 'workspaceActionMenuItem', we need to start using Const. | ||
(action) => { | ||
const containsAlias = Array.isArray(action.meta.workspaceActions) | ||
? action.meta.workspaceActions | ||
: [action.meta.workspaceActions].some((alias) => this.workspaceActions.includes(alias)); | ||
const isValidEntityType = !action.meta.entityTypes.length || action.meta.entityTypes.includes(entityType); | ||
return containsAlias && isValidEntityType; | ||
}, | ||
(ctrls) => { | ||
this._actions = ctrls; | ||
}, | ||
'workspaceActionExtensionsInitializer', | ||
'umb-entity-action', | ||
); | ||
|
||
this.#actionsInitializer.properties = { unique, entityType }; | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
#onPopoverToggle(event: ToggleEvent) { | ||
this._popoverOpen = event.newState === 'open'; | ||
} | ||
|
||
render() { | ||
return this._actions.length > 0 | ||
? html` | ||
<uui-button | ||
id="popover-trigger" | ||
popovertarget="workspace-action-popover" | ||
look="${this.look}" | ||
color="${this.color}" | ||
label=${this.localize.term('visuallyHiddenTexts_tabExpand')} | ||
compact> | ||
<uui-symbol-expand id="expand-symbol" .open=${this._popoverOpen}></uui-symbol-expand> | ||
</uui-button> | ||
<uui-popover-container | ||
id="workspace-action-popover" | ||
margin="5" | ||
placement="top-end" | ||
@toggle=${this.#onPopoverToggle}> | ||
<umb-popover-layout> | ||
<uui-scroll-container> | ||
${repeat( | ||
this._actions, | ||
(action) => action.alias, | ||
(action) => action.component, | ||
)} | ||
</uui-scroll-container> | ||
</umb-popover-layout> | ||
</uui-popover-container> | ||
` | ||
: nothing; | ||
} | ||
|
||
static styles: CSSResultGroup = [ | ||
UmbTextStyles, | ||
css` | ||
:host { | ||
--uui-menu-item-flat-structure: 1; | ||
} | ||
#expand-symbol { | ||
transform: rotate(-90deg); | ||
} | ||
#expand-symbol[open] { | ||
transform: rotate(0deg); | ||
} | ||
#workspace-action-popover { | ||
min-width: 200px; | ||
} | ||
#popover-trigger { | ||
--uui-button-padding-top-factor: 0.5; | ||
--uui-button-padding-bottom-factor: 0.1; | ||
--uui-button-border-radius: 0; | ||
} | ||
`, | ||
]; | ||
} | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
'umb-workspace-action-menu': UmbWorkspaceActionMenuElement; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
src/packages/core/workspace/components/workspace-action/shared/workspace-action/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './workspace-action.element.js'; |
Oops, something went wrong.