Repository navigation
Refactor/row actions #380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Refactor/row actions #380
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
347ed3b
refactor: replace row edit/delete icons with a row actions menu
ako3131 ec6fcdd
fix: revert row actions change on tabels not used in summit admin
ako3131 e98dff0
fix: disable edit and delete on editable tables
ako3131 3f8f274
fix: remove leftover hover, make extra actions button accessible, gua…
ako3131 a2af6eb
Fix: JSX syntax for row actions in sortable table
ako3131 1e2edea
fix: allow tables to take in the number of rows
ako3131 5ebd416
fix: remove row actions
ako3131 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -13,30 +13,58 @@ | |
|
|
||
| import * as React from "react"; | ||
| import PropTypes from "prop-types"; | ||
| import T from "i18n-react/dist/i18n-react"; | ||
| import IconButton from "@mui/material/IconButton"; | ||
| import Menu from "@mui/material/Menu"; | ||
| import MenuItem from "@mui/material/MenuItem"; | ||
| import Divider from "@mui/material/Divider"; | ||
| import Tooltip from "@mui/material/Tooltip"; | ||
| import MoreVertIcon from "@mui/icons-material/MoreVert"; | ||
|
|
||
| const RowActionsMenu = ({ actions }) => { | ||
| // built-in Edit/Delete keep every table's menu consistent; `actions` holds any extra items | ||
| const RowActionsMenu = ({ actions: actionsProp, onEdit, onDelete, disabled = false }) => { | ||
| const [anchorEl, setAnchorEl] = React.useState(null); | ||
| // getRowActions may return null for rows without extra actions | ||
| const actions = actionsProp ?? []; | ||
|
|
||
| if (!actions.length) return null; | ||
| const hasBuiltIns = !!(onEdit || onDelete); | ||
| if (!hasBuiltIns && !actions.length) return null; | ||
|
|
||
| return ( | ||
| <> | ||
| <IconButton | ||
| size="medium" | ||
| onClick={(e) => setAnchorEl(e.currentTarget)} | ||
| data-testid="row-actions-menu-trigger" | ||
| > | ||
| <MoreVertIcon /> | ||
| </IconButton> | ||
| <Tooltip title={T.translate("general.more_actions")}> | ||
| <span> | ||
| <IconButton | ||
| size="medium" | ||
| onClick={(e) => setAnchorEl(e.currentTarget)} | ||
| data-testid="row-actions-menu-trigger" | ||
| aria-label={T.translate("general.more_actions")} | ||
| aria-haspopup="true" | ||
| aria-expanded={anchorEl ? "true" : undefined} | ||
| disabled={ | ||
| (!hasBuiltIns || disabled) && actions.every((action) => action.disabled) | ||
| } | ||
| > | ||
| <MoreVertIcon /> | ||
| </IconButton> | ||
| </span> | ||
| </Tooltip> | ||
| <Menu | ||
| anchorEl={anchorEl} | ||
| open={Boolean(anchorEl)} | ||
| onClose={() => setAnchorEl(null)} | ||
| > | ||
| {onEdit && ( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like if we merge actions with onEdit, the code gets simpler |
||
| <MenuItem | ||
| disabled={disabled} | ||
| onClick={() => { | ||
| setAnchorEl(null); | ||
| onEdit(); | ||
| }} | ||
| > | ||
| {T.translate("general.edit")} | ||
| </MenuItem> | ||
| )} | ||
| {actions.map((action) => ( | ||
| <MenuItem | ||
| key={action.label} | ||
|
|
@@ -49,6 +77,19 @@ const RowActionsMenu = ({ actions }) => { | |
| {action.label} | ||
| </MenuItem> | ||
| ))} | ||
| {onDelete && (onEdit || actions.length > 0) && <Divider />} | ||
| {onDelete && ( | ||
| <MenuItem | ||
| disabled={disabled} | ||
| onClick={() => { | ||
| setAnchorEl(null); | ||
| onDelete(); | ||
| }} | ||
| sx={{ color: "error.main" }} | ||
| > | ||
| {T.translate("general.delete")} | ||
| </MenuItem> | ||
| )} | ||
| </Menu> | ||
| </> | ||
| ); | ||
|
|
@@ -61,7 +102,10 @@ RowActionsMenu.propTypes = { | |
| onClick: PropTypes.func.isRequired, | ||
| disabled: PropTypes.bool | ||
| }) | ||
| ).isRequired | ||
| ), | ||
| onEdit: PropTypes.func, | ||
| onDelete: PropTypes.func, | ||
| disabled: PropTypes.bool | ||
| }; | ||
|
|
||
| export default RowActionsMenu; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets move this to its own const