Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New: Thumbnails Sidebar #932

Merged
merged 29 commits into from
Feb 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ce82772
New: Thumbnails toggle button (#875)
Dec 3, 2018
76bab2a
New: Thumbnails toggle sidebar (#876)
Dec 11, 2018
3586c89
New: Expose thumbnails sidebar as preview option (#879)
Dec 11, 2018
631c554
New: Virtual scroll for the thumbnails sidebar (#880)
Dec 14, 2018
ca1dceb
Chore: adding unit tests for VirtualScroller (#882)
Jan 4, 2019
5be7787
Update: Thumbnails sidebar images (#887)
Jan 10, 2019
63061a7
Chore: unit tests for ThumbnailsSidebar and VirtualScroller (#888)
Jan 11, 2019
5a132f3
Update: Use correct thumbnails toggle icon (#890)
Jan 12, 2019
64a3fb9
Update: Thumbnails navigation (#889)
Jan 15, 2019
66ced4d
Chore: unit tests for Thumbnail Sidebar clicks (#891)
Jan 15, 2019
cfb9b9f
Update: Emit metrics for Thumbnail Sidebar usage (#892)
Jan 16, 2019
5d67e63
Chore: Thumbnail metrics unit tests (#894)
Jan 17, 2019
2dc3174
Update: Handle non uniform thumbnail sizes (#896)
Jan 23, 2019
f1417d4
Update: Emit thumbnails[Open|Close] viewer event (#898)
Jan 23, 2019
dba419e
Update: Change VirtualScroller.renderItems strategy (#900)
Jan 24, 2019
e9037fd
Update: Serially render thumbnail images (#901)
Jan 28, 2019
713da29
Update: Scroll into view (#906)
Feb 1, 2019
f07961b
Chore: fixing BaseViewer-test.js after rebase
Feb 1, 2019
240ad38
Chore: adding e2e tests for Thumbnails (#915)
Feb 6, 2019
3321ff2
Update: Add BoundedCache for Thumbnails Sidebar (#917)
Feb 8, 2019
42ebb44
Chore: Change thumbnail selection to be #444 (#920)
Feb 11, 2019
68c0ff7
Chore: Remove fractional thumbnail heights (#919)
Feb 12, 2019
8f37b46
Chore: Render the visible thumbnails first (#924)
Feb 13, 2019
ad6c761
Chore: Handle Thumbnails Sidebar resize event (#925)
Feb 13, 2019
8172a6f
Chore: Fix fullscreen nav and hide toggle thumbnail button (#926)
Feb 14, 2019
872cce7
Chore: Fix BaseMediaViewer's lowerlights mode (#928)
Feb 15, 2019
f0b73b9
Chore: Safari fullscreen (#930)
Feb 15, 2019
43ff2b3
Chore: Move loading wrapper inside bp-content (#931)
Feb 19, 2019
4a09b70
Chore: Rename ThumbnailsImageCache to BoundedCache test
Feb 19, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Upgrading Guide
=========================

Upgrading from 1.x to 2.x
-------------------------
Version 2 includes a breaking change to the DOM structure of the Preview element.

In version 1, the `.bp-navigate` buttons were siblings with the `.bp` container div
```
<div class="bp" tabindex="0">
...
</div>
<button class="bp-btn-plain bp-navigate bp-navigate-left bp-is-hidden">
...
</button>
<button class="bp-btn-plain bp-navigate bp-navigate-right bp-is-hidden">
...
</button>
```
But in version 2, the buttons are now inside a new container div `.bp-content`.
```
<div class="bp" tabindex="0">
<div class="bp-content">
<button class="bp-btn-plain bp-navigate bp-navigate-left bp-is-hidden">
...
</button>
<button class="bp-btn-plain bp-navigate bp-navigate-right bp-is-hidden">
...
</button>
</div>
</div>
```

`.bp-content` is also the new point in which the various viewers will be dynamically inserted as children, i.e. `.bp-doc`, `.bp-image`, etc...

This change in structure is to account for the new thumbnails sidebar which will appear to the left of the viewer content.
2 changes: 2 additions & 0 deletions src/i18n/en-US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ loading_preview=Loading Preview...
download_file=Download File
# Text shown when a text file has been truncated due to size limits.
text_truncated=This file has been truncated due to size limits. Please download to view the whole file.
# Button tooltip to toggle Thumbnails Sidebar
toggle_thumbnails=Toggle thumbnails

# Error messages
# Default preview error message
Expand Down
8 changes: 5 additions & 3 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
<input id='fileid-set' placeholder='Enter file ID' data-testid="fileid"/>
<button onClick="setProperty('fileid')" data-testid="fileid-set">Set new file ID</button>
</div>

<div class='container' id='load'>
<button onClick="loadPreview()" data-testid="load-preview">Load Preview</button>
</div>
</div>

<div class='preview-container' data-testid="preview-container"> </div>
Expand All @@ -77,9 +81,6 @@

// Cache it in local storage
localStorage.setItem(selector, value)

// Attempt to load Preview
loadPreview();
}

function loadPreview(options) {
Expand All @@ -102,6 +103,7 @@
// Try to load all properties from storage on page load
setProperty('token');
setProperty('fileid');
loadPreview();
</script>
</body>
</html>
62 changes: 62 additions & 0 deletions src/lib/BoundedCache.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import Cache from './Cache';

class BoundedCache extends Cache {
/** @property {Array} - Maintains the list of cache keys in order in which they were added to the cache */
cacheQueue;

/** @property {number} - The maximum number of entries in the cache */
maxEntries;

/**
* [constructor]
*
* @param {number} [maxEntries] - Override the maximum number of cache entries
*/
constructor(maxEntries) {
super();

this.maxEntries = maxEntries || 500;
this.cache = {};
this.cacheQueue = [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could initialize cacheQueue as a class field, above the constructor.

No need to set this.cache since that will happen in the super call

Also, give a default value to maxEntries parameter, then you can remove the ||

}

/**
* Destroys the bounded cache
*
* @return {void}
*/
destroy() {
this.cache = null;
this.cacheQueue = null;
}

/**
* Caches a simple object in memory. If the number of cache entries
* then exceeds the maxEntries value, then the earliest key in cacheQueue
* will be removed from the cache.
*
* @param {string} key - The cache key
* @param {*} value - The cache value
* @return {void}
*/
set(key, value) {
// If this key is not already in the cache, then add it
// to the cacheQueue. This avoids adding the same key to
// the cacheQueue multiple times if the cache entry gets updated
if (!this.inCache(key)) {
this.cacheQueue.push(key);
}

super.set(key, value);

// If the cacheQueue exceeds the maxEntries then remove the first
// key from the front of the cacheQueue and unset that entry
// from the cache
if (this.cacheQueue.length > this.maxEntries) {
const deleteKey = this.cacheQueue.shift();
this.unset(deleteKey);
}
}
}

export default BoundedCache;
3 changes: 3 additions & 0 deletions src/lib/Preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,9 @@ class Preview extends EventEmitter {
// Options that are applicable to certain file ids
this.options.fileOptions = options.fileOptions || {};

// Option to enable use of thumbnails sidebar for document types
this.options.enableThumbnailsSidebar = !!options.enableThumbnailsSidebar;

// Prefix any user created loaders before our default ones
this.loaders = (options.loaders || []).concat(loaderList);

Expand Down
1 change: 1 addition & 0 deletions src/lib/Preview.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
@import 'navigation';
@import './Controls';
@import './ProgressBar';
@import './VirtualScroller';
Loading