Skip to content

Commit

Permalink
adobeGH-96 - Ability to rename files and folders
Browse files Browse the repository at this point in the history
UI updates to provide rename option for files and folders.
  • Loading branch information
sukamat committed Apr 27, 2024
1 parent 936c59f commit f4e2bca
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 1 deletion.
27 changes: 26 additions & 1 deletion blocks/browse/da-browse/da-browse.css
Expand Up @@ -517,7 +517,6 @@ li.da-actions-menu-item button:hover {
min-height: 400px;
}


@media (min-width: 900px) {
.da-breadcrumb {
margin-bottom: 12px;
Expand All @@ -529,3 +528,29 @@ li.da-actions-menu-item button:hover {
display: block;
}
}

/* Loader */
.da-loader-overlay {
position: absolute;
background-color: rgba(228, 240, 255, 0.7);
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
top: 0;
left: 0;
z-index: 10;
}
.da-loader {
border: 4px solid #f3f3f3;
border-top: 4px solid var(--spectrum-blue-800);
border-radius: 50%;
width: 30px;
height: 30px;
animation: spin 2s linear infinite;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
53 changes: 53 additions & 0 deletions blocks/browse/da-browse/da-browse.js
Expand Up @@ -212,6 +212,53 @@ export default class DaBrowse extends LitElement {
this._canPaste = false;
}

handleRename() {
const item = this._selectedItems[0];
const listItems = this.shadowRoot.querySelectorAll('.da-item-list-item-title');

let listItem;
for (const li of listItems) {
const href = li.getAttribute('href');
const path = href.replace(/\/edit#|\/sheet#|\/media#|#/, '');
if (item.path.includes(path)) {
listItem = li;
break;
}
}

const input = document.createElement('input');
input.type = 'text';
input.value = item.name;
input.className = 'da-item-list-item-title';
listItem.replaceWith(input);
input.focus();

input.addEventListener('keydown', async (e) => {
const resetSelection = () => {
input.replaceWith(listItem);
input.remove();
this.clearSelection();
this.requestUpdate();
};

if (e.key === 'Enter') {
const newname = item.ext ? `${input.value}.${item.ext}` : input.value;
const formData = new FormData();
formData.append('newname', newname);
const opts = { method: 'POST', body: formData };
input.insertAdjacentHTML('afterend', '<div class="da-loader-overlay"><div class="da-loader"></div></div>');
await daFetch(`${DA_ORIGIN}/rename${item.path}`, opts);
input.nextElementSibling.remove();
// Update the item with new name and path
item.path = item.path.substring(0, item.path.lastIndexOf('/') + 1) + newname;
item.name = input.value;
resetSelection();
} else if (e.key === 'Escape') {
resetSelection();
}
});
}

handleTab(idx) {
const current = this._tabItems.find((item) => item.selected);
if (this._tabItems[idx].id === current.id) return;
Expand Down Expand Up @@ -292,6 +339,12 @@ export default class DaBrowse extends LitElement {
<span>${this._selectedItems.length} selected</span>
</div>
<div class="da-action-bar-right-rail">
<button
@click=${this.handleRename}
class="rename-button ${this._selectedItems.length === 1 ? '' : 'hide-button'}">
<img src="/blocks/browse/da-browse/img/Smock_TextEdit_18_N.svg" />
<span>Rename</span>
</button>
<button
@click=${this.handleCopy}
class="copy-button ${this._canPaste ? 'hide-button' : ''}">
Expand Down
12 changes: 12 additions & 0 deletions blocks/browse/da-browse/img/Smock_TextEdit_18_N.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f4e2bca

Please sign in to comment.