mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-22 08:13:12 +09:00
A plugin action can be disabled, and it becomes the main button when the user has no restart permission. Only the main button is disabled so the menu stays usable. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
import React from "react";
|
|
import { Button, Dropdown } from "antd";
|
|
|
|
import { MenuItemType } from "antd/es/menu/interface";
|
|
import { DropdownButtonProps } from "antd/es/dropdown";
|
|
|
|
export type VariableDropdownButtonProps = DropdownButtonProps & {
|
|
actions: (MenuItemType & { onClick?: () => void })[],
|
|
};
|
|
|
|
export default function VariableDropdownButton(props: VariableDropdownButtonProps) {
|
|
const menuActions = [...props.actions];
|
|
const mainAction = menuActions.shift();
|
|
if (!mainAction) {
|
|
return <></>;
|
|
}
|
|
|
|
const mainDisabled = props.disabled || mainAction.disabled;
|
|
const buttonProps: DropdownButtonProps = {
|
|
...props,
|
|
danger: mainAction.danger,
|
|
onClick: (event) => {
|
|
event.stopPropagation();
|
|
if (!mainDisabled && mainAction.onClick) {
|
|
mainAction.onClick();
|
|
}
|
|
},
|
|
};
|
|
|
|
return menuActions.length === 0
|
|
? <Button {...buttonProps} disabled={mainDisabled}>
|
|
{mainAction.label}
|
|
</Button>
|
|
: <Dropdown.Button
|
|
{...buttonProps}
|
|
// stopPropagation is needed to prevent propagation to table rows
|
|
menu={{ items: menuActions, onClick: (e: any) => e.domEvent.stopPropagation() }}
|
|
buttonsRender={([left, right]) => [
|
|
React.cloneElement(left as any, { disabled: mainDisabled }),
|
|
React.cloneElement(right as any, { onClick: (e: any) => e.stopPropagation() }),
|
|
]}
|
|
>
|
|
{mainAction.label}
|
|
</Dropdown.Button>;
|
|
}
|