Skip to content

Commit

Permalink
Merge pull request #22 from ian-r-rose/fixes
Browse files Browse the repository at this point in the history
Usability Fixes
  • Loading branch information
ian-r-rose authored Sep 4, 2018
2 parents bb7021e + b03a546 commit 1d2e87a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 18 deletions.
36 changes: 18 additions & 18 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { INotebookTracker, NotebookPanel } from '@jupyterlab/notebook';

import { Kernel, KernelMessage } from '@jupyterlab/services';

import { DaskDashboardLauncher } from './widget';
import { DaskDashboardLauncher, normalizeDashboardUrl } from './widget';

import '../style/index.css';

Expand All @@ -25,12 +25,14 @@ namespace CommandIDs {
export const launchPanel = 'dask:launch-dashboard';
}

const PLUGIN_ID = 'dask-labextension:plugin';

/**
* The dask dashboard extension.
*/
const plugin: JupyterLabPlugin<void> = {
activate,
id: 'jupyterlab-dask:plugin',
id: PLUGIN_ID,
requires: [
IConsoleTracker,
ILayoutRestorer,
Expand Down Expand Up @@ -134,22 +136,20 @@ function activate(
});

// Fetch the initial state of the settings.
Promise.all([
settings.load('jupyterlab-dask:plugin'),
state.fetch(id),
app.restored
]).then(res => {
const settings = res[0];
const url = (res[1] as { url: string }).url as string;
if (url) {
// If there is a URL in the statedb, let it have priority.
dashboardLauncher.input.url = url;
return;
Promise.all([settings.load(PLUGIN_ID), state.fetch(id), app.restored]).then(
res => {
const settings = res[0];
const url = (res[1] as { url: string }).url as string;
if (url) {
// If there is a URL in the statedb, let it have priority.
dashboardLauncher.input.url = url;
return;
}
// Otherwise set the default from the settings.
dashboardLauncher.input.url = settings.get('defaultURL')
.composite as string;
}
// Otherwise set the default from the settings.
dashboardLauncher.input.url = settings.get('defaultURL')
.composite as string;
});
);

// Add the command for launching a new dashboard item.
app.commands.addCommand(CommandIDs.launchPanel, {
Expand All @@ -158,7 +158,7 @@ function activate(
execute: args => {
// Construct the url for the dashboard.
const valid = dashboardLauncher.input.isValid;
const baseUrl = dashboardLauncher.input.url;
const baseUrl = normalizeDashboardUrl(dashboardLauncher.input.url);
const route = (args['route'] as string) || '';
const url = valid ? URLExt.join(baseUrl, route) : '';

Expand Down
14 changes: 14 additions & 0 deletions src/widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,19 @@ export namespace DaskDashboardLauncher {
];
}

/**
* Optionally remove a `status` route from a dashboard url.
*/
export function normalizeDashboardUrl(url: string): string {
if (url.endsWith('status')) {
return url.slice(0, -'status'.length);
}
if (url.endsWith('status/')) {
return url.slice(0, -'status/'.length);
}
return url;
}

/**
* A namespace for private functionality.
*/
Expand All @@ -415,6 +428,7 @@ namespace Private {
* Test whether a given URL hosts a dask dashboard.
*/
export function testDaskDashboard(url: string): Promise<boolean> {
url = normalizeDashboardUrl(url);
return new Promise<boolean>(resolve => {
// Hack Alert! We would like to test whether a given URL is actually
// a dask dashboard, since we will be iframe-ing it sight-unseen.
Expand Down

0 comments on commit 1d2e87a

Please sign in to comment.