From d4acd53fd501e90c51824187400c0e4e8a05a9d2 Mon Sep 17 00:00:00 2001 From: Jacob Overgaard <752371+iOvergaard@users.noreply.github.com> Date: Tue, 1 Apr 2025 12:36:27 +0200 Subject: [PATCH] fix: fixes an issue where the serverUrl was shown twice and changes the component to use `` instead (#18899) --- .../input-upload-field-file.element.ts | 91 +++---------------- 1 file changed, 14 insertions(+), 77 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/packages/media/media/components/input-upload-field/preview/input-upload-field-file.element.ts b/src/Umbraco.Web.UI.Client/src/packages/media/media/components/input-upload-field/preview/input-upload-field-file.element.ts index 6dd332e83b..3e349d20f4 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/media/media/components/input-upload-field/preview/input-upload-field-file.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/media/media/components/input-upload-field/preview/input-upload-field-file.element.ts @@ -1,103 +1,40 @@ -import { html, customElement, property, state, css, when } from '@umbraco-cms/backoffice/external/lit'; +import { html, customElement, property } from '@umbraco-cms/backoffice/external/lit'; import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'; -import { UMB_APP_CONTEXT } from '@umbraco-cms/backoffice/app'; -import type { PropertyValueMap } from '@umbraco-cms/backoffice/external/lit'; @customElement('umb-input-upload-field-file') export default class UmbInputUploadFieldFileElement extends UmbLitElement { - #loadingText = `(${this.localize.term('general_loading')}...)`; - - #serverUrl = ''; - @property() path: string = ''; /** * @description The file to be rendered. * @type {File} - * @required */ @property({ attribute: false }) file?: File; - @state() - extension = ''; - - @state() - label = ''; - - constructor() { - super(); - - this.consumeContext(UMB_APP_CONTEXT, (instance) => { - this.#serverUrl = instance.getServerUrl(); - }); + get #label() { + if (this.file) { + return this.file.name; + } + return this.path.split('/').pop() ?? `(${this.localize.term('general_loading')}...)`; } - protected override updated(_changedProperties: PropertyValueMap | Map): void { - super.updated(_changedProperties); - - if (_changedProperties.has('file') && this.file) { - this.extension = this.file.name.split('.').pop() ?? ''; - this.label = this.file.name || this.#loadingText; - } - - if (_changedProperties.has('path') && !this.file) { - this.extension = this.path.split('.').pop() ?? ''; - this.label = this.path.split('/').pop() ?? this.#loadingText; - } + get #fileExtension() { + return this.#label.split('.').pop() ?? ''; } override render() { - if (!this.label && !this.extension) return html``; + if (!this.path && !this.file) return html``; return html` - - - ${when( - !this.file && this.path, - () => html`${this.label}`, - () => html`${this.label}`, - )} - + `; } - - static override readonly styles = [ - css` - #main { - display: grid; - grid-template-rows: 150px auto; - box-sizing: border-box; - color: var(--uui-color-text); - } - - #file-symbol { - aspect-ratio: 1 / 1; - margin: auto; - max-width: 100%; - max-height: 100%; - } - - #label { - text-align: center; - overflow: hidden; - text-overflow: ellipsis; - white-space: nowrap; - color: var(--uui-color-text); - - &:is(a) { - text-decoration: none; - color: var(--uui-color-interactive); - - &:hover { - text-decoration: underline; - color: var(--uui-color-interactive-emphasis); - } - } - } - `, - ]; } declare global {