-
Notifications
You must be signed in to change notification settings - Fork 2
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
Changes from 1 commit
2cd0076
7e8918f
e4dfa10
d2dc03a
68a6002
a6fa649
9db2b26
186aea2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 }) { | ||
|
@@ -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 { | ||
|
@@ -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'> { | ||
/** | ||
|
@@ -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}`; | ||
} | ||
}); | ||
|
||
app.commands.addCommand(CommandIDs.deployApp, { | ||
krassowski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally we would use proper See |
||
}); | ||
} | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,10 @@ | |
outline-offset: -3px; | ||
outline-style: auto; | ||
} | ||
|
||
.nebari-DeployAppIcon { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
background-image: url('../style/icons/rocket-symbol.svg'); | ||
background-repeat: no-repeat; | ||
width: 100%; | ||
height: 100%; | ||
} |
There was a problem hiding this comment.
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