Skip to content

Commit 41e8774

Browse files
Introduce changes to keep all the attributes required by the IDrive interface, when picking a drive by its name in the list of available drives.
Add a toolbar to all the drive filebrowsers.
1 parent 0654a2c commit 41e8774

File tree

3 files changed

+40
-22
lines changed

3 files changed

+40
-22
lines changed

src/browser.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import { SidePanel } from '@jupyterlab/ui-components';
55

6-
export class DefaultAndDrivesFileBrowser extends SidePanel {
6+
export class DrivesFileBrowser extends SidePanel {
77
constructor() {
88
super();
99
this.addClass('jp-DefaultAndDriveBrowser');

src/drivelistmanager.tsx

+14-9
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,20 @@ export function DriveListManagerComponent(props: IProps) {
157157

158158
const updateSelectedDrives = (item: string, isName: boolean) => {
159159
updatedSelectedDrives = [...props.model.selectedDrives];
160-
let pickedDrive: IDrive;
161-
if (isName) {
162-
pickedDrive = { name: item, url: '' };
163-
} else {
164-
if (item !== driveUrl) {
165-
setDriveUrl(item);
160+
let pickedDrive: IDrive = { name: '', url: '' };
161+
162+
props.model.availableDrives.forEach(drive => {
163+
if (isName) {
164+
if (item === drive.name) {
165+
pickedDrive = drive;
166+
}
167+
} else {
168+
if (item !== driveUrl) {
169+
setDriveUrl(item);
170+
}
171+
pickedDrive = { name: '', url: driveUrl };
166172
}
167-
pickedDrive = { name: '', url: driveUrl };
168-
}
173+
});
169174

170175
const checkDrive = isDriveAlreadySelected(
171176
pickedDrive,
@@ -174,7 +179,7 @@ export function DriveListManagerComponent(props: IProps) {
174179
if (checkDrive === false) {
175180
updatedSelectedDrives.push(pickedDrive);
176181
} else {
177-
console.log('The selected drive is already in the list');
182+
console.warn('The selected drive is already in the list');
178183
}
179184

180185
setSelectedDrives(updatedSelectedDrives);

src/index.ts

+25-12
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { DriveListModel, DriveListView, IDrive } from './drivelistmanager';
2020
import { DriveIcon } from './icons';
2121
import { IDocumentManager } from '@jupyterlab/docmanager';
2222
import { Drive } from './contents';
23-
import { DefaultAndDrivesFileBrowser } from './browser';
23+
import { DrivesFileBrowser } from './browser';
2424

2525
const FILE_BROWSER_FACTORY = 'FileBrowser';
2626
const FILE_BROWSER_PLUGIN_ID = '@jupyter/drives:widget';
@@ -42,7 +42,7 @@ const availableList1 = [
4242
},
4343
{
4444
name: 'WaterMelonDrive',
45-
url: '/WaterMelonDrive/url'
45+
url: '/watermelondrive/url'
4646
},
4747
{
4848
name: 'MangoDrive',
@@ -66,34 +66,34 @@ const availableList1 = [
6666
},
6767
{
6868
name: '',
69-
url: '/mydrive/url'
69+
url: '/apple/url'
7070
},
7171
{
7272
name: 'RaspberryDrive',
7373
url: '/raspberrydrive/url'
7474
},
7575

7676
{
77-
name: 'PineAppleDrive',
78-
url: ''
77+
name: 'PineappleDrive',
78+
url: '/pineappledrive/url'
7979
},
8080

8181
{ name: 'PomeloDrive', url: '/https://pomelodrive/url' },
8282
{
8383
name: 'OrangeDrive',
84-
url: ''
84+
url: 'orangedrive/url'
8585
},
8686
{
8787
name: 'TomatoDrive',
88-
url: ''
88+
url: 'tomatodrive/url'
8989
},
9090
{
9191
name: '',
92-
url: 'superDrive/url'
92+
url: 'plumedrive/url'
9393
},
9494
{
9595
name: 'AvocadoDrive',
96-
url: ''
96+
url: 'avocadodrive/url'
9797
}
9898
];
9999

@@ -153,7 +153,7 @@ export async function activateAddDrivesPlugin(
153153

154154
const trans = translator.load('jupyter_drives');
155155
/* Add a left panel containing the default filebrowser and a dedicated browser for the selected drive*/
156-
const panel = new DefaultAndDrivesFileBrowser();
156+
const panel = new DrivesFileBrowser();
157157
const defaultBrowser = factory.createFileBrowser('default-browser', {
158158
refreshInterval: 300000
159159
});
@@ -183,7 +183,7 @@ export async function activateAddDrivesPlugin(
183183
drive1.name = 'mydrive1';
184184

185185
function addDriveContentsToPanel(
186-
panel: DefaultAndDrivesFileBrowser,
186+
panel: DrivesFileBrowser,
187187
addedDrive: Drive
188188
) {
189189
manager.services.contents.addDrive(addedDrive);
@@ -192,6 +192,19 @@ export async function activateAddDrivesPlugin(
192192
refreshInterval: 300000
193193
});
194194

195+
if (settingRegistry) {
196+
setToolbar(
197+
driveBrowser,
198+
createToolbarFactory(
199+
toolbarRegistry,
200+
settingRegistry,
201+
FILE_BROWSER_FACTORY,
202+
FILE_BROWSER_PLUGIN_ID,
203+
translator
204+
)
205+
);
206+
}
207+
195208
panel.addWidget(driveBrowser);
196209
}
197210

@@ -218,7 +231,7 @@ export async function activateAddDrivesPlugin(
218231
console.log('response:', response);
219232
addDriveContentsToPanel(panel, drive1);
220233
} else {
221-
console.log('Error, connection with the drive was not possible');
234+
console.warn('Connection with the drive was not possible');
222235
}
223236
}
224237
}

0 commit comments

Comments
 (0)