Skip to content

Commit

Permalink
Last modified header for wide layouts (jupyterlab#16207)
Browse files Browse the repository at this point in the history
* Revert "Alternate description for disabled filters"

This reverts commit 059fb7e.

* Revert "Revert "Alternate description for disabled filters""

This reverts commit 27ed1d0.

* Uses longer title in larger modified columns

* Updates timestamp format on initial render

* Update width thresholds to avoid overlap

* Uses container queries to show only a small or large modified header

* Update Playwright Snapshots

* Update Playwright Snapshots

* Fix error in kernels sidebar when switching kernels, remove unused prop (jupyterlab#16188)

* Do not crash if there are no sessions for kernel

* Revert snapshot incorrectly updated in jupyterlab#16046

* Remove unused private `shutdownAllLabel` prop from `List` and `ListWidget`

* Update Playwright Snapshots

* Updates examples

* Make `reateHeaderItemNodeWithSizes` private for now

* Revert flaky snapshot updates

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Michał Krassowski <5832902+krassowski@users.noreply.github.com>
  • Loading branch information
3 people authored and gderocher committed Apr 26, 2024
1 parent 06afe68 commit 81ccc13
Show file tree
Hide file tree
Showing 23 changed files with 68 additions and 5 deletions.
Binary file modified examples/app/example.spec.ts-snapshots/example-linux.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/federated/example.spec.ts-snapshots/example-linux.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/filebrowser/example.spec.ts-snapshots/example-linux.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 33 additions & 5 deletions packages/filebrowser/src/listing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -811,12 +811,13 @@ export class DirListing extends Widget {

// Update the modified column's size
private _updateModifiedSize(node: HTMLElement) {
const modified = DOMUtils.findElement(node, ITEM_MODIFIED_CLASS);
// Look for the modified column's header
const modified = DOMUtils.findElement(node, MODIFIED_ID_CLASS);
this._modifiedWidth = modified?.getBoundingClientRect().width ?? 83;
this._modifiedStyle =
this._modifiedWidth < 90
this._modifiedWidth < 100
? 'narrow'
: this._modifiedWidth > 110
: this._modifiedWidth > 120
? 'long'
: 'short';
}
Expand All @@ -825,7 +826,7 @@ export class DirListing extends Widget {
protected updateModified(items: Contents.IModel[], nodes: HTMLElement[]) {
items.forEach((item, i) => {
const node = nodes[i];
if (item.last_modified) {
if (node && item.last_modified) {
const modified = DOMUtils.findElement(node, ITEM_MODIFIED_CLASS);
if (this.renderer.updateItemModified !== undefined) {
this.renderer.updateItemModified(
Expand Down Expand Up @@ -987,6 +988,7 @@ export class DirListing extends Widget {

// Rerender item nodes' modified dates, if the modified style has changed.
const oldModifiedStyle = this._modifiedStyle;
// Update both size and style
this._updateModifiedSize(this.node);
if (oldModifiedStyle !== this._modifiedStyle) {
this.updateModified(this._sortedItems, this._items);
Expand Down Expand Up @@ -2368,7 +2370,10 @@ export namespace DirListing {
const trans = translator.load('jupyterlab');
const name = this.createHeaderItemNode(trans.__('Name'));
const narrow = document.createElement('div');
const modified = this.createHeaderItemNode(trans.__('Modified'));
const modified = this._createHeaderItemNodeWithSizes({
small: trans.__('Modified'),
large: trans.__('Last Modified')
});
const fileSize = this.createHeaderItemNode(trans.__('File Size'));
name.classList.add(NAME_ID_CLASS);
name.classList.add(SELECTED_CLASS);
Expand Down Expand Up @@ -2845,6 +2850,29 @@ export namespace DirListing {
node.appendChild(icon);
return node;
}

/**
* Create a node for a header item with multiple sizes.
*/
private _createHeaderItemNodeWithSizes(labels: {
[k: string]: string;
}): HTMLElement {
const node = document.createElement('div');
node.className = HEADER_ITEM_CLASS;
const icon = document.createElement('span');
icon.className = HEADER_ITEM_ICON_CLASS;
for (let k of Object.keys(labels)) {
const text = document.createElement('span');
text.classList.add(
HEADER_ITEM_TEXT_CLASS,
HEADER_ITEM_TEXT_CLASS + '-' + k
);
text.textContent = labels[k];
node.appendChild(text);
}
node.appendChild(icon);
return node;
}
}

/**
Expand Down
35 changes: 35 additions & 0 deletions packages/filebrowser/style/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,41 @@
flex: 1 0 70px;
border-left: var(--jp-border-width) solid var(--jp-border-color2);
text-align: right;
/* stylelint-disable */
container-type: inline-size;
/* stylelint-enable */
}

/**
* Use container queries (not yet supported by our version of stylelint)
* to display either a small or large header for the last-modified column.
*/
/* stylelint-disable */
@container (max-width: 300px) {
/* stylelint-enable */
.jp-DirListing-headerItem.jp-id-modified
> .jp-DirListing-headerItemText.jp-DirListing-headerItemText-small {
display: inline;
}

.jp-DirListing-headerItem.jp-id-modified
> .jp-DirListing-headerItemText.jp-DirListing-headerItemText-large {
display: none;
}
}

/* stylelint-disable */
@container (min-width: 300px) {
/* stylelint-enable */
.jp-DirListing-headerItem.jp-id-modified
> .jp-DirListing-headerItemText.jp-DirListing-headerItemText-small {
display: none;
}

.jp-DirListing-headerItem.jp-id-modified
> .jp-DirListing-headerItemText.jp-DirListing-headerItemText-large {
display: inline;
}
}

.jp-DirListing-headerItem.jp-id-filesize {
Expand Down

0 comments on commit 81ccc13

Please sign in to comment.