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

Add commands to open URL in new window, and to deploy App in new window #7

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"files": [
"lib/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf}",
"style/**/*.{css,js,eot,gif,html,jpg,json,png,svg,woff2,ttf}",
"src/**/*.{ts,tsx}"
"src/**/*.{ts,tsx}",
"schema/*.json"
],
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down Expand Up @@ -99,7 +100,8 @@
"@jupyterlab/application-extension:logo"
],
"extension": true,
"outputDir": "jupyterlab_nebari_mode/labextension"
"outputDir": "jupyterlab_nebari_mode/labextension",
"schemaDir": "schema"
},
"eslintIgnore": [
"node_modules",
Expand Down
39 changes: 39 additions & 0 deletions schema/jhub-apps-integration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"jupyter.lab.menus": {
"main": [
{
"id": "jp-mainmenu-services",
"label": "Services",
"rank": 1000,
"items": [
{
"command": "jhub-apps:deploy-app",
"args": {
"origin": "main-menu"
}
}
]
}
],
"context": [
{
"command": "jhub-apps:deploy-app",
"args": {
"origin": "context-menu"
},
"selector": ".jp-DirListing-item[data-isdir=\"false\"]",
"rank": 3
}
]
},
"jupyter.lab.toolbars": {
"Notebook": [
{
"name": "deploy-app",
"command": "jhub-apps:deploy-app"
}
]
},
"additionalProperties": false,
"type": "object"
}
6 changes: 6 additions & 0 deletions src/icons.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { LabIcon } from '@jupyterlab/ui-components';
import nebariLogo from '../style/icons/nebari-logo.svg';
import deployApp from '../style/icons/deploy-app.svg';

export const nebariIcon = new LabIcon({
name: 'nebari:logo',
svgstr: nebariLogo
});

export const deployAppIcon = new LabIcon({
name: 'jhub-apps:deploy-app',
svgstr: deployApp
});
59 changes: 57 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { ServerConnection } from '@jupyterlab/services';
import { PageConfig, URLExt } from '@jupyterlab/coreutils';
import { Widget } from '@lumino/widgets';
import { CommandRegistry } from '@lumino/commands';
import { nebariIcon } from './icons';
import { nebariIcon, deployAppIcon } from './icons';
import { DocumentWidget } from '@jupyterlab/docregistry';

class NebariLogo extends Widget {
constructor(options: { paths: JupyterFrontEnd.IPaths }) {
Expand Down Expand Up @@ -60,6 +61,10 @@ namespace CommandIDs {
* but assumes all properties of the first enabled command.
*/
export const runFirstEnabled = 'nebari:run-first-enabled';
/**
* Opens the URL to deploy the application with pre-populated fields
*/
export const deployApp = 'jhub-apps:deploy-app';
}

interface IOpenProxyArgs {
Expand Down Expand Up @@ -88,6 +93,10 @@ interface IRunFirstEnabledArgs {
commands?: ICommandDescription[];
}

interface IDeployAppArgs {
origin?: string;
}

const commandsPlugin: JupyterFrontEndPlugin<void> = {
id: 'jupyterlab-nebari-mode:commands',
description: 'Adds additional commands used by nebari.',
Expand Down Expand Up @@ -212,6 +221,52 @@ const logoPlugin: JupyterFrontEndPlugin<void> = {
}
};

const plugins = [commandsPlugin, logoPlugin];
const jhubAppsPlugin: JupyterFrontEndPlugin<void> = {
id: 'jupyterlab-nebari-mode:jhub-apps-integration',
description: 'Deploys an application with (almost) one click.',
autoStart: true,
requires: [],
activate: async (app: JupyterFrontEnd) => {
const openURL = async (url: string) => {
try {
window.open(url, '_blank', 'noopener,noreferrer');
} catch (error) {
console.warn(`Error opening ${url}: ${error}`);
}
};

const calculateIcon = (args: IDeployAppArgs) => {
switch (args.origin) {
case 'main-menu':
return undefined;
case 'context-menu':
return deployAppIcon;
case undefined:
return deployAppIcon;
default:
return deployAppIcon;
}
};

app.commands.addCommand(CommandIDs.deployApp, {
execute: async () => {
const currentWidget = app.shell.currentWidget;
const currentNotebookPath =
currentWidget && currentWidget instanceof DocumentWidget
? currentWidget.context.path
: '';
const deployUrl = `/services/japps/create-app?filepath=${encodeURIComponent(currentNotebookPath)}`;

await openURL(deployUrl);
},
label: 'Deploy App',
icon: args => {
return calculateIcon(args);
}
});
}
};

const plugins = [commandsPlugin, logoPlugin, jhubAppsPlugin];

export default plugins;
3 changes: 3 additions & 0 deletions style/icons/deploy-app.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading