forked from owid/owid-grapher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGdocsMoreMenu.tsx
103 lines (101 loc) · 3.22 KB
/
GdocsMoreMenu.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import React from "react"
import { Dropdown, Menu, Button, Modal } from "antd"
import {
faEllipsisVertical,
faTrash,
faXmark,
faBug,
} from "@fortawesome/free-solid-svg-icons"
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome/index.js"
import { OwidGdoc } from "@ourworldindata/utils"
enum GdocsMoreMenuAction {
Debug = "debug",
Unpublish = "unpublish",
Delete = "delete",
}
export const GdocsMoreMenu = ({
gdoc,
onDebug,
onUnpublish,
onDelete,
}: {
gdoc: OwidGdoc
onDebug: VoidFunction
onUnpublish: VoidFunction
onDelete: VoidFunction
}) => {
const confirmUnpublish = () => {
Modal.confirm({
title: "Are you sure you want to unpublish this article?",
content: "The article will no longer be visible to the public.",
okText: "Unpublish",
okType: "danger",
cancelText: "Cancel",
onOk() {
onUnpublish()
},
maskClosable: true,
})
}
const confirmDelete = () => {
Modal.confirm({
title: "Are you sure you want to delete this article?",
content:
"The article will be removed from the admin list and unpublished. The original Google Doc will be preserved.",
okText: "Delete",
okType: "danger",
cancelText: "Cancel",
onOk() {
onDelete()
},
maskClosable: true,
})
}
return (
<Dropdown
trigger={["click"]}
overlay={
<Menu
onClick={({ key }) => {
switch (key) {
case GdocsMoreMenuAction.Debug:
onDebug()
break
case GdocsMoreMenuAction.Unpublish:
confirmUnpublish()
break
case GdocsMoreMenuAction.Delete:
confirmDelete()
break
}
}}
items={[
{
key: GdocsMoreMenuAction.Debug,
label: "Debug",
icon: <FontAwesomeIcon icon={faBug} />,
},
{
key: GdocsMoreMenuAction.Unpublish,
label: "Unpublish",
danger: gdoc.published,
disabled: !gdoc.published,
icon: <FontAwesomeIcon icon={faXmark} />,
},
{
key: GdocsMoreMenuAction.Delete,
label: "Delete",
danger: true,
icon: <FontAwesomeIcon icon={faTrash} />,
},
]}
/>
}
placement="bottomRight"
>
<Button>
<FontAwesomeIcon icon={faEllipsisVertical} />
</Button>
</Dropdown>
)
}