RowActions.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import { useTranslation } from 'react-i18next';
  2. import { Button, Dropdown, type MenuProps } from 'antd';
  3. import {
  4. MoreOutlined,
  5. EditOutlined,
  6. QrcodeOutlined,
  7. CopyOutlined,
  8. ExportOutlined,
  9. RetweetOutlined,
  10. BlockOutlined,
  11. DeleteOutlined,
  12. InfoCircleOutlined,
  13. TagsOutlined,
  14. UsergroupAddOutlined,
  15. UsergroupDeleteOutlined,
  16. } from '@ant-design/icons';
  17. import { isInboundMultiUser, showQrCodeMenu } from './helpers';
  18. import type { DBInboundRecord, RowAction } from './types';
  19. interface RowActionsMenuProps {
  20. record: DBInboundRecord;
  21. subEnable: boolean;
  22. hasClients: boolean;
  23. onClick: (key: RowAction) => void;
  24. isMobile?: boolean;
  25. }
  26. export function buildRowActionsMenu({ record, subEnable, t, isMobile, hasClients }: { record: DBInboundRecord; subEnable: boolean; t: (k: string) => string; isMobile?: boolean; hasClients?: boolean }): MenuProps['items'] {
  27. const items: MenuProps['items'] = [];
  28. if (isMobile) {
  29. items.push({ key: 'edit', icon: <EditOutlined />, label: t('edit') });
  30. }
  31. if (showQrCodeMenu(record)) {
  32. items.push({ key: 'qrcode', icon: <QrcodeOutlined />, label: t('qrCode') });
  33. }
  34. if (isInboundMultiUser(record)) {
  35. items.push({ key: 'export', icon: <ExportOutlined />, label: t('pages.inbounds.export') });
  36. if (subEnable) {
  37. items.push({
  38. key: 'subs',
  39. icon: <ExportOutlined />,
  40. label: `${t('pages.inbounds.export')} — ${t('pages.settings.subSettings')}`,
  41. });
  42. }
  43. } else {
  44. items.push({ key: 'showInfo', icon: <InfoCircleOutlined />, label: t('pages.inbounds.inboundInfo') });
  45. }
  46. items.push({ key: 'clipboard', icon: <CopyOutlined />, label: t('pages.inbounds.exportInbound') });
  47. items.push({ key: 'resetTraffic', icon: <RetweetOutlined />, label: t('pages.inbounds.resetTraffic') });
  48. items.push({ key: 'clone', icon: <BlockOutlined />, label: t('pages.inbounds.clone') });
  49. if (isInboundMultiUser(record) && hasClients) {
  50. items.push({ key: 'attachClients', icon: <UsergroupAddOutlined />, label: t('pages.inbounds.attachClients') });
  51. items.push({ key: 'detachClients', icon: <UsergroupDeleteOutlined />, label: t('pages.inbounds.detachClients') });
  52. items.push({ key: 'addToGroup', icon: <TagsOutlined />, label: t('pages.inbounds.addClientsToGroup') });
  53. items.push({ type: 'divider' });
  54. items.push({ key: 'delAllClients', icon: <UsergroupDeleteOutlined />, danger: true, label: t('pages.inbounds.delAllClients') });
  55. } else {
  56. items.push({ type: 'divider' });
  57. }
  58. items.push({ key: 'delete', icon: <DeleteOutlined />, danger: true, label: t('delete') });
  59. return items;
  60. }
  61. export function RowActionsCell({ record, subEnable, hasClients, onClick }: RowActionsMenuProps) {
  62. const { t } = useTranslation();
  63. return (
  64. <div className="action-buttons">
  65. <Button type="text" size="small" icon={<EditOutlined />} onClick={() => onClick('edit')} />
  66. <Dropdown
  67. trigger={['click']}
  68. menu={{
  69. items: buildRowActionsMenu({ record, subEnable, t, hasClients }),
  70. onClick: ({ key }) => onClick(key as RowAction),
  71. }}
  72. >
  73. <Button type="text" size="small" icon={<MoreOutlined />} />
  74. </Dropdown>
  75. </div>
  76. );
  77. }