diff --git a/.editorconfig b/.editorconfig index 8ef8dba4..6625563e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -21,16 +21,19 @@ insert_final_newline = true [*.js] indent_style = space indent_size = 2 +quote_type = single # Set properties for TypeScript files: [*.ts] indent_style = space indent_size = 2 +quote_type = single # Set properties for TSX files: [*.tsx] indent_style = space indent_size = 2 +quote_type = single # Set properties for Python files: [*.py] diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b7191825..b63a7f19 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,12 +6,12 @@ jobs: - uses: actions/checkout@v1 - uses: actions/setup-python@v1 with: - python-version: "3.6" + python-version: '3.6' - uses: actions/setup-node@v1 with: - node-version: "10.x" + node-version: '10.x' - run: python -m pip install --upgrade pip - - run: pip install --pre jupyterlab + - run: pip install jupyterlab - run: jlpm - run: jlpm run lint:check test: @@ -21,15 +21,13 @@ jobs: - uses: actions/checkout@v1 - uses: actions/setup-python@v1 with: - python-version: "3.6" + python-version: '3.6' - uses: actions/setup-node@v1 with: - node-version: "10.x" + node-version: '10.x' - run: python -m pip install --upgrade pip - - run: pip install --pre jupyterlab + - run: pip install jupyterlab - run: jlpm run build - - run: jlpm run registry &>/dev/null & - - run: jlpm run registry:init - run: jupyter lab build --debug-log-path log.txt - if: failure() run: cat log.txt diff --git a/.yarnrc b/.yarnrc deleted file mode 100644 index 62f1b2a7..00000000 --- a/.yarnrc +++ /dev/null @@ -1,13 +0,0 @@ -#/ -# @license BSD-3-Clause -# -# Copyright (c) 2019 Project Jupyter Contributors. -# Distributed under the terms of the 3-Clause BSD License. -#/ - -# Configuration for [yarn][1]. -# -# [1]: https://yarnpkg.com/lang/en/docs/yarnrc/ - -# Disable the creation of a lock file: ---install.no-lockfile true diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8272ef7c..a624978b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -161,6 +161,21 @@ Tests should accompany **all** bug fixes and features. For guidance on how to wr Any [pull requests][github-pull-request] which include failing tests and/or lint errors will **not** be accepted. +To setup dev environment and run JupyterLab: + +```bash +$ jlpm run build +$ jupyter lab build +$ jupyter lab +``` + +To make changes and have JupyterLab rebuild withour restarting: + +```bash +$ jlpm run build:watch +$ jupyter lab --watch +``` + To run tests: ```bash diff --git a/README.md b/README.md index 97d12552..854a8a79 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ To experiment with the extension in a live notebook environment, - Bring any data type you can imagine! **Extensible** and **type safe** data registry system. - Register **conversions** between the different data types. - Data changing on you? Use [`RxJS` **observables**][rxjs] to represent data over time. -- Have a new way to look at your data? Create **React** or **Phosphor** components to view a certain type. +- Have a new way to look at your data? Create **React** or **lumino** components to view a certain type. - Built-in data **explorer UI** to find and use available datasets. - Dataset in your dataset? Use the **nested** datatype. - Building another data centric application? Use the [`@jupyterlab/dataregistry`][npm-package-dataregistry] package which can be used independently of [JupyterLab][jupyterlab]. diff --git a/binder/requirements.txt b/binder/requirements.txt index b434766c..28c823bf 100644 --- a/binder/requirements.txt +++ b/binder/requirements.txt @@ -1,3 +1,3 @@ pandas -jupyterlab>=1.0 +jupyterlab>=2.0 vega_datasets diff --git a/datasets.yml b/datasets.yml index a36d1aa8..18233524 100644 --- a/datasets.yml +++ b/datasets.yml @@ -1,13 +1,13 @@ children: - - "test:///hi" + - 'test:///hi' datasets: - - url: "test:///hi" - label: "Custom label!" + - url: 'test:///hi' + label: 'Custom label!' snippets: some code: "It's code!" other code: "It's code!" children: - - "test:///other" - - url: "test:///other" + - 'test:///other' + - url: 'test:///other' snippets: - more code: "another code" + more code: 'another code' diff --git a/etc/eslint/.eslintrc.js b/etc/eslint/.eslintrc.js index 6a61ee3d..79e0fcc7 100644 --- a/etc/eslint/.eslintrc.js +++ b/etc/eslint/.eslintrc.js @@ -10,31 +10,38 @@ const resolve = require('path').resolve; const config = { env: { browser: true, - es6: true + es6: true, }, extends: [ + 'eslint:recommended', 'plugin:@typescript-eslint/eslint-recommended', - 'prettier', - 'prettier/@typescript-eslint' + 'plugin:@typescript-eslint/recommended', + 'prettier/@typescript-eslint', ], parser: '@typescript-eslint/parser', parserOptions: { tsconfigRootDir: resolve(__dirname, '..', '..'), - project: './packages/**/tsconfig.json', + project: ['./tsconfig.test.json', './packages/**/tsconfig.json'], ecmaFeatures: { - jsx: true + jsx: true, }, ecmaVersion: 2018, - sourceType: 'module' + sourceType: 'module', }, plugins: ['prettier', 'react', 'react-hooks', '@typescript-eslint'], rules: { + '@typescript-eslint/no-use-before-define': 'off', + '@typescript-eslint/explicit-function-return-type': 'off', + '@typescript-eslint/no-non-null-assertion': 'off', + '@typescript-eslint/no-unused-vars': 'off', + '@typescript-eslint/interface-name-prefix': 'off', + '@typescript-eslint/no-explicit-any': 'off', 'react-hooks/rules-of-hooks': 'error', 'react-hooks/exhaustive-deps': 'warn', 'prettier/prettier': ['error', { singleQuote: true }], 'linebreak-style': ['error', 'unix'], - 'no-console': ['error', { allow: ['warn', 'error'] }] - } + 'no-console': ['error', { allow: ['warn', 'error'] }], + }, }; /** diff --git a/etc/jest/jest-environment.js b/etc/jest/jest-environment.js index db342601..c1884a29 100644 --- a/etc/jest/jest-environment.js +++ b/etc/jest/jest-environment.js @@ -27,7 +27,7 @@ class CustomEnvironment extends PuppeteerEnvironment { const jestScreenshot = new JestScreenshot({ page: this.global.page, dirName: resolve(__dirname, '..', '..'), - testName + testName, }); await jestScreenshot.setup(); diff --git a/etc/jest/jest-puppeteer.config.js b/etc/jest/jest-puppeteer.config.js index 6978dde9..05449efa 100644 --- a/etc/jest/jest-puppeteer.config.js +++ b/etc/jest/jest-puppeteer.config.js @@ -8,13 +8,13 @@ const config = { launch: { headless: process.env.HEADLESS !== 'false', - slowMo: process.env.SLOWMO === 'true' + slowMo: process.env.SLOWMO === 'true', }, // https://github.com/smooth-code/jest-puppeteer/tree/master/packages/jest-dev-server#options server: { command: "jupyter lab --port 8080 --no-browser --LabApp.token=''", - port: 8080 - } + port: 8080, + }, }; /** diff --git a/etc/jest/jest.config.js b/etc/jest/jest.config.js index 713e9bef..36677875 100644 --- a/etc/jest/jest.config.js +++ b/etc/jest/jest.config.js @@ -22,16 +22,16 @@ const config = { globalTeardown: 'jest-environment-puppeteer/teardown', setupFilesAfterEnv: ['expect-puppeteer'], transform: { - ...tsjPreset.transform + ...tsjPreset.transform, }, moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], testMatch: ['**/test/**/test*.ts?(x)'], testPathIgnorePatterns: ['/build/', '/lib/', '/node_modules/'], globals: { 'ts-jest': { - tsConfig: resolve(ROOT, 'tsconfig.test.json') - } - } + tsConfig: resolve(ROOT, 'tsconfig.test.json'), + }, + }, }; /** diff --git a/etc/lint-staged/lint-staged.config.js b/etc/lint-staged/lint-staged.config.js index eac0a277..aa7c6e92 100644 --- a/etc/lint-staged/lint-staged.config.js +++ b/etc/lint-staged/lint-staged.config.js @@ -13,8 +13,8 @@ const ignore = resolve(__dirname, '..', 'prettier', '.prettierignore'); const config = { '**/*{.ts,.tsx,.js,.jsx,.css,.json,.md}': [ 'prettier --config=' + rc + ' --ignore-path=' + ignore + ' --write', - 'git add' - ] + 'git add', + ], }; /** diff --git a/etc/prettier/.prettierignore b/etc/prettier/.prettierignore deleted file mode 100644 index 54b4d6d3..00000000 --- a/etc/prettier/.prettierignore +++ /dev/null @@ -1,9 +0,0 @@ -node_modules -**/node_modules -**/lib -**/build -**/static -tests/**/coverage -**/package.json -.eggs -.ipynb_checkpoints diff --git a/package.json b/package.json index 135adddd..6e11f7b9 100644 --- a/package.json +++ b/package.json @@ -6,37 +6,29 @@ ] }, "scripts": { - "all": "jlpm run clean && jlpm run build && jlpm run build:jupyter", - "all:watch": "jlpm run clean && jlpm run build && jlpm run build:jupyter:watch", - "build": "jlpm run build:dev", - "build:dev": "jlpm install && jlpm run clean:packages && lerna link && jlpm run build:packages && jlpm run link:packages && jupyter labextension list", - "build:jupyter": "(jupyter lab build || (jlpm run build:jupyter:remediate && jupyter lab build)) && jupyter lab", - "build:jupyter:remediate": "curr_dir=$PWD && (cd $(jupyter lab path | head -n1 | sed s/Application\\ directory:\\ *//)/staging && echo $PWD && echo '\"@jupyterlab:registry\" \"http://localhost:4873\"' >> .yarnrc && cat .yarnrc && YARN_REGISTRY=http://localhost:4873 node ./yarn.js install --non-interactive && cd $curr_dir) || cd $curr_dir", - "build:jupyter:watch": "(jupyter lab build || (jlpm run build:jupyter:remediate && jupyter lab build)) && jupyter lab --watch", - "build:packages": "lerna run build", - "build:watch": "tsc --build --watch --listEmittedFiles packages/*", + "build": "jlpm && lerna bootstrap --hoist && jlpm run build:packages && jlpm run build:packages:post && jlpm run link:packages", + "build:packages": "tsc --build packages/*", + "build:packages:post": "lerna run postBuild", + "build:watch": "jlpm run build:packages --watch --listEmittedFiles", "clean": "jlpm run clean:jupyter && jlpm clean:packages && jlpm clean:node", - "clean:jupyter": "jlpm run uninstall:extensions && (lerna run --no-bail unlink || echo 'At least one unlink command failed, but continuing...') && jupyter lab clean", - "clean:node": "lerna clean --yes && rimraf node_modules", + "clean:jupyter": "jlpm run uninstall:extensions && jupyter lab clean", + "clean:node": "lerna clean --yes && rimraf node_modules yarn.lock", "clean:packages": "lerna run clean", "link:packages": "jupyter labextension link ./packages/* --no-build", - "lint": "jlpm run lint:css && jlpm run lint:typescript", - "lint:check": "jlpm run prettier:check && jlpm run lint:css:check && jlpm run lint:typescript:check", - "lint:css": "stylelint packages/**/*.css --config ./etc/stylelint/.stylelintrc.json --fix", + "lint": "jlpm run lint:css && jlpm run lint:typescript && jlpm run prettier:write", + "lint:check": "jlpm run lint:css:check && jlpm run lint:typescript:check && jlpm run prettier", + "lint:css": "jlpm run lint:css:check --fix", "lint:css:check": "stylelint packages/**/*.css --config ./etc/stylelint/.stylelintrc.json", - "lint:typescript": "eslint --fix packages/**/src/*.ts --config ./etc/eslint/.eslintrc.js", - "lint:typescript:check": "eslint packages/**/src/*.ts --config ./etc/eslint/.eslintrc.js", - "prettier": "prettier --write '**/*{.ts,.tsx,.js,.jsx,.css,.json,.md}' --config ./etc/prettier/.prettierrc --ignore-path ./etc/prettier/.prettierignore", - "prettier:check": "prettier --list-different '**/*{.ts,.tsx,.js,.jsx,.css,.json,.md}' --config ./etc/prettier/.prettierrc --ignore-path ./etc/prettier/.prettierignore", + "lint:typescript": "jlpm run lint:typescript:check --fix", + "lint:typescript:check": "eslint . --ext 'ts,tsx' --ignore-path .gitignore --config ./etc/eslint/.eslintrc.js", + "prettier": "prettier . --config ./etc/prettier/.prettierrc --ignore-path .gitignore --check", + "prettier:write": "jlpm run prettier --write", "rebuild:packages": "jlpm run clean:packages && jlpm run build:packages", - "registry": "verdaccio", - "registry:init": "jlpm run registry:adduser && jlpm run registry:register", - "registry:adduser": "node ./scripts/registry.adduser.js", - "registry:register": "env NPM_USER=foo NPM_PASS=bar NPM_EMAIL=foo@bar.com NPM_REGISTRY=http://localhost:4873 NPM_SCOPE=@jupyterlab npm-cli-login && lerna exec --scope @jupyterlab/dataregistry --scope @jupyterlab/dataregistry-extension --scope @jupyterlab/dataregistry-csvviewer-extension --scope @jupyterlab/dataregistry-registry-extension -- npm publish --registry http://localhost:4873", - "test": "env JEST_PUPPETEER_CONFIG=./etc/jest/jest-puppeteer.config.js jest --runInBand --config ./etc/jest/jest.config.js", - "test:debug": "env HEADLESS=false SLOWMO=true jlpm test", - "uninstall:extensions": "jupyter labextension uninstall --all --no-build", - "unlink:packages": "lerna run unlink" + "test": "jlpm run test:packages && jlpm run test:integration", + "test:packages": "lerna run test", + "test:integration": "env JEST_PUPPETEER_CONFIG=./etc/jest/jest-puppeteer.config.js jest --runInBand --config ./etc/jest/jest.config.js", + "test:integration:debug": "env HEADLESS=false SLOWMO=true jlpm test", + "uninstall:extensions": "jupyter labextension uninstall --all" }, "husky": { "hooks": { @@ -45,34 +37,31 @@ }, "dependencies": {}, "devDependencies": { - "@rws-air/jestscreenshot": "^3.0.3", - "@types/expect-puppeteer": "^3.3.2", - "@types/jest": "^24.0.19", + "@rws-air/jestscreenshot": "^4.0.4", + "@types/expect-puppeteer": "^4.4.1", + "@types/jest": "^25.2.1", "@types/jest-environment-puppeteer": "^4.3.1", - "@types/puppeteer": "^1.20.2", - "@typescript-eslint/eslint-plugin": "^2.11.0", - "@typescript-eslint/parser": "^2.11.0", + "@types/puppeteer": "^2.0.1", + "@typescript-eslint/eslint-plugin": "^2.27.0", + "@typescript-eslint/parser": "^2.27.0", "eslint": "^6.1.0", "eslint-config-prettier": "^6.0.0", "eslint-plugin-prettier": "^3.1.1", "eslint-plugin-react": "^7.14.3", - "eslint-plugin-react-hooks": "^1.6.1", - "husky": "^3.0.9", - "jest": "^24.9.0", - "jest-circus": "^24.9.0", + "eslint-plugin-react-hooks": "^3.0.0", + "husky": "^4.2.3", + "jest": "^25.2.7", + "jest-circus": "^25.2.7", "jest-puppeteer": "^4.3.0", "lerna": "^3.16.4", - "lint-staged": "^9.4.2", - "npm-cli-login": "^0.1.1", - "npm-registry-client": "^8.6.0", - "prettier": "^1.18.2", + "lint-staged": "^10.1.2", + "prettier": "^2.0.4", "puppeteer": "^2.0.0", - "rimraf": "^2.6.2", - "stylelint": "^11.0.0", - "stylelint-config-prettier": "^6.0.0", - "stylelint-config-standard": "^19.0.0", - "ts-jest": "^24.1.0", - "typescript": "^3.5.3", - "verdaccio": "^4.3.2" + "rimraf": "^3.0.2", + "stylelint": "^13.3.0", + "stylelint-config-prettier": "^8.0.1", + "stylelint-config-standard": "^20.0.0", + "ts-jest": "^25.3.1", + "typescript": "^3.5.3" } } diff --git a/packages/dataregistry-csvviewer-extension/package.json b/packages/dataregistry-csvviewer-extension/package.json index e25441f3..ded24438 100644 --- a/packages/dataregistry-csvviewer-extension/package.json +++ b/packages/dataregistry-csvviewer-extension/package.json @@ -28,21 +28,21 @@ "scripts": { "build": "tsc --build", "clean": "rimraf lib tsconfig.tsbuildinfo", - "link": "jupyter labextension link ./ --no-build", "prepublishOnly": "npm run clean && npm run build", - "unlink": "jupyter labextension unlink ./ --no-build", "watch": "tsc --build --watch --listEmittedFiles" }, "dependencies": { - "@jupyterlab/application": "^2.0.0-alpha.4", - "@jupyterlab/csvviewer": "^2.0.0-alpha.4", - "@jupyterlab/dataregistry": "^4.0.0", - "@jupyterlab/dataregistry-registry-extension": "^1.0.0", - "@lumino/datagrid": "^0.3.0", - "@lumino/messaging": "^1.3.0", + "@jupyterlab/application": "^2.1.0", + "@jupyterlab/csvviewer": "^2.1.0", + "@lumino/datagrid": "^0.6.0", + "@lumino/messaging": "^1.2.3", "@lumino/widgets": "^1.9.0", "rxjs": "^6.5.2" }, + "devDependencies": { + "@jupyterlab/dataregistry": "^4.0.0", + "@jupyterlab/dataregistry-registry-extension": "^1.0.0" + }, "publishConfig": { "access": "public" }, diff --git a/packages/dataregistry-csvviewer-extension/src/activate.ts b/packages/dataregistry-csvviewer-extension/src/activate.ts index a711caec..86ec2b6d 100644 --- a/packages/dataregistry-csvviewer-extension/src/activate.ts +++ b/packages/dataregistry-csvviewer-extension/src/activate.ts @@ -20,8 +20,8 @@ import csv2datagrid from './csv_to_data_grid'; */ function activate(app: JupyterFrontEnd, registry: Registry) { registry.addConverter(extension2mimetype()); - registry.addConverter(text2csv()); - registry.addConverter(csv2datagrid()); + registry.addConverter(text2csv); + registry.addConverter(csv2datagrid); } /** diff --git a/packages/dataregistry-csvviewer-extension/src/csv_to_data_grid.ts b/packages/dataregistry-csvviewer-extension/src/csv_to_data_grid.ts index b7e5b5de..be2166ba 100644 --- a/packages/dataregistry-csvviewer-extension/src/csv_to_data_grid.ts +++ b/packages/dataregistry-csvviewer-extension/src/csv_to_data_grid.ts @@ -8,60 +8,15 @@ import { createConverter } from '@jupyterlab/dataregistry'; import datatypes from './datatypes'; // FIXME import DataGrid from './data_grid'; - -/** - * Interface describing an object containing data to convert. - * - * @private - */ -interface Data { - /** - * Data to convert. - */ - data: any; -} - -/** - * Converts CSV data to a data grid. - * - * @private - * @param obj - data object - * @param obj.data - data to convert - * @returns converted data - */ -function convert(obj: Data) { - return { - type: 'Grid', - data: getData - }; - - /** - * Returns a data grid. - * - * @private - * @returns data grid - */ - function getData() { - return new DataGrid(obj.data); - } -} - -/** - * Returns a converter for converting CSV data to a data grid. - * - * @private - * @returns data type converter - */ -function csv2datagrid() { - const conversion = { - from: datatypes.csv, - to: datatypes.widget - }; - - return createConverter(conversion, convert); -} +import { Widget } from '@lumino/widgets'; /** * Exports. */ -export default csv2datagrid; +export default createConverter( + { + from: datatypes.csv, + to: datatypes.widget, + }, + ({ data }) => ({ type: 'Grid', data: (): Widget => new DataGrid(data) }) +); diff --git a/packages/dataregistry-csvviewer-extension/src/data_grid.ts b/packages/dataregistry-csvviewer-extension/src/data_grid.ts index 028d869b..75f3d73b 100644 --- a/packages/dataregistry-csvviewer-extension/src/data_grid.ts +++ b/packages/dataregistry-csvviewer-extension/src/data_grid.ts @@ -10,7 +10,7 @@ import { BasicKeyHandler, BasicMouseHandler, BasicSelectionModel, - DataGrid + DataGrid, } from '@lumino/datagrid'; import { Message } from '@lumino/messaging'; import { DSVModel } from '@jupyterlab/csvviewer'; @@ -41,9 +41,7 @@ class CSVDataGrid extends DataGrid { * * @param msg - message */ - protected onBeforeAttach(msg: Message) { - const self = this; - this._subscription = this._data.subscribe(onData); + protected onBeforeAttach(msg: Message): void { super.onBeforeAttach(msg); /** @@ -52,20 +50,21 @@ class CSVDataGrid extends DataGrid { * @private * @param data - CSV data */ - function onData(data: string) { - if (self.dataModel) { - (self.dataModel as DSVModel).dispose(); + const onData = (data: string): void => { + if (this.dataModel) { + (this.dataModel as DSVModel).dispose(); } - self.dataModel = new DSVModel({ + this.dataModel = new DSVModel({ data: data, - delimiter: ',' + delimiter: ',', }); - self.keyHandler = new BasicKeyHandler(); - self.mouseHandler = new BasicMouseHandler(); - self.selectionModel = new BasicSelectionModel({ - dataModel: self.dataModel + this.keyHandler = new BasicKeyHandler(); + this.mouseHandler = new BasicMouseHandler(); + this.selectionModel = new BasicSelectionModel({ + dataModel: this.dataModel, }); - } + }; + this._subscription = this._data.subscribe(onData); } /** @@ -73,7 +72,7 @@ class CSVDataGrid extends DataGrid { * * @param msg - message */ - protected onBeforeDetach(msg: Message) { + protected onBeforeDetach(msg: Message): void { this._subscription && this._subscription.unsubscribe(); super.onBeforeDetach(msg); } diff --git a/packages/dataregistry-csvviewer-extension/src/datatypes.ts b/packages/dataregistry-csvviewer-extension/src/datatypes.ts index 4c7446e3..20cbfec4 100644 --- a/packages/dataregistry-csvviewer-extension/src/datatypes.ts +++ b/packages/dataregistry-csvviewer-extension/src/datatypes.ts @@ -26,7 +26,7 @@ const datatypes = { widget: new DataTypeStringArg<() => Widget>( 'application/x.jupyter.widget', 'label' - ) + ), }; /** diff --git a/packages/dataregistry-csvviewer-extension/src/extension_to_mimetype.ts b/packages/dataregistry-csvviewer-extension/src/extension_to_mimetype.ts index 68c1714f..e5665656 100644 --- a/packages/dataregistry-csvviewer-extension/src/extension_to_mimetype.ts +++ b/packages/dataregistry-csvviewer-extension/src/extension_to_mimetype.ts @@ -5,7 +5,7 @@ * Distributed under the terms of the 3-Clause BSD License. */ -import { resolveExtensionConverter } from '@jupyterlab/dataregistry'; +import { resolveExtensionConverter, Converter } from '@jupyterlab/dataregistry'; import datatypes from './datatypes'; // FIXME /** @@ -14,7 +14,7 @@ import datatypes from './datatypes'; // FIXME * @private * @returns data type converter */ -function extension2mimetype() { +function extension2mimetype(): Converter { return resolveExtensionConverter('.csv', datatypes.csv.createMimeType()); } diff --git a/packages/dataregistry-csvviewer-extension/src/index.ts b/packages/dataregistry-csvviewer-extension/src/index.ts index 86665657..1cfafaa8 100644 --- a/packages/dataregistry-csvviewer-extension/src/index.ts +++ b/packages/dataregistry-csvviewer-extension/src/index.ts @@ -16,7 +16,7 @@ const extension: JupyterFrontEndPlugin = { id: '@jupyterlab/dataregistry-extension:csv-viewer', activate: activate, autoStart: true, - requires: [IRegistry] + requires: [IRegistry], }; /** diff --git a/packages/dataregistry-csvviewer-extension/src/text_to_csv.ts b/packages/dataregistry-csvviewer-extension/src/text_to_csv.ts index 141da470..4a63f56d 100644 --- a/packages/dataregistry-csvviewer-extension/src/text_to_csv.ts +++ b/packages/dataregistry-csvviewer-extension/src/text_to_csv.ts @@ -8,58 +8,21 @@ import { createConverter } from '@jupyterlab/dataregistry'; import datatypes from './datatypes'; // FIXME -/** - * Interface describing an object containing data to convert. - * - * @private - */ -interface Data { - /** - * Data to convert. - */ - data: any; - - /** - * Desired data type. - */ - type: string; -} - // Generate the CSV MIME type: const CSV_MIME_TYPE: string = datatypes.csv.createMimeType(); -/** - * Converts from text data to CSV. - * - * @private - * @param obj - data object - * @param obj.data - data to convert - * @param obj.type - desired type - * @returns converted data - */ -function convert(obj: Data) { - if (obj.type === CSV_MIME_TYPE) { - return obj.data; - } - return null; -} - -/** - * Returns a converter for converting text data to CSV. - * - * @private - * @returns data type converter - */ -function text2csv() { - const conversion = { - from: datatypes.text, - to: datatypes.csv - }; - - return createConverter(conversion, convert); -} - /** * Exports. */ -export default text2csv; +export default createConverter( + { + from: datatypes.text, + to: datatypes.csv, + }, + ({ type, data }) => { + if (type === CSV_MIME_TYPE) { + return data; + } + return null; + } +); diff --git a/packages/dataregistry-extension/package.json b/packages/dataregistry-extension/package.json index 3642d3ac..8d19691a 100644 --- a/packages/dataregistry-extension/package.json +++ b/packages/dataregistry-extension/package.json @@ -28,45 +28,40 @@ "lib": "./lib" }, "scripts": { - "build": "tsc --build && jlpm run generateSchema", + "build": "tsc --build && jlpm run postBuild", + "postBuild": "jlpm run generateSchema", "clean": "rimraf lib tsconfig.tsbuildinfo", "generateSchema": "ts-json-schema-generator --type datasetsObjectType --no-type-check -f tsconfig.json > lib/datasets-file.schema.json", - "link": "jupyter labextension link ./ --no-build", "prepublishOnly": "npm run clean && npm run build", - "unlink": "jupyter labextension unlink ./ --no-build", "watch": "tsc --build --watch --listEmittedFiles" }, "dependencies": { - "@jupyterlab/application": "^2.0.0-alpha.4", - "@jupyterlab/apputils": "^2.0.0-alpha.4", - "@jupyterlab/cells": "^2.0.0-alpha.4", - "@jupyterlab/dataregistry": "^4.0.0", - "@jupyterlab/dataregistry-registry-extension": "^1.0.0", - "@jupyterlab/docmanager": "^2.0.0-alpha.4", - "@jupyterlab/docregistry": "^2.0.0-alpha.4", - "@jupyterlab/filebrowser": "^2.0.0-alpha.4", - "@jupyterlab/notebook": "^2.0.0-alpha.4", - "@jupyterlab/observables": "^3.0.0-alpha.4", - "@jupyterlab/outputarea": "^2.0.0-alpha.4", - "@jupyterlab/rendermime": "^2.0.0-alpha.4", - "@jupyterlab/services": "^5.0.0-alpha.4", - "@lumino/algorithm": "^1.2.0", - "@lumino/coreutils": "^1.3.1", - "@lumino/signaling": "^1.3.0", - "@lumino/widgets": "^1.9.0", - "@nteract/data-explorer": "7.0.1", + "@jupyterlab/application": "^2.1.0", + "@jupyterlab/apputils": "^2.1.0", + "@jupyterlab/coreutils": "^4.1.0", + "@jupyterlab/csvviewer": "^2.1.0", + "@jupyterlab/docmanager": "^2.1.0", + "@jupyterlab/docregistry": "^2.1.0", + "@jupyterlab/filebrowser": "^2.1.0", + "@jupyterlab/notebook": "^2.1.0", + "@jupyterlab/rendermime": "^2.1.0", + "@lumino/datagrid": "^0.6.0", + "@lumino/messaging": "^1.2.3", + "@lumino/widgets": "^1.8.0", + "@nteract/data-explorer": "8.0.3", "ajv": "^6.10.2", "js-yaml": "^3.13.1", - "path": "~0.12.7", - "react": "~16.8.4", - "react-inspector": "^3.0.0", + "path": "0.12.7", + "react": "^16.8.4", + "react-inspector": "^5.0.1", "rxjs": "^6.5.2", - "styled-components": "^4.3.2", - "typestyle": "^2.0.1" + "styled-components": "^5.1.0" }, "devDependencies": { + "@jupyterlab/dataregistry": "^4.0.0", + "@jupyterlab/dataregistry-registry-extension": "^1.0.0", "@types/js-yaml": "^3.12.1", - "ts-json-schema-generator": "0.52.14" + "ts-json-schema-generator": "0.65.0" }, "publishConfig": { "access": "public" diff --git a/packages/dataregistry-extension/src/active.ts b/packages/dataregistry-extension/src/active.ts index 2f34a927..661864d5 100644 --- a/packages/dataregistry-extension/src/active.ts +++ b/packages/dataregistry-extension/src/active.ts @@ -8,14 +8,14 @@ import { ILabShell, JupyterFrontEnd, - JupyterFrontEndPlugin + JupyterFrontEndPlugin, } from '@jupyterlab/application'; import { createConverter, nestedDataType, Registry, resolveDataType, - URL_ + URL_, } from '@jupyterlab/dataregistry'; import { IRegistry } from '@jupyterlab/dataregistry-registry-extension'; import { IDocumentManager } from '@jupyterlab/docmanager'; @@ -25,7 +25,7 @@ import { BehaviorSubject } from 'rxjs'; import { map } from 'rxjs/operators'; import { hasURL_ } from './widgets'; -export interface IActiveDataset extends BehaviorSubject {} +export type IActiveDataset = BehaviorSubject; export const IActiveDataset = new Token( '@jupyterlab/dataregistry:IActiveDataset' ); @@ -39,7 +39,7 @@ export default { id: '@jupyterlab/dataregistry-extension:active-dataset', requires: [ILabShell, IRegistry, IDocumentManager], provides: IActiveDataset, - autoStart: true + autoStart: true, } as JupyterFrontEndPlugin; function activate( @@ -52,7 +52,7 @@ function activate( // Show active datasets in explorer registry.addConverter( - createConverter( + createConverter( { from: resolveDataType }, ({ url }) => { if (url.toString() !== ACTIVE_URL) { @@ -60,7 +60,7 @@ function activate( } return { type: nestedDataType.createMimeType(), - data: active.pipe(map(url => (url ? new Set([url]) : new Set()))) + data: active.pipe(map((url) => (url ? new Set([url]) : new Set()))), }; } ) @@ -82,7 +82,7 @@ function getURL_( } const context = docManager.contextForWidget(widget); if (context) { - return new URL(context.session.path, 'file:').toString(); + return new URL(context.path, 'file:').toString(); } if (hasURL_(widget)) { return widget.url; diff --git a/packages/dataregistry-extension/src/browser.tsx b/packages/dataregistry-extension/src/browser.tsx index adb396cb..fd9cdfd1 100644 --- a/packages/dataregistry-extension/src/browser.tsx +++ b/packages/dataregistry-extension/src/browser.tsx @@ -10,20 +10,20 @@ import { ILayoutRestorer, JupyterFrontEnd, JupyterFrontEndPlugin, - ILabShell + ILabShell, } from '@jupyterlab/application'; import { ReactWidget } from '@jupyterlab/apputils'; import { Registry, relativeNestedDataType, nestedDataType, - URL_ + URL_, } from '@jupyterlab/dataregistry'; import { IRegistry } from '@jupyterlab/dataregistry-registry-extension'; import { Widget } from '@lumino/widgets'; import { widgetDataType, reactDataType } from './widgets'; import { IActiveDataset } from '.'; -import { PhosphorWidget } from './utils'; +import { LuminoWidget } from './utils'; import { Observable } from 'rxjs'; function InnerBrowser({ registry, url }: { registry: Registry; url: URL_ }) { @@ -56,9 +56,9 @@ function InnerBrowser({ registry, url }: { registry: Registry; url: URL_ }) { React.useEffect(() => { if (children$) { const subscription = children$.subscribe({ - next: value => { + next: (value) => { setChildren([...value]); - } + }, }); return () => subscription.unsubscribe(); } @@ -81,7 +81,7 @@ function InnerBrowser({ registry, url }: { registry: Registry; url: URL_ }) { for (const child of children) { options.set(`child-${child}`, { value: child, - type: 'child' + type: 'child', }); } @@ -93,7 +93,7 @@ function InnerBrowser({ registry, url }: { registry: Registry; url: URL_ }) { if (!options.has(label) && options.size) { setLabel(options.keys().next().value); } - }, [label, widgets, children]); + }, [label, widgets, children, options]); const Component: React.ReactElement | undefined = React.useMemo(() => { const selected = options.get(label); @@ -104,14 +104,14 @@ function InnerBrowser({ registry, url }: { registry: Registry; url: URL_ }) { const widgetCreator = widgets.get(name); return ( components.get(name) || - (widgetCreator && ) + (widgetCreator && ) ); }, [options, label, components, widgets]); // Use the widget creator to set the current widget return ( <> - setLabel(event.target.value)}> {[...options.entries()].map(([idx, { value, type }]) => (