Skip to content

Commit

Permalink
Added size label.
Browse files Browse the repository at this point in the history
  • Loading branch information
ericsnekbytes committed Nov 7, 2024
1 parent 2d252c8 commit 70e4163
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
22 changes: 20 additions & 2 deletions src/FssTreeItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export class FssTreeItem {
model: any;
// icon: HTMLElement;
nameLbl: HTMLElement;
sizeLbl: HTMLElement;
dirSymbol: HTMLElement;
container: HTMLElement;
clickSlots: any;
Expand Down Expand Up @@ -60,6 +61,12 @@ export class FssTreeItem {
container.appendChild(nameLbl);
this.nameLbl = nameLbl;

// Show the name of this file/folder (a single path segment)
let sizeLbl = document.createElement('div');
sizeLbl.classList.add('jfss-filesize-lbl');
container.appendChild(sizeLbl);
this.sizeLbl = sizeLbl;

// Add click and right click handlers to the tree component
root.addEventListener('contextmenu', this.handleContext.bind(this));
root.addEventListener('click', this.handleClick.bind(this), true);
Expand All @@ -74,8 +81,18 @@ export class FssTreeItem {
this.root.appendChild(elem);
}

setMetadata(value: string) {
this.root.dataset.fss = value;
setMetadata(user_path: string, size: string) {
this.root.dataset.fss = user_path;
this.root.dataset.fsize = size;

let sizeDisplay = `(${size.toLocaleString()})`;
// if (parseInt(size) > 100) {
// const sizeFormat = new Intl.NumberFormat(undefined, {
// notation: 'scientific',
// });
// sizeDisplay = `(${sizeFormat.format(parseInt(size))})`;
// }
this.sizeLbl.innerText = sizeDisplay;
}

setText(value: string) {
Expand All @@ -89,6 +106,7 @@ export class FssTreeItem {
if (symbol == 'dir') {
folderIcon.element({container: this.dirSymbol});
this.isDir = true;
this.sizeLbl.style.display = 'none';
}
if (symbol == 'file') {
fileIcon.element({container: this.dirSymbol});
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ class FsspecWidget extends Widget {
}
for (let [pathSegment, pathInfo] of Object.entries(childPaths)) {
let item = new FssTreeItem(this.model, [this.lazyLoad.bind(this)], true, true);
item.setMetadata((pathInfo as any).path);
item.setMetadata((pathInfo as any).path, (pathInfo as any).metadata.size);
item.setText(pathSegment);
// (pathInfo as any).ui = item;
elemParent.appendChild(item.root);
Expand Down
5 changes: 5 additions & 0 deletions style/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@
display: flex;
}

.jfss-filesize-lbl {
margin-left: .5rem;
color: var(--jp-ui-font-color3)
}

.jfss-hseparator {
box-sizing: border-box;

Expand Down

0 comments on commit 70e4163

Please sign in to comment.