-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: display actions in table rows (#388)
* feat: display actions in table rows * add changeset
- Loading branch information
Showing
6 changed files
with
62 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@premieroctet/next-admin": patch | ||
--- | ||
|
||
feat: display actions in table rows (#387) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import clsx from "clsx"; | ||
import { useAction } from "../hooks/useAction"; | ||
import { ModelAction, ModelName } from "../types"; | ||
import { DropdownItem } from "./radix/Dropdown"; | ||
import { useI18n } from "../context/I18nContext"; | ||
|
||
type Props = { | ||
action: ModelAction | Omit<ModelAction, "action">; | ||
resource: ModelName; | ||
resourceIds: string[] | number[]; | ||
}; | ||
|
||
const ActionDropdownItem = ({ action, resource, resourceIds }: Props) => { | ||
const { t } = useI18n(); | ||
const { runAction } = useAction(resource, resourceIds); | ||
|
||
return ( | ||
<DropdownItem | ||
key={action.title} | ||
className={clsx("cursor-pointer rounded-md px-2 py-1", { | ||
"text-red-700 dark:text-red-400": action.style === "destructive", | ||
"hover:bg-red-50": action.style === "destructive", | ||
})} | ||
onClick={(evt) => { | ||
evt.stopPropagation(); | ||
runAction(action); | ||
}} | ||
> | ||
{t(action.title)} | ||
</DropdownItem> | ||
); | ||
}; | ||
|
||
export default ActionDropdownItem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters