Skip to content

Commit 8453b92

Browse files
committed
Merge branch 'main' into forman-x-reorganising_components
# Conflicts: # chartlets.js/src/lib/components/Typography.tsx # chartlets.js/src/lib/types/state/component.ts
2 parents 99825ef + f3a299a commit 8453b92

File tree

9 files changed

+220
-21
lines changed

9 files changed

+220
-21
lines changed

.github/workflows/backend-ci.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Backend CI workflow
2+
3+
on:
4+
push:
5+
paths:
6+
- chartlets.py/**
7+
8+
jobs:
9+
backend:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: git-checkout chartlets
13+
uses: actions/checkout@v4
14+
15+
- name: Set up Micromamba
16+
uses: mamba-org/setup-micromamba@v1
17+
with:
18+
environment-file: chartlets.py/environment.yml
19+
20+
- name: Run unit tests
21+
shell: bash -l {0}
22+
run: |
23+
cd chartlets.py
24+
pytest

.github/workflows/frontend-ci.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Frontend CI workflow
2+
3+
on:
4+
push:
5+
paths:
6+
- chartlets.js/**
7+
8+
jobs:
9+
frontend:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: git-checkout chartlets
13+
uses: actions/checkout@v4
14+
15+
- name: Set up Node.js
16+
uses: actions/setup-node@v4
17+
with:
18+
node-version: '18.x'
19+
20+
- name: Install dependencies
21+
run: |
22+
cd chartlets.js
23+
npm install
24+
25+
- name: Linter
26+
run: |
27+
cd chartlets.js
28+
npm run lint
29+
30+
- name: Run frontend tests
31+
run: |
32+
cd chartlets.js
33+
npm run test
34+
35+
- name: Build frontend application
36+
run: |
37+
cd chartlets.js
38+
npm run build

.github/workflows/publish.yml

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
name: Package and Publish
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
python-tests:
9+
runs-on: ubuntu-latest
10+
strategy:
11+
fail-fast: false
12+
matrix:
13+
python-version: ["3.10", "3.11", "3.12"]
14+
15+
steps:
16+
- uses: actions/checkout@v3
17+
18+
- name: Set up Python ${{ matrix.python-version }}
19+
uses: actions/setup-python@v3
20+
with:
21+
python-version: ${{ matrix.python-version }}
22+
23+
- name: Install dependencies
24+
run: |
25+
python -m pip install --upgrade pip
26+
pip install .[dev]
27+
28+
- name: Lint with flake8
29+
run: |
30+
# stop the build if there are Python syntax errors or undefined names
31+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
32+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
33+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
34+
35+
- name: Test with pytest
36+
run: |
37+
pytest --cov=chartlets
38+
39+
- name: Upload coverage reports to Codecov
40+
uses: codecov/codecov-action@v3
41+
env:
42+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
43+
44+
PyPi-Deploy:
45+
name: Publish Python Package to PyPI
46+
runs-on: ubuntu-latest
47+
needs: python-tests
48+
49+
steps:
50+
- uses: actions/checkout@v4
51+
52+
- name: Set up Python
53+
uses: actions/setup-python@v5
54+
with:
55+
python-version: '3.x'
56+
57+
- name: Install dependencies
58+
run: |
59+
python -m pip install --upgrade pip
60+
pip install build
61+
62+
- name: Build package
63+
run: |
64+
python -m build
65+
66+
- name: Publish to PyPI
67+
run: |
68+
pip install twine
69+
python -m twine upload --username __token__ --password ${{ secrets.PYPI_API_TOKEN }} dist/*
70+
71+
npm-tests:
72+
runs-on: ubuntu-latest
73+
74+
strategy:
75+
matrix:
76+
node-version: [16.x, 18.x, 20.x]
77+
# See supported Node.js release schedule at
78+
# https://nodejs.org/en/about/releases/
79+
80+
steps:
81+
- uses: actions/checkout@v3
82+
- name: Use Node.js ${{ matrix.node-version }}
83+
uses: actions/setup-node@v3
84+
with:
85+
node-version: ${{ matrix.node-version }}
86+
cache: 'npm'
87+
- run: npm ci
88+
- run: npm run lint
89+
- run: npm run build
90+
- run: npm run test
91+
92+
npm-Deploy:
93+
name: Publish TS-React Package to npmjs
94+
runs-on: ubuntu-latest
95+
needs: npm-tests
96+
97+
steps:
98+
- uses: actions/checkout@v4
99+
100+
- name: Set up Node.js
101+
uses: actions/setup-node@v4
102+
with:
103+
node-version: '18.x'
104+
registry-url: 'https://registry.npmjs.org'
105+
- run: npm ci
106+
- run: npm run build
107+
- run: npm publish --access public
108+
env:
109+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

chartlets.js/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# chartlets
22

3+
[![Frontend CI workflow](https://github.com/bcdev/chartlets/actions/workflows/frontend-ci.yml/badge.svg)](https://github.com/bcdev/chartlets/actions/workflows/frontend-ci.yml)
4+
[![NPM Version](https://badge.fury.io/js/chartlets.svg)](https://npmjs.org/package/chartlets)
5+
![](https://img.shields.io/badge/Linting-TypeScript%20%26%20Prettier-blue?logo=typescript&logoColor=white)
6+
7+
8+
[![NPM Download Stats](https://nodei.co/npm/chartlets.png?downloads=true)](https://www.npmjs.com/package/chartlets)
9+
310
Chartlets is a software framework that allows websites developed with
411
React to be extended by server-side widgets programmed in Python or other
512
programming languages.

chartlets.js/src/lib/components/Box.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ export interface BoxProps extends Omit<BoxState, "type"> {
1212
onChange: ComponentChangeHandler;
1313
}
1414

15-
export function Box({ id, style, children: components, onChange }: BoxProps) {
15+
export function Box({ id, style, children, onChange }: BoxProps) {
1616
return (
1717
<MuiBox id={id} style={style}>
18-
<ComponentChildren components={components} onChange={onChange} />
18+
<ComponentChildren nodes={children} onChange={onChange} />
1919
</MuiBox>
2020
);
2121
}

chartlets.js/src/lib/components/ComponentChildren.tsx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
import { type ComponentChangeHandler } from "@/lib/types/state/event";
22
import {
3-
type ComponentItem,
3+
type ComponentNode,
44
isComponentState,
55
} from "@/lib/types/state/component";
66
import { Component } from "./Component";
77

88
export interface ComponentChildrenProps {
9-
components?: ComponentItem[];
9+
nodes?: ComponentNode[];
1010
onChange: ComponentChangeHandler;
1111
}
1212

13-
export function ComponentChildren({
14-
components,
15-
onChange,
16-
}: ComponentChildrenProps) {
17-
if (!components || components.length === 0) {
13+
export function ComponentChildren({ nodes, onChange }: ComponentChildrenProps) {
14+
if (!nodes || nodes.length === 0) {
1815
return null;
1916
}
2017
return (
2118
<>
22-
{components.map((item, index) => {
23-
if (isComponentState(item)) {
24-
const key = item.id || index;
25-
return <Component key={key} {...item} onChange={onChange} />;
19+
{nodes.map((node, index) => {
20+
if (isComponentState(node)) {
21+
const key = node.id || index;
22+
return <Component key={key} {...node} onChange={onChange} />;
23+
} else if (typeof node === "string") {
24+
return node;
25+
} else if (!node) {
26+
// This is ok, just as with React, don't render
2627
} else {
27-
return item;
28+
console.warn("chartlets: invalid child node encountered:", node);
2829
}
2930
})}
3031
</>

chartlets.js/src/lib/types/state/component.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,38 @@
11
import { type CSSProperties } from "react";
22
import { isObject } from "@/lib/utils/isObject";
33

4+
export type ComponentType =
5+
| "Box"
6+
| "Button"
7+
| "Checkbox"
8+
| "Plot"
9+
| "Select"
10+
| "Typography";
11+
12+
export type ComponentNode =
13+
| ComponentState
14+
| string
15+
| 0
16+
| false
17+
| null
18+
| undefined;
19+
420
export interface ComponentState {
5-
type: string;
6-
label?: string;
7-
children?: ComponentItem[];
21+
// TODO: Rename to tag, so we can also have
22+
// (Html)ElementState along with ComponentState
23+
type: ComponentType;
24+
children?: ComponentNode[];
825
// common HTML attributes
926
id?: string;
1027
name?: string;
1128
value?: boolean | string | number | null | undefined;
1229
style?: CSSProperties;
1330
disabled?: boolean;
31+
label?: string;
1432
}
1533

16-
export type ComponentItem = ComponentState | string;
17-
1834
export interface ContainerState extends ComponentState {
19-
children: ComponentItem[];
35+
children: ComponentNode[];
2036
}
2137

2238
export function isComponentState(object: unknown): object is ComponentState {

chartlets.py/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# chartlets
22

3+
[![Backend CI workflow](https://github.com/bcdev/chartlets/actions/workflows/backend-ci.yml/badge.svg)](https://github.com/bcdev/chartlets/actions/workflows/backend-ci.yml)
4+
[![PyPI Version](https://img.shields.io/pypi/v/chartlets)](https://pypi.org/project/chartlets/)
5+
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
6+
37
Chartlets is a software framework that allows websites developed with
48
React to be extended by server-side widgets programmed in Python or other
59
programming languages.

chartlets.py/chartlets/component.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Component(ABC):
3434
color: str | None = None
3535
"""HTML `color` attribute. Optional."""
3636

37-
children: list[Union["Component", str]] | None = None
37+
children: list[Union["Component", str, None]] | None = None
3838
"""Children used by many specific components. Optional."""
3939

4040
@property

0 commit comments

Comments
 (0)