Skip to content

Commit 69cad4b

Browse files
committed
use Plotly for charts; use pyproject.toml
1 parent 7759d5f commit 69cad4b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+6012
-5483
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ docs/
22
build/
33
rest_pandas/static/
44
packages/analyst/index.js
5+
index.unpkg.js

.github/workflows/test.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ jobs:
4040
- name: Install dependencies
4141
run: |
4242
python -m pip install --upgrade pip
43+
python -m pip install build
4344
python -m pip install flake8 wheel
4445
python -m pip install django==${{ matrix.django-version }}
4546
python -m pip install djangorestframework==${{ matrix.drf-version }}
@@ -59,6 +60,8 @@ jobs:
5960
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
6061
- name: Test with unittest
6162
run: python -m unittest discover -s tests -t . -v
63+
- name: Test build
64+
run: python -m build
6265
npm:
6366
name: "@wq/${{ matrix.package }}"
6467
runs-on: ubuntu-22.04
@@ -102,8 +105,9 @@ jobs:
102105
- name: Publish to Github Packages
103106
if: github.event_name == 'push'
104107
run: |
108+
python -m pip install setuptools-scm
105109
./set_dev_version.sh
106-
cd packages/$PACKAGE
107110
echo "registry=https://npm.pkg.github.com/wq" > .npmrc
108111
echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" >> .npmrc
112+
cd packages/$PACKAGE
109113
npm publish

babel.config.cjs

+8-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@ module.exports = {
22
plugins: [["@babel/plugin-transform-react-jsx", { useSpread: true }]],
33
env: {
44
test: {
5-
presets: [
6-
["@babel/preset-env", { targets: { node: "current" } }],
7-
"@babel/preset-react",
5+
presets: [["@babel/preset-env", { targets: { node: "current" } }]],
6+
},
7+
build: {
8+
plugins: [
9+
[
10+
"transform-rename-import",
11+
{ original: "^(.+?)\\.jsx$", replacement: "$1.js" },
12+
],
813
],
914
},
1015
},

package-lock.json

+4,825-3,077
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+20-23
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,32 @@
66
"build": "npm run build --workspaces --if-present",
77
"jest": "jest --verbose",
88
"rollup": "rollup",
9+
"rollup-all": "npm run rollup --workspaces --if-present",
10+
"babel": "babel --ignore **/__tests__/**",
911
"prettier": "prettier --write .",
1012
"lint": "eslint ."
1113
},
1214
"devDependencies": {
13-
"@babel/cli": "^7.20.7",
14-
"@babel/eslint-parser": "^7.19.1",
15-
"@babel/plugin-transform-runtime": "^7.19.6",
16-
"@babel/preset-env": "^7.20.2",
17-
"@babel/preset-react": "^7.18.6",
18-
"@babel/preset-typescript": "^7.18.6",
19-
"@babel/runtime": "^7.20.7",
20-
"@rollup/plugin-babel": "^6.0.3",
21-
"@rollup/plugin-commonjs": "^24.0.0",
22-
"@rollup/plugin-json": "^6.0.0",
23-
"@rollup/plugin-node-resolve": "^15.0.1",
24-
"@rollup/plugin-replace": "^5.0.2",
25-
"@rollup/plugin-terser": "^0.3.0",
15+
"@babel/cli": "^7.23.0",
16+
"@babel/eslint-parser": "^7.22.15",
17+
"@babel/plugin-transform-react-jsx": "^7.22.15",
18+
"@babel/preset-env": "^7.23.2",
19+
"@rollup/plugin-babel": "^6.0.4",
20+
"@rollup/plugin-commonjs": "^25.0.5",
21+
"@rollup/plugin-node-resolve": "^15.2.3",
22+
"@rollup/plugin-replace": "^5.0.3",
23+
"@rollup/plugin-terser": "^0.4.4",
24+
"@wq/rollup-plugin": "^2.0.0-beta.1",
2625
"babel-plugin-direct-import": "^1.0.0",
27-
"eslint": "^8.32.0",
28-
"eslint-plugin-import": "^2.27.5",
29-
"eslint-plugin-jest": "^27.2.1",
30-
"eslint-plugin-react": "^7.32.1",
31-
"jest": "^29.3.1",
32-
"jest-environment-jsdom": "^29.4.3",
26+
"babel-plugin-transform-rename-import": "^2.3.0",
27+
"eslint": "^8.51.0",
28+
"eslint-plugin-import": "^2.28.1",
29+
"eslint-plugin-jest": "^27.4.2",
30+
"eslint-plugin-react": "^7.33.2",
31+
"jest": "^29.7.0",
3332
"jest-fetch-mock": "^3.0.3",
34-
"prettier": "^2.8.3",
35-
"rollup": "^3.10.0",
36-
"rollup-plugin-analyzer": "^4.0.0",
37-
"rollup-plugin-ignore": "^1.0.10"
33+
"prettier": "^3.0.3",
34+
"rollup": "^4.0.2"
3835
},
3936
"prettier": {
4037
"tabWidth": 4

packages/analyst/.gitignore

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
index.js
2-
index.js.map
3-
version.js
1+
/index.js
2+
/icons.js
3+
/hooks.js
4+
/components/
5+
/views/

packages/analyst/.npmignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.tgz
2+
__tests__
3+
rollup.config.js

packages/analyst/package.json

+14-10
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
{
22
"name": "@wq/analyst",
33
"version": "2.0.0-alpha.0",
4-
"description": "wq framework plugin providing interactive data tables for Django REST Pandas",
4+
"description": "wq framework plugin providing interactive data tables & charts for Django REST Pandas",
55
"main": "index.js",
6-
"files": [
7-
"src/",
8-
"index.js"
9-
],
6+
"unpkg": "dist/index.unpkg.js",
107
"type": "module",
118
"scripts": {
129
"test": "cd ../../ && npm run jest packages/analyst",
10+
"build": "NODE_ENV=build npm run babel && npm run prettier",
11+
"babel": "cd ../../ && npm run babel -- packages/analyst/src --out-dir packages/analyst/",
1312
"prettier": "cd ../../ && npm run prettier",
1413
"lint": "cd ../../ && npm run lint",
15-
"build": "cd ../../ && npm run rollup -- -c packages/analyst/rollup.config.js"
14+
"rollup": "cd ../../ && npm run rollup -- -c packages/analyst/rollup.config.js"
1615
},
1716
"repository": {
1817
"type": "git",
@@ -31,11 +30,16 @@
3130
},
3231
"homepage": "https://django-rest-pandas.wq.io/@wq/analyst",
3332
"dependencies": {
34-
"@wq/material": "^2.0.0-alpha.0",
35-
"@wq/material-web": "^2.0.0-alpha.0",
36-
"@wq/pandas": "^2.0.0-alpha.0"
33+
"@wq/chart": "^2.0.0-alpha.0",
34+
"@wq/pandas": "^2.0.0-alpha.0",
35+
"mustache": "^4.2.0"
36+
},
37+
"peerDependencies": {
38+
"@wq/material": "*",
39+
"@wq/material-web": "*"
3740
},
3841
"devDependencies": {
39-
"@wq/rollup-plugin": "^1.3.0"
42+
"@wq/material": "^2.0.0-alpha.1",
43+
"@wq/material-web": "^2.0.0-alpha.2"
4044
}
4145
}

packages/analyst/rollup.config.js

+27-20
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,20 @@ const dir = `packages/${pkg.name.replace("@wq/", "")}`;
1919
const config = {
2020
input: `${dir}/src/index.js`,
2121
plugins: [
22+
{
23+
resolveId(id) {
24+
if (id === "@wq/pandas") {
25+
return "packages/pandas/src/index.js";
26+
}
27+
},
28+
},
2229
wq(),
2330
babel({
2431
plugins: [
2532
"@babel/transform-react-jsx",
2633
[
2734
"babel-plugin-direct-import",
28-
{ modules: ["@mui/material", "@mui/icons-material"] },
35+
{ modules: ["@mui/icons-material"] },
2936
],
3037
],
3138
babelHelpers: "inline",
@@ -35,7 +42,6 @@ const config = {
3542
terser({ keep_fnames: /^([A-Z]|use[A-Z])/ }), // Preserve component & hook names
3643
],
3744
output: {
38-
file: `${dir}/index.js`,
3945
banner,
4046
format: "esm",
4147
sourcemap: true,
@@ -48,24 +54,6 @@ const config = {
4854
};
4955

5056
export default [
51-
// @wq/app plugin (npm main)
52-
{
53-
...config,
54-
external: [
55-
"react",
56-
"prop-types",
57-
"@wq/react",
58-
"@wq/pandas",
59-
"@mui/material",
60-
"@mui/icons-material",
61-
],
62-
plugins: [
63-
babel({
64-
plugins: ["@babel/transform-react-jsx"],
65-
babelHelpers: "inline",
66-
}),
67-
],
68-
},
6957
// wq.app staticfiles plugin (for rest-pandas python package)
7058
{
7159
...config,
@@ -78,4 +66,23 @@ export default [
7866
},
7967
},
8068
},
69+
// wq.app staticfiles plugin (unpkg)
70+
{
71+
...config,
72+
plugins: [
73+
replace({
74+
...replaceConfig,
75+
"./wq.js": "https://unpkg.com/wq",
76+
"./chart.js": "https://unpkg.com/@wq/chart",
77+
}),
78+
...config.plugins,
79+
],
80+
output: {
81+
...config.output,
82+
file: `${dir}/dist/index.unpkg.js`,
83+
sourcemapPathTransform(path) {
84+
return path.replace("./", "wq/analyst/");
85+
},
86+
},
87+
},
8188
];

packages/analyst/src/components/AnalystDownload.js packages/analyst/src/components/AnalystDownload.jsx

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import React, { useState } from "react";
2-
import { Menu, MenuItem } from "@mui/material";
2+
import { Menu, MenuItem, useMediaQuery } from "@mui/material";
33
import { useComponents } from "@wq/react";
44
import PropTypes from "prop-types";
55

66
export default function AnalystDownload({ url, title, formats }) {
77
const [anchorEl, setAnchorEl] = useState(null),
8-
{ Button, HorizontalView, Typography, View } = useComponents(),
8+
{ Button, IconButton, HorizontalView, Typography, View } =
9+
useComponents(),
10+
mobile = useMediaQuery((theme) => theme.breakpoints.down("md")),
11+
DownloadButton = mobile ? IconButton : Button,
912
menuId = "analyst-download",
10-
baseUrl = url.replace(/\.[^.]+$/, "");
13+
currentUrl = new URL(url, window.location.href),
14+
baseUrl = currentUrl.pathname.replace(/\.[^.]+$/, ""),
15+
params = currentUrl.search;
1116
return (
1217
<>
1318
<HorizontalView>
@@ -16,15 +21,16 @@ export default function AnalystDownload({ url, title, formats }) {
1621
) : (
1722
<View />
1823
)}
19-
<Button
24+
<DownloadButton
2025
aria-controls={menuId}
2126
onClick={(evt) => setAnchorEl(evt.target)}
2227
icon="download"
2328
variant="contained"
2429
color="primary"
30+
title="Download Data"
2531
>
2632
Download Data
27-
</Button>
33+
</DownloadButton>
2834
</HorizontalView>
2935
<Menu
3036
id={menuId}
@@ -36,7 +42,7 @@ export default function AnalystDownload({ url, title, formats }) {
3642
<MenuItem
3743
key={format}
3844
component="a"
39-
href={`${baseUrl}.${format}`}
45+
href={`${baseUrl}.${format}${params}`}
4046
target="_blank"
4147
>
4248
{label}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import React from "react";
2+
import { Formik } from "formik";
3+
import { Grid } from "@mui/material";
4+
import { AutoInput } from "@wq/react";
5+
import { View } from "@wq/material";
6+
import PropTypes from "prop-types";
7+
8+
export default function AnalystForm({ form, options, setOptions }) {
9+
return (
10+
<Formik
11+
initialValues={options}
12+
enableReinitialize={true}
13+
validate={setOptions}
14+
>
15+
<View sx={{ p: 2 }}>
16+
<Grid container spacing={1} sx={{}}>
17+
{form.map((field) => (
18+
<GridInput key={field.name} {...field} />
19+
))}
20+
</Grid>
21+
</View>
22+
</Formik>
23+
);
24+
}
25+
26+
AnalystForm.propTypes = {
27+
form: PropTypes.arrayOf(PropTypes.object),
28+
options: PropTypes.object,
29+
setOptions: PropTypes.func,
30+
};
31+
32+
function GridInput(props) {
33+
if (props.type === "hidden") {
34+
return <AutoInput {...props} />;
35+
} else if (props.fullwidth) {
36+
return (
37+
<Grid item xs={12} lg={6} xl={4}>
38+
<AutoInput {...props} />
39+
</Grid>
40+
);
41+
} else {
42+
return (
43+
<Grid item xs={12} md={6} lg={3} xl={2}>
44+
<AutoInput {...props} />
45+
</Grid>
46+
);
47+
}
48+
}
49+
50+
GridInput.propTypes = {
51+
type: PropTypes.string,
52+
fullwidth: PropTypes.bool,
53+
};

0 commit comments

Comments
 (0)