-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
ReportActionContextMenu.js
122 lines (112 loc) · 3.45 KB
/
ReportActionContextMenu.js
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import React from 'react';
const contextMenuRef = React.createRef();
/**
* Show the ReportActionContextMenu modal popover.
*
* @param {string} type - the context menu type to display [EMAIL, LINK, REPORT_ACTION]
* @param {Object} [event] - A press event.
* @param {String} [selection] - Copied content.
* @param {Element} contextMenuAnchor - popoverAnchor
* @param {String} reportID - Active Report Id
* @param {Object} reportAction - ReportAction for ContextMenu
* @param {String} draftMessage - ReportAction Draftmessage
* @param {Function} [onShow=() => {}] - Run a callback when Menu is shown
* @param {Function} [onHide=() => {}] - Run a callback when Menu is hidden
* @param {Boolean} isArchivedRoom - Whether the provided report is an archived room
* @param {Boolean} isChronosReport - Flag to check if the chat participant is Chronos
*/
function showContextMenu(
type,
event,
selection,
contextMenuAnchor,
reportID = '0',
reportAction = {},
draftMessage = '',
onShow = () => {},
onHide = () => {},
isArchivedRoom = false,
isChronosReport = false,
) {
if (!contextMenuRef.current) {
return;
}
contextMenuRef.current.showContextMenu(
type,
event,
selection,
contextMenuAnchor,
reportID,
reportAction,
draftMessage,
onShow,
onHide,
isArchivedRoom,
isChronosReport,
);
}
/**
* Hide the ReportActionContextMenu modal popover.
* Hides the popover menu with an optional delay
* @param {Boolean} shouldDelay - whether the menu should close after a delay
* @param {Function} [onHideCallback=() => {}] - Callback to be called after Context Menu is completely hidden
*/
function hideContextMenu(shouldDelay, onHideCallback = () => {}) {
if (!contextMenuRef.current) {
return;
}
if (!shouldDelay) {
contextMenuRef.current.hideContextMenu(onHideCallback);
return;
}
// Save the active instanceID for which hide action was called.
// If menu is being closed with a delay, check that whether the same instance exists or a new was created.
// If instance is not same, cancel the hide action
const instanceID = contextMenuRef.current.instanceID;
setTimeout(() => {
if (contextMenuRef.current.instanceID !== instanceID) {
return;
}
contextMenuRef.current.hideContextMenu(onHideCallback);
}, 800);
}
function hideDeleteModal() {
if (!contextMenuRef.current) {
return;
}
contextMenuRef.current.hideDeleteModal();
}
/**
* Opens the Confirm delete action modal
* @param {String} reportID
* @param {Object} reportAction
* @param {Boolean} [shouldSetModalVisibility]
* @param {Function} [onConfirm]
* @param {Function} [onCancel]
*/
function showDeleteModal(reportID, reportAction, shouldSetModalVisibility, onConfirm, onCancel) {
if (!contextMenuRef.current) {
return;
}
contextMenuRef.current.showDeleteModal(reportID, reportAction, shouldSetModalVisibility, onConfirm, onCancel);
}
/**
* Whether Context Menu is active for the Report Action.
*
* @param {Number|String} actionID
* @return {Boolean}
*/
function isActiveReportAction(actionID) {
if (!contextMenuRef.current) {
return;
}
return contextMenuRef.current.isActiveReportAction(actionID);
}
export {
contextMenuRef,
showContextMenu,
hideContextMenu,
isActiveReportAction,
showDeleteModal,
hideDeleteModal,
};