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

Hide gallery without exhibits #20

Merged
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
1 change: 1 addition & 0 deletions jupyterlab_gallery/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def get(self):
{
"title": self.gallery_manager.title,
"exhibitsConfigured": len(self.gallery_manager.exhibits) != 0,
"hideGalleryWithoutExhibits": self.gallery_manager.hideGalleryWithoutExhibits,
andrewfulton9 marked this conversation as resolved.
Show resolved Hide resolved
"apiVersion": "1.0",
}
)
Expand Down
8 changes: 7 additions & 1 deletion jupyterlab_gallery/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from threading import Thread

from traitlets.config.configurable import LoggingConfigurable
from traitlets import Dict, List, Unicode
from traitlets import Dict, List, Unicode, Bool

from .git_utils import (
extract_repository_owner,
Expand Down Expand Up @@ -69,6 +69,12 @@ def __init__(self, *args, **kwargs):
config=True,
)

hideGalleryWithoutExhibits = Bool(
andrewfulton9 marked this conversation as resolved.
Show resolved Hide resolved
help="Hide Gallery if no exhibits are configured",
default_value=False,
config=True
)

def get_local_path(self, exhibit) -> Path:
clone_destination = Path(self.destination)
repository_name = extract_repository_name(exhibit["git"])
Expand Down
11 changes: 9 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,17 @@ const plugin: JupyterFrontEndPlugin<void> = {
`jupyter-gallery API version out of sync, expected ${expectedVersion}, got ${data.apiVersion}`
);
}

const title = data.title === 'Gallery' ? trans.__('Gallery') : data.title;

// hide the widget if no exhibits are configured
if (data.hideGalleryWithoutExhibits && !data.exhibitsConfigured) {
console.log(
'Gallery extension will not add any UI elements because no exhibits are configured'
);
return;
andrewfulton9 marked this conversation as resolved.
Show resolved Hide resolved
}
// add the widget to sidebar before waiting for server reply to reduce UI jitter
if (launcher && isNewLauncher(launcher) && data.exhibitsConfigured) {
if (launcher && isNewLauncher(launcher)) {
launcher.addSection({
title,
className: 'jp-Launcher-openExample',
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export interface IGalleryReply {
title: string;
apiVersion: string;
exhibitsConfigured: boolean;
hideGalleryWithoutExhibits: boolean;
}

export interface IExhibitReply {
Expand Down
Loading