Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
klen committed Jul 11, 2024
2 parents 65a9e56 + cfa4289 commit c66f125
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "muffin-admin",
"version": "3.6.3",
"version": "3.7.0",
"description": "NPM package for https://github.com/klen/muffin-admin",
"files": [
"src",
Expand Down
12 changes: 7 additions & 5 deletions frontend/src/buttons/ActionButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ export type ActionPayloadProps = {
onHandle: (payload: any) => void
}

export function ActionButton({ action, confirm, ...props }: AdminAction) {
export function ActionButton({ paths, confirm, ...props }: AdminAction) {
const translate = useTranslate()
const record = useRecordContext()
const confirmation = useConfirmation()
const { mutate, isPending } = useAction(action)
const path = paths.find((p) => p.includes("{id}")) || paths[paths.length - 1]
const { mutate, isPending } = useAction(path)

const confirmMessage =
typeof confirm === "string" ? translate(confirm) : "Do you confirm this action?"
Expand All @@ -37,10 +38,11 @@ export function ActionButton({ action, confirm, ...props }: AdminAction) {
return <ActionButtonBase {...props} isPending={isPending} onHandle={onHandle} />
}

export function BulkActionButton({ action, confirm, ...props }: AdminAction) {
export function BulkActionButton({ paths, confirm, ...props }: AdminAction) {
const translate = useTranslate()
const { selectedIds } = useListContext()
const { mutate, isPending } = useAction(action)
const path = paths.find((p) => !p.includes("{id}")) || paths[0]
const { mutate, isPending } = useAction(path)
const confirmation = useConfirmation()

const confirmMessage =
Expand Down Expand Up @@ -85,7 +87,7 @@ function ActionButtonBase({
icon,
schema,
id,
}: Omit<AdminAction, "action"> & {
}: Omit<AdminAction, "paths"> & {
isPending?: boolean
onHandle: (payload?: any) => void
}) {
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type AdminAction = {
label: string
title: string
icon: string
action: string
paths: string[]
confirm?: string | false
schema?: AdminInput[]
}
Expand All @@ -35,11 +35,11 @@ export type AdminResourceProps = {
actions: AdminAction[]
create: AdminInput[] | false
edit:
| {
inputs: AdminInput[]
remove?: boolean
}
| false
| {
inputs: AdminInput[]
remove?: boolean
}
| false
list: {
limit: number
limitMax: number
Expand Down
7 changes: 3 additions & 4 deletions muffin_admin/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ def get_selected(self, request: Request):
@classmethod
def action( # noqa: PLR0913
cls,
path: str,
*,
*paths: str,
methods: Optional[TMethods] = None,
icon: Optional[str] = None,
label: Optional[str] = None,
Expand Down Expand Up @@ -138,11 +137,11 @@ async def wrapper(self, request: Request, **kwargs):

return await method(self, request, data=data, **kwargs)

wrapper.__route__ = (path,), methods # type: ignore[]
wrapper.__route__ = paths, methods # type: ignore[]
wrapper.__action__ = { # type: ignore[]
"view": [view] if isinstance(view, str) else view or ["show"],
"icon": icon,
"action": path,
"paths": paths,
"title": method.__doc__,
"id": method.__name__,
"label": label or " ".join(method.__name__.split("_")).capitalize(),
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 = "muffin-admin"
version = "3.6.3"
version = "3.7.0"
description = "Admin interface for Muffin Framework"
readme = "README.rst"
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ async def base_action(self, request, response=None):
{
"view": ["show"],
"icon": None,
"action": "/base",
"paths": ("/base",),
"title": None,
"label": "Base action",
"id": "base_action",
Expand Down

0 comments on commit c66f125

Please sign in to comment.