Skip to content

Commit

Permalink
Introduce changes to keep all the attributes required by the IDrive i…
Browse files Browse the repository at this point in the history
…nterface, when picking a drive by its name in the list of available drives.

Add a toolbar to all the drive filebrowsers.
  • Loading branch information
HaudinFlorence committed Nov 16, 2023
1 parent 0654a2c commit 41e8774
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

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

export class DefaultAndDrivesFileBrowser extends SidePanel {
export class DrivesFileBrowser extends SidePanel {
constructor() {
super();
this.addClass('jp-DefaultAndDriveBrowser');
Expand Down
23 changes: 14 additions & 9 deletions src/drivelistmanager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,20 @@ export function DriveListManagerComponent(props: IProps) {

const updateSelectedDrives = (item: string, isName: boolean) => {
updatedSelectedDrives = [...props.model.selectedDrives];
let pickedDrive: IDrive;
if (isName) {
pickedDrive = { name: item, url: '' };
} else {
if (item !== driveUrl) {
setDriveUrl(item);
let pickedDrive: IDrive = { name: '', url: '' };

props.model.availableDrives.forEach(drive => {
if (isName) {
if (item === drive.name) {
pickedDrive = drive;
}
} else {
if (item !== driveUrl) {
setDriveUrl(item);
}
pickedDrive = { name: '', url: driveUrl };
}
pickedDrive = { name: '', url: driveUrl };
}
});

const checkDrive = isDriveAlreadySelected(
pickedDrive,
Expand All @@ -174,7 +179,7 @@ export function DriveListManagerComponent(props: IProps) {
if (checkDrive === false) {
updatedSelectedDrives.push(pickedDrive);
} else {
console.log('The selected drive is already in the list');
console.warn('The selected drive is already in the list');
}

setSelectedDrives(updatedSelectedDrives);
Expand Down
37 changes: 25 additions & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { DriveListModel, DriveListView, IDrive } from './drivelistmanager';
import { DriveIcon } from './icons';
import { IDocumentManager } from '@jupyterlab/docmanager';
import { Drive } from './contents';
import { DefaultAndDrivesFileBrowser } from './browser';
import { DrivesFileBrowser } from './browser';

const FILE_BROWSER_FACTORY = 'FileBrowser';
const FILE_BROWSER_PLUGIN_ID = '@jupyter/drives:widget';
Expand All @@ -42,7 +42,7 @@ const availableList1 = [
},
{
name: 'WaterMelonDrive',
url: '/WaterMelonDrive/url'
url: '/watermelondrive/url'
},
{
name: 'MangoDrive',
Expand All @@ -66,34 +66,34 @@ const availableList1 = [
},
{
name: '',
url: '/mydrive/url'
url: '/apple/url'
},
{
name: 'RaspberryDrive',
url: '/raspberrydrive/url'
},

{
name: 'PineAppleDrive',
url: ''
name: 'PineappleDrive',
url: '/pineappledrive/url'
},

{ name: 'PomeloDrive', url: '/https://pomelodrive/url' },
{
name: 'OrangeDrive',
url: ''
url: 'orangedrive/url'
},
{
name: 'TomatoDrive',
url: ''
url: 'tomatodrive/url'
},
{
name: '',
url: 'superDrive/url'
url: 'plumedrive/url'
},
{
name: 'AvocadoDrive',
url: ''
url: 'avocadodrive/url'
}
];

Expand Down Expand Up @@ -153,7 +153,7 @@ export async function activateAddDrivesPlugin(

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

function addDriveContentsToPanel(
panel: DefaultAndDrivesFileBrowser,
panel: DrivesFileBrowser,
addedDrive: Drive
) {
manager.services.contents.addDrive(addedDrive);
Expand All @@ -192,6 +192,19 @@ export async function activateAddDrivesPlugin(
refreshInterval: 300000
});

if (settingRegistry) {
setToolbar(
driveBrowser,
createToolbarFactory(
toolbarRegistry,
settingRegistry,
FILE_BROWSER_FACTORY,
FILE_BROWSER_PLUGIN_ID,
translator
)
);
}

panel.addWidget(driveBrowser);
}

Expand All @@ -218,7 +231,7 @@ export async function activateAddDrivesPlugin(
console.log('response:', response);
addDriveContentsToPanel(panel, drive1);
} else {
console.log('Error, connection with the drive was not possible');
console.warn('Connection with the drive was not possible');
}
}
}
Expand Down

0 comments on commit 41e8774

Please sign in to comment.