Skip to content

Commit 3aaf87f

Browse files
authored
Link editor tab (#8)
1 parent 3083e9d commit 3aaf87f

File tree

8 files changed

+79
-18
lines changed

8 files changed

+79
-18
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@
6161
"@jupyterlab/coreutils": "^6.0.0-beta.0",
6262
"@jupyterlab/mainmenu": "^4.0.0-beta.0",
6363
"@jupyterlab/services": "^7.0.0-beta.0",
64+
"@jupyterlab/ui-components": "^4.0.0-beta.0",
65+
"@lumino/algorithm": "^2.0.0",
66+
"@lumino/coreutils": "^2.0.0",
67+
"@lumino/signaling": "^2.0.0",
68+
"@lumino/widgets": "^2.0.0",
6469
"gridstack": "^6.0.1"
6570
},
6671
"devDependencies": {

src/common/tabPanel.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { LabIcon, classes, TabBarSvg } from '@jupyterlab/ui-components';
22
import { Widget, TabBar, StackedPanel, BoxPanel, Title } from '@lumino/widgets';
33
import { find, ArrayExt } from '@lumino/algorithm';
44
import { Signal, ISignal } from '@lumino/signaling';
5+
56
export class HTabPanel extends BoxPanel {
67
constructor(options: HTabPanel.IOptions) {
78
const direction = options.tabBarPosition

src/controlPanel/data/dataPanel.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,6 @@ export class DataPanel extends SidePanel {
2323
onClick: () => console.log('clicked')
2424
})
2525
);
26-
this.toolbar.addItem(
27-
'Link data',
28-
new ToolbarButton({
29-
tooltip: 'Link Data',
30-
label: 'Link Data',
31-
onClick: () => console.log('clicked')
32-
})
33-
);
3426
const dataset = new DatasetsWidget({ model: this._model });
3527
this.addWidget(dataset);
3628

src/controlPanel/layers/layerPanel.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@ export class LayerPanel extends SidePanel {
1414
onClick: () => console.log('clicked')
1515
})
1616
);
17-
this.toolbar.addItem(
18-
'Link data',
19-
new ToolbarButton({
20-
tooltip: 'Link Data',
21-
label: 'Link Data',
22-
onClick: () => console.log('clicked')
23-
})
24-
);
2517
this._model.tabsChanged.connect(() => {
2618
this.content.widgets.forEach(w => this.content.layout?.removeWidget(w));
2719

src/linkPanel/linkPanel.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { JSONObject } from '@lumino/coreutils';
2+
import { BoxPanel } from '@lumino/widgets';
3+
4+
import { IGlueSessionSharedModel } from '../types';
5+
6+
/**
7+
* The link editor widget.
8+
*/
9+
export class LinkWidget extends BoxPanel {
10+
constructor(options: LinkWidget.IOptions) {
11+
super({ direction: 'left-to-right' });
12+
this._sharedModel = options.sharedModel;
13+
this.addClass('glue-link-editor');
14+
this.title.label = 'Link Data';
15+
this.title.className = 'glue-LinkEditor-title';
16+
17+
this.node.innerText = 'Link editor widget';
18+
this._sharedModel.changed.connect(this._onSharedModelChanged, this);
19+
}
20+
21+
get sharedModel(): IGlueSessionSharedModel {
22+
return this._sharedModel;
23+
}
24+
25+
private _onSharedModelChanged() {
26+
if (!this._sharedModel.contents.__main__) {
27+
this.node.innerText = `Link editor widget for ${
28+
this._sharedModel.state.path || '(no session)'
29+
}\nNo data`;
30+
return;
31+
}
32+
33+
const dataCollection: string =
34+
((this._sharedModel.contents.__main__ as JSONObject).data as string) ||
35+
'';
36+
const dataNames: string[] = (
37+
this._sharedModel.contents[dataCollection] as JSONObject
38+
).data as string[];
39+
this.node.innerText = `Link editor widget for ${
40+
this._sharedModel.state.path || '(no session)'
41+
}\nExisting data: ${JSON.stringify(dataNames)}`;
42+
}
43+
private _sharedModel: IGlueSessionSharedModel;
44+
}
45+
46+
namespace LinkWidget {
47+
export interface IOptions extends BoxPanel.IOptions {
48+
sharedModel: IGlueSessionSharedModel;
49+
}
50+
}

src/viewPanel/sessionWidget.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { HTabPanel } from '../common/tabPanel';
44
import { IGlueSessionSharedModel } from '../types';
55
import { TabView } from './tabView';
66
import { TabModel } from './tabModel';
7+
import { LinkWidget } from '../linkPanel/linkPanel';
78

89
export class SessionWidget extends BoxPanel {
910
constructor(options: SessionWidget.IOptions) {
@@ -18,7 +19,11 @@ export class SessionWidget extends BoxPanel {
1819
addButtonEnabled: true
1920
}
2021
});
21-
this._tabPanel.activateTab(0);
22+
23+
if (this._model) {
24+
this._linkWidget = new LinkWidget({ sharedModel: this._model });
25+
this._tabPanel.addTab(this._linkWidget, 0);
26+
}
2227

2328
this.addWidget(this._tabPanel);
2429
BoxPanel.setStretch(this._tabPanel, 1);
@@ -34,10 +39,12 @@ export class SessionWidget extends BoxPanel {
3439
});
3540
const tabWidget = new TabView({ model });
3641

37-
this._tabPanel.addTab(tabWidget, idx);
42+
this._tabPanel.addTab(tabWidget, idx + 1);
3843
});
44+
this._tabPanel.activateTab(1);
3945
}
4046
private _tabPanel: HTabPanel;
47+
private _linkWidget: LinkWidget | undefined = undefined;
4148
private _model: IGlueSessionSharedModel;
4249
private _rendermime: IRenderMimeRegistry;
4350
}

style/base.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@
6363
margin-left: 0;
6464
}
6565

66+
.glue-Session-tabBar .lm-TabBar-tab.glue-LinkEditor-title {
67+
flex: none;
68+
background-color: var(--jp-brand-color1);
69+
}
70+
71+
.glue-Session-tabBar .lm-TabBar-tab.lm-mod-current.glue-LinkEditor-title {
72+
background: var(--jp-brand-color2);
73+
}
74+
6675
.glue-Session-gridhost {
6776
background: var(--jp-layout-color3);
6877
background-image: unset !important;

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5816,6 +5816,11 @@ __metadata:
58165816
"@jupyterlab/mainmenu": ^4.0.0-beta.0
58175817
"@jupyterlab/services": ^7.0.0-beta.0
58185818
"@jupyterlab/testutils": ^4.0.0-beta.0
5819+
"@jupyterlab/ui-components": ^4.0.0-beta.0
5820+
"@lumino/algorithm": ^2.0.0
5821+
"@lumino/coreutils": ^2.0.0
5822+
"@lumino/signaling": ^2.0.0
5823+
"@lumino/widgets": ^2.0.0
58195824
"@types/jest": ^29.2.0
58205825
"@typescript-eslint/eslint-plugin": ^4.8.1
58215826
"@typescript-eslint/parser": ^4.8.1

0 commit comments

Comments
 (0)