Skip to content

Commit

Permalink
Fix issue with modal inline dialogs. Fix issue with m2m multiple select.
Browse files Browse the repository at this point in the history
  • Loading branch information
vsdudakov committed Aug 7, 2024
1 parent d86cb1c commit 90d1670
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 65 deletions.
6 changes: 6 additions & 0 deletions docs/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ def read_cls_docstring(cls):

def get_versions():
return [
{
"version": "0.2.9",
"changes": [
"Fix issue with modal inline dialogs. Fix issue with m2m multiple select.",
],
},
{
"version": "0.2.8",
"changes": [
Expand Down
4 changes: 2 additions & 2 deletions docs/index.html

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion examples/fastapi_sqlalchemy/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
## FastAPI + SQLAlchemy 2.x Example

- Uses in-memory SQLite 3 instance
- Creates User mode
- Creates "admin/admin" superuser

```bash
Expand Down
10 changes: 9 additions & 1 deletion examples/fastapi_sqlalchemy/example.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from models import Base, BaseEvent, Event, Tournament, User, sqlalchemy_engine, sqlalchemy_sessionmaker
from sqlalchemy import select, update

Expand Down Expand Up @@ -53,7 +54,6 @@ class BaseEventModelAdmin(SqlAlchemyModelAdmin):
class EventModelAdmin(SqlAlchemyModelAdmin):
actions = ("make_is_active", "make_is_not_active")
list_display = ("id", "name_with_price", "rating", "event_type", "is_active", "started")
raw_id_fields = ("base",)

@action(description="Make user active")
async def make_is_active(self, ids):
Expand Down Expand Up @@ -107,3 +107,11 @@ async def startup():


app.mount("/admin", admin_app)

app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
1 change: 0 additions & 1 deletion examples/fastapi_tortoiseorm/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
## FastAPI + Tortoise ORM Example

- Uses in-memory SQLite 3 instance
- Creates User mode
- Creates "admin/admin" superuser

```bash
Expand Down
10 changes: 9 additions & 1 deletion examples/fastapi_tortoiseorm/example.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from models import BaseEvent, Event, Tournament, User
from tortoise import Tortoise

Expand Down Expand Up @@ -49,7 +50,6 @@ class BaseEventModelAdmin(TortoiseModelAdmin):
class EventModelAdmin(TortoiseModelAdmin):
actions = ("make_is_active", "make_is_not_active")
list_display = ("id", "name_with_price", "rating", "event_type", "is_active", "started")
raw_id_fields = ("base",)

@action(description="Make user active")
async def make_is_active(self, ids):
Expand Down Expand Up @@ -96,3 +96,11 @@ async def shutdown():


app.mount("/admin", admin_app)

app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
106 changes: 53 additions & 53 deletions fastadmin/static/index.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<meta name="description" content="Fast Admin"/>
<title>Fast Admin</title>
<script>
window.SERVER_DOMAIN = 'http://localhost:8000';
window.SERVER_URL = 'http://localhost:8000/admin/api';
window.SERVER_DOMAIN = 'http://localhost:8090';
window.SERVER_URL = 'http://localhost:8090/admin/api';
</script>
</head>
<body>
Expand Down
15 changes: 12 additions & 3 deletions frontend/src/components/async-select/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export interface IAsyncSelect {
labelFields: string[];

value?: any;

parentModel: string;
}

Expand Down Expand Up @@ -160,6 +159,8 @@ export const AsyncSelect: React.FC<IAsyncSelect> = ({
mutateChange(payload);
};

const isMultipleMode = (props as any).mode === "multiple";

return (
<>
<Space.Compact style={{ width: "100%" }}>
Expand All @@ -174,7 +175,7 @@ export const AsyncSelect: React.FC<IAsyncSelect> = ({
<PlusCircleOutlined />
</Button>
</Tooltip>
{value && (
{value && !isMultipleMode && (
<Tooltip
title={_t(
`Edit ${
Expand All @@ -200,7 +201,15 @@ export const AsyncSelect: React.FC<IAsyncSelect> = ({
label: item[labelField],
};
})}
value={value ? `${value}` : undefined}
value={
isMultipleMode
? value
? value.map((v: any) => `${v}`)
: []
: value
? `${value}`
: undefined
}
{...props}
/>
</Space.Compact>
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/components/form-container/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ export const FormContainer: React.FC<IFormContainer> = ({
}
}, [hasOperationError, modelConfiguration?.fieldsets]);

useEffect(() => {
form.setFieldsValue(initialValues);
}, [form, initialValues]);

const getWidget = useCallback(
(
configurationField: IAddConfigurationField | IChangeConfigurationField,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "fastadmin"
version = "0.2.8"
version = "0.2.9"
description = "FastAdmin is an easy-to-use Admin Dashboard App for FastAPI/Flask/Django inspired by Django Admin."
authors = ["Seva D <vsdudakov@gmail.com>"]
license = "MIT"
Expand Down

0 comments on commit 90d1670

Please sign in to comment.