-
Notifications
You must be signed in to change notification settings - Fork 2.8k
<umb-content-workspace-property> DX #19399
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
Merged
Changes from 2 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8ba49bc
introduce umb-content-workspace-property to improve dx
madsrasmussen 00d70db
make property responsible for observing the view guard
madsrasmussen ae3247d
Update src/Umbraco.Web.UI.Client/src/packages/content/content/global-…
nielslyngsoe f877e96
context consumer update tests
nielslyngsoe 5ad6d91
Merge branch 'release/16.0' into v16/hotfix/content-property-dx
nielslyngsoe 66df544
no need to import when exporting
nielslyngsoe 3cc2cc1
only observe aliases
nielslyngsoe 7b32d0d
merge the two component for less complexity
nielslyngsoe 99b0420
Merge remote-tracking branch 'origin/v16/hotfix/fix-context-api-test'…
nielslyngsoe aa017cc
added property settings
nielslyngsoe 16830cf
ensure this works with extension begin removed
nielslyngsoe 878bbf9
Merge branch 'release/16.0' into v16/hotfix/content-property-dx
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
104 changes: 104 additions & 0 deletions
104
...ient/src/packages/content/content/global-components/content-workspace-property.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,104 @@ | ||
import { UMB_CONTENT_WORKSPACE_CONTEXT } from '../constants.js'; | ||
import { html, customElement, property, state, nothing } from '@umbraco-cms/backoffice/external/lit'; | ||
import type { UmbPropertyTypeModel } from '@umbraco-cms/backoffice/content-type'; | ||
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'; | ||
import { UMB_PROPERTY_DATASET_CONTEXT } from '@umbraco-cms/backoffice/property'; | ||
import { UmbVariantId } from '@umbraco-cms/backoffice/variant'; | ||
|
||
import '../workspace/views/edit/content-editor-property.element.js'; | ||
|
||
@customElement('umb-content-workspace-property') | ||
export class UmbContentWorkspacePropertyElement extends UmbLitElement { | ||
private _alias?: string | undefined; | ||
|
||
@property() | ||
public get alias(): string | undefined { | ||
return this._alias; | ||
} | ||
public set alias(value: string | undefined) { | ||
this._alias = value; | ||
this.#observePropertyType(); | ||
} | ||
|
||
@state() | ||
_datasetVariantId?: UmbVariantId; | ||
|
||
@state() | ||
_dataPath?: string; | ||
|
||
@state() | ||
_viewable?: boolean; | ||
|
||
@state() | ||
_writeable?: boolean; | ||
|
||
@state() | ||
_workspaceContext?: typeof UMB_CONTENT_WORKSPACE_CONTEXT.TYPE; | ||
|
||
@state() | ||
_propertyType?: UmbPropertyTypeModel; | ||
|
||
constructor() { | ||
super(); | ||
|
||
// The Property Dataset is local to the active variant, we use this to retrieve the variant we like to gather the value from. | ||
this.consumeContext(UMB_PROPERTY_DATASET_CONTEXT, (datasetContext) => { | ||
this._datasetVariantId = datasetContext?.getVariantId(); | ||
}); | ||
|
||
// The Content Workspace Context is used to retrieve the property type we like to observe. | ||
// This gives us the configuration from the property type as part of the data type. | ||
this.consumeContext(UMB_CONTENT_WORKSPACE_CONTEXT, async (workspaceContext) => { | ||
this._workspaceContext = workspaceContext; | ||
this.#observePropertyType(); | ||
}); | ||
} | ||
|
||
async #observePropertyType() { | ||
if (!this._alias || !this._workspaceContext) return; | ||
|
||
this.observe(await this._workspaceContext?.structure.propertyStructureByAlias(this._alias), (propertyType) => { | ||
this._propertyType = propertyType; | ||
this.#checkViewGuard(); | ||
}); | ||
} | ||
|
||
#checkViewGuard() { | ||
if (!this._workspaceContext || !this._propertyType || !this._datasetVariantId) return; | ||
Check warning on line 67 in src/Umbraco.Web.UI.Client/src/packages/content/content/global-components/content-workspace-property.element.ts
|
||
|
||
const propertyVariantId = new UmbVariantId( | ||
this._propertyType.variesByCulture ? this._datasetVariantId.culture : null, | ||
this._propertyType.variesBySegment ? this._datasetVariantId.segment : null, | ||
); | ||
|
||
this.observe( | ||
this._workspaceContext.propertyViewGuard.isPermittedForVariantAndProperty( | ||
propertyVariantId, | ||
this._propertyType, | ||
this._datasetVariantId, | ||
), | ||
(permitted) => { | ||
this._viewable = permitted; | ||
}, | ||
`umbObservePropertyViewGuard`, | ||
); | ||
} | ||
|
||
override render() { | ||
if (!this._viewable) return nothing; | ||
if (!this._datasetVariantId && !this._propertyType) return nothing; | ||
|
||
return html`<umb-content-workspace-view-edit-property | ||
class="property" | ||
.variantId=${this._datasetVariantId} | ||
.property=${this._propertyType}></umb-content-workspace-view-edit-property>`; | ||
} | ||
} | ||
|
||
export default UmbContentWorkspacePropertyElement; | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
'umb-content-workspace-property': UmbContentWorkspacePropertyElement; | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
src/Umbraco.Web.UI.Client/src/packages/content/content/global-components/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,2 @@ | ||
import './content-workspace-property.element.js'; | ||
export * from './content-workspace-property.element.js'; |
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
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
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
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.