Skip to content

Commit

Permalink
Generate TyepScript interface completely from Python (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelcolvin committed Dec 20, 2023
1 parent 6b7c7cb commit 4274a8d
Show file tree
Hide file tree
Showing 63 changed files with 1,354 additions and 2,577 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
node-version: 18

- run: pip install -r src/python-fastui/requirements/all.txt
- run: pip install src/python-fastui

- run: npm install

Expand Down
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ repos:
entry: npm run typecheck
language: system
pass_filenames: false
- id: js-json-schema
name: js-json-schema
types_or: [ts, tsx]
entry: npm run generate-json-schema
- id: python-generate-ts
name: python-generate-ts
types_or: [python]
entry: fastui generate fastui:FastUI src/npm-fastui/src/models.d.ts
language: system
pass_filenames: false
2 changes: 1 addition & 1 deletion demo/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def auth_login(user: Annotated[str | None, Depends(get_user)]) -> list[AnyCompon
)
),
c.Heading(text='Login'),
c.ModelForm[LoginForm](submit_url='/api/auth/login'),
c.ModelForm(model=LoginForm, submit_url='/api/auth/login'),
title='Authentication',
)
else:
Expand Down
6 changes: 3 additions & 3 deletions demo/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,19 @@ def form_content(kind: FormKind):
return [
c.Heading(text='Login Form', level=2),
c.Paragraph(text='Simple login form with email and password.'),
c.ModelForm[LoginForm](submit_url='/api/forms/login'),
c.ModelForm(model=LoginForm, submit_url='/api/forms/login'),
]
case 'select':
return [
c.Heading(text='Select Form', level=2),
c.Paragraph(text='Form showing different ways of doing select.'),
c.ModelForm[SelectForm](submit_url='/api/forms/select'),
c.ModelForm(model=SelectForm, submit_url='/api/forms/select'),
]
case 'big':
return [
c.Heading(text='Large Form', level=2),
c.Paragraph(text='Form with a lot of fields.'),
c.ModelForm[BigModel](submit_url='/api/forms/big'),
c.ModelForm(model=BigModel, submit_url='/api/forms/big'),
]
case _:
raise ValueError(f'Invalid kind {kind!r}')
Expand Down
8 changes: 5 additions & 3 deletions demo/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,17 @@ def cities_view(page: int = 1, country: str | None = None) -> list[AnyComponent]
filter_form_initial['country'] = {'value': country, 'label': country_name}
return demo_page(
*tabs(),
c.ModelForm[FilterForm](
c.ModelForm(
model=FilterForm,
submit_url='.',
initial=filter_form_initial,
method='GOTO',
submit_on_change=True,
display_mode='inline',
),
c.Table[City](
c.Table(
data=cities[(page - 1) * page_size : page * page_size],
data_model=City,
columns=[
DisplayLookup(field='city', on_click=GoToEvent(url='./{id}'), table_width_percent=33),
DisplayLookup(field='country', table_width_percent=33),
Expand Down Expand Up @@ -107,7 +109,7 @@ class User(BaseModel):
def users_view() -> list[AnyComponent]:
return demo_page(
*tabs(),
c.Table[User](
c.Table(
data=users,
columns=[
DisplayLookup(field='name', on_click=GoToEvent(url='/table/users/{id}/')),
Expand Down

0 comments on commit 4274a8d

Please sign in to comment.