From 1afa3ff980c81a9d1217f5fbbbc58880ef739518 Mon Sep 17 00:00:00 2001 From: DenisaCG Date: Wed, 18 Dec 2024 13:28:11 +0100 Subject: [PATCH 1/6] reorganize plugins structure --- src/index.ts | 373 +----------------- src/plugins/driveBrowserPlugin.ts | 259 ++++++++++++ src/plugins/driveDialogPlugin.ts | 129 ++++++ src/{ => plugins}/drivelistmanager.tsx | 0 src/plugins/index.ts | 3 + .../launcherPlugin.ts} | 0 tsconfig.json | 2 +- 7 files changed, 399 insertions(+), 367 deletions(-) create mode 100644 src/plugins/driveBrowserPlugin.ts create mode 100644 src/plugins/driveDialogPlugin.ts rename src/{ => plugins}/drivelistmanager.tsx (100%) create mode 100644 src/plugins/index.ts rename src/{launcher.ts => plugins/launcherPlugin.ts} (100%) diff --git a/src/index.ts b/src/index.ts index a1b6d1b..680438a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,315 +1,10 @@ +import { JupyterFrontEndPlugin } from '@jupyterlab/application'; import { - ILabShell, - ILayoutRestorer, - IRouter, - JupyterFrontEnd, - JupyterFrontEndPlugin -} from '@jupyterlab/application'; -import { - IFileBrowserFactory, - FileBrowser, - Uploader -} from '@jupyterlab/filebrowser'; -import { ITranslator } from '@jupyterlab/translation'; -import { addJupyterLabThemeChangeListener } from '@jupyter/web-components'; -import { - createToolbarFactory, - IToolbarWidgetRegistry, - setToolbar, - Dialog, - showDialog -} from '@jupyterlab/apputils'; -import { ISettingRegistry } from '@jupyterlab/settingregistry'; -import { FilenameSearcher, IScore } from '@jupyterlab/ui-components'; -import { CommandRegistry } from '@lumino/commands'; - -import { DriveListModel, DriveListView, IDrive } from './drivelistmanager'; -import { DriveIcon, driveBrowserIcon } from './icons'; -import { Drive } from './contents'; -import { getDrivesList, setListingLimit } from './requests'; -import { IDriveInfo, IDrivesList } from './token'; -import { launcherPlugin } from './launcher'; - -/** - * The command IDs used by the driveBrowser plugin. - */ -namespace CommandIDs { - export const openDrivesDialog = 'drives:open-drives-dialog'; - export const openPath = 'drives:open-path'; - export const toggleBrowser = 'drives:toggle-main'; -} - -/** - * The file browser factory ID. - */ -const FILE_BROWSER_FACTORY = 'DriveBrowser'; - -/** - * The class name added to the drive filebrowser filterbox node. - */ -const FILTERBOX_CLASS = 'jp-drive-browser-search-box'; - -const openDriveDialogPlugin: JupyterFrontEndPlugin = { - id: 'jupyter-drives:widget', - description: 'Open a dialog to select drives to be added in the filebrowser.', - requires: [IFileBrowserFactory, ITranslator], - autoStart: true, - activate: ( - app: JupyterFrontEnd, - factory: IFileBrowserFactory, - translator: ITranslator - ): void => { - addJupyterLabThemeChangeListener(); - const { commands } = app; - const { tracker } = factory; - const trans = translator.load('jupyter_drives'); - const selectedDrivesModelMap = new Map(); - - let selectedDrives: IDrive[] = [ - { - name: 'CoconutDrive', - url: '/coconut/url' - } - ]; - - const availableDrives: IDrive[] = [ - { - name: 'CoconutDrive', - url: '/coconut/url' - }, - { - name: 'PearDrive', - url: '/pear/url' - }, - { - name: 'StrawberryDrive', - url: '/strawberrydrive/url' - }, - { - name: 'BlueberryDrive', - url: '/blueberrydrive/url' - }, - { - name: '', - url: '/mydrive/url' - }, - { - name: 'RaspberryDrive', - url: '/raspberrydrive/url' - }, - - { - name: 'PineAppleDrive', - url: '' - }, - - { name: 'PomeloDrive', url: '/https://pomelodrive/url' }, - { - name: 'OrangeDrive', - url: '' - }, - { - name: 'TomatoDrive', - url: '' - }, - { - name: '', - url: 'superDrive/url' - }, - { - name: 'AvocadoDrive', - url: '' - } - ]; - let model = selectedDrivesModelMap.get(selectedDrives); - - //const model = new DriveListModel(availableDrives, selectedDrives); - - commands.addCommand(CommandIDs.openDrivesDialog, { - execute: args => { - const widget = tracker.currentWidget; - - if (!model) { - model = new DriveListModel(availableDrives, selectedDrives); - selectedDrivesModelMap.set(selectedDrives, model); - } else { - selectedDrives = model.selectedDrives; - selectedDrivesModelMap.set(selectedDrives, model); - } - if (widget) { - if (model) { - showDialog({ - body: new DriveListView(model), - buttons: [Dialog.cancelButton()] - }); - } - } - }, - - icon: DriveIcon.bindprops({ stylesheet: 'menuItem' }), - caption: trans.__('Add drives to filebrowser.'), - label: trans.__('Add Drives To Filebrowser') - }); - } -}; - -/** - * The drives list provider. - */ -const drivesListProvider: JupyterFrontEndPlugin = { - id: 'jupyter-drives:drives-list', - description: 'The drives list provider.', - provides: IDrivesList, - activate: async (_: JupyterFrontEnd): Promise => { - let drives: IDriveInfo[] = []; - try { - drives = await getDrivesList(); - } catch (error) { - console.log('Failed loading available drives list, with error: ', error); - } - return drives; - } -}; - -/** - * The drive file browser factory provider. - */ -const driveFileBrowser: JupyterFrontEndPlugin = { - id: 'jupyter-drives:drives-file-browser', - description: 'The drive file browser factory provider.', - autoStart: true, - requires: [ - IFileBrowserFactory, - IToolbarWidgetRegistry, - ISettingRegistry, - ITranslator, - IDrivesList - ], - optional: [ - IRouter, - JupyterFrontEnd.ITreeResolver, - ILabShell, - ILayoutRestorer - ], - activate: async ( - app: JupyterFrontEnd, - fileBrowserFactory: IFileBrowserFactory, - toolbarRegistry: IToolbarWidgetRegistry, - settingsRegistry: ISettingRegistry, - translator: ITranslator, - drivesList: IDriveInfo[], - router: IRouter | null, - tree: JupyterFrontEnd.ITreeResolver | null, - labShell: ILabShell | null, - restorer: ILayoutRestorer | null - ): Promise => { - console.log( - 'JupyterLab extension jupyter-drives:drives-file-browser is activated!' - ); - const { commands } = app; - - // create drive for drive file browser - const drive = new Drive({ - name: 's3', - drivesList: drivesList - }); - - app.serviceManager.contents.addDrive(drive); - - // get registered file types - drive.getRegisteredFileTypes(app); - - // Manually restore and load the drive file browser. - const driveBrowser = fileBrowserFactory.createFileBrowser('drivebrowser', { - auto: false, - restore: false, - driveName: drive.name - }); - - // Set attributes when adding the browser to the UI - driveBrowser.node.setAttribute('role', 'region'); - driveBrowser.node.setAttribute('aria-label', 'Drive Browser Section'); - driveBrowser.title.icon = driveBrowserIcon; - driveBrowser.title.caption = 'Drive File Browser'; - driveBrowser.id = 'drive-file-browser'; - - void Private.restoreBrowser(driveBrowser, commands, router, tree, labShell); - - app.shell.add(driveBrowser, 'left', { rank: 102, type: 'File Browser' }); - if (restorer) { - restorer.add(driveBrowser, 'drive-file-browser'); - } - - toolbarRegistry.addFactory( - FILE_BROWSER_FACTORY, - 'uploader', - (fileBrowser: FileBrowser) => - new Uploader({ model: fileBrowser.model, translator }) - ); - - toolbarRegistry.addFactory( - FILE_BROWSER_FACTORY, - 'file-name-searcher', - (fileBrowser: FileBrowser) => { - const searcher = FilenameSearcher({ - updateFilter: ( - filterFn: (item: string) => Partial | null, - query?: string - ) => { - fileBrowser.model.setFilter(value => { - return filterFn(value.name.toLowerCase()); - }); - }, - useFuzzyFilter: true, - placeholder: 'Filter files by names', - forceRefresh: true - }); - searcher.addClass(FILTERBOX_CLASS); - return searcher; - } - ); - - // connect the filebrowser toolbar to the settings registry for the plugin - setToolbar( - driveBrowser, - createToolbarFactory( - toolbarRegistry, - settingsRegistry, - FILE_BROWSER_FACTORY, - driveFileBrowser.id, - translator - ) - ); - - /** - * Load the settings for this extension - * - * @param setting Extension settings - */ - function loadSetting(setting: ISettingRegistry.ISettings): void { - // Read the settings and convert to the correct type - const maxFilesListed = setting.get('maxFilesListed').composite as number; - // Set new limit. - setListingLimit(maxFilesListed); - } - - // Wait for the application to be restored and - // for the settings for this plugin to be loaded - Promise.all([app.restored, settingsRegistry.load(driveFileBrowser.id)]) - .then(([, setting]) => { - // Read the settings - loadSetting(setting); - - // Listen for your plugin setting changes using Signal - setting.changed.connect(loadSetting); - }) - .catch(reason => { - console.error( - `Something went wrong when reading the settings.\n${reason}` - ); - }); - } -}; + driveFileBrowser, + drivesListProvider, + openDriveDialogPlugin, + launcherPlugin +} from './plugins'; const plugins: JupyterFrontEndPlugin[] = [ driveFileBrowser, @@ -317,59 +12,5 @@ const plugins: JupyterFrontEndPlugin[] = [ openDriveDialogPlugin, launcherPlugin ]; -export default plugins; - -namespace Private { - /** - * Restores file browser state and overrides state if tree resolver resolves. - */ - export async function restoreBrowser( - browser: FileBrowser, - commands: CommandRegistry, - router: IRouter | null, - tree: JupyterFrontEnd.ITreeResolver | null, - labShell: ILabShell | null - ): Promise { - const restoring = 'jp-mod-restoring'; - browser.addClass(restoring); - - if (!router) { - await browser.model.restore(browser.id); - await browser.model.refresh(); - browser.removeClass(restoring); - return; - } - - const listener = async () => { - router.routed.disconnect(listener); - - const paths = await tree?.paths; - if (paths?.file || paths?.browser) { - // Restore the model without populating it. - await browser.model.restore(browser.id, false); - if (paths.file) { - await commands.execute(CommandIDs.openPath, { - path: paths.file, - dontShowBrowser: true - }); - } - if (paths.browser) { - await commands.execute(CommandIDs.openPath, { - path: paths.browser, - dontShowBrowser: true - }); - } - } else { - await browser.model.restore(browser.id); - await browser.model.refresh(); - } - browser.removeClass(restoring); - - if (labShell?.isEmpty('main')) { - void commands.execute('launcher:create'); - } - }; - router.routed.connect(listener); - } -} +export default plugins; diff --git a/src/plugins/driveBrowserPlugin.ts b/src/plugins/driveBrowserPlugin.ts new file mode 100644 index 0000000..96e73a3 --- /dev/null +++ b/src/plugins/driveBrowserPlugin.ts @@ -0,0 +1,259 @@ +import { + ILabShell, + ILayoutRestorer, + IRouter, + JupyterFrontEnd, + JupyterFrontEndPlugin + } from '@jupyterlab/application'; + import { + IFileBrowserFactory, + FileBrowser, + Uploader + } from '@jupyterlab/filebrowser'; + import { ITranslator } from '@jupyterlab/translation'; + import { + createToolbarFactory, + IToolbarWidgetRegistry, + setToolbar + } from '@jupyterlab/apputils'; + import { ISettingRegistry } from '@jupyterlab/settingregistry'; + import { FilenameSearcher, IScore } from '@jupyterlab/ui-components'; + import { CommandRegistry } from '@lumino/commands'; + + import { driveBrowserIcon } from '../icons'; + import { Drive } from '../contents'; + import { getDrivesList, setListingLimit } from '../requests'; + import { IDriveInfo, IDrivesList } from '../token'; + + /** + * The command IDs used by the driveBrowser plugin. + */ + namespace CommandIDs { + export const openDrivesDialog = 'drives:open-drives-dialog'; + export const openPath = 'drives:open-path'; + export const toggleBrowser = 'drives:toggle-main'; + } + + /** + * The file browser factory ID. + */ + const FILE_BROWSER_FACTORY = 'DriveBrowser'; + + /** + * The class name added to the drive filebrowser filterbox node. + */ + const FILTERBOX_CLASS = 'jp-drive-browser-search-box'; + + /** + * The drives list provider. + */ + export const drivesListProvider: JupyterFrontEndPlugin = { + id: 'jupyter-drives:drives-list', + description: 'The drives list provider.', + provides: IDrivesList, + activate: async (_: JupyterFrontEnd): Promise => { + let drives: IDriveInfo[] = []; + try { + drives = await getDrivesList(); + } catch (error) { + console.log('Failed loading available drives list, with error: ', error); + } + return drives; + } + }; + + /** + * The drive file browser factory provider. + */ + export const driveFileBrowser: JupyterFrontEndPlugin = { + id: 'jupyter-drives:drives-file-browser', + description: 'The drive file browser factory provider.', + autoStart: true, + requires: [ + IFileBrowserFactory, + IToolbarWidgetRegistry, + ISettingRegistry, + ITranslator, + IDrivesList + ], + optional: [ + IRouter, + JupyterFrontEnd.ITreeResolver, + ILabShell, + ILayoutRestorer + ], + activate: async ( + app: JupyterFrontEnd, + fileBrowserFactory: IFileBrowserFactory, + toolbarRegistry: IToolbarWidgetRegistry, + settingsRegistry: ISettingRegistry, + translator: ITranslator, + drivesList: IDriveInfo[], + router: IRouter | null, + tree: JupyterFrontEnd.ITreeResolver | null, + labShell: ILabShell | null, + restorer: ILayoutRestorer | null + ): Promise => { + console.log( + 'JupyterLab extension jupyter-drives:drives-file-browser is activated!' + ); + const { commands } = app; + + // create drive for drive file browser + const drive = new Drive({ + name: 's3', + drivesList: drivesList + }); + + app.serviceManager.contents.addDrive(drive); + + // get registered file types + drive.getRegisteredFileTypes(app); + + // Manually restore and load the drive file browser. + const driveBrowser = fileBrowserFactory.createFileBrowser('drivebrowser', { + auto: false, + restore: false, + driveName: drive.name + }); + + // Set attributes when adding the browser to the UI + driveBrowser.node.setAttribute('role', 'region'); + driveBrowser.node.setAttribute('aria-label', 'Drive Browser Section'); + driveBrowser.title.icon = driveBrowserIcon; + driveBrowser.title.caption = 'Drive File Browser'; + driveBrowser.id = 'drive-file-browser'; + + void Private.restoreBrowser(driveBrowser, commands, router, tree, labShell); + + app.shell.add(driveBrowser, 'left', { rank: 102, type: 'File Browser' }); + if (restorer) { + restorer.add(driveBrowser, 'drive-file-browser'); + } + + toolbarRegistry.addFactory( + FILE_BROWSER_FACTORY, + 'uploader', + (fileBrowser: FileBrowser) => + new Uploader({ model: fileBrowser.model, translator }) + ); + + toolbarRegistry.addFactory( + FILE_BROWSER_FACTORY, + 'file-name-searcher', + (fileBrowser: FileBrowser) => { + const searcher = FilenameSearcher({ + updateFilter: ( + filterFn: (item: string) => Partial | null, + query?: string + ) => { + fileBrowser.model.setFilter(value => { + return filterFn(value.name.toLowerCase()); + }); + }, + useFuzzyFilter: true, + placeholder: 'Filter files by names', + forceRefresh: true + }); + searcher.addClass(FILTERBOX_CLASS); + return searcher; + } + ); + + // connect the filebrowser toolbar to the settings registry for the plugin + setToolbar( + driveBrowser, + createToolbarFactory( + toolbarRegistry, + settingsRegistry, + FILE_BROWSER_FACTORY, + driveFileBrowser.id, + translator + ) + ); + + /** + * Load the settings for this extension + * + * @param setting Extension settings + */ + function loadSetting(setting: ISettingRegistry.ISettings): void { + // Read the settings and convert to the correct type + const maxFilesListed = setting.get('maxFilesListed').composite as number; + // Set new limit. + setListingLimit(maxFilesListed); + } + + // Wait for the application to be restored and + // for the settings for this plugin to be loaded + Promise.all([app.restored, settingsRegistry.load(driveFileBrowser.id)]) + .then(([, setting]) => { + // Read the settings + loadSetting(setting); + + // Listen for your plugin setting changes using Signal + setting.changed.connect(loadSetting); + }) + .catch(reason => { + console.error( + `Something went wrong when reading the settings.\n${reason}` + ); + }); + } + }; + + namespace Private { + /** + * Restores file browser state and overrides state if tree resolver resolves. + */ + export async function restoreBrowser( + browser: FileBrowser, + commands: CommandRegistry, + router: IRouter | null, + tree: JupyterFrontEnd.ITreeResolver | null, + labShell: ILabShell | null + ): Promise { + const restoring = 'jp-mod-restoring'; + + browser.addClass(restoring); + + if (!router) { + await browser.model.restore(browser.id); + await browser.model.refresh(); + browser.removeClass(restoring); + return; + } + + const listener = async () => { + router.routed.disconnect(listener); + + const paths = await tree?.paths; + if (paths?.file || paths?.browser) { + // Restore the model without populating it. + await browser.model.restore(browser.id, false); + if (paths.file) { + await commands.execute(CommandIDs.openPath, { + path: paths.file, + dontShowBrowser: true + }); + } + if (paths.browser) { + await commands.execute(CommandIDs.openPath, { + path: paths.browser, + dontShowBrowser: true + }); + } + } else { + await browser.model.restore(browser.id); + await browser.model.refresh(); + } + browser.removeClass(restoring); + + if (labShell?.isEmpty('main')) { + void commands.execute('launcher:create'); + } + }; + router.routed.connect(listener); + } + } + \ No newline at end of file diff --git a/src/plugins/driveDialogPlugin.ts b/src/plugins/driveDialogPlugin.ts new file mode 100644 index 0000000..6fec972 --- /dev/null +++ b/src/plugins/driveDialogPlugin.ts @@ -0,0 +1,129 @@ +import { + JupyterFrontEnd, + JupyterFrontEndPlugin + } from '@jupyterlab/application'; + import { + IFileBrowserFactory + } from '@jupyterlab/filebrowser'; + import { ITranslator } from '@jupyterlab/translation'; + import { addJupyterLabThemeChangeListener } from '@jupyter/web-components'; + import { + Dialog, + showDialog + } from '@jupyterlab/apputils'; + + import { DriveListModel, DriveListView, IDrive } from './drivelistmanager'; + import { DriveIcon } from '../icons'; + + /** + * The command IDs used by the driveBrowser plugin. + */ + namespace CommandIDs { + export const openDrivesDialog = 'drives:open-drives-dialog'; + export const openPath = 'drives:open-path'; + export const toggleBrowser = 'drives:toggle-main'; + } + + export const openDriveDialogPlugin: JupyterFrontEndPlugin = { + id: 'jupyter-drives:widget', + description: 'Open a dialog to select drives to be added in the filebrowser.', + requires: [IFileBrowserFactory, ITranslator], + autoStart: true, + activate: ( + app: JupyterFrontEnd, + factory: IFileBrowserFactory, + translator: ITranslator + ): void => { + addJupyterLabThemeChangeListener(); + const { commands } = app; + const { tracker } = factory; + const trans = translator.load('jupyter_drives'); + const selectedDrivesModelMap = new Map(); + + let selectedDrives: IDrive[] = [ + { + name: 'CoconutDrive', + url: '/coconut/url' + } + ]; + + const availableDrives: IDrive[] = [ + { + name: 'CoconutDrive', + url: '/coconut/url' + }, + { + name: 'PearDrive', + url: '/pear/url' + }, + { + name: 'StrawberryDrive', + url: '/strawberrydrive/url' + }, + { + name: 'BlueberryDrive', + url: '/blueberrydrive/url' + }, + { + name: '', + url: '/mydrive/url' + }, + { + name: 'RaspberryDrive', + url: '/raspberrydrive/url' + }, + + { + name: 'PineAppleDrive', + url: '' + }, + + { name: 'PomeloDrive', url: '/https://pomelodrive/url' }, + { + name: 'OrangeDrive', + url: '' + }, + { + name: 'TomatoDrive', + url: '' + }, + { + name: '', + url: 'superDrive/url' + }, + { + name: 'AvocadoDrive', + url: '' + } + ]; + let model = selectedDrivesModelMap.get(selectedDrives); + + //const model = new DriveListModel(availableDrives, selectedDrives); + + commands.addCommand(CommandIDs.openDrivesDialog, { + execute: args => { + const widget = tracker.currentWidget; + + if (!model) { + model = new DriveListModel(availableDrives, selectedDrives); + selectedDrivesModelMap.set(selectedDrives, model); + } else { + selectedDrives = model.selectedDrives; + selectedDrivesModelMap.set(selectedDrives, model); + } + if (widget) { + if (model) { + showDialog({ + body: new DriveListView(model), + buttons: [Dialog.cancelButton()] + }); + } + } + }, + + icon: DriveIcon.bindprops({ stylesheet: 'menuItem' }), + caption: trans.__('Add drives to filebrowser.'), + label: trans.__('Add Drives To Filebrowser') + }); + } + }; diff --git a/src/drivelistmanager.tsx b/src/plugins/drivelistmanager.tsx similarity index 100% rename from src/drivelistmanager.tsx rename to src/plugins/drivelistmanager.tsx diff --git a/src/plugins/index.ts b/src/plugins/index.ts new file mode 100644 index 0000000..b173dc0 --- /dev/null +++ b/src/plugins/index.ts @@ -0,0 +1,3 @@ +export * from './driveBrowserPlugin'; +export * from './launcherPlugin'; +export * from './driveDialogPlugin'; \ No newline at end of file diff --git a/src/launcher.ts b/src/plugins/launcherPlugin.ts similarity index 100% rename from src/launcher.ts rename to src/plugins/launcherPlugin.ts diff --git a/tsconfig.json b/tsconfig.json index 9897917..f7b35af 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -19,5 +19,5 @@ "strictNullChecks": true, "target": "ES2018" }, - "include": ["src/*"] + "include": ["src/**/*"] } From 7c152189c49f6d204e376cd6eb2704937eec3fb9 Mon Sep 17 00:00:00 2001 From: DenisaCG Date: Wed, 18 Dec 2024 13:30:20 +0100 Subject: [PATCH 2/6] lint --- src/plugins/driveBrowserPlugin.ts | 489 +++++++++++++++--------------- src/plugins/driveDialogPlugin.ts | 245 ++++++++------- src/plugins/index.ts | 2 +- 3 files changed, 365 insertions(+), 371 deletions(-) diff --git a/src/plugins/driveBrowserPlugin.ts b/src/plugins/driveBrowserPlugin.ts index 96e73a3..865dae6 100644 --- a/src/plugins/driveBrowserPlugin.ts +++ b/src/plugins/driveBrowserPlugin.ts @@ -1,259 +1,258 @@ import { - ILabShell, - ILayoutRestorer, - IRouter, - JupyterFrontEnd, - JupyterFrontEndPlugin - } from '@jupyterlab/application'; - import { + ILabShell, + ILayoutRestorer, + IRouter, + JupyterFrontEnd, + JupyterFrontEndPlugin +} from '@jupyterlab/application'; +import { + IFileBrowserFactory, + FileBrowser, + Uploader +} from '@jupyterlab/filebrowser'; +import { ITranslator } from '@jupyterlab/translation'; +import { + createToolbarFactory, + IToolbarWidgetRegistry, + setToolbar +} from '@jupyterlab/apputils'; +import { ISettingRegistry } from '@jupyterlab/settingregistry'; +import { FilenameSearcher, IScore } from '@jupyterlab/ui-components'; +import { CommandRegistry } from '@lumino/commands'; + +import { driveBrowserIcon } from '../icons'; +import { Drive } from '../contents'; +import { getDrivesList, setListingLimit } from '../requests'; +import { IDriveInfo, IDrivesList } from '../token'; + +/** + * The command IDs used by the driveBrowser plugin. + */ +namespace CommandIDs { + export const openDrivesDialog = 'drives:open-drives-dialog'; + export const openPath = 'drives:open-path'; + export const toggleBrowser = 'drives:toggle-main'; +} + +/** + * The file browser factory ID. + */ +const FILE_BROWSER_FACTORY = 'DriveBrowser'; + +/** + * The class name added to the drive filebrowser filterbox node. + */ +const FILTERBOX_CLASS = 'jp-drive-browser-search-box'; + +/** + * The drives list provider. + */ +export const drivesListProvider: JupyterFrontEndPlugin = { + id: 'jupyter-drives:drives-list', + description: 'The drives list provider.', + provides: IDrivesList, + activate: async (_: JupyterFrontEnd): Promise => { + let drives: IDriveInfo[] = []; + try { + drives = await getDrivesList(); + } catch (error) { + console.log('Failed loading available drives list, with error: ', error); + } + return drives; + } +}; + +/** + * The drive file browser factory provider. + */ +export const driveFileBrowser: JupyterFrontEndPlugin = { + id: 'jupyter-drives:drives-file-browser', + description: 'The drive file browser factory provider.', + autoStart: true, + requires: [ IFileBrowserFactory, - FileBrowser, - Uploader - } from '@jupyterlab/filebrowser'; - import { ITranslator } from '@jupyterlab/translation'; - import { - createToolbarFactory, IToolbarWidgetRegistry, - setToolbar - } from '@jupyterlab/apputils'; - import { ISettingRegistry } from '@jupyterlab/settingregistry'; - import { FilenameSearcher, IScore } from '@jupyterlab/ui-components'; - import { CommandRegistry } from '@lumino/commands'; + ISettingRegistry, + ITranslator, + IDrivesList + ], + optional: [ + IRouter, + JupyterFrontEnd.ITreeResolver, + ILabShell, + ILayoutRestorer + ], + activate: async ( + app: JupyterFrontEnd, + fileBrowserFactory: IFileBrowserFactory, + toolbarRegistry: IToolbarWidgetRegistry, + settingsRegistry: ISettingRegistry, + translator: ITranslator, + drivesList: IDriveInfo[], + router: IRouter | null, + tree: JupyterFrontEnd.ITreeResolver | null, + labShell: ILabShell | null, + restorer: ILayoutRestorer | null + ): Promise => { + console.log( + 'JupyterLab extension jupyter-drives:drives-file-browser is activated!' + ); + const { commands } = app; - import { driveBrowserIcon } from '../icons'; - import { Drive } from '../contents'; - import { getDrivesList, setListingLimit } from '../requests'; - import { IDriveInfo, IDrivesList } from '../token'; - - /** - * The command IDs used by the driveBrowser plugin. - */ - namespace CommandIDs { - export const openDrivesDialog = 'drives:open-drives-dialog'; - export const openPath = 'drives:open-path'; - export const toggleBrowser = 'drives:toggle-main'; - } - - /** - * The file browser factory ID. - */ - const FILE_BROWSER_FACTORY = 'DriveBrowser'; - - /** - * The class name added to the drive filebrowser filterbox node. - */ - const FILTERBOX_CLASS = 'jp-drive-browser-search-box'; - - /** - * The drives list provider. - */ - export const drivesListProvider: JupyterFrontEndPlugin = { - id: 'jupyter-drives:drives-list', - description: 'The drives list provider.', - provides: IDrivesList, - activate: async (_: JupyterFrontEnd): Promise => { - let drives: IDriveInfo[] = []; - try { - drives = await getDrivesList(); - } catch (error) { - console.log('Failed loading available drives list, with error: ', error); + // create drive for drive file browser + const drive = new Drive({ + name: 's3', + drivesList: drivesList + }); + + app.serviceManager.contents.addDrive(drive); + + // get registered file types + drive.getRegisteredFileTypes(app); + + // Manually restore and load the drive file browser. + const driveBrowser = fileBrowserFactory.createFileBrowser('drivebrowser', { + auto: false, + restore: false, + driveName: drive.name + }); + + // Set attributes when adding the browser to the UI + driveBrowser.node.setAttribute('role', 'region'); + driveBrowser.node.setAttribute('aria-label', 'Drive Browser Section'); + driveBrowser.title.icon = driveBrowserIcon; + driveBrowser.title.caption = 'Drive File Browser'; + driveBrowser.id = 'drive-file-browser'; + + void Private.restoreBrowser(driveBrowser, commands, router, tree, labShell); + + app.shell.add(driveBrowser, 'left', { rank: 102, type: 'File Browser' }); + if (restorer) { + restorer.add(driveBrowser, 'drive-file-browser'); + } + + toolbarRegistry.addFactory( + FILE_BROWSER_FACTORY, + 'uploader', + (fileBrowser: FileBrowser) => + new Uploader({ model: fileBrowser.model, translator }) + ); + + toolbarRegistry.addFactory( + FILE_BROWSER_FACTORY, + 'file-name-searcher', + (fileBrowser: FileBrowser) => { + const searcher = FilenameSearcher({ + updateFilter: ( + filterFn: (item: string) => Partial | null, + query?: string + ) => { + fileBrowser.model.setFilter(value => { + return filterFn(value.name.toLowerCase()); + }); + }, + useFuzzyFilter: true, + placeholder: 'Filter files by names', + forceRefresh: true + }); + searcher.addClass(FILTERBOX_CLASS); + return searcher; } - return drives; + ); + + // connect the filebrowser toolbar to the settings registry for the plugin + setToolbar( + driveBrowser, + createToolbarFactory( + toolbarRegistry, + settingsRegistry, + FILE_BROWSER_FACTORY, + driveFileBrowser.id, + translator + ) + ); + + /** + * Load the settings for this extension + * + * @param setting Extension settings + */ + function loadSetting(setting: ISettingRegistry.ISettings): void { + // Read the settings and convert to the correct type + const maxFilesListed = setting.get('maxFilesListed').composite as number; + // Set new limit. + setListingLimit(maxFilesListed); } - }; - + + // Wait for the application to be restored and + // for the settings for this plugin to be loaded + Promise.all([app.restored, settingsRegistry.load(driveFileBrowser.id)]) + .then(([, setting]) => { + // Read the settings + loadSetting(setting); + + // Listen for your plugin setting changes using Signal + setting.changed.connect(loadSetting); + }) + .catch(reason => { + console.error( + `Something went wrong when reading the settings.\n${reason}` + ); + }); + } +}; + +namespace Private { /** - * The drive file browser factory provider. + * Restores file browser state and overrides state if tree resolver resolves. */ - export const driveFileBrowser: JupyterFrontEndPlugin = { - id: 'jupyter-drives:drives-file-browser', - description: 'The drive file browser factory provider.', - autoStart: true, - requires: [ - IFileBrowserFactory, - IToolbarWidgetRegistry, - ISettingRegistry, - ITranslator, - IDrivesList - ], - optional: [ - IRouter, - JupyterFrontEnd.ITreeResolver, - ILabShell, - ILayoutRestorer - ], - activate: async ( - app: JupyterFrontEnd, - fileBrowserFactory: IFileBrowserFactory, - toolbarRegistry: IToolbarWidgetRegistry, - settingsRegistry: ISettingRegistry, - translator: ITranslator, - drivesList: IDriveInfo[], - router: IRouter | null, - tree: JupyterFrontEnd.ITreeResolver | null, - labShell: ILabShell | null, - restorer: ILayoutRestorer | null - ): Promise => { - console.log( - 'JupyterLab extension jupyter-drives:drives-file-browser is activated!' - ); - const { commands } = app; - - // create drive for drive file browser - const drive = new Drive({ - name: 's3', - drivesList: drivesList - }); - - app.serviceManager.contents.addDrive(drive); - - // get registered file types - drive.getRegisteredFileTypes(app); - - // Manually restore and load the drive file browser. - const driveBrowser = fileBrowserFactory.createFileBrowser('drivebrowser', { - auto: false, - restore: false, - driveName: drive.name - }); - - // Set attributes when adding the browser to the UI - driveBrowser.node.setAttribute('role', 'region'); - driveBrowser.node.setAttribute('aria-label', 'Drive Browser Section'); - driveBrowser.title.icon = driveBrowserIcon; - driveBrowser.title.caption = 'Drive File Browser'; - driveBrowser.id = 'drive-file-browser'; - - void Private.restoreBrowser(driveBrowser, commands, router, tree, labShell); - - app.shell.add(driveBrowser, 'left', { rank: 102, type: 'File Browser' }); - if (restorer) { - restorer.add(driveBrowser, 'drive-file-browser'); - } - - toolbarRegistry.addFactory( - FILE_BROWSER_FACTORY, - 'uploader', - (fileBrowser: FileBrowser) => - new Uploader({ model: fileBrowser.model, translator }) - ); - - toolbarRegistry.addFactory( - FILE_BROWSER_FACTORY, - 'file-name-searcher', - (fileBrowser: FileBrowser) => { - const searcher = FilenameSearcher({ - updateFilter: ( - filterFn: (item: string) => Partial | null, - query?: string - ) => { - fileBrowser.model.setFilter(value => { - return filterFn(value.name.toLowerCase()); - }); - }, - useFuzzyFilter: true, - placeholder: 'Filter files by names', - forceRefresh: true + export async function restoreBrowser( + browser: FileBrowser, + commands: CommandRegistry, + router: IRouter | null, + tree: JupyterFrontEnd.ITreeResolver | null, + labShell: ILabShell | null + ): Promise { + const restoring = 'jp-mod-restoring'; + + browser.addClass(restoring); + + if (!router) { + await browser.model.restore(browser.id); + await browser.model.refresh(); + browser.removeClass(restoring); + return; + } + + const listener = async () => { + router.routed.disconnect(listener); + + const paths = await tree?.paths; + if (paths?.file || paths?.browser) { + // Restore the model without populating it. + await browser.model.restore(browser.id, false); + if (paths.file) { + await commands.execute(CommandIDs.openPath, { + path: paths.file, + dontShowBrowser: true }); - searcher.addClass(FILTERBOX_CLASS); - return searcher; } - ); - - // connect the filebrowser toolbar to the settings registry for the plugin - setToolbar( - driveBrowser, - createToolbarFactory( - toolbarRegistry, - settingsRegistry, - FILE_BROWSER_FACTORY, - driveFileBrowser.id, - translator - ) - ); - - /** - * Load the settings for this extension - * - * @param setting Extension settings - */ - function loadSetting(setting: ISettingRegistry.ISettings): void { - // Read the settings and convert to the correct type - const maxFilesListed = setting.get('maxFilesListed').composite as number; - // Set new limit. - setListingLimit(maxFilesListed); - } - - // Wait for the application to be restored and - // for the settings for this plugin to be loaded - Promise.all([app.restored, settingsRegistry.load(driveFileBrowser.id)]) - .then(([, setting]) => { - // Read the settings - loadSetting(setting); - - // Listen for your plugin setting changes using Signal - setting.changed.connect(loadSetting); - }) - .catch(reason => { - console.error( - `Something went wrong when reading the settings.\n${reason}` - ); - }); - } - }; - - namespace Private { - /** - * Restores file browser state and overrides state if tree resolver resolves. - */ - export async function restoreBrowser( - browser: FileBrowser, - commands: CommandRegistry, - router: IRouter | null, - tree: JupyterFrontEnd.ITreeResolver | null, - labShell: ILabShell | null - ): Promise { - const restoring = 'jp-mod-restoring'; - - browser.addClass(restoring); - - if (!router) { + if (paths.browser) { + await commands.execute(CommandIDs.openPath, { + path: paths.browser, + dontShowBrowser: true + }); + } + } else { await browser.model.restore(browser.id); await browser.model.refresh(); - browser.removeClass(restoring); - return; } - - const listener = async () => { - router.routed.disconnect(listener); - - const paths = await tree?.paths; - if (paths?.file || paths?.browser) { - // Restore the model without populating it. - await browser.model.restore(browser.id, false); - if (paths.file) { - await commands.execute(CommandIDs.openPath, { - path: paths.file, - dontShowBrowser: true - }); - } - if (paths.browser) { - await commands.execute(CommandIDs.openPath, { - path: paths.browser, - dontShowBrowser: true - }); - } - } else { - await browser.model.restore(browser.id); - await browser.model.refresh(); - } - browser.removeClass(restoring); - - if (labShell?.isEmpty('main')) { - void commands.execute('launcher:create'); - } - }; - router.routed.connect(listener); - } + browser.removeClass(restoring); + + if (labShell?.isEmpty('main')) { + void commands.execute('launcher:create'); + } + }; + router.routed.connect(listener); } - \ No newline at end of file +} diff --git a/src/plugins/driveDialogPlugin.ts b/src/plugins/driveDialogPlugin.ts index 6fec972..dcf4e7d 100644 --- a/src/plugins/driveDialogPlugin.ts +++ b/src/plugins/driveDialogPlugin.ts @@ -1,129 +1,124 @@ import { - JupyterFrontEnd, - JupyterFrontEndPlugin - } from '@jupyterlab/application'; - import { - IFileBrowserFactory - } from '@jupyterlab/filebrowser'; - import { ITranslator } from '@jupyterlab/translation'; - import { addJupyterLabThemeChangeListener } from '@jupyter/web-components'; - import { - Dialog, - showDialog - } from '@jupyterlab/apputils'; - - import { DriveListModel, DriveListView, IDrive } from './drivelistmanager'; - import { DriveIcon } from '../icons'; + JupyterFrontEnd, + JupyterFrontEndPlugin +} from '@jupyterlab/application'; +import { IFileBrowserFactory } from '@jupyterlab/filebrowser'; +import { ITranslator } from '@jupyterlab/translation'; +import { addJupyterLabThemeChangeListener } from '@jupyter/web-components'; +import { Dialog, showDialog } from '@jupyterlab/apputils'; - /** - * The command IDs used by the driveBrowser plugin. - */ - namespace CommandIDs { - export const openDrivesDialog = 'drives:open-drives-dialog'; - export const openPath = 'drives:open-path'; - export const toggleBrowser = 'drives:toggle-main'; - } - - export const openDriveDialogPlugin: JupyterFrontEndPlugin = { - id: 'jupyter-drives:widget', - description: 'Open a dialog to select drives to be added in the filebrowser.', - requires: [IFileBrowserFactory, ITranslator], - autoStart: true, - activate: ( - app: JupyterFrontEnd, - factory: IFileBrowserFactory, - translator: ITranslator - ): void => { - addJupyterLabThemeChangeListener(); - const { commands } = app; - const { tracker } = factory; - const trans = translator.load('jupyter_drives'); - const selectedDrivesModelMap = new Map(); - - let selectedDrives: IDrive[] = [ - { - name: 'CoconutDrive', - url: '/coconut/url' - } - ]; - - const availableDrives: IDrive[] = [ - { - name: 'CoconutDrive', - url: '/coconut/url' - }, - { - name: 'PearDrive', - url: '/pear/url' - }, - { - name: 'StrawberryDrive', - url: '/strawberrydrive/url' - }, - { - name: 'BlueberryDrive', - url: '/blueberrydrive/url' - }, - { - name: '', - url: '/mydrive/url' - }, - { - name: 'RaspberryDrive', - url: '/raspberrydrive/url' - }, - - { - name: 'PineAppleDrive', - url: '' - }, - - { name: 'PomeloDrive', url: '/https://pomelodrive/url' }, - { - name: 'OrangeDrive', - url: '' - }, - { - name: 'TomatoDrive', - url: '' - }, - { - name: '', - url: 'superDrive/url' - }, - { - name: 'AvocadoDrive', - url: '' +import { DriveListModel, DriveListView, IDrive } from './drivelistmanager'; +import { DriveIcon } from '../icons'; + +/** + * The command IDs used by the driveBrowser plugin. + */ +namespace CommandIDs { + export const openDrivesDialog = 'drives:open-drives-dialog'; + export const openPath = 'drives:open-path'; + export const toggleBrowser = 'drives:toggle-main'; +} + +export const openDriveDialogPlugin: JupyterFrontEndPlugin = { + id: 'jupyter-drives:widget', + description: 'Open a dialog to select drives to be added in the filebrowser.', + requires: [IFileBrowserFactory, ITranslator], + autoStart: true, + activate: ( + app: JupyterFrontEnd, + factory: IFileBrowserFactory, + translator: ITranslator + ): void => { + addJupyterLabThemeChangeListener(); + const { commands } = app; + const { tracker } = factory; + const trans = translator.load('jupyter_drives'); + const selectedDrivesModelMap = new Map(); + + let selectedDrives: IDrive[] = [ + { + name: 'CoconutDrive', + url: '/coconut/url' + } + ]; + + const availableDrives: IDrive[] = [ + { + name: 'CoconutDrive', + url: '/coconut/url' + }, + { + name: 'PearDrive', + url: '/pear/url' + }, + { + name: 'StrawberryDrive', + url: '/strawberrydrive/url' + }, + { + name: 'BlueberryDrive', + url: '/blueberrydrive/url' + }, + { + name: '', + url: '/mydrive/url' + }, + { + name: 'RaspberryDrive', + url: '/raspberrydrive/url' + }, + + { + name: 'PineAppleDrive', + url: '' + }, + + { name: 'PomeloDrive', url: '/https://pomelodrive/url' }, + { + name: 'OrangeDrive', + url: '' + }, + { + name: 'TomatoDrive', + url: '' + }, + { + name: '', + url: 'superDrive/url' + }, + { + name: 'AvocadoDrive', + url: '' + } + ]; + let model = selectedDrivesModelMap.get(selectedDrives); + + //const model = new DriveListModel(availableDrives, selectedDrives); + + commands.addCommand(CommandIDs.openDrivesDialog, { + execute: args => { + const widget = tracker.currentWidget; + + if (!model) { + model = new DriveListModel(availableDrives, selectedDrives); + selectedDrivesModelMap.set(selectedDrives, model); + } else { + selectedDrives = model.selectedDrives; + selectedDrivesModelMap.set(selectedDrives, model); } - ]; - let model = selectedDrivesModelMap.get(selectedDrives); - - //const model = new DriveListModel(availableDrives, selectedDrives); - - commands.addCommand(CommandIDs.openDrivesDialog, { - execute: args => { - const widget = tracker.currentWidget; - - if (!model) { - model = new DriveListModel(availableDrives, selectedDrives); - selectedDrivesModelMap.set(selectedDrives, model); - } else { - selectedDrives = model.selectedDrives; - selectedDrivesModelMap.set(selectedDrives, model); - } - if (widget) { - if (model) { - showDialog({ - body: new DriveListView(model), - buttons: [Dialog.cancelButton()] - }); - } + if (widget) { + if (model) { + showDialog({ + body: new DriveListView(model), + buttons: [Dialog.cancelButton()] + }); } - }, - - icon: DriveIcon.bindprops({ stylesheet: 'menuItem' }), - caption: trans.__('Add drives to filebrowser.'), - label: trans.__('Add Drives To Filebrowser') - }); - } - }; + } + }, + + icon: DriveIcon.bindprops({ stylesheet: 'menuItem' }), + caption: trans.__('Add drives to filebrowser.'), + label: trans.__('Add Drives To Filebrowser') + }); + } +}; diff --git a/src/plugins/index.ts b/src/plugins/index.ts index b173dc0..c71e029 100644 --- a/src/plugins/index.ts +++ b/src/plugins/index.ts @@ -1,3 +1,3 @@ export * from './driveBrowserPlugin'; export * from './launcherPlugin'; -export * from './driveDialogPlugin'; \ No newline at end of file +export * from './driveDialogPlugin'; From f036cf8ba135aadb3202103fc2436a0abdd4a8db Mon Sep 17 00:00:00 2001 From: DenisaCG Date: Wed, 18 Dec 2024 13:32:51 +0100 Subject: [PATCH 3/6] move namespace CommandIDs to token.ts --- src/plugins/driveBrowserPlugin.ts | 11 +---------- src/plugins/driveDialogPlugin.ts | 10 +--------- src/plugins/launcherPlugin.ts | 7 +------ src/token.ts | 10 ++++++++++ 4 files changed, 13 insertions(+), 25 deletions(-) diff --git a/src/plugins/driveBrowserPlugin.ts b/src/plugins/driveBrowserPlugin.ts index 865dae6..eca6cde 100644 --- a/src/plugins/driveBrowserPlugin.ts +++ b/src/plugins/driveBrowserPlugin.ts @@ -23,16 +23,7 @@ import { CommandRegistry } from '@lumino/commands'; import { driveBrowserIcon } from '../icons'; import { Drive } from '../contents'; import { getDrivesList, setListingLimit } from '../requests'; -import { IDriveInfo, IDrivesList } from '../token'; - -/** - * The command IDs used by the driveBrowser plugin. - */ -namespace CommandIDs { - export const openDrivesDialog = 'drives:open-drives-dialog'; - export const openPath = 'drives:open-path'; - export const toggleBrowser = 'drives:toggle-main'; -} +import { IDriveInfo, IDrivesList, CommandIDs } from '../token'; /** * The file browser factory ID. diff --git a/src/plugins/driveDialogPlugin.ts b/src/plugins/driveDialogPlugin.ts index dcf4e7d..75480f7 100644 --- a/src/plugins/driveDialogPlugin.ts +++ b/src/plugins/driveDialogPlugin.ts @@ -9,15 +9,7 @@ import { Dialog, showDialog } from '@jupyterlab/apputils'; import { DriveListModel, DriveListView, IDrive } from './drivelistmanager'; import { DriveIcon } from '../icons'; - -/** - * The command IDs used by the driveBrowser plugin. - */ -namespace CommandIDs { - export const openDrivesDialog = 'drives:open-drives-dialog'; - export const openPath = 'drives:open-path'; - export const toggleBrowser = 'drives:toggle-main'; -} +import { CommandIDs } from '../token'; export const openDriveDialogPlugin: JupyterFrontEndPlugin = { id: 'jupyter-drives:widget', diff --git a/src/plugins/launcherPlugin.ts b/src/plugins/launcherPlugin.ts index 3889233..ca7e767 100644 --- a/src/plugins/launcherPlugin.ts +++ b/src/plugins/launcherPlugin.ts @@ -12,12 +12,7 @@ import { find } from '@lumino/algorithm'; import { ReadonlyPartialJSONObject } from '@lumino/coreutils'; import { DockPanel, TabBar, Widget } from '@lumino/widgets'; -/** - * The command IDs used by the launcher plugin. - */ -namespace CommandIDs { - export const launcher = 'launcher:create'; -} +import { CommandIDs } from '../token'; /** * A service providing an interface to the the launcher. diff --git a/src/token.ts b/src/token.ts index c5cc57a..1516805 100644 --- a/src/token.ts +++ b/src/token.ts @@ -1,6 +1,16 @@ import { Token } from '@lumino/coreutils'; import { Contents } from '@jupyterlab/services'; +/** + * The command IDs used by the driveBrowser plugin. + */ +export namespace CommandIDs { + export const openDrivesDialog = 'drives:open-drives-dialog'; + export const openPath = 'drives:open-path'; + export const toggleBrowser = 'drives:toggle-main'; + export const launcher = 'launcher:create'; +} + /** * A token for the plugin that provides the list of drives. */ From 01876d6cbf344fda4c457867c1bbe3039bea7cbe Mon Sep 17 00:00:00 2001 From: DenisaCG Date: Wed, 18 Dec 2024 13:37:45 +0100 Subject: [PATCH 4/6] move DrivesResponseError class --- src/drivesError.ts | 35 ----------------------------------- src/handler.ts | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 36 deletions(-) delete mode 100644 src/drivesError.ts diff --git a/src/drivesError.ts b/src/drivesError.ts deleted file mode 100644 index 36a6f87..0000000 --- a/src/drivesError.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { ReadonlyJSONObject } from '@lumino/coreutils'; -import { ServerConnection } from '@jupyterlab/services'; - -/** - * A wrapped error for a fetch response. - */ -export class DrivesResponseError extends ServerConnection.ResponseError { - /** - * Create a new response error. - */ - constructor( - response: Response, - message = `Invalid response: ${response.status} ${response.statusText}`, - traceback = '', - json: ReadonlyJSONObject | null = {} - ) { - super(response, message); - this.traceback = traceback; // traceback added in mother class in 2.2.x - this._json = json ?? {}; - } - - /** - * The error response JSON body - */ - get json(): ReadonlyJSONObject { - return this._json; - } - - /** - * The traceback associated with the error. - */ - traceback: string; - - protected _json: ReadonlyJSONObject; -} diff --git a/src/handler.ts b/src/handler.ts index a2f8cc2..f286444 100644 --- a/src/handler.ts +++ b/src/handler.ts @@ -2,7 +2,7 @@ import { URLExt } from '@jupyterlab/coreutils'; import { ServerConnection } from '@jupyterlab/services'; import { ReadonlyJSONObject } from '@lumino/coreutils'; -import { DrivesResponseError } from './drivesError'; +// import { DrivesResponseError } from './drivesError'; /** * Array of Jupyter Drives Auth Error Messages. @@ -15,6 +15,39 @@ export const AUTH_ERROR_MESSAGES = [ 'Authentication error' ]; +/** + * A wrapped error for a fetch response. + */ +export class DrivesResponseError extends ServerConnection.ResponseError { + /** + * Create a new response error. + */ + constructor( + response: Response, + message = `Invalid response: ${response.status} ${response.statusText}`, + traceback = '', + json: ReadonlyJSONObject | null = {} + ) { + super(response, message); + this.traceback = traceback; // traceback added in mother class in 2.2.x + this._json = json ?? {}; + } + + /** + * The error response JSON body + */ + get json(): ReadonlyJSONObject { + return this._json; + } + + /** + * The traceback associated with the error. + */ + traceback: string; + + protected _json: ReadonlyJSONObject; +} + /** * Call the API extension * From 4a6252998c6dec6a648d39b7d2c6f17865fb5a14 Mon Sep 17 00:00:00 2001 From: DenisaCG Date: Wed, 18 Dec 2024 13:40:28 +0100 Subject: [PATCH 5/6] remove extra drive icon --- src/icons.ts | 6 ---- src/plugins/driveDialogPlugin.ts | 4 +-- style/drive.svg | 58 -------------------------------- 3 files changed, 2 insertions(+), 66 deletions(-) delete mode 100644 style/drive.svg diff --git a/src/icons.ts b/src/icons.ts index 722bc45..23a6a94 100644 --- a/src/icons.ts +++ b/src/icons.ts @@ -1,12 +1,6 @@ import { LabIcon } from '@jupyterlab/ui-components'; -import driveSvgstr from '../style/drive.svg'; import driveBrowserSvg from '../style/driveIconFileBrowser.svg'; -export const DriveIcon = new LabIcon({ - name: 'jupyter-drives:drive', - svgstr: driveSvgstr -}); - export const driveBrowserIcon = new LabIcon({ name: 'jupyter-drives:drive-browser', svgstr: driveBrowserSvg diff --git a/src/plugins/driveDialogPlugin.ts b/src/plugins/driveDialogPlugin.ts index 75480f7..81b125f 100644 --- a/src/plugins/driveDialogPlugin.ts +++ b/src/plugins/driveDialogPlugin.ts @@ -8,7 +8,7 @@ import { addJupyterLabThemeChangeListener } from '@jupyter/web-components'; import { Dialog, showDialog } from '@jupyterlab/apputils'; import { DriveListModel, DriveListView, IDrive } from './drivelistmanager'; -import { DriveIcon } from '../icons'; +import { driveBrowserIcon } from '../icons'; import { CommandIDs } from '../token'; export const openDriveDialogPlugin: JupyterFrontEndPlugin = { @@ -108,7 +108,7 @@ export const openDriveDialogPlugin: JupyterFrontEndPlugin = { } }, - icon: DriveIcon.bindprops({ stylesheet: 'menuItem' }), + icon: driveBrowserIcon.bindprops({ stylesheet: 'menuItem' }), caption: trans.__('Add drives to filebrowser.'), label: trans.__('Add Drives To Filebrowser') }); diff --git a/style/drive.svg b/style/drive.svg deleted file mode 100644 index 3fbc51e..0000000 --- a/style/drive.svg +++ /dev/null @@ -1,58 +0,0 @@ - - - - - - - From 82eecb844b0bf38fb549c0770bf0c55e60af5ab7 Mon Sep 17 00:00:00 2001 From: DenisaCG Date: Wed, 18 Dec 2024 13:41:38 +0100 Subject: [PATCH 6/6] remove unused import --- src/handler.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/handler.ts b/src/handler.ts index f286444..5763253 100644 --- a/src/handler.ts +++ b/src/handler.ts @@ -2,8 +2,6 @@ import { URLExt } from '@jupyterlab/coreutils'; import { ServerConnection } from '@jupyterlab/services'; import { ReadonlyJSONObject } from '@lumino/coreutils'; -// import { DrivesResponseError } from './drivesError'; - /** * Array of Jupyter Drives Auth Error Messages. */