@@ -17,97 +17,44 @@ import {
17
17
} from '@jupyterlab/apputils' ;
18
18
19
19
import { SidePanel } from '@jupyterlab/ui-components' ;
20
- import { IBucket } from './s3requests' ;
21
20
import { Dialog , ICommandPalette , showDialog } from '@jupyterlab/apputils' ;
22
21
import { DriveListModel , DriveListView } from './drivelistmanager' ;
23
22
import { addJupyterLabThemeChangeListener } from '@jupyter/web-components' ;
24
- import {
25
- getDriveContents ,
26
- getDrivesList ,
27
- postDriveMounted
28
- } from './s3requests' ;
29
-
30
- /**
31
- * The class name added to the filebrowser filterbox node.
32
- */
33
- //const FILTERBOX_CLASS = 'jp-FileBrowser-filterBox';
23
+ import { getDrivesList , IBucket } from './s3requests' ;
34
24
35
25
const FILE_BROWSER_FACTORY = 'DrivePanel' ;
36
26
const FILE_BROWSER_PLUGIN_ID = '@jupyter/drives:widget' ;
37
27
38
- function buildMountedDriveNameList ( driveList : Drive [ ] ) : string [ ] {
28
+ function buildAddedDriveNameList ( driveList : Drive [ ] ) : string [ ] {
39
29
const driveNameList : string [ ] = [ ] ;
40
30
driveList . forEach ( drive => {
41
31
driveNameList . push ( drive . name ) ;
42
32
} ) ;
43
33
return driveNameList ;
44
34
}
45
35
46
- const s3AvailableBuckets = await getDrivesList ( ) ;
47
- console . log ( 'List of buckets is:' , s3AvailableBuckets ) ;
48
- const driveName = 'jupyter-drive-bucket1' ;
49
- const path = 'examples' ;
50
- await postDriveMounted ( driveName ) ;
51
- const driveContent = await getDriveContents ( driveName , path ) ;
52
- console . log ( 'driveContent:' , driveContent ) ;
53
- /*const s3AvailableBuckets1: IBucket[] = [
54
- {
55
- creation_date: '2023-12-15T13:27:57.000Z',
56
- name: 'jupyterDriveBucket1',
57
- provider: 'S3',
58
- region: 'us-east-1',
59
- status: 'active'
60
- },
61
- {
62
- creation_date: '2023-12-19T08:57:29.000Z',
63
- name: 'jupyterDriveBucket2',
64
- provider: 'S3',
65
- region: 'us-east-1',
66
- status: 'inactive'
67
- },
68
- {
69
- creation_date: '2023-12-19T09:07:29.000Z',
70
- name: 'jupyterDriveBucket3',
71
- provider: 'S3',
72
- region: 'us-east-1',
73
- status: 'inactive'
74
- },
75
- {
76
- creation_date: '2023-12-19T09:07:29.000Z',
77
- name: 'jupyterDriveBucket4',
78
- provider: 'S3',
79
- region: 'us-east-1',
80
- status: 'active'
81
- },
82
- {
83
- creation_date: '2024-01-12T09:07:29.000Z',
84
- name: 'jupyterDriveBucket5',
85
- provider: 'S3',
86
- region: 'us-east-1',
87
- status: 'active'
88
- }
89
- ];*/
90
-
91
36
namespace CommandIDs {
92
37
export const openDrivesDialog = 'drives:open-drives-dialog' ;
93
38
export const removeDriveBrowser = 'drives:remove-drive-browser' ;
94
39
}
95
40
96
- /*async*/ function createDrivesList ( bucketList : IBucket [ ] ) {
41
+ async function createDrivesList ( ) {
42
+ const response = await getDrivesList ( ) ;
43
+ const bucketList : Array < IBucket > = response [ 'data' ] ;
97
44
const S3Drives : Drive [ ] = [ ] ;
98
45
bucketList . forEach ( item => {
99
46
const drive = new Drive ( ) ;
100
47
drive . name = item . name ;
101
48
drive . baseUrl = '' ;
102
49
drive . region = item . region ;
103
- drive . status = item . status ;
50
+ drive . status = 'active' ;
104
51
drive . provider = item . provider ;
105
52
S3Drives . push ( drive ) ;
106
53
} ) ;
107
54
return S3Drives ;
108
55
}
109
56
110
- function camelCaseToDashedCase ( name : string ) {
57
+ export function camelCaseToDashedCase ( name : string ) {
111
58
if ( name !== name . toLowerCase ( ) ) {
112
59
name = name . replace ( / [ A - Z ] / g, m => '-' + m . toLowerCase ( ) ) ;
113
60
}
@@ -117,14 +64,6 @@ function camelCaseToDashedCase(name: string) {
117
64
function restoreDriveName ( id : string ) {
118
65
const list1 = id . split ( '-file-' ) ;
119
66
let driveName = list1 [ 0 ] ;
120
- for ( let i = 0 ; i < driveName . length ; i ++ ) {
121
- if ( driveName [ i ] === '-' ) {
122
- const index = i ;
123
- const char = driveName . charAt ( index + 1 ) . toUpperCase ( ) ;
124
- driveName = driveName . replace ( driveName . charAt ( index + 1 ) , char ) ;
125
- driveName = driveName . replace ( driveName . charAt ( index ) , '' ) ;
126
- }
127
- }
128
67
return driveName ;
129
68
}
130
69
@@ -161,7 +100,7 @@ const AddDrivesPlugin: JupyterFrontEndPlugin<void> = {
161
100
activate : activateAddDrivesPlugin
162
101
} ;
163
102
164
- export /* async */ function activateAddDrivesPlugin (
103
+ export async function activateAddDrivesPlugin (
165
104
app : JupyterFrontEnd ,
166
105
palette : ICommandPalette ,
167
106
manager : IDocumentManager ,
@@ -174,10 +113,9 @@ export /*async */ function activateAddDrivesPlugin(
174
113
addJupyterLabThemeChangeListener ( ) ;
175
114
const selectedDrivesModelMap = new Map < Drive [ ] , DriveListModel > ( ) ;
176
115
let selectedDrives : Drive [ ] = [ ] ;
177
- const availableDrives = createDrivesList ( s3AvailableBuckets ) ;
116
+ const availableDrives = await createDrivesList ( ) ;
178
117
let driveListModel = selectedDrivesModelMap . get ( selectedDrives ) ;
179
- const mountedDriveNameList : string [ ] =
180
- buildMountedDriveNameList ( selectedDrives ) ;
118
+ const addedDriveNameList : string [ ] = buildAddedDriveNameList ( selectedDrives ) ;
181
119
console . log ( 'AddDrives plugin is activated!' ) ;
182
120
const trans = translator . load ( 'jupyter-drives' ) ;
183
121
@@ -211,12 +149,9 @@ export /*async */ function activateAddDrivesPlugin(
211
149
}
212
150
213
151
app . commands . addCommand ( CommandIDs . openDrivesDialog , {
214
- execute : /* async*/ ( ) => {
152
+ execute : async ( ) => {
215
153
if ( ! driveListModel ) {
216
- driveListModel = new DriveListModel (
217
- /*await*/ availableDrives ,
218
- selectedDrives
219
- ) ;
154
+ driveListModel = new DriveListModel ( availableDrives , selectedDrives ) ;
220
155
selectedDrivesModelMap . set ( selectedDrives , driveListModel ) ;
221
156
} else {
222
157
selectedDrives = driveListModel . selectedDrives ;
@@ -226,9 +161,13 @@ export /*async */ function activateAddDrivesPlugin(
226
161
function onDriveAdded ( driveList : Drive [ ] ) {
227
162
const drive : Drive = driveList [ driveList . length - 1 ] ;
228
163
if ( driveListModel ) {
229
- if ( ! mountedDriveNameList . includes ( drive . name ) ) {
164
+ if ( ! addedDriveNameList . includes ( drive . name ) ) {
230
165
createDriveFileBrowser ( drive ) ;
231
- mountedDriveNameList . push ( drive . name ) ;
166
+ addedDriveNameList . push ( drive . name ) ;
167
+ } else {
168
+ console . warn (
169
+ 'The selected drive is already in the list of added drives'
170
+ ) ;
232
171
}
233
172
}
234
173
}
@@ -285,5 +224,5 @@ export /*async */ function activateAddDrivesPlugin(
285
224
} ) ;
286
225
}
287
226
288
- const plugins : JupyterFrontEndPlugin < any > [ ] = [ plugin , AddDrivesPlugin ] ;
227
+ const plugins : JupyterFrontEndPlugin < any > [ ] = [ AddDrivesPlugin ] ;
289
228
export default plugins ;
0 commit comments