-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Document URLs Data Resolver #19316
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
nielslyngsoe
merged 20 commits into
release/16.0
from
v16/hotfix/document-urls-data-resolver
May 19, 2025
Merged
Document URLs Data Resolver #19316
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
21c9b95
remove padding
madsrasmussen 02d82da
add document urls data resolver
madsrasmussen 91b0254
use in url info app
madsrasmussen 0848497
handle invariant cases
madsrasmussen 4a778dd
do not render culture if all links have the same culture
madsrasmussen fb2e0ac
use if defined
madsrasmussen 24b00fe
handle variant with no links
madsrasmussen 8a6ee60
Update types.ts
madsrasmussen ab43da9
fix lint errors
madsrasmussen 200f004
get variant aware document data
madsrasmussen bfdcb38
remove unused
madsrasmussen cc6d4f1
use media item repository
madsrasmussen 8181250
temp remove check
madsrasmussen 49c9452
populate url
madsrasmussen e159d15
add spacing to reference app
madsrasmussen 55b1eeb
Merge branch 'release/16.0' into v16/hotfix/document-urls-data-resolver
nielslyngsoe b1d81fe
Merge branch 'release/16.0' into v16/hotfix/document-urls-data-resolver
madsrasmussen 113989d
reset the url when removing document or media
madsrasmussen 217a837
add validator
madsrasmussen 2f7394f
make url input required
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
94 changes: 94 additions & 0 deletions
94
...Umbraco.Web.UI.Client/src/packages/documents/documents/url/document-urls-data-resolver.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,94 @@ | ||
import type { UmbDocumentUrlModel } from './repository/types.js'; | ||
import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api'; | ||
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api'; | ||
import { UmbArrayState } from '@umbraco-cms/backoffice/observable-api'; | ||
import { UMB_PROPERTY_DATASET_CONTEXT } from '@umbraco-cms/backoffice/property'; | ||
import type { UmbVariantId } from '@umbraco-cms/backoffice/variant'; | ||
|
||
/** | ||
* A controller for resolving data for document urls | ||
* @exports | ||
* @class UmbDocumentUrlsDataResolver | ||
* @augments {UmbControllerBase} | ||
*/ | ||
export class UmbDocumentUrlsDataResolver extends UmbControllerBase { | ||
#appCulture?: string; | ||
#propertyDataSetCulture?: UmbVariantId; | ||
#data?: Array<UmbDocumentUrlModel> | undefined; | ||
|
||
#init: Promise<unknown>; | ||
|
||
#urls = new UmbArrayState<UmbDocumentUrlModel>([], (url) => url.url); | ||
/** | ||
* The urls for the current culture | ||
* @returns {ObservableArray<UmbDocumentUrlModel>} The urls for the current culture | ||
* @memberof UmbDocumentUrlsDataResolver | ||
*/ | ||
public readonly urls = this.#urls.asObservable(); | ||
|
||
constructor(host: UmbControllerHost) { | ||
super(host); | ||
|
||
// TODO: listen for UMB_VARIANT_CONTEXT when available | ||
this.#init = Promise.all([ | ||
this.consumeContext(UMB_PROPERTY_DATASET_CONTEXT, (context) => { | ||
this.#propertyDataSetCulture = context?.getVariantId(); | ||
this.#setCultureAwareValues(); | ||
}).asPromise(), | ||
]); | ||
} | ||
|
||
/** | ||
* Get the current data | ||
* @returns {Array<UmbDocumentUrlModel> | undefined} The current data | ||
* @memberof UmbDocumentUrlsDataResolver | ||
*/ | ||
getData(): Array<UmbDocumentUrlModel> | undefined { | ||
return this.#data; | ||
} | ||
|
||
/** | ||
* Set the current data | ||
* @param {Array<UmbDocumentUrlModel> | undefined} data The current data | ||
* @memberof UmbDocumentUrlsDataResolver | ||
*/ | ||
setData(data: Array<UmbDocumentUrlModel> | undefined) { | ||
this.#data = data; | ||
|
||
if (!this.#data) { | ||
this.#urls.setValue([]); | ||
return; | ||
} | ||
|
||
this.#setCultureAwareValues(); | ||
} | ||
|
||
/** | ||
* Get the urls for the current culture | ||
* @returns {(Promise<Array<UmbDocumentUrlModel> | []>)} The urls for the current culture | ||
* @memberof UmbDocumentUrlsDataResolver | ||
*/ | ||
async getUrls(): Promise<Array<UmbDocumentUrlModel> | []> { | ||
await this.#init; | ||
return this.#urls.getValue(); | ||
} | ||
|
||
#setCultureAwareValues() { | ||
this.#setUrls(); | ||
} | ||
|
||
#setUrls() { | ||
const data = this.#getDataForCurrentCulture(); | ||
this.#urls.setValue(data ?? []); | ||
} | ||
|
||
#getCurrentCulture(): string | undefined { | ||
return this.#propertyDataSetCulture?.culture || this.#appCulture; | ||
} | ||
|
||
#getDataForCurrentCulture(): Array<UmbDocumentUrlModel> | undefined { | ||
const culture = this.#getCurrentCulture(); | ||
// If there is no culture context (invariant data) we return all urls | ||
return culture ? this.#data?.filter((x) => x.culture === culture) : this.#data; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
src/Umbraco.Web.UI.Client/src/packages/documents/documents/url/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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { UmbDocumentUrlRepository, UMB_DOCUMENT_URL_REPOSITORY_ALIAS } from './repository/index.js'; | ||
|
||
export * from './constants.js'; | ||
export * from './document-urls-data-resolver.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.
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.