/
action-button.tsx
56 lines (52 loc) · 1.59 KB
/
action-button.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { CloseOutlined, MoreOutlined, RetweetOutlined } from '@ant-design/icons';
import { Button, type MenuProps, Dropdown } from 'antd';
import { useState } from 'react';
import { UpdateEditorModal } from './update-editor-modal';
import { KubeObject } from '@/k8slens/kube-object';
import { DeletePopconfirm } from './delete-popconfirm';
interface Props<K extends KubeObject> {
obj: K;
}
export const ActionButton = <K extends KubeObject = KubeObject>({ obj }: Props<K>) => {
const [openUpdateModal, setOpenUpdateModal] = useState(false);
const items: MenuProps['items'] = [
{
key: 'delete',
label: (
<DeletePopconfirm obj={obj}>
<Button icon={<CloseOutlined />} type="link" size="small" danger>
Delete
</Button>
</DeletePopconfirm>
)
},
{
key: 'update',
label: (
<Button
icon={<RetweetOutlined />}
type="link"
size="small"
onClick={() => setOpenUpdateModal(true)}
>
Update
</Button>
)
}
].filter((item) => item.label);
return (
// wrapper to stop click event propagation
<div onClick={(e) => e.stopPropagation()}>
<Dropdown disabled={items.length === 0} menu={{ items }} arrow trigger={['click']}>
<MoreOutlined className="text-[25px] text-[#667085] hover:text-[#24282C]" />
</Dropdown>
<UpdateEditorModal
key={'update'}
obj={obj}
open={openUpdateModal}
onCancel={() => setOpenUpdateModal(false)}
onOk={() => setOpenUpdateModal(false)}
/>
</div>
);
};