Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

jupyter_ext: Added reminding information when there isn't nni kicked off #4188

Merged
merged 2 commits into from
Sep 23, 2021
Merged
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
22 changes: 18 additions & 4 deletions ts/jupyter_extension/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { JupyterFrontEnd, JupyterFrontEndPlugin } from '@jupyterlab/application';
import { ICommandPalette, IFrame } from '@jupyterlab/apputils';
import { ICommandPalette, IFrame, Dialog, showDialog } from '@jupyterlab/apputils';
import { PageConfig } from '@jupyterlab/coreutils';
import { ILauncher } from '@jupyterlab/launcher';
import { LabIcon } from '@jupyterlab/ui-components';
import React from 'react';

const nniIconSvg = `
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 162 84">
Expand All @@ -14,15 +15,16 @@ const nniIconSvg = `
`;
const nniIcon = new LabIcon({ name: 'nni', svgstr: nniIconSvg });

const NNI_URL = PageConfig.getBaseUrl() + 'nni/index';
class NniWidget extends IFrame {
constructor() {
constructor(url) {
super({
sandbox: [
'allow-same-origin',
'allow-scripts',
]
});
this.url = PageConfig.getBaseUrl() + 'nni/index';
this.url = url;
this.id = 'nni';
this.title.label = 'NNI';
this.title.icon = nniIcon;
Expand All @@ -41,7 +43,19 @@ async function activate(app: JupyterFrontEnd, palette: ICommandPalette, launcher
caption: 'NNI',
icon: (args) => (args.isPalette ? null : nniIcon),
execute: () => {
shell.add(new NniWidget(), 'main');
fetch(NNI_URL).then(async (resp) => {
if (resp.status !== 200) {
showDialog({
title: 'NNI-HPO Launcher Error',
body: React.createElement("div", null,
"please run command:",
React.createElement("div", { style: { color: 'blue', fontSize: "14px", lineHeight: "28px" } }, "nnictl create --config experiment.yml")),
buttons: [Dialog.warnButton({ label: 'OK' })]
});
return;
}
shell.add(new NniWidget(NNI_URL), 'main');
});
}
});

Expand Down