-
Notifications
You must be signed in to change notification settings - Fork 116
/
Copy pathheaders-context-menu-builder.ts
111 lines (82 loc) · 2.95 KB
/
headers-context-menu-builder.ts
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
import { action, runInAction } from 'mobx';
import { AccountStore } from '../../../model/account/account-store';
import { UiStore } from '../../../model/ui/ui-store';
import { IEList, IncludeExcludeList } from '../../../model/IncludeExcludeList';
import { copyToClipboard } from '../../../util/ui';
import { ContextMenuItem } from '../../../model/ui/context-menu';
export interface HeadersHeaderClickedData {
HeadersIncludeExcludeList : IncludeExcludeList<string>
}
export interface HeaderEvent {
HeadersIncludeExcludeList: IncludeExcludeList<string>,
header_name: string;
header_value: string[];
}
export class HeadersHeaderContextMenuBuilder {
constructor(
private uiStore: UiStore
) {}
getContextMenuCallback(event: HeadersHeaderClickedData) {
return (mouseEvent: React.MouseEvent) => {
let excluded = event.HeadersIncludeExcludeList.GetKeysOnList(IEList.Exclude);
this.uiStore.handleContextMenuEvent(mouseEvent, [
{
type: 'submenu',
enabled: excluded.length > 0,
label: `Excluded`,
items: [
{
type: 'option',
label: `Clear All Excluded Headers`,
callback: async (data) => data.HeadersIncludeExcludeList.ClearList(IEList.Exclude)
},
...
(excluded.map((headerName) => ({
type: 'option',
label: `Clear '${headerName}'`,
callback: async (data: HeadersHeaderClickedData) =>
data.HeadersIncludeExcludeList.RemoveFromList(headerName,IEList.Exclude)
}
))
) as ContextMenuItem<HeadersHeaderClickedData>[]
]
}
], event
);
};
}
}
export class HeadersContextMenuBuilder {
constructor(
private accountStore: AccountStore,
private uiStore: UiStore
) {}
getContextMenuCallback(event: HeaderEvent) {
return (mouseEvent: React.MouseEvent) => {
const { isPaidUser } = this.accountStore;
let isPinned = event.HeadersIncludeExcludeList.IsKeyOnList(event.header_name,IEList.Favorite);
this.uiStore.handleContextMenuEvent(mouseEvent, [
{
type: 'option',
label: (isPinned ? `Unpin` : `Pin`) + ` This Header`,
callback: async (data) => {
isPinned ? data.HeadersIncludeExcludeList.RemoveFromList(data.header_name,IEList.Favorite) : data.HeadersIncludeExcludeList.AddOrUpdateToList(data.header_name,IEList.Favorite);
}
},
{
type: 'option',
label: `Exclude This Header`,
callback: async (data) => {
data.HeadersIncludeExcludeList.AddOrUpdateToList(data.header_name,IEList.Exclude);
}
},
{
type: 'option',
label: `Copy Header Value`,
callback: async (data) => copyToClipboard( data.header_value.join("\n" ) )
}
], event
);
};
}
}