Skip to content

Commit

Permalink
Fixing context menu on Launcher
Browse files Browse the repository at this point in the history
  • Loading branch information
AnastasiaSliusar committed Jul 25, 2024
1 parent 802924b commit e8c6a88
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 105 deletions.
2 changes: 1 addition & 1 deletion packages/apputils/src/sessioncontext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1665,7 +1665,7 @@ namespace Private {
'data-custom-env-vars',
JSON.stringify(envConfiguration)
);
}, translator);
}, false, translator);
//trans.__('Start Preferred Kernel');
//Update widget

Expand Down
64 changes: 36 additions & 28 deletions packages/notebook-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ import {
refreshIcon,
runIcon,
stopIcon,
tableRowsIcon
tableRowsIcon,
CustomEnvWidget
} from '@jupyterlab/ui-components';
import { ArrayExt } from '@lumino/algorithm';
import { CommandRegistry } from '@lumino/commands';
Expand All @@ -137,7 +138,6 @@ import {
NotebookMetadataField
} from './tool-widgets/metadataEditorFields';
import { ISpecModel } from '@jupyterlab/services/src/kernelspec/restapi';
import { CustomEnvWidget } from '@jupyterlab/ui-components/src/components';

/**
* The command IDs used by the notebook plugin.
Expand Down Expand Up @@ -1992,9 +1992,7 @@ function activateNotebookHandler(
}
});

const showCustomEnvVarsDialog = async(
spec: ISpecModel | undefined
) => {
const showCustomEnvVarsDialog = async (spec: ISpecModel | undefined, node: HTMLElement) => {
let envConfiguration: PartialJSONObject = {};
let label = trans.__('Cancel');
const buttons = [
Expand All @@ -2003,35 +2001,41 @@ function activateNotebookHandler(
}),
Dialog.okButton({
label: trans.__('Setup'),
ariaLabel: trans.__('setup custom env variables')
ariaLabel: trans.__('Setup custom env variables')
})
];
let defaultEnvValues = {}

let defaultEnvValues = {};
const dialog = new Dialog({
title: trans.__('Setup custom environment variables'),
body: new CustomEnvWidget(envConfiguration, defaultEnvValues, formData => {
envConfiguration = formData as PartialJSONObject;
console.log('envConfiguration');
console.dir(envConfiguration);
}, translator),
title: '',
body: new CustomEnvWidget(
envConfiguration,
defaultEnvValues,
formData => {
envConfiguration = formData as PartialJSONObject;
console.log('envConfiguration');
console.dir(envConfiguration);
}, true,
translator
),
buttons
});

const result = await dialog.launch();

if (!result.button.accept) {
return;
}

console.log('result.value');
console.dir(result.value);
if (result.value) {
if (Object.keys(envConfiguration).length>0 && spec) {
node.setAttribute("custom-env-vars", JSON.stringify(envConfiguration));
//saveve for each kernel spec
}
};

const LAUNCHER_LABEL = "jp-LauncherCard";
const LAUNCHER_LABEL = 'jp-LauncherCard';
const isLauncherLabel = (node: HTMLElement) =>
node.classList.contains(LAUNCHER_LABEL);
let selectedSpec: ISpecModel | undefined;
Expand All @@ -2052,9 +2056,9 @@ function activateNotebookHandler(

console.log('node');
console.dir(node);
let defaultName = node.getAttribute('titile');
console.log('defaultName');
console.dir(defaultName);
let defaultName = node.innerText;
console.log('defaultName');
console.dir(defaultName);
for (const name in specs.kernelspecs) {
const spec = specs.kernelspecs[name];
if (spec && spec.display_name === defaultName) {
Expand All @@ -2063,11 +2067,10 @@ function activateNotebookHandler(
}
console.log('selectedSpec');
console.dir(selectedSpec);
showCustomEnvVarsDialog(selectedSpec);
showCustomEnvVarsDialog(selectedSpec, node);
}
});


// Add a launcher item if the launcher is available.
if (launcher) {
void services.ready.then(() => {
Expand Down Expand Up @@ -2107,12 +2110,17 @@ function activateNotebookHandler(
onSpecsChanged();
services.kernelspecs.specsChanged.connect(onSpecsChanged);
});

app.contextMenu.addItem({
command: CommandIDs.setupCustomEnv,
selector: '.jp-LauncherCard',
rank: 0
});
const allow_custom_env_variables =
PageConfig.getOption('allow_custom_env_variables') === 'true'
? true
: false;
if (allow_custom_env_variables) {
app.contextMenu.addItem({
command: CommandIDs.setupCustomEnv,
selector: '.jp-LauncherCard',
rank: 0
});
}
}

return tracker;
Expand Down
Loading

0 comments on commit e8c6a88

Please sign in to comment.