This repository has been archived by the owner on Dec 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 272
[SIP-4] add lerna monorepo and@superset-ui/core
package with SupersetClient
#1
Merged
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a6e7fe9
[core] add lerna boilerplate + core package
williaster 0ffdf03
[core][tests] cleaner promise tests
williaster aa8d153
[monorepo] move PR template into .github/
williaster c512518
[monorepo] sort .gitignore entries
williaster 984c865
[core] refactor callApi into multiple pieces, use jest over sinon for…
williaster ae94774
[core] use Promise-based queuing in SupersetClient
williaster 1ef6da5
[core] use jest for spys not sinon
williaster a89cb0e
[core] update aborting details in readme + misc fixes
williaster 49f9c54
[core] fix broken timeout test
williaster b3ffc4e
[core] fix linting
williaster 1fc92cf
[core][tests] clarify function() calls in test names
williaster File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
💔 Breaking Changes | ||
|
||
🏆 Enhancements | ||
|
||
📜 Documentation | ||
|
||
🐛 Bug Fix | ||
|
||
🏠 Internal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
.babelrc | ||
.eslintcache | ||
.eslintignore | ||
.eslintrc.js | ||
.idea | ||
.npm | ||
.prettierignore | ||
.yarnclean | ||
|
||
*.log | ||
*.map | ||
*.min.js | ||
|
||
build/ | ||
coverage/ | ||
esm/ | ||
jest.config.js | ||
lib/ | ||
logs/ | ||
node_modules/ | ||
prettier.config.js |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# `@superset-ui` | ||
|
||
Collection of packages that power the Apache Superset UI, and can be used to craft custom data | ||
applications that leverage a Superset backend :chart_with_upwards_trend: | ||
|
||
## Packages | ||
|
||
[@superset-ui/core](https://github.com/apache-superset/superset-ui/tree/master/packages/superset-ui-core) | ||
[![Version](https://img.shields.io/npm/v/@superset-ui/core.svg?style=flat)](https://img.shields.io/npm/v/@superset-ui/core.svg?style=flat) | ||
|
||
#### Coming :soon: | ||
|
||
- Data providers | ||
- Embeddable charts | ||
- Chart collections | ||
- Demo storybook package | ||
|
||
### Development | ||
|
||
[lerna](https://github.com/lerna/lerna/) is used to manage versions and dependencies between | ||
packages in this monorepo. | ||
|
||
``` | ||
superset-ui/ | ||
lerna.json | ||
package.json | ||
... | ||
packages/ | ||
package1/ | ||
package.json | ||
... | ||
src/ | ||
test/ | ||
... | ||
lib/ | ||
esm/ | ||
... | ||
... | ||
``` | ||
|
||
For easiest development | ||
|
||
1. clone this repo | ||
2. install the root npm modules including lerna and yarn | ||
3. have lerna install package dependencies and manage the symlinking between packages for you | ||
|
||
```sh | ||
git clone ...superset-ui && cd superset-ui | ||
npm install | ||
lerna bootstrap | ||
``` | ||
|
||
### Builds, linting, and testing | ||
|
||
Each package defines its own build config, linting, and testing. You can have lerna run commands | ||
across all packages using the syntax `lerna exec test` from the root `@superset/monorepo` root | ||
directory. | ||
|
||
### License | ||
|
||
Apache-2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"lerna": "3.2.1", | ||
"packages": ["packages/*"], | ||
"version": "0.0.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"name": "@superset-ui/monorepo", | ||
"version": "0.0.0", | ||
"description": "Superset UI", | ||
"private": true, | ||
"scripts": { | ||
"build": "lerna run build", | ||
"jest": "lerna run test", | ||
"lint": "lerna run lint", | ||
"prerelease": "yarn run build", | ||
"prepare-release": "git checkout master && git pull --rebase origin master && yarn run test", | ||
"release": "yarn run prepare-release && lerna publish && lerna run gh-pages", | ||
"test": "lerna bootstrap && yarn run lint && yarn run jest" | ||
}, | ||
"repository": "https://github.com/apache-superset/superset-ui.git", | ||
"keywords": [ | ||
"apache", | ||
"superset", | ||
"data", | ||
"analytics", | ||
"analysis", | ||
"visualization", | ||
"react", | ||
"d3", | ||
"data-ui", | ||
"vx" | ||
], | ||
"license": "Apache-2.0", | ||
"devDependencies": { | ||
"lerna": "^3.2.1", | ||
"yarn": "^1.9.4" | ||
}, | ||
"engines": { | ||
"node": ">=8.10.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
## `@superset-ui/core` | ||
|
||
[![Version](https://img.shields.io/npm/v/@superset-ui/core.svg?style=flat)](https://img.shields.io/npm/v/@superset-ui/core.svg?style=flat) | ||
|
||
Core modules for Superset: | ||
|
||
- `SupersetClient` requests and authentication | ||
- (future) `i18n` locales and translation | ||
|
||
### SupersetClient | ||
|
||
The `SupersetClient` handles all client-side requests to the Superset backend. It can be configured | ||
for use within the Superset application, or used to issue `CORS` requests in other applications. At | ||
a high-level it supports: | ||
|
||
- `CSRF` token authentication | ||
- queues requests in the case that another request is made before the token is received | ||
- it checks for a token before every request, an external app that uses this can detect this by | ||
catching errors, or explicitly checking `SupersetClient.isAuthorized()` | ||
- supports `GET` and `POST` requests (no `PUT` or `DELETE`) | ||
- timeouts | ||
- query aborts through the `AbortController` API | ||
|
||
#### Example usage | ||
|
||
```javascript | ||
// appSetup.js | ||
import { SupersetClient } from `@superset-ui/core`; | ||
// or import SupersetClient from `@superset-ui/core/lib|esm/SupersetClient`; | ||
|
||
SupersetClient.configure(...clientConfig); | ||
SupersetClient.init(); // CSRF auth, can also chain `.configure().init(); | ||
|
||
// anotherFile.js | ||
import { SupersetClient } from `@superset-ui/core`; | ||
|
||
SupersetClient.post(...requestConfig) | ||
.then(({ request, json }) => ...) | ||
.catch((error) => ...); | ||
``` | ||
|
||
#### API | ||
|
||
##### Client Configuration | ||
|
||
The following flags can be passed in the client config call | ||
`SupersetClient.configure(...clientConfig);` | ||
|
||
- `protocol = 'http'` | ||
- `host` | ||
- `headers` | ||
- `credentials = 'same-origin'` (set to `include` for non-Superset apps) | ||
- `mode = 'same-origin'` (set to `cors` for non-Superset apps) | ||
- `timeout` | ||
|
||
##### Per-request Configuration | ||
|
||
The following flags can be passed on a per-request call `SupersetClient.get/post(...requestConfig);` | ||
|
||
- `url` or `endpoint` | ||
- `headers` | ||
- `body` | ||
- `timeout` | ||
- `signal` (for aborting, from `const { signal } = (new AbortController())`) | ||
- for `POST` requests | ||
- `postPayload` (key values are added to a `new FormData()`) | ||
- `stringify` whether to call `JSON.stringify` on `postPayload` values | ||
|
||
##### Request aborting | ||
|
||
Per-request aborting is implemented through the `AbortController` API: | ||
|
||
```javascript | ||
import { SupersetClient } from '@superset-ui/core'; | ||
import AbortController from 'abortcontroller-polyfill'; | ||
|
||
const controller = new AbortController(); | ||
const { signal } = controller; | ||
|
||
SupersetClient.get({ ..., signal }).then(...).catch(...); | ||
|
||
if (IWantToCancelForSomeReason) { | ||
signal.abort(); // Promise is rejected, request `catch` is invoked | ||
} | ||
``` | ||
|
||
### Development | ||
|
||
`@data-ui/build-config` is used to manage the build configuration for this package including babel | ||
builds, jest testing, eslint, and prettier. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
{ | ||
"name": "@superset-ui/core", | ||
"version": "0.0.0", | ||
"description": "Superset UI core 🤖", | ||
"sideEffects": false, | ||
"main": "lib/index.js", | ||
"module": "esm/index.js", | ||
"files": [ | ||
"esm", | ||
"lib" | ||
], | ||
"scripts": { | ||
"build:cjs": "beemo babel ./src --out-dir lib/ --minify", | ||
"build:esm": "beemo babel ./src --out-dir esm/ --esm --minify", | ||
"build": "yarn run build:cjs && yarn run build:esm", | ||
"dev": "beemo babel --watch ./src --out-dir esm/ --esm", | ||
"jest": "beemo jest --color --coverage", | ||
"eslint": "beemo eslint \"./{src,test}/**/*.{js,jsx,json,md}\"", | ||
"lint": "yarn run prettier --write && yarn run eslint --fix", | ||
"test": "yarn run jest", | ||
"prettier": "beemo prettier \"./{src,test}/**/*.{js,jsx,json,md}\"", | ||
"sync:gitignore": "beemo sync-dotfiles --filter=gitignore", | ||
"prepublish": "yarn run build" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/apache-superset/superset-ui.git" | ||
}, | ||
"keywords": [ | ||
"superset", | ||
"client", | ||
"core", | ||
"data" | ||
], | ||
"author": "", | ||
"license": "Apache-2.0", | ||
"bugs": { | ||
"url": "https://github.com/apache-superset/superset-ui/issues" | ||
}, | ||
"homepage": "https://github.com/apache-superset/superset-ui#readme", | ||
"devDependencies": { | ||
"@data-ui/build-config": "0.0.10", | ||
"fetch-mock": "^6.5.2" | ||
}, | ||
"dependencies": { | ||
"url-search-params-polyfill": "^4.0.1", | ||
"whatwg-fetch": "^2.0.4" | ||
}, | ||
"beemo": { | ||
"module": "@data-ui/build-config", | ||
"drivers": [ | ||
"babel", | ||
"eslint", | ||
{ | ||
"driver": "jest", | ||
"env": { | ||
"NODE_ENV": "test" | ||
} | ||
}, | ||
"prettier" | ||
], | ||
"eslint": { | ||
"rules": { | ||
"prefer-promise-reject-errors": "off" | ||
} | ||
}, | ||
"jest": { | ||
"testPathIgnorePatterns": [ | ||
"node_modules" | ||
] | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it cancel every outgoing request? Is there a way to cancel just one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops I forgot an important part of this usage (I'll update), you pass the signal to the request, so it's per-request aborting.
see here for an example in superset.