-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Front-end Example: Initial name example #20899
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
Merged
+52
−0
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
734ba7b
initial name example
nielslyngsoe a87ae34
Merge branch 'main' into v17/improvement/example-initial-name
nielslyngsoe d47574d
Merge branch 'main' into v17/improvement/example-initial-name
nielslyngsoe 3545397
Update src/Umbraco.Web.UI.Client/examples/workspace-context-initial-n…
nielslyngsoe b6f5cac
Update src/Umbraco.Web.UI.Client/examples/workspace-context-initial-n…
nielslyngsoe 06496d7
Update src/Umbraco.Web.UI.Client/examples/workspace-context-initial-n…
nielslyngsoe 7d38665
Update src/Umbraco.Web.UI.Client/examples/workspace-context-initial-n…
nielslyngsoe 7752d85
update example
nielslyngsoe daa9531
remove log
nielslyngsoe 7cf8585
switch to use promise for awaiting load
nielslyngsoe 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
3 changes: 3 additions & 0 deletions
3
src/Umbraco.Web.UI.Client/examples/workspace-context-initial-name/README.md
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 @@ | ||
| # Workspace Context for setting an Initial Name | ||
|
|
||
| This example of a Workspace Context demonstrates how to manipulate the name of the workspaces entity. |
16 changes: 16 additions & 0 deletions
16
src/Umbraco.Web.UI.Client/examples/workspace-context-initial-name/index.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,16 @@ | ||
| import { UMB_WORKSPACE_CONDITION_ALIAS } from '@umbraco-cms/backoffice/workspace'; | ||
|
|
||
| export const manifests: Array<UmbExtensionManifest> = [ | ||
| { | ||
| type: 'workspaceContext', | ||
| name: 'Example Name Manipulation Workspace Context', | ||
| alias: 'example.workspaceContext.nameManipulation', | ||
| api: () => import('./workspace-context.js'), | ||
| conditions: [ | ||
| { | ||
| alias: UMB_WORKSPACE_CONDITION_ALIAS, | ||
| match: 'Umb.Workspace.Document', | ||
| }, | ||
| ], | ||
| }, | ||
| ]; |
41 changes: 41 additions & 0 deletions
41
src/Umbraco.Web.UI.Client/examples/workspace-context-initial-name/workspace-context.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,41 @@ | ||
| 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'; | ||
| import { UMB_DOCUMENT_WORKSPACE_CONTEXT } from '@umbraco-cms/backoffice/document'; | ||
| import { UmbVariantId } from '@umbraco-cms/backoffice/variant'; | ||
|
|
||
| // The Example Workspace Context Controller: | ||
| export class WorkspaceContextNameManipulation extends UmbContextBase { | ||
| constructor(host: UmbControllerHost) { | ||
| super(host, MANIPULATE_NAME_WORKSPACE_CONTEXT); | ||
|
|
||
| this.consumeContext(UMB_DOCUMENT_WORKSPACE_CONTEXT, (workspace) => { | ||
| this.observe(workspace?.loading.isOn, (isLoading) => { | ||
| // Only manipulate the name when we are not loading: | ||
| if (isLoading) return; | ||
| // Get if new: | ||
| const isNew = workspace?.getIsNew() ?? false; | ||
madsrasmussen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (isNew) { | ||
| // Set the name if it's already empty (We do not want to overwrite if it's a Blueprint) | ||
| // Notice we can put a ! on the workspace, if the Document is new, then we also know we have a workspace. | ||
| // Notice we need to provide a Variant-ID to getName, as Document names are variant specific. Here we get the Invariant name — this will need to be extended if you are looking to support multiple variants. | ||
| const variantId = UmbVariantId.CreateInvariant(); | ||
| const name = workspace!.getName(variantId); | ||
| if (name === undefined) { | ||
| const manipulatedName = `New Document - ${new Date().toLocaleDateString('en-GB')}`; | ||
| workspace!.setName(manipulatedName, variantId); | ||
| } | ||
| } | ||
| }); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| // Declare a api export, so Extension Registry can initialize this class: | ||
| export const api = WorkspaceContextNameManipulation; | ||
madsrasmussen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // Declare a Context Token that other elements can use to request the WorkspaceContextNameManipulation: | ||
| export const MANIPULATE_NAME_WORKSPACE_CONTEXT = new UmbContextToken<WorkspaceContextNameManipulation>( | ||
nielslyngsoe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 'UmbWorkspaceContext', | ||
| 'example.workspaceContext.initialName', | ||
| ); | ||
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.