Skip to content

Commit

Permalink
Merge pull request #17 from the-virtual-brain/EBR-97
Browse files Browse the repository at this point in the history
EBR-97: resolve uploading files to bucket from file browser
  • Loading branch information
liadomide authored Sep 11, 2024
2 parents 8c0ec94 + bdd0b63 commit bf63e27
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 128 deletions.
51 changes: 33 additions & 18 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ on:
pull_request:
types: [opened, synchronize, reopened]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
build:
Expand All @@ -29,15 +26,15 @@ jobs:
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1

- name: Install dependencies
run: python -m pip install -U "jupyterlab>=4.0.0,<5" ebrains-drive pytest pytest-mock "pytest-jupyter[server]>=0.6.0" pytest_tornasync pytest-cov
run: python -m pip install -U "jupyterlab>=4.0.0,<5" ebrains-drive pytest pytest-mock "pytest-jupyter[server]>=0.6.0" pytest_tornasync build

- name: Lint the extension
run: |
set -eux
jlpm
jlpm run lint:check
- name: Test the extension
- name: Test the extension with jlpm
run: |
set -eux
jlpm run test
Expand All @@ -47,13 +44,15 @@ jobs:
set -eux
python -m pip install .[test]
pytest -vv -r ap --cov --cov-report=xml tvb_ext_bucket
jupyter server extension list
jupyter server extension list 2>&1 | grep -ie "tvb_ext_bucket.*OK"
jupyter labextension list
jupyter labextension list 2>&1 | grep -ie "tvb-ext-bucket.*OK"
python -m jupyterlab.browser_check
- name: Run Python & JS tests
run: |
set -eux
pytest tvb_ext_bucket -r ap
yarn test
- name: Package the extension
run: |
Expand All @@ -63,19 +62,38 @@ jobs:
python -m build
pip uninstall -y "tvb-ext-bucket" jupyterlab
- name: SonarCloud Scan
uses: sonarsource/sonarcloud-github-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

- name: Upload extension packages
uses: actions/upload-artifact@v4
with:
name: extension-artifacts-${{ matrix.python-version }}
path: dist/tvb_ext_bucket*
if-no-files-found: error

sonar_cloud:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Base Setup
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1

- name: Install dependencies
run: python -m pip install -U "jupyterlab>=4.0.0,<5" ebrains-drive pytest pytest-mock "pytest-jupyter[server]>=0.6.0" pytest_tornasync pytest-cov

- name: Compute coverage
run: |
python -m pip install .[test]
pytest -vv -r ap --cov --cov-report=xml tvb_ext_bucket
yarn test --coverage
- name: SonarCloud Scan
uses: sonarsource/sonarcloud-github-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

test_isolated:
needs: build
runs-on: ubuntu-latest
Expand All @@ -99,10 +117,7 @@ jobs:
pip install "jupyterlab>=4.0.0,<5" tvb_ext_bucket*.whl
jupyter server extension list
jupyter server extension list 2>&1 | grep -ie "tvb_ext_bucket.*OK"
jupyter labextension list
jupyter labextension list 2>&1 | grep -ie "tvb-ext-bucket.*OK"
python -m jupyterlab.browser_check --no-browser-test
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pip install -e ".[test]"
# Link your development version of the extension with JupyterLab
jupyter labextension develop . --overwrite
# Server extension must be manually installed in develop mode
jupyter server extension enable tvb_ext_bucket
jupyter server extension enable tvbextbucket
# Rebuild extension Typescript source after making changes
jlpm build
```
Expand Down
32 changes: 15 additions & 17 deletions src/DropZone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import React, {
useCallback,
useMemo
} from 'react';
import { Drag, IDragEvent } from '@lumino/dragdrop'; // must use the deprecated interface
import { Drag } from '@lumino/dragdrop';
import { useBucketContext } from './BucketContext';
import { JpFileBrowser } from './JpFileBrowser';
import { MimeData } from '@lumino/coreutils';
Expand Down Expand Up @@ -62,10 +62,9 @@ export const DropZone: React.FC<DropZone.IProps> = ({
let isValidDragSource = false;

let item = possibleTargets?.next();
while (item) {
const currentItem = item.value;
items.push(currentItem);
if (currentItem.name === dragSourceElement?.innerText) {
while (item.value) {
items.push(item.value);
if (item.value.name === dragSourceElement?.innerText) {
isValidDragSource = true;
}
item = possibleTargets?.next();
Expand Down Expand Up @@ -100,43 +99,43 @@ export const DropZone: React.FC<DropZone.IProps> = ({
console.log('handling: ', ev.type);
switch (ev.type) {
case 'lm-dragenter':
handler._dragEnter(ev as IDragEvent);
handler._dragEnter(ev as Drag.Event);
break;
case 'lm-dragover':
handler._dragOver(ev as IDragEvent);
handler._dragOver(ev as Drag.Event);
break;
case 'lm-drop':
handler
._drop(ev as IDragEvent)
._drop(ev as Drag.Event)
.then(() => console.log('drop handled'));
break;
case 'lm-dragleave':
handler._dragLeave(ev as IDragEvent);
handler._dragLeave(ev as Drag.Event);
break;
}
},
_dragEnter: (ev: IDragEvent): void => {
_dragEnter: (ev: Drag.Event): void => {
ev.preventDefault();
ev.stopPropagation();
setMode('hover');
Drag.overrideCursor('pointer');
},
_dragOver: (ev: IDragEvent): void => {
_dragOver: (ev: Drag.Event): void => {
ev.preventDefault();
ev.stopPropagation();
ev.dropAction = ev.proposedAction; // needed to trigger lm-drop
Drag.overrideCursor('pointer');
setMode('hover');
},
_dragLeave: (ev: IDragEvent): void => {
_dragLeave: (ev: Drag.Event): void => {
ev.preventDefault();
ev.stopPropagation();
Drag.overrideCursor('auto');
setMode('default');
},
_drop: async (ev: IDragEvent): Promise<void> => {
_drop: async (ev: Drag.Event): Promise<void> => {
ev.preventDefault();
ev.stopPropagation();
if (!ev.source) {
return;
}
if (uploadingRef.current) {
await showErrorMessage(
notAllowedUpload.title,
Expand All @@ -154,7 +153,6 @@ export const DropZone: React.FC<DropZone.IProps> = ({
);
}

Drag.overrideCursor('auto');
setMode('default');
setUploading(false);
}
Expand Down
13 changes: 9 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import {
JupyterFrontEndPlugin
} from '@jupyterlab/application';

import { IFileBrowserFactory } from '@jupyterlab/filebrowser';
import {
IFileBrowserFactory,
IDefaultFileBrowser
} from '@jupyterlab/filebrowser';

import { ICommandPalette, WidgetTracker } from '@jupyterlab/apputils';

Expand All @@ -27,20 +30,22 @@ const plugin: JupyterFrontEndPlugin<void> = {
ILayoutRestorer,
IConsoleTracker,
ILabShell,
IFileBrowserFactory
IFileBrowserFactory,
IDefaultFileBrowser
],
activate: (
app: JupyterFrontEnd,
palette: ICommandPalette,
restorer: ILayoutRestorer,
consoleTracker: IConsoleTracker,
labShell: ILabShell,
fileBrowserFactory: IFileBrowserFactory
fileBrowserFactory: IFileBrowserFactory,
defaultFileBrowser: IDefaultFileBrowser
) => {
console.log('JupyterLab extension tvb-ext-bucket is activated!');

// set up the default file browser
JpFileBrowser.current = fileBrowserFactory.createFileBrowser('default');
JpFileBrowser.current = defaultFileBrowser;

const id = 'tvb-ext-bucket';
const sidebar = new BucketWidget();
Expand Down
Loading

0 comments on commit bf63e27

Please sign in to comment.