Skip to content

Commit 75e7bb4

Browse files
authored
Render all URLs in document workspace info tab and ensure protocol-less links can be used to access the intended URL. (#17926)
* Render all URLs in document workspace info tab and ensure protocol-less links can be used to access the intended URL. * Removed unused import. * Removed scheme from resolved URL.
1 parent 0eb6a16 commit 75e7bb4

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

src/Umbraco.Web.UI.Client/src/packages/documents/documents/workspace/views/info/document-workspace-view-info-links.element.ts

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { UMB_ACTION_EVENT_CONTEXT } from '@umbraco-cms/backoffice/action';
1010
import { observeMultiple } from '@umbraco-cms/backoffice/observable-api';
1111
import { DocumentVariantStateModel } from '@umbraco-cms/backoffice/external/backend-api';
1212
import { debounce } from '@umbraco-cms/backoffice/utils';
13+
import { UMB_APP_LANGUAGE_CONTEXT } from '@umbraco-cms/backoffice/language';
1314

1415
interface UmbDocumentInfoViewLink {
1516
culture: string;
@@ -36,6 +37,9 @@ export class UmbDocumentWorkspaceViewInfoLinksElement extends UmbLitElement {
3637
@state()
3738
private _links: Array<UmbDocumentInfoViewLink> = [];
3839

40+
@state()
41+
private _defaultCulture?: string;
42+
3943
#urls: Array<UmbDocumentUrlModel> = [];
4044

4145
#documentWorkspaceContext?: typeof UMB_DOCUMENT_WORKSPACE_CONTEXT.TYPE;
@@ -75,24 +79,38 @@ export class UmbDocumentWorkspaceViewInfoLinksElement extends UmbLitElement {
7579
this.#setLinks();
7680
});
7781
});
82+
83+
this.consumeContext(UMB_APP_LANGUAGE_CONTEXT, (instance) => {
84+
this.observe(instance.appDefaultLanguage, (value) => {
85+
this._defaultCulture = value?.unique;
86+
this.#setLinks();
87+
});
88+
});
7889
}
7990

8091
#setLinks() {
81-
const possibleVariantCultures = this._variantOptions?.map((variantOption) => variantOption.culture) ?? [];
82-
const possibleUrlCultures = this.#urls.map((link) => link.culture);
83-
const possibleCultures = [...new Set([...possibleVariantCultures, ...possibleUrlCultures])].filter(
84-
Boolean,
85-
) as string[];
86-
87-
const links: Array<UmbDocumentInfoViewLink> = possibleCultures.map((culture) => {
88-
const url = this.#urls.find((link) => link.culture === culture)?.url;
92+
const links: Array<UmbDocumentInfoViewLink> = this.#urls.map((u) => {
93+
const culture = u.culture ?? this._defaultCulture ?? "";
94+
const url = u.url;
8995
const state = this._variantOptions?.find((variantOption) => variantOption.culture === culture)?.variant?.state;
9096
return { culture, url, state };
9197
});
9298

9399
this._links = links;
94100
}
95101

102+
#getTargetUrl (url: string | undefined) {
103+
if (!url || url.length === 0) {
104+
return url;
105+
}
106+
107+
if (url.includes(".") && !url.includes("//")) {
108+
return "//" + url;
109+
}
110+
111+
return url;
112+
}
113+
96114
async #requestUrls() {
97115
if (this._isNew) return;
98116
if (!this._unique) return;
@@ -181,7 +199,7 @@ export class UmbDocumentWorkspaceViewInfoLinksElement extends UmbLitElement {
181199
}
182200

183201
return html`
184-
<a class="link-item" href=${link.url} target="_blank">
202+
<a class="link-item" href=${this.#getTargetUrl(link.url)} target="_blank">
185203
<span>
186204
${this.#renderLinkCulture(link.culture)}
187205
<span>${link.url}</span>

0 commit comments

Comments
 (0)