Unverified Commit 126782b4 authored by Johnsonms's avatar Johnsonms Committed by GitHub
Browse files

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


Co-authored-by: default avatarzhaofu li <zhaofu.li@alibaba-inc.com>
parent b06f3921
import { JupyterFrontEnd, JupyterFrontEndPlugin } from '@jupyterlab/application'; 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 { PageConfig } from '@jupyterlab/coreutils';
import { ILauncher } from '@jupyterlab/launcher'; import { ILauncher } from '@jupyterlab/launcher';
import { LabIcon } from '@jupyterlab/ui-components'; import { LabIcon } from '@jupyterlab/ui-components';
import React from 'react';
const nniIconSvg = ` const nniIconSvg = `
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 162 84"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 162 84">
...@@ -14,15 +15,16 @@ const nniIconSvg = ` ...@@ -14,15 +15,16 @@ const nniIconSvg = `
`; `;
const nniIcon = new LabIcon({ name: 'nni', svgstr: nniIconSvg }); const nniIcon = new LabIcon({ name: 'nni', svgstr: nniIconSvg });
const NNI_URL = PageConfig.getBaseUrl() + 'nni/index';
class NniWidget extends IFrame { class NniWidget extends IFrame {
constructor() { constructor(url) {
super({ super({
sandbox: [ sandbox: [
'allow-same-origin', 'allow-same-origin',
'allow-scripts', 'allow-scripts',
] ]
}); });
this.url = PageConfig.getBaseUrl() + 'nni/index'; this.url = url;
this.id = 'nni'; this.id = 'nni';
this.title.label = 'NNI'; this.title.label = 'NNI';
this.title.icon = nniIcon; this.title.icon = nniIcon;
...@@ -41,7 +43,19 @@ async function activate(app: JupyterFrontEnd, palette: ICommandPalette, launcher ...@@ -41,7 +43,19 @@ async function activate(app: JupyterFrontEnd, palette: ICommandPalette, launcher
caption: 'NNI', caption: 'NNI',
icon: (args) => (args.isPalette ? null : nniIcon), icon: (args) => (args.isPalette ? null : nniIcon),
execute: () => { 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');
});
} }
}); });
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment