Skip to content

Commit d2124b1

Browse files
Add a getDrivesList request and a createDrivesList in index.ts to get the informations about the list of drives and create the corresponding new Drive instances with faked contents at this
stage.
1 parent f25ec49 commit d2124b1

File tree

2 files changed

+61
-18
lines changed

2 files changed

+61
-18
lines changed

src/index.ts

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import {
2424
/*FilenameSearcher, IScore, */ SidePanel
2525
} from '@jupyterlab/ui-components';
2626

27+
import { IBucket } from './s3requests';
28+
2729
/**
2830
* The class name added to the filebrowser filterbox node.
2931
*/
@@ -48,6 +50,46 @@ namespace CommandIDs {
4850
console.log('JupyterLab extension @jupyter/drives is activated!');
4951
}
5052
};*/
53+
54+
async function createDrivesList(manager: IDocumentManager) {
55+
/*const s3BucketsList: IBucket[] = await getDrivesList();*/
56+
const s3BucketsList: IBucket[] = [
57+
{
58+
creation_date: '2023-12-15T13:27:57.000Z',
59+
name: 'jupyter-drive-bucket1',
60+
provider: 'S3',
61+
region: 'us-east-1',
62+
status: 'active'
63+
},
64+
{
65+
creation_date: '2023-12-19T08:57:29.000Z',
66+
name: 'jupyter-drive-bucket2',
67+
provider: 'S3',
68+
region: 'us-east-1',
69+
status: 'inactive'
70+
},
71+
{
72+
creation_date: '2023-12-19T09:07:29.000Z',
73+
name: 'jupyter-drive-bucket3',
74+
provider: 'S3',
75+
region: 'us-east-1',
76+
status: 'active'
77+
}
78+
];
79+
80+
const availableS3Buckets: Drive[] = [];
81+
s3BucketsList.forEach(item => {
82+
const drive = new Drive();
83+
drive.name = item.name;
84+
drive.baseUrl = '';
85+
drive.region = item.region;
86+
drive.status = item.status;
87+
drive.provider = item.provider;
88+
manager.services.contents.addDrive(drive);
89+
availableS3Buckets.push(drive);
90+
});
91+
return availableS3Buckets;
92+
}
5193
const AddDrivesPlugin: JupyterFrontEndPlugin<void> = {
5294
id: '@jupyter/drives:add-drives',
5395
description: 'Open a dialog to select drives to be added in the filebrowser.',
@@ -74,21 +116,7 @@ export async function activateAddDrivesPlugin(
74116
) {
75117
console.log('AddDrives plugin is activated!');
76118
const trans = translator.load('jupyter-drives');
77-
const cocoDrive = new Drive();
78-
cocoDrive.name = 'coconutDrive';
79-
cocoDrive.baseUrl = '/coconut/url';
80-
cocoDrive.region = '';
81-
cocoDrive.status = 'active';
82-
cocoDrive.provider = '';
83-
manager.services.contents.addDrive(cocoDrive);
84-
const bananaDrive = new Drive();
85-
bananaDrive.name = 'bananaDrive';
86-
bananaDrive.baseUrl = '/banana/url';
87-
bananaDrive.region = '';
88-
bananaDrive.status = 'active';
89-
bananaDrive.provider = '';
90-
manager.services.contents.addDrive(bananaDrive);
91-
const driveList: Drive[] = [cocoDrive, bananaDrive];
119+
const driveList: Drive[] = await createDrivesList(manager);
92120

93121
function camelCaseToDashedCase(name: string) {
94122
if (name !== name.toLowerCase()) {
@@ -112,7 +140,7 @@ export async function activateAddDrivesPlugin(
112140
}
113141

114142
app.commands.addCommand(CommandIDs.addDriveBrowser, {
115-
execute: args => {
143+
execute: async args => {
116144
function createSidePanel(driveName: string) {
117145
const panel = new SidePanel();
118146
panel.title.icon = DriveIcon;
@@ -158,9 +186,9 @@ export async function activateAddDrivesPlugin(
158186
);
159187
}
160188

161-
driveList.forEach(drive => {
189+
/*driveList.forEach(drive => {
162190
addDriveToPanel(drive, factory);
163-
});
191+
});*/
164192
},
165193
caption: trans.__('Add drive filebrowser.'),
166194
label: trans.__('Add Drive Filebrowser')

src/s3requests.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { requestAPI } from './handler';
2+
3+
export interface IBucket {
4+
name: string;
5+
region: string;
6+
provider: string;
7+
creation_date: string;
8+
status: string;
9+
}
10+
11+
export async function getDrivesList() {
12+
return await requestAPI<Array<IBucket>>('drives', {
13+
method: 'GET'
14+
});
15+
}

0 commit comments

Comments
 (0)