Skip to content

State in the table for running kernels does not get updated #68

@krassowski

Description

@krassowski

The second table in the dialog does not get updated when the kernel state changes

{runningKernelsItems.length > 0 ? (
<>
<h3 className="jp-KernelSelector-Section">
{this.trans.__('Connect to a running kernel')}
</h3>
<KernelTable
trans={this.trans}
commands={this.commands}
items={runningKernelsItems}
settings={this._settings}
query=""
showSearchBox={false}
onClick={item => {
this._selection = item;
this.options.acceptDialog();
}}
hideColumns={['last-used', 'star']}
favouritesChanged={this._favoritesDatabase.changed}
lastUsedChanged={this._lastUsedDatabase.changed}
/>
</>
) : null}

Because it includes things like "state: starting" it needs to be dynamically updated. We need to trigger forceUpdate when item metadata changes, and for that we need to pass through another signal, like with lastUsedChanged:

// Hoisted to avoid "Rendered fewer hooks than expected" error on toggling the Star column
const [, forceUpdate] = React.useReducer(x => x + 1, 0);
React.useEffect(() => {
props.favouritesChanged.connect(forceUpdate);
return () => {
props.favouritesChanged.disconnect(forceUpdate);
};
});
React.useEffect(() => {
props.lastUsedChanged.connect(forceUpdate);
return () => {
props.lastUsedChanged.disconnect(forceUpdate);
};
});

We derive the items from the sessions object passed in options:

for (const model of this.options.data.sessions!) {

and we fetch the sessions when creating the dialog:

body: new KernelSelector({
data: {
specs: sessionContext.specsManager.specs,
sessions: sessionContext.sessionManager.running(),
preference: sessionContext.kernelPreference
},

The SessionManager emits runningChanged signal which we could use.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions