Skip to content

Commit

Permalink
Allow customising show actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamsorcerer committed Jul 31, 2023
1 parent ed98578 commit 93631a0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion admin-js/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ const DatagridSingle = (props) => (
const COMPONENTS = {
Datagrid, DatagridSingle,

BulkDeleteButton,
BulkDeleteButton, BulkExportButton, BulkUpdateButton, CloneButton, CreateButton,
ExportButton, FilterButton, ListButton, ShowButton,

BooleanField, DateField, NumberField, ReferenceField, ReferenceManyField,
ReferenceOneField, SelectField, TextField, TimeField,
Expand Down Expand Up @@ -291,6 +292,7 @@ const AiohttpList = (resource, name, permissions) => {
const AiohttpShow = (resource, name, permissions) => {
const ShowActions = () => (
<TopToolbar>
{resource["show_actions"].map(evaluate)}
<WithRecord render={(record) => hasPermission(`${name}.edit`, permissions, record) && <EditButton />} />
</TopToolbar>
);
Expand Down
2 changes: 1 addition & 1 deletion aiohttp_admin/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def setup_resources(admin: web.Application, schema: Schema) -> None:

state = {"fields": fields, "inputs": inputs, "list_omit": tuple(omit_fields),
"repr": repr_field, "label": r.get("label"), "icon": r.get("icon"),
"bulk_update": r.get("bulk_update", {})}
"bulk_update": r.get("bulk_update", {}), "show_actions": r.get("show_actions", ())}
admin["state"]["resources"][m.name] = state


Expand Down
3 changes: 3 additions & 0 deletions aiohttp_admin/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ class _Resource(TypedDict, total=False):
field_props: dict[str, dict[str, Any]]
# Custom props to add to inputs.
input_props: dict[str, dict[str, Any]]
# Custom components to add to the actions in the show view.
show_actions: Sequence[ComponentState]


class Resource(_Resource):
Expand All @@ -111,6 +113,7 @@ class _ResourceState(TypedDict):
display: Sequence[str]
fields: dict[str, ComponentState]
inputs: dict[str, InputState]
show_actions: Sequence[ComponentState]
repr: str
icon: Optional[str]
urls: dict[str, tuple[str, str]] # (method, url)
Expand Down

0 comments on commit 93631a0

Please sign in to comment.