Skip to content

Commit 6b85b05

Browse files
committed
refactor: Update DeepnoteEnvironmentTreeItem to use consistent IDs for info items
- Modified createInfoItem method to accept an ID parameter for better identification of info items. - Updated instances of createInfoItem across the DeepnoteEnvironmentTreeDataProvider to use the new ID format. - Enhanced unit tests to reflect changes in info item creation and ensure proper functionality. Signed-off-by: Tomas Kislan <[email protected]>
1 parent fb0fa93 commit 6b85b05

File tree

3 files changed

+59
-10
lines changed

3 files changed

+59
-10
lines changed

src/kernels/deepnote/environments/deepnoteEnvironmentTreeDataProvider.node.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,45 +85,61 @@ export class DeepnoteEnvironmentTreeDataProvider implements TreeDataProvider<Dee
8585
if (statusInfo?.status === EnvironmentStatus.Running && config.serverInfo) {
8686
items.push(
8787
DeepnoteEnvironmentTreeItem.createInfoItem(
88+
'ports',
8889
`Ports: jupyter=${config.serverInfo.jupyterPort}, lsp=${config.serverInfo.lspPort}`,
8990
'port'
9091
)
9192
);
92-
items.push(DeepnoteEnvironmentTreeItem.createInfoItem(`URL: ${config.serverInfo.url}`, 'globe'));
93+
items.push(DeepnoteEnvironmentTreeItem.createInfoItem('url', `URL: ${config.serverInfo.url}`, 'globe'));
9394
}
9495

9596
// Python interpreter
9697
items.push(
9798
DeepnoteEnvironmentTreeItem.createInfoItem(
99+
'python',
98100
`Python: ${config.pythonInterpreter.uri.fsPath}`,
99101
'symbol-namespace'
100102
)
101103
);
102104

103105
// Venv path
104-
items.push(DeepnoteEnvironmentTreeItem.createInfoItem(`Venv: ${config.venvPath.fsPath}`, 'folder'));
106+
items.push(DeepnoteEnvironmentTreeItem.createInfoItem('venv', `Venv: ${config.venvPath.fsPath}`, 'folder'));
105107

106108
// Packages
107109
if (config.packages && config.packages.length > 0) {
108110
items.push(
109-
DeepnoteEnvironmentTreeItem.createInfoItem(`Packages: ${config.packages.join(', ')}`, 'package')
111+
DeepnoteEnvironmentTreeItem.createInfoItem(
112+
'packages',
113+
`Packages: ${config.packages.join(', ')}`,
114+
'package'
115+
)
110116
);
111117
} else {
112-
items.push(DeepnoteEnvironmentTreeItem.createInfoItem('Packages: (none)', 'package'));
118+
items.push(DeepnoteEnvironmentTreeItem.createInfoItem('packages', 'Packages: (none)', 'package'));
113119
}
114120

115121
// Toolkit version
116122
if (config.toolkitVersion) {
117-
items.push(DeepnoteEnvironmentTreeItem.createInfoItem(`Toolkit: ${config.toolkitVersion}`, 'versions'));
123+
items.push(
124+
DeepnoteEnvironmentTreeItem.createInfoItem('toolkit', `Toolkit: ${config.toolkitVersion}`, 'versions')
125+
);
118126
}
119127

120128
// Timestamps
121129
items.push(
122-
DeepnoteEnvironmentTreeItem.createInfoItem(`Created: ${config.createdAt.toLocaleString()}`, 'history')
130+
DeepnoteEnvironmentTreeItem.createInfoItem(
131+
'created',
132+
`Created: ${config.createdAt.toLocaleString()}`,
133+
'history'
134+
)
123135
);
124136

125137
items.push(
126-
DeepnoteEnvironmentTreeItem.createInfoItem(`Last used: ${config.lastUsedAt.toLocaleString()}`, 'clock')
138+
DeepnoteEnvironmentTreeItem.createInfoItem(
139+
'lastUsed',
140+
`Last used: ${config.lastUsedAt.toLocaleString()}`,
141+
'clock'
142+
)
127143
);
128144

129145
return items;

src/kernels/deepnote/environments/deepnoteEnvironmentTreeItem.node.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ export enum EnvironmentTreeItemType {
1212
CreateAction = 'create'
1313
}
1414

15+
export type DeepnoteEnvironmentTreeInfoItemId =
16+
| 'ports'
17+
| 'url'
18+
| 'python'
19+
| 'venv'
20+
| 'packages'
21+
| 'toolkit'
22+
| 'created'
23+
| 'lastUsed';
24+
1525
/**
1626
* Tree item for displaying environments and related info
1727
*/
@@ -37,8 +47,13 @@ export class DeepnoteEnvironmentTreeItem extends TreeItem {
3747
/**
3848
* Create an info item to display under an environment
3949
*/
40-
public static createInfoItem(label: string, icon?: string): DeepnoteEnvironmentTreeItem {
50+
public static createInfoItem(
51+
id: DeepnoteEnvironmentTreeInfoItemId,
52+
label: string,
53+
icon?: string
54+
): DeepnoteEnvironmentTreeItem {
4155
const item = new DeepnoteEnvironmentTreeItem(EnvironmentTreeItemType.InfoItem, undefined, undefined, label);
56+
item.id = `info-${id}`;
4257

4358
if (icon) {
4459
item.iconPath = new ThemeIcon(icon);
@@ -54,6 +69,7 @@ export class DeepnoteEnvironmentTreeItem extends TreeItem {
5469

5570
const statusVisual = getDeepnoteEnvironmentStatusVisual(this.status ?? EnvironmentStatus.Stopped);
5671

72+
this.id = this.environment.id;
5773
this.label = `${this.environment.name} [${statusVisual.text}]`;
5874
this.iconPath = new ThemeIcon(statusVisual.icon, new ThemeColor(statusVisual.themeColorId));
5975
this.contextValue = statusVisual.contextValue;
@@ -76,6 +92,7 @@ export class DeepnoteEnvironmentTreeItem extends TreeItem {
7692
}
7793

7894
private setupCreateAction(): void {
95+
this.id = 'create';
7996
this.label = l10n.t('Create New Environment');
8097
this.iconPath = new ThemeIcon('add');
8198
this.contextValue = 'deepnoteEnvironment.create';

src/kernels/deepnote/environments/deepnoteEnvironmentTreeItem.unit.test.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,15 @@ suite('DeepnoteEnvironmentTreeItem', () => {
149149
});
150150

151151
test('should create info item with icon', () => {
152-
const item = DeepnoteEnvironmentTreeItem.createInfoItem('Port: 8888', 'circle-filled');
152+
const item = DeepnoteEnvironmentTreeItem.createInfoItem('ports', 'Port: 8888', 'circle-filled');
153153

154154
assert.strictEqual(item.label, 'Port: 8888');
155155
assert.instanceOf(item.iconPath, ThemeIcon);
156156
assert.strictEqual((item.iconPath as ThemeIcon).id, 'circle-filled');
157157
});
158158

159159
test('should create info item without icon', () => {
160-
const item = DeepnoteEnvironmentTreeItem.createInfoItem('No icon');
160+
const item = DeepnoteEnvironmentTreeItem.createInfoItem('ports', 'No icon');
161161

162162
assert.strictEqual(item.label, 'No icon');
163163
assert.isUndefined(item.iconPath);
@@ -201,6 +201,22 @@ suite('DeepnoteEnvironmentTreeItem', () => {
201201
assert.include(item.description as string, 'just now');
202202
});
203203

204+
test('should handle negative time (few seconds in the past)', () => {
205+
const fewSecondsAgo = new Date(Date.now() - 5 * 1000);
206+
const config: DeepnoteEnvironment = {
207+
...testEnvironment,
208+
lastUsedAt: fewSecondsAgo
209+
};
210+
211+
const item = new DeepnoteEnvironmentTreeItem(
212+
EnvironmentTreeItemType.Environment,
213+
config,
214+
EnvironmentStatus.Stopped
215+
);
216+
217+
assert.include(item.description as string, 'just now');
218+
});
219+
204220
test('should show minutes ago', () => {
205221
const fiveMinutesAgo = new Date(Date.now() - 5 * 60 * 1000);
206222
const config: DeepnoteEnvironment = {

0 commit comments

Comments
 (0)