Skip to content

Commit ee231c7

Browse files
authored
Corrects filename label on the Upload File component (#18205)
* Corrects input upload filename label Fixes #18195 * Refactored input upload file code
1 parent 2cdcacb commit ee231c7

File tree

1 file changed

+30
-36
lines changed

1 file changed

+30
-36
lines changed

src/Umbraco.Web.UI.Client/src/packages/media/media/components/input-upload-field/preview/input-upload-field-file.element.ts

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1+
import { html, customElement, property, state, css, when } from '@umbraco-cms/backoffice/external/lit';
2+
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
13
import { UMB_APP_CONTEXT } from '@umbraco-cms/backoffice/app';
24
import type { PropertyValueMap } from '@umbraco-cms/backoffice/external/lit';
3-
import { html, customElement, property, state, css } from '@umbraco-cms/backoffice/external/lit';
4-
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
55

66
@customElement('umb-input-upload-field-file')
77
export default class UmbInputUploadFieldFileElement extends UmbLitElement {
8-
@property({ type: String })
8+
#loadingText = `(${this.localize.term('general_loading')}...)`;
9+
10+
#serverUrl = '';
11+
12+
@property()
913
path: string = '';
1014

1115
/**
@@ -22,53 +26,39 @@ export default class UmbInputUploadFieldFileElement extends UmbLitElement {
2226
@state()
2327
label = '';
2428

25-
#serverUrl = '';
26-
27-
#loadingText = `(${this.localize.term('general_loading')}...)`;
28-
29-
/**
30-
*
31-
*/
3229
constructor() {
3330
super();
31+
3432
this.consumeContext(UMB_APP_CONTEXT, (instance) => {
3533
this.#serverUrl = instance.getServerUrl();
36-
}).asPromise();
34+
});
3735
}
3836

3937
protected override updated(_changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>): void {
4038
super.updated(_changedProperties);
39+
4140
if (_changedProperties.has('file') && this.file) {
4241
this.extension = this.file.name.split('.').pop() ?? '';
4342
this.label = this.file.name || this.#loadingText;
4443
}
4544

46-
if (_changedProperties.has('path')) {
47-
if (this.#serverUrl) {
48-
if (this.file) return;
49-
50-
this.extension = this.path.split('.').pop() ?? '';
51-
this.label = this.#serverUrl ? this.path.substring(this.#serverUrl.length) : this.#loadingText;
52-
}
45+
if (_changedProperties.has('path') && !this.file) {
46+
this.extension = this.path.split('.').pop() ?? '';
47+
this.label = this.path.split('/').pop() ?? this.#loadingText;
5348
}
5449
}
5550

56-
#renderLabel() {
57-
if (this.path) {
58-
// Don't make it a link if it's a temp file upload.
59-
return this.file ? this.label : html`<a id="label" href=${this.path} target="_blank">${this.label}</a>`;
60-
}
61-
62-
return html`<span id="label">${this.label}</span>`;
63-
}
64-
6551
override render() {
6652
if (!this.label && !this.extension) return html`<uui-loader></uui-loader>`;
6753

6854
return html`
6955
<div id="main">
7056
<uui-symbol-file id="file-symbol" .type=${this.extension}></uui-symbol-file>
71-
${this.#renderLabel()}
57+
${when(
58+
!this.file && this.path,
59+
() => html`<a id="label" href="${this.#serverUrl}${this.path}" target="_blank">${this.label}</a>`,
60+
() => html`<span id="label">${this.label}</span>`,
61+
)}
7262
</div>
7363
`;
7464
}
@@ -81,26 +71,30 @@ export default class UmbInputUploadFieldFileElement extends UmbLitElement {
8171
box-sizing: border-box;
8272
color: var(--uui-color-text);
8373
}
74+
8475
#file-symbol {
8576
aspect-ratio: 1 / 1;
8677
margin: auto;
8778
max-width: 100%;
8879
max-height: 100%;
8980
}
81+
9082
#label {
9183
text-align: center;
9284
overflow: hidden;
9385
text-overflow: ellipsis;
9486
white-space: nowrap;
9587
color: var(--uui-color-text);
96-
}
97-
a#label {
98-
text-decoration: none;
99-
color: var(--uui-color-interactive);
100-
}
101-
a#label:hover {
102-
text-decoration: underline;
103-
color: var(--uui-color-interactive-emphasis);
88+
89+
&:is(a) {
90+
text-decoration: none;
91+
color: var(--uui-color-interactive);
92+
93+
&:hover {
94+
text-decoration: underline;
95+
color: var(--uui-color-interactive-emphasis);
96+
}
97+
}
10498
}
10599
`,
106100
];

0 commit comments

Comments
 (0)