diff --git a/src/packages/documents/documents/workspace/views/info/document-workspace-view-info-links.element.ts b/src/packages/documents/documents/workspace/views/info/document-workspace-view-info-links.element.ts index 6b0fcb58ab..f244371dfa 100644 --- a/src/packages/documents/documents/workspace/views/info/document-workspace-view-info-links.element.ts +++ b/src/packages/documents/documents/workspace/views/info/document-workspace-view-info-links.element.ts @@ -1,23 +1,28 @@ import { UmbDocumentUrlRepository } from '../../../repository/url/document-url.repository.js'; import { UMB_DOCUMENT_WORKSPACE_CONTEXT } from '../../document-workspace.context-token.js'; -import type { UmbDocumentUrlModel } from '../../../repository/url/types.js'; -import { css, customElement, html, nothing, repeat, state, when } from '@umbraco-cms/backoffice/external/lit'; +import type { UmbDocumentVariantOptionModel } from '../../../types.js'; +import { css, customElement, html, map, nothing, state, when } from '@umbraco-cms/backoffice/external/lit'; import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'; import { UmbRequestReloadStructureForEntityEvent } from '@umbraco-cms/backoffice/entity-action'; -import { UmbTextStyles } from '@umbraco-cms/backoffice/style'; import { UMB_ACTION_EVENT_CONTEXT } from '@umbraco-cms/backoffice/action'; +import { observeMultiple } from '@umbraco-cms/backoffice/observable-api'; +import { DocumentVariantStateModel } from '@umbraco-cms/backoffice/external/backend-api'; @customElement('umb-document-workspace-view-info-links') export class UmbDocumentWorkspaceViewInfoLinksElement extends UmbLitElement { #documentUrlRepository = new UmbDocumentUrlRepository(this); - #workspaceContext?: typeof UMB_DOCUMENT_WORKSPACE_CONTEXT.TYPE; + @state() + private _isNew = false; + + @state() + private _unique?: string; @state() - private _invariantCulture = 'en-US'; + private _variantOptions?: Array; @state() - private _items?: Array; + private _lookup: Record = {}; constructor() { super(); @@ -29,96 +34,135 @@ export class UmbDocumentWorkspaceViewInfoLinksElement extends UmbLitElement { }); this.consumeContext(UMB_DOCUMENT_WORKSPACE_CONTEXT, (context) => { - this.#workspaceContext = context; - this.#requestUrls(); + this.observe( + observeMultiple([context.isNew, context.unique, context.variantOptions]), + ([isNew, unique, variantOptions]) => { + this._isNew = isNew === true; + this._unique = unique; + this._variantOptions = variantOptions; + this.#requestUrls(); + }, + ); }); } async #requestUrls() { - const unique = this.#workspaceContext?.getUnique(); - if (!unique) throw new Error('Document unique is required'); + if (this._isNew) return; + + if (!this._unique) throw new Error('Document unique is required'); - const { data } = await this.#documentUrlRepository.requestItems([unique]); + const { data } = await this.#documentUrlRepository.requestItems([this._unique]); if (data?.length) { - this._items = data[0].urls; + data[0].urls.forEach((item) => { + if (item.culture && item.url) { + this._lookup[item.culture] = item.url; + } + }); + this.requestUpdate('_lookup'); } } - override render() { - return html` - - - - `; + #getStateLocalizationKey(variantOption: UmbDocumentVariantOptionModel) { + switch (variantOption.variant?.state) { + case null: + case undefined: + case DocumentVariantStateModel.NOT_CREATED: + return 'content_notCreated'; + case DocumentVariantStateModel.DRAFT: + return 'content_itemNotPublished'; + case DocumentVariantStateModel.PUBLISHED: + return 'content_routeErrorCannotRoute'; + default: + return 'content_parentNotPublishedAnomaly'; + } } - #renderUrls() { - if (!this._items) return nothing; + override render() { return html` - ${repeat( - this._items!, - (item) => item.culture, - (item) => html` - - ${item.culture} - ${item.url} - - - `, - )} + + ${when( + this._isNew, + () => this.#renderNotCreated(), + () => this.#renderUrls(), + )} + `; } - #renderUnpublished() { + #renderNotCreated() { return html` `; } + #renderUrls() { + if (!this._variantOptions?.length) return nothing; + return map(this._variantOptions, (variantOption) => this.#renderUrl(variantOption)); + } + + #renderUrl(variantOption: UmbDocumentVariantOptionModel) { + const varies = !!variantOption.culture; + const culture = varies ? variantOption.culture! : variantOption.language.unique; + const url = this._lookup[culture]; + return when( + url, + () => html` + + + ${varies ? culture : nothing} + ${url} + + + + `, + () => html` + + `, + ); + } + static override styles = [ - UmbTextStyles, css` - #link-section { - display: flex; - flex-direction: column; - text-align: left; + uui-box { + --uui-box-default-padding: 0; } .link-item { - padding: var(--uui-size-space-4) var(--uui-size-space-6); - display: grid; - grid-template-columns: auto 1fr auto; + display: flex; + justify-content: space-between; + align-items: center; gap: var(--uui-size-6); - color: inherit; - text-decoration: none; + + padding: var(--uui-size-space-4) var(--uui-size-space-6); &:is(a) { cursor: pointer; + color: inherit; + text-decoration: none; } &:is(a):hover { background: var(--uui-color-divider); } - .culture { - color: var(--uui-color-divider-emphasis); + & > span { + display: flex; + align-items: center; + gap: var(--uui-size-6); } - uui-icon { - margin-right: var(--uui-size-space-2); - vertical-align: middle; + .culture { + color: var(--uui-color-divider-emphasis); } } `,