Skip to content

Commit

Permalink
Fix bug with the toolbar and the error message related to setFilter a…
Browse files Browse the repository at this point in the history
…nd update index.ts and drivelistmanager to be able to add and remove panels containing drive filebrowsers for drives selected in the dialog.
  • Loading branch information
HaudinFlorence committed Jan 16, 2024
1 parent b03aaf3 commit d22b5ee
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 172 deletions.
2 changes: 1 addition & 1 deletion schema/widget.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"jupyter.lab.toolbars": {
"FileBrowser": [
"DrivePanel": [
{
"name": "new-directory",
"command": "filebrowser:create-new-directory",
Expand Down
2 changes: 1 addition & 1 deletion src/contents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ export class Drive implements Contents.IDrive {
const data = await response.json();*/

const data = drive1Contents;
Contents.validateContentsModel(data);
//Contents.validateContentsModel(data);
return data;
}

Expand Down
75 changes: 17 additions & 58 deletions src/drivelistmanager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
import { useState } from 'react';
import { Drive } from './contents';
import { DocumentRegistry } from '@jupyterlab/docregistry';
import { SidePanel } from '@jupyterlab/ui-components';
import { FileBrowser } from '@jupyterlab/filebrowser';
import { ILayoutRestorer, JupyterFrontEnd } from '@jupyterlab/application';
//import { SidePanel } from '@jupyterlab/ui-components';
//import { FileBrowser } from '@jupyterlab/filebrowser';
//import { ILayoutRestorer, JupyterFrontEnd } from '@jupyterlab/application';

interface IProps {
model: DriveListModel;
Expand Down Expand Up @@ -157,7 +157,6 @@ export function DriveListManagerComponent(props: IProps) {
};

const updateSelectedDrives = (item: string, isName: boolean) => {
console.log('you have clicked on add drive button');
updatedSelectedDrives = [...props.model.selectedDrives];
let pickedDrive = new Drive();

Expand All @@ -174,14 +173,21 @@ export function DriveListManagerComponent(props: IProps) {
}
});

const checkDrive = isDriveAlreadySelected(
pickedDrive,
updatedSelectedDrives
);
if (checkDrive === false) {
updatedSelectedDrives.push(pickedDrive);
if (pickedDrive.status === 'active') {
if (
isDriveAlreadySelected(pickedDrive, updatedSelectedDrives) === false
) {
updatedSelectedDrives.push(pickedDrive);
console.log(`Drive filebrowser is added for ${pickedDrive.name} drive`);
} else {
console.warn(
`There is already a drive filebrowser for ${pickedDrive.name} drive`
);
}
} else {
console.warn('The selected drive is already in the list');
console.warn(
`The selected drive ${pickedDrive.name} is inactive and cannot be mounted`
);
}

setSelectedDrives(updatedSelectedDrives);
Expand Down Expand Up @@ -264,53 +270,6 @@ export class DriveListModel extends VDomModel {
setSelectedDrives(selectedDrives: Drive[]) {
this.selectedDrives = selectedDrives;
}
async sendConnectionRequest(selectedDrives: Drive[]): Promise<boolean> {
const lastAddedDrive = selectedDrives[selectedDrives.length - 1];
let response: boolean;
console.log('Checking the status of selected drive ', lastAddedDrive.name);
if (lastAddedDrive.status === 'active') {
response = true;
} else {
console.warn('The selected drive is inactive');
response = false;
}
/*requestAPI('send_connectionRequest', {
method: 'POST'
})
.then(data => {
console.log('data:', data);
return data;
})
.catch(reason => {
console.error(
`The jupyter_drive server extension appears to be missing.\n${reason}`
);
return;
});*/
return response;
}

async addPanel(
drive: Drive,
panel: SidePanel,
filebrowser: FileBrowser,
app: JupyterFrontEnd,
restorer: ILayoutRestorer | null
): Promise<boolean> {
let response: boolean;
if (drive.name === 'active') {
response = true;
panel.addWidget(filebrowser);
//app.shell.add(panel, 'left', { rank: 102 });
if (restorer) {
restorer.add(panel, drive.name + '-browser');
}
} else {
response = false;
console.warn('The selected drive is inactive');
}
return response;
}
}

export class DriveListView extends VDomRenderer<DriveListModel> {
Expand Down
Loading

0 comments on commit d22b5ee

Please sign in to comment.