From 89d7bc0876019defa0907a9f61000692284480a8 Mon Sep 17 00:00:00 2001 From: Eric Gentry Date: Fri, 8 Nov 2024 13:27:31 -0500 Subject: [PATCH 1/2] Added selection indicator to sources list, UI tweaks. --- src/FssFilesysItem.ts | 50 +++++++++++++++++++++++++++++++++++-------- src/index.ts | 32 ++++++++++++++++++++++----- style/base.css | 7 +++--- 3 files changed, 72 insertions(+), 17 deletions(-) diff --git a/src/FssFilesysItem.ts b/src/FssFilesysItem.ts index aacd56d..c791a7b 100644 --- a/src/FssFilesysItem.ts +++ b/src/FssFilesysItem.ts @@ -1,6 +1,11 @@ // Element for displaying a single fsspec filesystem import { FssContextMenu } from './treeContext'; +// import { Logger } from "./logger" + +const HOVER = 'var(--jp-layout-color3)'; +const UNHOVER = 'var(--jp-layout-color2)'; +const SELECTED = 'var(--jp-layout-color4)'; class FssFilesysItem { root: HTMLElement; @@ -9,7 +14,9 @@ class FssFilesysItem { fsInfo: any; clickSlots: any; nameField: any; - typeField: any; + pathField: any; + _selected = false; + _hovered = false; constructor(fsInfo: any, userClickSlots: any) { this.filesysName = fsInfo.name; @@ -25,6 +32,7 @@ class FssFilesysItem { fsItem.classList.add('jfss-fsitem-root'); fsItem.addEventListener('mouseenter', this.handleFsysHover.bind(this)); fsItem.addEventListener('mouseleave', this.handleFsysHover.bind(this)); + fsItem.dataset.fssname = fsInfo.name; this.root = fsItem; // Set the tooltip @@ -35,10 +43,10 @@ class FssFilesysItem { this.nameField.innerText = this.filesysName; fsItem.appendChild(this.nameField); - this.typeField = document.createElement('div'); - this.typeField.classList.add('jfss-fsitem-type'); - this.typeField.innerText = 'Type: ' + this.filesysType; - fsItem.appendChild(this.typeField); + this.pathField = document.createElement('div'); + this.pathField.classList.add('jfss-fsitem-type'); + this.pathField.innerText = 'Path: ' + fsInfo.path; + fsItem.appendChild(this.pathField); fsItem.addEventListener('click', this.handleClick.bind(this)); fsItem.addEventListener('contextmenu', this.handleContext.bind(this)); @@ -91,18 +99,42 @@ class FssFilesysItem { this.root.dataset.fss = value; } + set selected(value: boolean) { + this._selected = value; + if (value) { + this.root.style.backgroundColor = SELECTED; + } + else { + this.hovered = this._hovered; + } + } + + set hovered(state: boolean) { + this._hovered = state; + if (this._selected) { + this.root.style.backgroundColor = SELECTED; + } + else { + if (state) { + this.root.style.backgroundColor = HOVER; + } + else { + this.root.style.backgroundColor = UNHOVER; + } + } + } + handleFsysHover(event: any) { if (event.type == 'mouseenter') { - this.root.style.backgroundColor = 'var(--jp-layout-color3)'; - this.root.style.backgroundColor = 'var(--jp-layout-color3)'; + this.hovered = true; } else { - this.root.style.backgroundColor = 'var(--jp-layout-color2)'; - this.root.style.backgroundColor = 'var(--jp-layout-color2)'; + this.hovered = false; } } handleClick(_event: any) { + this.selected = true; for (const slot of this.clickSlots) { slot(this.fsInfo); } diff --git a/src/index.ts b/src/index.ts index 9d9607a..7684356 100644 --- a/src/index.ts +++ b/src/index.ts @@ -43,7 +43,8 @@ class FsspecWidget extends Widget { detailName: any; detailPath: any; treeView: any; - elementHeap: any = {}; + elementHeap: any = {}; // Holds FssTreeItem's keyed by path + sourcesHeap: any = {}; // Holds FssFilesysItem's keyed by name filesysContainer: any; dirTree: any = {}; @@ -96,10 +97,10 @@ class FsspecWidget extends Widget { let lowerArea = document.createElement('div'); lowerArea.classList.add('jfss-lowerarea'); - let browserAreaLabel = document.createElement('div'); - browserAreaLabel.classList.add('jfss-browseAreaLabel'); - browserAreaLabel.innerText = 'Browse Filesystem'; - lowerArea.appendChild(browserAreaLabel); + // let browserAreaLabel = document.createElement('div'); + // browserAreaLabel.classList.add('jfss-browseAreaLabel'); + // browserAreaLabel.innerText = 'Browse Filesystem'; + // lowerArea.appendChild(browserAreaLabel); this.selectedFsLabel = document.createElement('div'); this.selectedFsLabel.classList.add('jfss-selectedFsLabel'); @@ -122,6 +123,7 @@ class FsspecWidget extends Widget { } async fetchConfig() { + this.selectedFsLabel.innerText = '