-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Content Type Workspace: Create condition that checks content type uniques. #20906
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
engijlr
wants to merge
20
commits into
main
Choose a base branch
from
v17/improvement/workspace-content-type-unique-condition
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+261
−67
Open
Changes from 6 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
7c8c3ff
Created condition for workspace content type unique.
engijlr 4d77e7e
Merge branch 'main' into v17/improvement/workspace-content-type-uniqu…
engijlr 7872b19
Changed import.
engijlr 356807f
Merge branch 'main' into v17/improvement/workspace-content-type-uniqu…
engijlr 2aaf93f
Revert import.
engijlr e1bd529
Merge branch 'v17/improvement/workspace-content-type-unique-condition…
engijlr f60ec04
Updated name in the alias example and also import.
engijlr 39cefbc
Update src/Umbraco.Web.UI.Client/examples/entity-content-type-conditi…
engijlr 14c70f9
Update src/Umbraco.Web.UI.Client/examples/entity-content-type-conditi…
engijlr aa34cf5
Moved the manifest definition to the manifest file.
engijlr 65c2dd8
Changed default export.
engijlr 26450e9
Updated example element to render the real GUID.
engijlr ac668cd
Merge branch 'main' into v17/improvement/workspace-content-type-uniqu…
engijlr ae4a216
Fixed import.
engijlr 09cd053
Replaced CONTENT_WORKSPACE for PROPERTY_STRUCTURE_WORKSPACE context.
engijlr 5c0efaa
Moved content type unique condition to the content type folder.
engijlr 7edfec1
Merge branch 'main' into v17/improvement/workspace-content-type-uniqu…
engijlr 64f1d44
Fixed import.
engijlr 196c25a
Merge branch 'v17/improvement/workspace-content-type-unique-condition…
engijlr 5a5e6eb
final adjustments
madsrasmussen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
20 changes: 20 additions & 0 deletions
20
...aco.Web.UI.Client/examples/entity-content-type-condition/workspace-view-unique.element.ts
This file contains hidden or 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,20 @@ | ||
| import { html, customElement } from '@umbraco-cms/backoffice/external/lit'; | ||
| import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'; | ||
|
|
||
| @customElement('umb-example-entity-content-type-condition-unique') | ||
engijlr marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| export class UmbWorkspaceExampleViewUniqueElement extends UmbLitElement { | ||
| override render() { | ||
| return html`<uui-box> | ||
| <h3>Content Type Unique Condition Test</h3> | ||
| <p>It appears only on documents with GUID: <strong>42d7572e-1ba1-458d-a765-95b60040c3ac</strong></p> | ||
madsrasmussen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </uui-box>`; | ||
| } | ||
| } | ||
|
|
||
| export default UmbWorkspaceExampleViewUniqueElement; | ||
madsrasmussen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| declare global { | ||
| interface HTMLElementTagNameMap { | ||
| 'umb-example-entity-content-type-condition-unique': UmbWorkspaceExampleViewUniqueElement; | ||
| } | ||
| } | ||
1 change: 1 addition & 0 deletions
1
src/Umbraco.Web.UI.Client/src/packages/core/workspace/conditions/constants.ts
This file contains hidden or 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,4 @@ | ||
| export * from './workspace-alias/constants.js'; | ||
| export * from './workspace-entity-is-new/constants.js'; | ||
| export * from './workspace-entity-type/constants.js'; | ||
| export * from './workspace-content-type-unique/constants.js'; |
2 changes: 2 additions & 0 deletions
2
src/Umbraco.Web.UI.Client/src/packages/core/workspace/conditions/manifests.ts
This file contains hidden or 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,9 +1,11 @@ | ||
| import { manifests as workspaceAliasCondition } from './workspace-alias/manifests.js'; | ||
| import { manifests as workspaceEntityIsNewCondition } from './workspace-entity-is-new/manifests.js'; | ||
| import { manifests as workspaceEntityTypeCondition } from './workspace-entity-type/manifests.js'; | ||
| import { manifests as workspaceViewUnique } from './workspace-content-type-unique/manifests.js'; | ||
|
|
||
| export const manifests: Array<UmbExtensionManifest> = [ | ||
| ...workspaceAliasCondition, | ||
| ...workspaceEntityIsNewCondition, | ||
| ...workspaceEntityTypeCondition, | ||
| ...workspaceViewUnique, | ||
| ]; |
1 change: 1 addition & 0 deletions
1
src/Umbraco.Web.UI.Client/src/packages/core/workspace/conditions/types.ts
This file contains hidden or 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,4 @@ | ||
| export type * from './workspace-alias/types.js'; | ||
| export type * from './workspace-entity-is-new/types.js'; | ||
| export type * from './workspace-entity-type/types.js'; | ||
| export type * from './workspace-content-type-unique/types.js'; |
4 changes: 4 additions & 0 deletions
4
....Client/src/packages/core/workspace/conditions/workspace-content-type-unique/constants.ts
This file contains hidden or 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,4 @@ | ||
| /** | ||
| * Workspace Content Type Unique condition alias | ||
| */ | ||
| export const UMB_WORKSPACE_CONTENT_TYPE_UNIQUE_CONDITION_ALIAS = 'Umb.Condition.WorkspaceContentTypeUnique'; |
3 changes: 3 additions & 0 deletions
3
....Client/src/packages/core/workspace/conditions/workspace-content-type-unique/manifests.ts
This file contains hidden or 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,3 @@ | ||
| import { manifest as workspaceContentTypeUniqueCondition } from './workspace-content-type-unique.condition.js'; | ||
|
|
||
| export const manifests: Array<UmbExtensionManifest> = [workspaceContentTypeUniqueCondition]; |
25 changes: 25 additions & 0 deletions
25
...b.UI.Client/src/packages/core/workspace/conditions/workspace-content-type-unique/types.ts
This file contains hidden or 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,25 @@ | ||
| import type { UMB_WORKSPACE_CONTENT_TYPE_UNIQUE_CONDITION_ALIAS } from './constants.js'; | ||
| import type { UmbConditionConfigBase } from '@umbraco-cms/backoffice/extension-api'; | ||
|
|
||
| export type UmbWorkspaceContentTypeUniqueConditionConfig = UmbConditionConfigBase< | ||
| typeof UMB_WORKSPACE_CONTENT_TYPE_UNIQUE_CONDITION_ALIAS | ||
| > & { | ||
| /** | ||
| * Define a content type unique (GUID) in which workspace this extension should be available | ||
| * @example | ||
| * Depends on implementation, but i.e. "d59be02f-1df9-4228-aa1e-01917d806cda" | ||
| */ | ||
| match?: string; | ||
| /** | ||
| * Define one or more content type unique (GUIDs) in which workspace this extension should be available | ||
| * @example | ||
| * ["d59be02f-1df9-4228-aa1e-01917d806cda", "42d7572e-1ba1-458d-a765-95b60040c3ac"] | ||
| */ | ||
| oneOf?: Array<string>; | ||
| }; | ||
|
|
||
| declare global { | ||
| interface UmbExtensionConditionConfigMap { | ||
| umbWorkspaceContentTypeUniqueConditionConfig: UmbWorkspaceContentTypeUniqueConditionConfig; | ||
| } | ||
| } |
54 changes: 54 additions & 0 deletions
54
...space/conditions/workspace-content-type-unique/workspace-content-type-unique.condition.ts
This file contains hidden or 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,54 @@ | ||
| import { UMB_CONTENT_WORKSPACE_CONTEXT } from '@umbraco-cms/backoffice/content'; | ||
| import type { UmbWorkspaceContentTypeUniqueConditionConfig } from './types.js'; | ||
| import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api'; | ||
| import type { UmbConditionControllerArguments, UmbExtensionCondition } from '@umbraco-cms/backoffice/extension-api'; | ||
| import { UmbConditionBase } from '@umbraco-cms/backoffice/extension-registry'; | ||
|
|
||
| const ObserveSymbol = Symbol(); | ||
|
|
||
| /** | ||
| * Condition to apply workspace extension based on a content type unique (GUID) | ||
| */ | ||
| export class UmbWorkspaceContentTypeUniqueCondition | ||
| extends UmbConditionBase<UmbWorkspaceContentTypeUniqueConditionConfig> | ||
| implements UmbExtensionCondition | ||
| { | ||
| constructor( | ||
| host: UmbControllerHost, | ||
| args: UmbConditionControllerArguments<UmbWorkspaceContentTypeUniqueConditionConfig>, | ||
| ) { | ||
| super(host, args); | ||
|
|
||
| let permissionCheck: ((contentTypeUniques: string[]) => boolean) | undefined = undefined; | ||
| if (this.config.match) { | ||
| permissionCheck = (contentTypeUniques: string[]) => contentTypeUniques.includes(this.config.match!); | ||
| } else if (this.config.oneOf) { | ||
| permissionCheck = (contentTypeUniques: string[]) => | ||
| contentTypeUniques.some((item) => this.config.oneOf!.includes(item)); | ||
| } | ||
|
|
||
| if (permissionCheck !== undefined) { | ||
| this.consumeContext(UMB_CONTENT_WORKSPACE_CONTEXT, (context) => { | ||
madsrasmussen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| this.observe( | ||
| context?.structure.contentTypeUniques, | ||
| (contentTypeUniques) => { | ||
| const result = contentTypeUniques ? permissionCheck!(contentTypeUniques) : false; | ||
| this.permitted = result; | ||
| }, | ||
| ObserveSymbol, | ||
| ); | ||
| }); | ||
| } else { | ||
| throw new Error( | ||
| 'Condition `Umb.Condition.WorkspaceContentTypeUnique` could not be initialized properly. Either "match" or "oneOf" must be defined', | ||
| ); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| export const manifest: UmbExtensionManifest = { | ||
madsrasmussen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| type: 'condition', | ||
| name: 'Workspace Content Type Unique Condition', | ||
| alias: 'Umb.Condition.WorkspaceContentTypeUnique', | ||
| api: UmbWorkspaceContentTypeUniqueCondition, | ||
| }; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.