From d2124b1708a11c1825a8eedc770d6170a0bbe607 Mon Sep 17 00:00:00 2001 From: HaudinFlorence Date: Thu, 21 Dec 2023 15:41:13 +0100 Subject: [PATCH] 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. --- src/index.ts | 64 ++++++++++++++++++++++++++++++++++------------- src/s3requests.ts | 15 +++++++++++ 2 files changed, 61 insertions(+), 18 deletions(-) create mode 100644 src/s3requests.ts diff --git a/src/index.ts b/src/index.ts index 3ab9e4c..ff94f03 100644 --- a/src/index.ts +++ b/src/index.ts @@ -24,6 +24,8 @@ import { /*FilenameSearcher, IScore, */ SidePanel } from '@jupyterlab/ui-components'; +import { IBucket } from './s3requests'; + /** * The class name added to the filebrowser filterbox node. */ @@ -48,6 +50,46 @@ namespace CommandIDs { console.log('JupyterLab extension @jupyter/drives is activated!'); } };*/ + +async function createDrivesList(manager: IDocumentManager) { + /*const s3BucketsList: IBucket[] = await getDrivesList();*/ + const s3BucketsList: IBucket[] = [ + { + creation_date: '2023-12-15T13:27:57.000Z', + name: 'jupyter-drive-bucket1', + provider: 'S3', + region: 'us-east-1', + status: 'active' + }, + { + creation_date: '2023-12-19T08:57:29.000Z', + name: 'jupyter-drive-bucket2', + provider: 'S3', + region: 'us-east-1', + status: 'inactive' + }, + { + creation_date: '2023-12-19T09:07:29.000Z', + name: 'jupyter-drive-bucket3', + provider: 'S3', + region: 'us-east-1', + status: 'active' + } + ]; + + const availableS3Buckets: Drive[] = []; + s3BucketsList.forEach(item => { + const drive = new Drive(); + drive.name = item.name; + drive.baseUrl = ''; + drive.region = item.region; + drive.status = item.status; + drive.provider = item.provider; + manager.services.contents.addDrive(drive); + availableS3Buckets.push(drive); + }); + return availableS3Buckets; +} const AddDrivesPlugin: JupyterFrontEndPlugin = { id: '@jupyter/drives:add-drives', description: 'Open a dialog to select drives to be added in the filebrowser.', @@ -74,21 +116,7 @@ export async function activateAddDrivesPlugin( ) { console.log('AddDrives plugin is activated!'); const trans = translator.load('jupyter-drives'); - const cocoDrive = new Drive(); - cocoDrive.name = 'coconutDrive'; - cocoDrive.baseUrl = '/coconut/url'; - cocoDrive.region = ''; - cocoDrive.status = 'active'; - cocoDrive.provider = ''; - manager.services.contents.addDrive(cocoDrive); - const bananaDrive = new Drive(); - bananaDrive.name = 'bananaDrive'; - bananaDrive.baseUrl = '/banana/url'; - bananaDrive.region = ''; - bananaDrive.status = 'active'; - bananaDrive.provider = ''; - manager.services.contents.addDrive(bananaDrive); - const driveList: Drive[] = [cocoDrive, bananaDrive]; + const driveList: Drive[] = await createDrivesList(manager); function camelCaseToDashedCase(name: string) { if (name !== name.toLowerCase()) { @@ -112,7 +140,7 @@ export async function activateAddDrivesPlugin( } app.commands.addCommand(CommandIDs.addDriveBrowser, { - execute: args => { + execute: async args => { function createSidePanel(driveName: string) { const panel = new SidePanel(); panel.title.icon = DriveIcon; @@ -158,9 +186,9 @@ export async function activateAddDrivesPlugin( ); } - driveList.forEach(drive => { + /*driveList.forEach(drive => { addDriveToPanel(drive, factory); - }); + });*/ }, caption: trans.__('Add drive filebrowser.'), label: trans.__('Add Drive Filebrowser') diff --git a/src/s3requests.ts b/src/s3requests.ts new file mode 100644 index 0000000..ac7ac28 --- /dev/null +++ b/src/s3requests.ts @@ -0,0 +1,15 @@ +import { requestAPI } from './handler'; + +export interface IBucket { + name: string; + region: string; + provider: string; + creation_date: string; + status: string; +} + +export async function getDrivesList() { + return await requestAPI>('drives', { + method: 'GET' + }); +}