Skip to content

Commit

Permalink
Update RowActions (#6106)
Browse files Browse the repository at this point in the history
* Update RowActions

- Show text labels (again)
- Revert to Menu.Item
- Adjust placement
- Add optional tooltip

* Remove unused import
  • Loading branch information
SchrodingersGat authored Dec 16, 2023
1 parent 95d29f1 commit bee3e93
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
41 changes: 24 additions & 17 deletions src/frontend/src/components/tables/RowActions.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { t } from '@lingui/macro';
import { ActionIcon, Group, Tooltip } from '@mantine/core';
import { ActionIcon, Tooltip } from '@mantine/core';
import { Menu } from '@mantine/core';
import { IconCopy, IconDots, IconEdit, IconTrash } from '@tabler/icons-react';
import { ReactNode, useMemo, useState } from 'react';
Expand All @@ -9,6 +9,7 @@ import { notYetImplemented } from '../../functions/notifications';
// Type definition for a table row action
export type RowAction = {
title: string;
tooltip?: string;
color?: string;
icon: ReactNode;
onClick?: () => void;
Expand All @@ -18,14 +19,17 @@ export type RowAction = {
// Component for duplicating a row in a table
export function RowDuplicateAction({
onClick,
tooltip,
hidden
}: {
onClick?: () => void;
tooltip?: string;
hidden?: boolean;
}): RowAction {
return {
title: t`Duplicate`,
color: 'green',
tooltip: tooltip,
onClick: onClick,
icon: <IconCopy />,
hidden: hidden
Expand All @@ -35,14 +39,17 @@ export function RowDuplicateAction({
// Component for editing a row in a table
export function RowEditAction({
onClick,
tooltip,
hidden
}: {
onClick?: () => void;
tooltip?: string;
hidden?: boolean;
}): RowAction {
return {
title: t`Edit`,
color: 'blue',
tooltip: tooltip,
onClick: onClick,
icon: <IconEdit />,
hidden: hidden
Expand All @@ -52,14 +59,17 @@ export function RowEditAction({
// Component for deleting a row in a table
export function RowDeleteAction({
onClick,
tooltip,
hidden
}: {
onClick?: () => void;
tooltip?: string;
hidden?: boolean;
}): RowAction {
return {
title: t`Delete`,
color: 'red',
tooltip: tooltip,
onClick: onClick,
icon: <IconTrash />,
hidden: hidden
Expand Down Expand Up @@ -97,10 +107,14 @@ export function RowActions({
// Render a single action icon
function RowActionIcon(action: RowAction) {
return (
<Tooltip withinPortal={true} label={action.title} key={action.title}>
<ActionIcon
<Tooltip
withinPortal={true}
label={action.tooltip ?? action.title}
key={action.title}
>
<Menu.Item
color={action.color}
size={20}
icon={action.icon}
onClick={(event) => {
// Prevent clicking on the action from selecting the row itself
event?.preventDefault();
Expand All @@ -116,23 +130,18 @@ export function RowActions({
setOpened(false);
}}
>
{action.icon}
</ActionIcon>
{action.title}
</Menu.Item>
</Tooltip>
);
}

// If only a single action is available, display that
if (visibleActions.length == 1) {
return <RowActionIcon {...visibleActions[0]} />;
}

return (
visibleActions.length > 0 && (
<Menu
withinPortal={true}
disabled={disabled}
position="left"
position="bottom-end"
opened={opened}
onChange={setOpened}
>
Expand All @@ -149,11 +158,9 @@ export function RowActions({
</Tooltip>
</Menu.Target>
<Menu.Dropdown>
<Group position="right" spacing="xs" p={8}>
{visibleActions.map((action) => (
<RowActionIcon key={action.title} {...action} />
))}
</Group>
{visibleActions.map((action) => (
<RowActionIcon key={action.title} {...action} />
))}
</Menu.Dropdown>
</Menu>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export function PartParameterTable({ partId }: { partId: any }) {

actions.push(
RowEditAction({
tooltip: t`Edit Part Parameter`,
hidden: !user.hasChangeRole(UserRoles.part),
onClick: () => {
openEditApiForm({
Expand All @@ -132,6 +133,7 @@ export function PartParameterTable({ partId }: { partId: any }) {

actions.push(
RowDeleteAction({
tooltip: t`Delete Part Parameter`,
hidden: !user.hasDeleteRole(UserRoles.part),
onClick: () => {
openDeleteApiForm({
Expand Down

0 comments on commit bee3e93

Please sign in to comment.