mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-30 18:50:53 +00:00
React UI improvements (#5756)
* Add CompanyDetail page * Add "edit company" button (and associated form) * Implement dropdown actions for company page * Update actions for PartDetail * Adds overlay while modal is loading - Lets the user know that something is at least happening in the background * Update panels * Implement separate pages for different company types - Mostly for better breadcrumbs * Placeholder actions for build detail * Add stock table to company page * typescript linting * Fix unused variables * remove dodgy improt
This commit is contained in:
65
src/frontend/src/components/items/ActionDropdown.tsx
Normal file
65
src/frontend/src/components/items/ActionDropdown.tsx
Normal file
@ -0,0 +1,65 @@
|
||||
import { ActionIcon, Menu, Tooltip } from '@mantine/core';
|
||||
import { ReactNode, useMemo } from 'react';
|
||||
|
||||
import { notYetImplemented } from '../../functions/notifications';
|
||||
|
||||
export type ActionDropdownItem = {
|
||||
icon: ReactNode;
|
||||
name: string;
|
||||
tooltip?: string;
|
||||
disabled?: boolean;
|
||||
onClick?: () => void;
|
||||
};
|
||||
|
||||
/**
|
||||
* A simple Menu component which renders a set of actions.
|
||||
*
|
||||
* If no "active" actions are provided, the menu will not be rendered
|
||||
*/
|
||||
export function ActionDropdown({
|
||||
icon,
|
||||
tooltip,
|
||||
actions
|
||||
}: {
|
||||
icon: ReactNode;
|
||||
tooltip?: string;
|
||||
actions: ActionDropdownItem[];
|
||||
}) {
|
||||
const hasActions = useMemo(() => {
|
||||
return actions.some((action) => !action.disabled);
|
||||
}, [actions]);
|
||||
|
||||
return hasActions ? (
|
||||
<Menu position="bottom-end">
|
||||
<Menu.Target>
|
||||
<Tooltip label={tooltip}>
|
||||
<ActionIcon size="lg" radius="sm" variant="outline">
|
||||
{icon}
|
||||
</ActionIcon>
|
||||
</Tooltip>
|
||||
</Menu.Target>
|
||||
<Menu.Dropdown>
|
||||
{actions.map((action, index) =>
|
||||
action.disabled ? null : (
|
||||
<Tooltip label={action.tooltip}>
|
||||
<Menu.Item
|
||||
icon={action.icon}
|
||||
key={index}
|
||||
onClick={() => {
|
||||
if (action.onClick != undefined) {
|
||||
action.onClick();
|
||||
} else {
|
||||
notYetImplemented();
|
||||
}
|
||||
}}
|
||||
disabled={action.disabled}
|
||||
>
|
||||
{action.name}
|
||||
</Menu.Item>
|
||||
</Tooltip>
|
||||
)
|
||||
)}
|
||||
</Menu.Dropdown>
|
||||
</Menu>
|
||||
) : null;
|
||||
}
|
Reference in New Issue
Block a user