work on context proxy and conditions
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
import { UMB_BLOCK_GRID_TYPE_WORKSPACE_ALIAS } from '../../block-grid/workspace/index.js';
|
||||
import { UMB_BLOCK_LIST_TYPE_WORKSPACE_ALIAS } from '../../block-list/workspace/index.js';
|
||||
import { UMB_BLOCK_RTE_TYPE_WORKSPACE_ALIAS } from '../../block-rte/workspace/index.js';
|
||||
import { UmbSaveWorkspaceAction } from '@umbraco-cms/backoffice/workspace';
|
||||
import type { ManifestWorkspaceAction } from '@umbraco-cms/backoffice/extension-registry';
|
||||
|
||||
@@ -12,5 +15,15 @@ export const manifests: Array<ManifestWorkspaceAction> = [
|
||||
look: 'primary',
|
||||
color: 'positive',
|
||||
},
|
||||
conditions: [
|
||||
{
|
||||
alias: 'Umb.Condition.WorkspaceAlias',
|
||||
oneOf: [
|
||||
UMB_BLOCK_GRID_TYPE_WORKSPACE_ALIAS,
|
||||
UMB_BLOCK_LIST_TYPE_WORKSPACE_ALIAS,
|
||||
UMB_BLOCK_RTE_TYPE_WORKSPACE_ALIAS,
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
@@ -53,7 +53,7 @@ export class UmbModalElement extends UmbLitElement {
|
||||
// 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 the Modal Context.
|
||||
if (event.apiAlias !== UMB_MODAL_CONTEXT_TOKEN.contextAlias) {
|
||||
event.stopPropagation();
|
||||
event.stopImmediatePropagation();
|
||||
const clonedEvent = new UmbContextRequestEventImplementation(
|
||||
event.contextAlias,
|
||||
event.apiAlias,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { UMB_WORKSPACE_CONTEXT } from './workspace-context/index.js';
|
||||
import { UMB_WORKSPACE_CONTEXT, type UmbWorkspaceContextInterface } from './workspace-context/index.js';
|
||||
import { UmbBaseController } from '@umbraco-cms/backoffice/class-api';
|
||||
import {
|
||||
ManifestCondition,
|
||||
@@ -16,10 +16,25 @@ export class UmbWorkspaceAliasCondition extends UmbBaseController implements Umb
|
||||
super(args.host);
|
||||
this.config = args.config;
|
||||
this.#onChange = args.onChange;
|
||||
this.consumeContext(UMB_WORKSPACE_CONTEXT, (context) => {
|
||||
this.permitted = context.workspaceAlias === this.config.match;
|
||||
this.#onChange();
|
||||
});
|
||||
|
||||
let permissionCheck: ((context: UmbWorkspaceContextInterface) => boolean) | undefined = undefined;
|
||||
if (this.config.match) {
|
||||
permissionCheck = (context: UmbWorkspaceContextInterface) => context.workspaceAlias === this.config.match;
|
||||
} else if (this.config.oneOf) {
|
||||
permissionCheck = (context: UmbWorkspaceContextInterface) =>
|
||||
this.config.oneOf!.indexOf(context.workspaceAlias) !== -1;
|
||||
}
|
||||
|
||||
if (permissionCheck !== undefined) {
|
||||
this.consumeContext(UMB_WORKSPACE_CONTEXT, (context) => {
|
||||
this.permitted = permissionCheck!(context);
|
||||
this.#onChange();
|
||||
});
|
||||
} else {
|
||||
throw new Error(
|
||||
'Condition `Umb.Condition.WorkspaceAlias` could not be initialized properly. Either "match" or "oneOf" must be defined',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +45,14 @@ export type WorkspaceAliasConditionConfig = UmbConditionConfigBase<'Umb.Conditio
|
||||
* @example
|
||||
* "Umb.Workspace.Document"
|
||||
*/
|
||||
match: string;
|
||||
match?: string;
|
||||
/**
|
||||
* Define one or more workspaces that this extension should be available in
|
||||
*
|
||||
* @example
|
||||
* ["Umb.Workspace.Document", "Umb.Workspace.Media"]
|
||||
*/
|
||||
oneOf?: Array<string>;
|
||||
};
|
||||
|
||||
export const manifest: ManifestCondition = {
|
||||
|
||||
@@ -5,6 +5,8 @@ import type {
|
||||
ManifestWorkspaceView,
|
||||
} from '@umbraco-cms/backoffice/extension-registry';
|
||||
|
||||
export const UMB_DOCUMENT_TYPE_WORKSPACE_ALIAS = 'Umb.Workspace.DocumentType';
|
||||
|
||||
const workspace: ManifestWorkspace = {
|
||||
type: 'workspace',
|
||||
alias: 'Umb.Workspace.DocumentType',
|
||||
@@ -30,7 +32,7 @@ const workspaceViews: Array<ManifestWorkspaceView> = [
|
||||
conditions: [
|
||||
{
|
||||
alias: 'Umb.Condition.WorkspaceAlias',
|
||||
match: workspace.alias,
|
||||
match: UMB_DOCUMENT_TYPE_WORKSPACE_ALIAS,
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -48,7 +50,7 @@ const workspaceViews: Array<ManifestWorkspaceView> = [
|
||||
conditions: [
|
||||
{
|
||||
alias: 'Umb.Condition.WorkspaceAlias',
|
||||
match: workspace.alias,
|
||||
match: UMB_DOCUMENT_TYPE_WORKSPACE_ALIAS,
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -66,7 +68,7 @@ const workspaceViews: Array<ManifestWorkspaceView> = [
|
||||
conditions: [
|
||||
{
|
||||
alias: 'Umb.Condition.WorkspaceAlias',
|
||||
match: workspace.alias,
|
||||
match: UMB_DOCUMENT_TYPE_WORKSPACE_ALIAS,
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -84,7 +86,7 @@ const workspaceViews: Array<ManifestWorkspaceView> = [
|
||||
conditions: [
|
||||
{
|
||||
alias: 'Umb.Condition.WorkspaceAlias',
|
||||
match: workspace.alias,
|
||||
match: UMB_DOCUMENT_TYPE_WORKSPACE_ALIAS,
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -104,7 +106,7 @@ const workspaceActions: Array<ManifestWorkspaceAction> = [
|
||||
conditions: [
|
||||
{
|
||||
alias: 'Umb.Condition.WorkspaceAlias',
|
||||
match: workspace.alias,
|
||||
match: UMB_DOCUMENT_TYPE_WORKSPACE_ALIAS,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user