Skip to content

Commit

Permalink
Fix a kernel selection dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
AnastasiaSliusar committed Jul 30, 2024
1 parent b21f63c commit 2e88b88
Showing 1 changed file with 87 additions and 4 deletions.
91 changes: 87 additions & 4 deletions packages/apputils/src/sessioncontext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1855,14 +1855,20 @@ namespace Private {
sessionContext: ISessionContext,
translator?: ITranslator
) =>
new KernelSelector({
node: createSelectorNode(sessionContext, translator)
});
new KernelSelector(sessionContext, translator);

/**
* A widget that provides a kernel selection.
*/
export class KernelSelector extends Widget {
sessionContext: ISessionContext;
translator: ITranslator | undefined;

constructor(sessionContext: ISessionContext, translator?: ITranslator) {
super({ node: createSelectorNode(sessionContext, translator) });
this.sessionContext = sessionContext;
this.translator = translator;
}
/**
* Get the value of the kernel selector widget.
*/
Expand Down Expand Up @@ -1907,6 +1913,30 @@ namespace Private {
}
return kernelData;
}

protected onAfterAttach(msg: Message): void {
super.onAfterAttach(msg);
const envVarsDiv = this.node.querySelector(
'div.jp-custom-env-vars-block'
) as HTMLDivElement;
console.log('envVarsDiv');
console.log(envVarsDiv);
const allow_custom_env_variables =
PageConfig.getOption('allow_custom_env_variables') === 'true'
? true
: false;
console.log('allow_custom_env_variables');
console.log(allow_custom_env_variables);
if (allow_custom_env_variables) {
/*let defaultEnvValues = this.sessionContext.kernelPreference?.customEnvVars as PartialJSONObject;
const options = SessionContextDialogs.kernelOptions(
this.sessionContext,
this.translator
);*/
// toogleAddEnvBlock(envVarsDiv, this.sessionContext, defaultEnvValues, options, this.translator)

}
}
}

/**
Expand All @@ -1932,22 +1962,62 @@ namespace Private {
sessionContext,
translator
);

const allow_custom_env_variables =
PageConfig.getOption('allow_custom_env_variables') === 'true'
? true
: false;
console.log('allow_custom_env_variables');
console.log(allow_custom_env_variables);
const envVarsDiv = document.createElement('div');
envVarsDiv.setAttribute('class', 'jp-custom-env-vars-block');
envVarsDiv.setAttribute('data-custom-env-vars', '');


console.log('options');
console.dir(options);
if (options.disabled) select.disabled = true;
for (const group of options.groups) {
const { label, options } = group;
const optgroup = document.createElement('optgroup');
optgroup.label = label;
for (const { selected, text, title, value } of options) {
const option = document.createElement('option');
if (selected) option.selected = true;
if (selected) {
option.selected = true;
let val = JSON.parse(value);
let id = val && val.id? val.id: '';
console.log("id");
console.dir(id);
if (allow_custom_env_variables && !id) {
let defaultEnvValue = {};
envVarsDiv.innerHTML = ''

Check notice

Code scanning / CodeQL

Semicolon insertion Note

Avoid automated semicolon insertion (94% of all statements in
the enclosing function
have an explicit semicolon).
addEnvBlock(envVarsDiv, sessionContext, defaultEnvValue, translator);
}
}

if (title) option.title = title;
option.text = text;
option.value = value;
optgroup.appendChild(option);
}
select.appendChild(optgroup);
}

select.onchange = () => {
let kernelData = JSON.parse(select.value) as Kernel.IModel;
console.log('kernelData');
console.dir(kernelData);
if (allow_custom_env_variables && !kernelData.id) {
console.log('--allow_custom_env_variables--');
let defaultEnvValue = {};
envVarsDiv.innerHTML = ''
addEnvBlock(envVarsDiv, sessionContext, defaultEnvValue, translator);

}
}

Check notice

Code scanning / CodeQL

Semicolon insertion Note

Avoid automated semicolon insertion (94% of all statements in
the enclosing function
have an explicit semicolon).
body.appendChild(select);
body.appendChild(envVarsDiv);
return body;
}

Expand Down Expand Up @@ -1981,7 +2051,20 @@ namespace Private {
Widget.attach(customEnvBlock, body);
}
}
/* function toogleAddEnvBlock(
body: HTMLDivElement,
sessionContext: ISessionContext,
defaultEnvValues:PartialJSONObject,
options:SessionContextDialogs.IKernelOptions,
translator?: ITranslator
) {
addEnvBlock(body, sessionContext, defaultEnvValues, translator);
}
*/


/**
* Get the default kernel name given select options.
*/
Expand Down

0 comments on commit 2e88b88

Please sign in to comment.