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 1 commit
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
60 changes: 60 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { PageConfig, URLExt } from '@jupyterlab/coreutils';
import { Widget } from '@lumino/widgets';
import { CommandRegistry } from '@lumino/commands';
import { nebariIcon } from './icons';
import { DocumentWidget } from '@jupyterlab/docregistry';

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

interface IOpenProxyArgs {
Expand All @@ -69,6 +78,17 @@ interface IOpenProxyArgs {
name?: string;
}

interface IOpenURLArgs {
/**
* URL to open.
*/
url?: string;
/**
* Alias for the URL.
*/
alias?: string;
}

interface ICommandDescription
extends Omit<CommandRegistry.ICommandOptions, 'execute'> {
/**
Expand Down Expand Up @@ -194,6 +214,46 @@ const commandsPlugin: JupyterFrontEndPlugin<void> = {
return returnFirstEnabled(args, 'className') ?? '';
}
});

const resolveURLAndAlias = (args: IOpenURLArgs = {}) => {
const { url = '/', alias } = args;
const resolvedAlias =
alias || (url === '/' ? 'JupyterHub' : 'user-configured URL');
return { url, alias: resolvedAlias };
};

app.commands.addCommand(CommandIDs.openURL, {
execute: async (args: IOpenURLArgs) => {
const { url } = resolveURLAndAlias(args);
try {
window.open(url, '_blank', 'noopener,noreferrer');
} catch (error) {
console.warn('Error opening URL:', url, error);
return;
}
},
label: (args: IOpenURLArgs = {}) => {
const { alias } = resolveURLAndAlias(args);
return `Open ${alias}`;
}
});
Copy link
Member

Choose a reason for hiding this comment

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

I would suggest removing the command for opening an arbitrary URL to reduce the API surface


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 app.commands.execute(CommandIDs.openURL, {
url: deployUrl
});
},
label: () => 'Deploy App',
iconClass: () => 'nebari-DeployAppIcon'
Copy link
Member

Choose a reason for hiding this comment

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

Ideally we would use proper icon (an instance of LabIcon) here - iconClass is de-facto deprecated. The less CSS rules the better for performance.

See
https://github.com/nebari-dev/jupyterlab-gallery/blob/ef56fc616bae4ec8305c01e3341b773ca4cfd48f/src/icons.ts#L5-L8 and https://github.com/nebari-dev/jupyterlab-gallery/blob/ef56fc616bae4ec8305c01e3341b773ca4cfd48f/src/svg.d.ts

});
}
};

Expand Down
7 changes: 7 additions & 0 deletions style/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,10 @@
outline-offset: -3px;
outline-style: auto;
}

.nebari-DeployAppIcon {
Copy link
Author

Choose a reason for hiding this comment

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

The CSS needs to be fixed - currently it only displays when I give fixed size (e.g. 16px).

background-image: url('../style/icons/rocket-symbol.svg');
background-repeat: no-repeat;
width: 100%;
height: 100%;
}
3 changes: 3 additions & 0 deletions style/icons/rocket-symbol.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading