Skip to content

Commit 9ad4a7e

Browse files
Adds Clear Clipboard button & logic (#20757)
* Adds new dictionary/localization item for the clipboard dialog clear all prompt * Removes the wrapping uui-box and moved inside the component itself * Adds Clear Clipboard button and logic * Adds uui-box from outer components consuimg this into this component * Adds a header to uui-box * Adds a conditional uui-button when we have items in clipboard * Adds confirm dialog/prompt to ask if user wants to clear all items * Adds in general_clipboard item to use in the UUI-box header * Removes extra space & moves the requestItems outside the for loop * Be a better citizen Make sure the promise for the modal is caught and we return out early if user explictiy cancels modal or presses ESC * Cleanup my noisy comments for a re-review --------- Co-authored-by: Jacob Overgaard <752371+iOvergaard@users.noreply.github.com>
1 parent 0858d02 commit 9ad4a7e

File tree

4 files changed

+64
-22
lines changed

4 files changed

+64
-22
lines changed

src/Umbraco.Web.UI.Client/src/assets/lang/en.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,7 @@ export default {
10171017
if (new Date(date).getTime() < new Date(now).getTime()) return `${duration} ago`;
10181018
return `in ${duration}`;
10191019
},
1020+
clipboard: 'Clipboard',
10201021
},
10211022
colors: {
10221023
black: 'Black',
@@ -2508,6 +2509,7 @@ export default {
25082509
labelForCopyToClipboard: 'Copy to clipboard',
25092510
confirmDeleteHeadline: 'Delete from clipboard',
25102511
confirmDeleteDescription: 'Are you sure you want to delete <strong>{0}</strong> from the clipboard?',
2512+
confirmClearDescription: 'Are you sure you want to clear the clipboard?',
25112513
copySuccessHeadline: 'Copied to clipboard',
25122514
},
25132515
propertyActions: {

src/Umbraco.Web.UI.Client/src/packages/block/block/modals/block-catalogue/block-catalogue-modal.element.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,9 @@ export class UmbBlockCatalogueModalElement extends UmbModalBaseElement<
194194

195195
#renderClipboard() {
196196
return html`
197-
<uui-box>
198-
<umb-clipboard-entry-picker
199-
.config=${{ multiple: true, asyncFilter: this.data?.clipboardFilter }}
200-
@selection-change=${this.#onClipboardPickerSelectionChange}></umb-clipboard-entry-picker>
201-
</uui-box>
197+
<umb-clipboard-entry-picker
198+
.config=${{ multiple: true, asyncFilter: this.data?.clipboardFilter }}
199+
@selection-change=${this.#onClipboardPickerSelectionChange}></umb-clipboard-entry-picker>
202200
`;
203201
}
204202

src/Umbraco.Web.UI.Client/src/packages/clipboard/clipboard-entry/picker-modal/clipboard-entry-picker-modal.element.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,10 @@ export class UmbClipboardEntryPickerModalElement extends UmbModalBaseElement<
2727

2828
override render() {
2929
return html`<umb-body-layout headline="Clipboard">
30-
<uui-box>
31-
<umb-clipboard-entry-picker
32-
.selection=${this.value?.selection}
33-
.config=${this.data}
34-
@selection-change=${this.#onSelectionChange}></umb-clipboard-entry-picker>
35-
</uui-box>
30+
<umb-clipboard-entry-picker
31+
.selection=${this.value?.selection}
32+
.config=${this.data}
33+
@selection-change=${this.#onSelectionChange}></umb-clipboard-entry-picker>
3634
<div slot="actions">
3735
<uui-button label="Close" @click=${this.#close}></uui-button>
3836
<uui-button label="Submit" look="primary" color="positive" @click=${this.#submit}></uui-button>

src/Umbraco.Web.UI.Client/src/packages/clipboard/clipboard-entry/picker/clipboard-entry-picker.element.ts

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { UmbClipboardCollectionRepository } from '../../collection/index.js';
22
import type { UmbClipboardEntryDetailModel } from '../types.js';
3-
import { css, customElement, html, property, repeat, state, when } from '@umbraco-cms/backoffice/external/lit';
3+
import UmbClipboardEntryDetailRepository from '../detail/clipboard-entry-detail.repository.js';
4+
import { css, customElement, html, nothing, property, repeat, state, when } from '@umbraco-cms/backoffice/external/lit';
45
import { UmbEntityContext } from '@umbraco-cms/backoffice/entity';
56
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
67
import {
@@ -10,6 +11,7 @@ import {
1011
import { UmbSelectionManager } from '@umbraco-cms/backoffice/utils';
1112
import { UMB_ACTION_EVENT_CONTEXT } from '@umbraco-cms/backoffice/action';
1213
import type { UmbEntityUnique } from '@umbraco-cms/backoffice/entity';
14+
import { umbConfirmModal } from '@umbraco-cms/backoffice/modal';
1315

1416
// TODO: make this into an extension point (Picker) with two kinds of pickers: tree-item-picker and collection-item-picker;
1517
@customElement('umb-clipboard-entry-picker')
@@ -28,6 +30,8 @@ export class UmbClipboardEntryPickerElement extends UmbLitElement {
2830
#entityContext = new UmbEntityContext(this);
2931
#actionEventContext?: typeof UMB_ACTION_EVENT_CONTEXT.TYPE;
3032

33+
#clipboardDetailRepository = new UmbClipboardEntryDetailRepository(this);
34+
3135
constructor() {
3236
super();
3337
this.#entityContext.setEntityType('clipboard-entry');
@@ -117,17 +121,57 @@ export class UmbClipboardEntryPickerElement extends UmbLitElement {
117121
}
118122
};
119123

124+
async #clearClipboard() {
125+
try {
126+
await umbConfirmModal(this, {
127+
headline: '#clipboard_labelForClearClipboard',
128+
content: '#clipboard_confirmClearDescription',
129+
color: 'danger',
130+
confirmLabel: '#general_clear',
131+
cancelLabel: '#general_cancel',
132+
});
133+
} catch {
134+
return;
135+
}
136+
137+
for (const item of this._items) {
138+
const { error } = await this.#clipboardDetailRepository.delete(item.unique);
139+
if (error) {
140+
console.error(`Unable to delete clipboard item with unique ${item.unique}`, error);
141+
}
142+
}
143+
144+
this.#requestItems();
145+
}
146+
120147
override render() {
121-
return when(
122-
this._items.length > 0,
123-
() =>
124-
repeat(
125-
this._items,
126-
(item) => item.unique,
127-
(item) => this.#renderItem(item),
128-
),
129-
() => html`<p>There are no items in the clipboard.</p>`,
130-
);
148+
return html`
149+
<uui-box headline=${this.localize.term('general_clipboard')}>
150+
<span slot="header-actions">
151+
${when(
152+
this._items.length > 0,
153+
() => html`
154+
<uui-button color="default" look="default" @click="${this.#clearClipboard}">
155+
<uui-icon name="delete"></uui-icon>
156+
<umb-localize key="clipboard_labelForClearClipboard">Clear Clipboard</umb-localize>
157+
</uui-button>
158+
`,
159+
() => nothing,
160+
)}
161+
</span>
162+
163+
${when(
164+
this._items.length > 0,
165+
() =>
166+
repeat(
167+
this._items,
168+
(item) => item.unique,
169+
(item) => this.#renderItem(item),
170+
),
171+
() => html`<p>There are no items in the clipboard.</p>`,
172+
)}
173+
</uui-box>
174+
`;
131175
}
132176

133177
#renderItem(item: UmbClipboardEntryDetailModel) {

0 commit comments

Comments
 (0)