Skip to content

Commit

Permalink
[PUI] Make actions recognisable (#8005)
Browse files Browse the repository at this point in the history
* Make dropdowns better recogniseable
Closes invenhost#98

* change to button with section

* only draw border if needed

* allign drowdowns in header

* use light instead of subtle

* refactor option dropdowns to reduce duplications
  • Loading branch information
matmair authored Sep 3, 2024
1 parent d81d168 commit 355b493
Show file tree
Hide file tree
Showing 14 changed files with 79 additions and 69 deletions.
1 change: 1 addition & 0 deletions src/frontend/src/components/buttons/AdminButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export default function AdminButton(props: AdminButtonProps) {
tooltip={t`Open in admin interface`}
hidden={!enabled}
onClick={openAdmin}
tooltipAlignment="bottom"
/>
);
}
47 changes: 40 additions & 7 deletions src/frontend/src/components/items/ActionDropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { t } from '@lingui/macro';
import {
ActionIcon,
Button,
Indicator,
IndicatorProps,
Menu,
Tooltip
} from '@mantine/core';
import { modals } from '@mantine/modals';
import {
IconChevronDown,
IconCopy,
IconDotsVertical,
IconEdit,
IconLink,
IconQrcode,
Expand Down Expand Up @@ -42,13 +44,15 @@ export function ActionDropdown({
tooltip,
actions,
disabled = false,
hidden = false
hidden = false,
noindicator = false
}: {
icon: ReactNode;
tooltip: string;
actions: ActionDropdownItem[];
disabled?: boolean;
hidden?: boolean;
noindicator?: boolean;
}) {
const hasActions = useMemo(() => {
return actions.some((action) => !action.hidden);
Expand All @@ -66,16 +70,25 @@ export function ActionDropdown({
<Menu position="bottom-end" key={menuName}>
<Indicator disabled={!indicatorProps} {...indicatorProps?.indicator}>
<Menu.Target>
<Tooltip label={tooltip} hidden={!tooltip}>
<ActionIcon
size="lg"
<Tooltip label={tooltip} hidden={!tooltip} position="bottom">
<Button
radius="sm"
variant="transparent"
variant={noindicator ? 'transparent' : 'light'}
disabled={disabled}
aria-label={menuName}
p="0"
size="sm"
rightSection={
noindicator || disabled ? null : (
<IconChevronDown stroke={1.5} />
)
}
styles={{
section: { margin: 0 }
}}
>
{icon}
</ActionIcon>
</Button>
</Tooltip>
</Menu.Target>
</Indicator>
Expand Down Expand Up @@ -110,6 +123,26 @@ export function ActionDropdown({
) : null;
}

export function OptionsActionDropdown({
actions = [],
tooltip = t`Options`,
hidden = false
}: {
actions: ActionDropdownItem[];
tooltip?: string;
hidden?: boolean;
}) {
return (
<ActionDropdown
icon={<IconDotsVertical />}
tooltip={tooltip}
actions={actions}
hidden={hidden}
noindicator
/>
);
}

// Dropdown menu for barcode actions
export function BarcodeActionDropdown({
model,
Expand Down
8 changes: 3 additions & 5 deletions src/frontend/src/pages/build/BuildDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
IconChecklist,
IconClipboardCheck,
IconClipboardList,
IconDots,
IconInfoCircle,
IconList,
IconListCheck,
Expand All @@ -25,12 +24,12 @@ import { DetailsImage } from '../../components/details/DetailsImage';
import { ItemDetailsGrid } from '../../components/details/ItemDetails';
import NotesEditor from '../../components/editors/NotesEditor';
import {
ActionDropdown,
BarcodeActionDropdown,
CancelItemAction,
DuplicateItemAction,
EditItemAction,
HoldItemAction
HoldItemAction,
OptionsActionDropdown
} from '../../components/items/ActionDropdown';
import InstanceDetail from '../../components/nav/InstanceDetail';
import { PageDetail } from '../../components/nav/PageDetail';
Expand Down Expand Up @@ -474,9 +473,8 @@ export default function BuildDetail() {
items={[build.pk]}
enableReports
/>,
<ActionDropdown
<OptionsActionDropdown
tooltip={t`Build Order Actions`}
icon={<IconDots />}
actions={[
EditItemAction({
onClick: () => editBuild.open(),
Expand Down
8 changes: 3 additions & 5 deletions src/frontend/src/pages/company/CompanyDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Grid, Skeleton, Stack } from '@mantine/core';
import {
IconBuildingFactory2,
IconBuildingWarehouse,
IconDots,
IconInfoCircle,
IconMap2,
IconNotes,
Expand All @@ -25,9 +24,9 @@ import { DetailsImage } from '../../components/details/DetailsImage';
import { ItemDetailsGrid } from '../../components/details/ItemDetails';
import NotesEditor from '../../components/editors/NotesEditor';
import {
ActionDropdown,
DeleteItemAction,
EditItemAction
EditItemAction,
OptionsActionDropdown
} from '../../components/items/ActionDropdown';
import { Breadcrumb } from '../../components/nav/BreadcrumbList';
import InstanceDetail from '../../components/nav/InstanceDetail';
Expand Down Expand Up @@ -302,9 +301,8 @@ export default function CompanyDetail(props: Readonly<CompanyDetailProps>) {
const companyActions = useMemo(() => {
return [
<AdminButton model={ModelType.company} pk={company.pk} />,
<ActionDropdown
<OptionsActionDropdown
tooltip={t`Company Actions`}
icon={<IconDots />}
actions={[
EditItemAction({
hidden: !user.hasChangeRole(UserRoles.purchase_order),
Expand Down
8 changes: 3 additions & 5 deletions src/frontend/src/pages/company/ManufacturerPartDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { t } from '@lingui/macro';
import { Grid, Skeleton, Stack } from '@mantine/core';
import {
IconBuildingWarehouse,
IconDots,
IconInfoCircle,
IconList,
IconNotes,
Expand All @@ -17,10 +16,10 @@ import { DetailsImage } from '../../components/details/DetailsImage';
import { ItemDetailsGrid } from '../../components/details/ItemDetails';
import NotesEditor from '../../components/editors/NotesEditor';
import {
ActionDropdown,
DeleteItemAction,
DuplicateItemAction,
EditItemAction
EditItemAction,
OptionsActionDropdown
} from '../../components/items/ActionDropdown';
import InstanceDetail from '../../components/nav/InstanceDetail';
import { PageDetail } from '../../components/nav/PageDetail';
Expand Down Expand Up @@ -236,9 +235,8 @@ export default function ManufacturerPartDetail() {
model={ModelType.manufacturerpart}
pk={manufacturerPart.pk}
/>,
<ActionDropdown
<OptionsActionDropdown
tooltip={t`Manufacturer Part Actions`}
icon={<IconDots />}
actions={[
DuplicateItemAction({
hidden: !user.hasAddRole(UserRoles.purchase_order),
Expand Down
8 changes: 3 additions & 5 deletions src/frontend/src/pages/company/SupplierPartDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { t } from '@lingui/macro';
import { Grid, Skeleton, Stack } from '@mantine/core';
import {
IconCurrencyDollar,
IconDots,
IconInfoCircle,
IconNotes,
IconPackages,
Expand All @@ -18,11 +17,11 @@ import { DetailsImage } from '../../components/details/DetailsImage';
import { ItemDetailsGrid } from '../../components/details/ItemDetails';
import NotesEditor from '../../components/editors/NotesEditor';
import {
ActionDropdown,
BarcodeActionDropdown,
DeleteItemAction,
DuplicateItemAction,
EditItemAction
EditItemAction,
OptionsActionDropdown
} from '../../components/items/ActionDropdown';
import InstanceDetail from '../../components/nav/InstanceDetail';
import { PageDetail } from '../../components/nav/PageDetail';
Expand Down Expand Up @@ -272,9 +271,8 @@ export default function SupplierPartDetail() {
hash={supplierPart.barcode_hash}
perm={user.hasChangeRole(UserRoles.purchase_order)}
/>,
<ActionDropdown
<OptionsActionDropdown
tooltip={t`Supplier Part Actions`}
icon={<IconDots />}
actions={[
DuplicateItemAction({
hidden: !user.hasAddRole(UserRoles.purchase_order),
Expand Down
8 changes: 3 additions & 5 deletions src/frontend/src/pages/part/CategoryDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { t } from '@lingui/macro';
import { Group, LoadingOverlay, Skeleton, Stack, Text } from '@mantine/core';
import {
IconCategory,
IconDots,
IconInfoCircle,
IconListDetails,
IconSitemap
Expand All @@ -14,9 +13,9 @@ import AdminButton from '../../components/buttons/AdminButton';
import { DetailsField, DetailsTable } from '../../components/details/Details';
import { ItemDetailsGrid } from '../../components/details/ItemDetails';
import {
ActionDropdown,
DeleteItemAction,
EditItemAction
EditItemAction,
OptionsActionDropdown
} from '../../components/items/ActionDropdown';
import { ApiIcon } from '../../components/items/ApiIcon';
import InstanceDetail from '../../components/nav/InstanceDetail';
Expand Down Expand Up @@ -212,9 +211,8 @@ export default function CategoryDetail() {
const categoryActions = useMemo(() => {
return [
<AdminButton model={ModelType.partcategory} pk={category.pk} />,
<ActionDropdown
<OptionsActionDropdown
tooltip={t`Category Actions`}
icon={<IconDots />}
actions={[
EditItemAction({
hidden: !id || !user.hasChangeRole(UserRoles.part_category),
Expand Down
7 changes: 3 additions & 4 deletions src/frontend/src/pages/part/PartDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
IconCalendarStats,
IconClipboardList,
IconCurrencyDollar,
IconDots,
IconInfoCircle,
IconLayersLinked,
IconList,
Expand Down Expand Up @@ -51,7 +50,8 @@ import {
BarcodeActionDropdown,
DeleteItemAction,
DuplicateItemAction,
EditItemAction
EditItemAction,
OptionsActionDropdown
} from '../../components/items/ActionDropdown';
import { PlaceholderPanel } from '../../components/items/Placeholder';
import { StylishText } from '../../components/items/StylishText';
Expand Down Expand Up @@ -1030,9 +1030,8 @@ export default function PartDetail() {
}
]}
/>,
<ActionDropdown
<OptionsActionDropdown
tooltip={t`Part Actions`}
icon={<IconDots />}
actions={[
DuplicateItemAction({
hidden: !user.hasAddRole(UserRoles.part),
Expand Down
8 changes: 3 additions & 5 deletions src/frontend/src/pages/purchasing/PurchaseOrderDetail.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { t } from '@lingui/macro';
import { Accordion, Grid, Skeleton, Stack } from '@mantine/core';
import {
IconDots,
IconInfoCircle,
IconList,
IconNotes,
Expand All @@ -19,12 +18,12 @@ import { DetailsImage } from '../../components/details/DetailsImage';
import { ItemDetailsGrid } from '../../components/details/ItemDetails';
import NotesEditor from '../../components/editors/NotesEditor';
import {
ActionDropdown,
BarcodeActionDropdown,
CancelItemAction,
DuplicateItemAction,
EditItemAction,
HoldItemAction
HoldItemAction,
OptionsActionDropdown
} from '../../components/items/ActionDropdown';
import { StylishText } from '../../components/items/StylishText';
import InstanceDetail from '../../components/nav/InstanceDetail';
Expand Down Expand Up @@ -408,9 +407,8 @@ export default function PurchaseOrderDetail() {
items={[order.pk]}
enableReports
/>,
<ActionDropdown
<OptionsActionDropdown
tooltip={t`Order Actions`}
icon={<IconDots />}
actions={[
EditItemAction({
hidden: !canEdit,
Expand Down
8 changes: 3 additions & 5 deletions src/frontend/src/pages/sales/ReturnOrderDetail.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { t } from '@lingui/macro';
import { Accordion, Grid, Skeleton, Stack } from '@mantine/core';
import {
IconDots,
IconInfoCircle,
IconList,
IconNotes,
Expand All @@ -18,12 +17,12 @@ import { DetailsImage } from '../../components/details/DetailsImage';
import { ItemDetailsGrid } from '../../components/details/ItemDetails';
import NotesEditor from '../../components/editors/NotesEditor';
import {
ActionDropdown,
BarcodeActionDropdown,
CancelItemAction,
DuplicateItemAction,
EditItemAction,
HoldItemAction
HoldItemAction,
OptionsActionDropdown
} from '../../components/items/ActionDropdown';
import { StylishText } from '../../components/items/StylishText';
import InstanceDetail from '../../components/nav/InstanceDetail';
Expand Down Expand Up @@ -409,9 +408,8 @@ export default function ReturnOrderDetail() {
items={[order.pk]}
enableReports
/>,
<ActionDropdown
<OptionsActionDropdown
tooltip={t`Order Actions`}
icon={<IconDots />}
actions={[
EditItemAction({
hidden: !user.hasChangeRole(UserRoles.return_order),
Expand Down
8 changes: 3 additions & 5 deletions src/frontend/src/pages/sales/SalesOrderDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { t } from '@lingui/macro';
import { Accordion, Grid, Skeleton, Stack } from '@mantine/core';
import {
IconBookmark,
IconDots,
IconInfoCircle,
IconList,
IconNotes,
Expand All @@ -21,12 +20,12 @@ import { DetailsImage } from '../../components/details/DetailsImage';
import { ItemDetailsGrid } from '../../components/details/ItemDetails';
import NotesEditor from '../../components/editors/NotesEditor';
import {
ActionDropdown,
BarcodeActionDropdown,
CancelItemAction,
DuplicateItemAction,
EditItemAction,
HoldItemAction
HoldItemAction,
OptionsActionDropdown
} from '../../components/items/ActionDropdown';
import { StylishText } from '../../components/items/StylishText';
import InstanceDetail from '../../components/nav/InstanceDetail';
Expand Down Expand Up @@ -449,9 +448,8 @@ export default function SalesOrderDetail() {
items={[order.pk]}
enableReports
/>,
<ActionDropdown
<OptionsActionDropdown
tooltip={t`Order Actions`}
icon={<IconDots />}
actions={[
EditItemAction({
hidden: !canEdit,
Expand Down
Loading

0 comments on commit 355b493

Please sign in to comment.