Skip to content

Commit

Permalink
Merge pull request #5 from fcollonval/enh/customize-launcher-card
Browse files Browse the repository at this point in the history
Add launcher customization
  • Loading branch information
echarles authored Apr 4, 2024
2 parents f712c6b + 951d84b commit edb4f74
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 22 deletions.
31 changes: 24 additions & 7 deletions datalayer/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@
import tornado

from jupyter_server.base.handlers import APIHandler, JupyterHandler
from jupyter_server.extension.handler import ExtensionHandlerMixin, ExtensionHandlerJinjaMixin
from jupyter_server.extension.handler import (
ExtensionHandlerMixin,
ExtensionHandlerJinjaMixin,
)

from ._version import __version__


# pylint: disable=W0223
class BaseTemplateHandler(ExtensionHandlerJinjaMixin, ExtensionHandlerMixin, JupyterHandler):
class BaseTemplateHandler(
ExtensionHandlerJinjaMixin, ExtensionHandlerMixin, JupyterHandler
):
"""The Base handler for the templates."""


Expand All @@ -31,9 +36,21 @@ class ConfigHandler(ExtensionHandlerMixin, APIHandler):
def get(self):
"""Returns the configuration of the server extension."""
settings = self.settings["datalayer_config"]
res = json.dumps({
"extension": "datalayer",
"version": __version__,
"settings": settings,
})
self.log.critical(str(settings))
res = json.dumps(
{
"extension": "datalayer",
"version": __version__,
"settings": dict(
api_server_url=settings.api_server_url,
launcher={
"category": settings.launcher.category,
"name": settings.launcher.name,
"icon": settings.launcher.icon_svg_url,
"rank": settings.launcher.rank,
},
white_label=settings.white_label,
),
}
)
self.finish(res)
59 changes: 47 additions & 12 deletions datalayer/serverapplication.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""The Datalayer Server application."""

import json
import os
import typing as t

from traitlets import (
Unicode, Bool,
)
from traitlets import default, Bool, CInt, Instance, Unicode
from traitlets.config import Configurable

from jupyter_server.utils import url_path_join
from jupyter_server.extension.application import ExtensionApp, ExtensionAppJinjaMixin
Expand All @@ -30,23 +31,57 @@ class DatalayerExtensionApp(ExtensionAppJinjaMixin, ExtensionApp):
static_paths = [DEFAULT_STATIC_FILES_PATH]
template_paths = [DEFAULT_TEMPLATE_FILES_PATH]

api_server_url = Unicode("https://io.datalayer.run",
api_server_url = Unicode(
"https://io.datalayer.run",
config=True,
help="""Hostname to connect to the Datalayer APIs."""
help="""Hostname to connect to the Datalayer APIs.""",
)

white_label = Bool(False, config=True, help="""Display white label content.""")

class Launcher(Configurable):
"""Datalayer launcher configuration"""

category = Unicode(
"Datalayer",
config=True,
help=("Application launcher card category."),
)
launcher_category = Unicode("Datalayer",
config=True,
help=("Category to use for the application launcher."),

name = Unicode(
"Jupyter kernels",
config=True,
help=("Application launcher card name."),
)
white_label = Bool(False,
config=True,
help="""Display white label content."""

icon_svg_url = Unicode(
None,
allow_none=True,
config=True,
help=("Application launcher card icon."),
)

rank = CInt(
0,
config=True,
help=("Application launcher card rank."),
)

launcher = Instance(Launcher)

@default("launcher")
def _default_launcher(self):
return DatalayerExtensionApp.Launcher(parent=self, config=self.config)

def initialize_settings(self):
settings = dict(
api_server_url=self.api_server_url,
launcher_category=self.launcher_category,
launcher={
"category": self.launcher.category,
"name": self.launcher.name,
"icon": self.launcher.icon_svg_url,
"rank": self.launcher.rank,
},
white_label=self.white_label,
)
self.settings.update(**settings)
Expand Down
4 changes: 2 additions & 2 deletions src/jupyterlab/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const plugin: JupyterFrontEndPlugin<IDatalayer> = {
datalayerStore.getState().setVersion(data.version);
const configuration = {
apiServerUrl: data.settings.api_server_url,
launcherCategory: data.settings.launcher_category,
launcher: data.settings.launcher,
whiteLabel: data.settings.white_label
};
datalayer.configuration.configuration = configuration;
Expand Down Expand Up @@ -107,7 +107,7 @@ const plugin: JupyterFrontEndPlugin<IDatalayer> = {
tracker.add(widget);
}
});
const category = configuration.launcherCategory;
const category = configuration.launcher.category;
palette.addItem({ command, category });
const settingsUpdated = (settings: ISettingRegistry.ISettings) => {
const showInLauncher = settings.get('showInLauncher')
Expand Down
28 changes: 27 additions & 1 deletion src/jupyterlab/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,34 @@ import { Token } from '@lumino/coreutils';
import { ISignal, Signal } from '@lumino/signaling';

export type IDatalayerConfig = {
/**
* Cloud API URL
*/
apiServerUrl: string;
launcherCategory: string;
/**
* Launcher card customization
*/
launcher: {
/**
* Card category
*/
category: string;
/**
* Card name
*/
name: string;
/**
* Card icon SVG URL
*/
icon: string | null;
/**
* Card rank
*/
rank: number;
};
/**
* Whether to display the white labelled user interface or not.
*/
whiteLabel: boolean;
};

Expand Down

0 comments on commit edb4f74

Please sign in to comment.