-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Expand file tree
/
Copy pathindex.js
More file actions
179 lines (161 loc) · 6.48 KB
/
index.js
File metadata and controls
179 lines (161 loc) · 6.48 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import React from 'react';
import { useSelector, useDispatch } from 'react-redux';
import find from 'lodash/find';
import { IconSettings, IconCookie, IconTool, IconSearch, IconPalette, IconBrandGithub } from '@tabler/icons';
import Mousetrap from 'mousetrap';
import { getKeyBindingsForActionAllOS } from 'providers/Hotkeys/keyMappings';
import ToolHint from 'components/ToolHint';
import Cookies from 'components/Cookies';
import Notifications from 'components/Notifications';
import Portal from 'components/Portal';
import ThemeDropdown from './ThemeDropdown';
import { openConsole } from 'providers/ReduxStore/slices/logs';
import { addTab } from 'providers/ReduxStore/slices/tabs';
import { useApp } from 'providers/App';
import { openCookiesModal, closeCookiesModal } from 'providers/ReduxStore/slices/app';
import StyledWrapper from './StyledWrapper';
const StatusBar = () => {
const dispatch = useDispatch();
const activeWorkspaceUid = useSelector((state) => state.workspaces.activeWorkspaceUid);
const workspaces = useSelector((state) => state.workspaces.workspaces);
const showHomePage = useSelector((state) => state.app.showHomePage);
const showManageWorkspacePage = useSelector((state) => state.app.showManageWorkspacePage);
const showApiSpecPage = useSelector((state) => state.app.showApiSpecPage);
const isCookiesModalOpen = useSelector((state) => state.app.isCookiesModalOpen);
const tabs = useSelector((state) => state.tabs.tabs);
const activeTabUid = useSelector((state) => state.tabs.activeTabUid);
const activeTab = find(tabs, (t) => t.uid === activeTabUid);
const logs = useSelector((state) => state.logs.logs);
const { version } = useApp();
const activeWorkspace = workspaces.find((w) => w.uid === activeWorkspaceUid);
const errorCount = logs.filter((log) => log.type === 'error').length;
const handleConsoleClick = () => {
dispatch(openConsole());
};
const handlePreferencesClick = () => {
const collectionUid = activeTab?.collectionUid || activeWorkspace?.scratchCollectionUid;
dispatch(
addTab({
type: 'preferences',
uid: collectionUid ? `${collectionUid}-preferences` : 'preferences',
collectionUid: collectionUid
})
);
};
const openGlobalSearch = () => {
const bindings = getKeyBindingsForActionAllOS('globalSearch') || [];
bindings.forEach((binding) => {
Mousetrap.trigger(binding);
});
};
return (
<StyledWrapper>
{isCookiesModalOpen && (
<Portal>
<Cookies
onClose={() => {
dispatch(closeCookiesModal());
document.querySelector('[data-trigger="cookies"]').focus();
}}
aria-modal="true"
role="dialog"
aria-labelledby="cookies-title"
aria-describedby="cookies-description"
/>
</Portal>
)}
<div className="status-bar">
<div className="status-bar-section">
<div className="status-bar-group">
<ToolHint text="Preferences" toolhintId="Preferences" place="top-start" offset={10}>
<button
className="status-bar-button preferences-button"
data-trigger="preferences"
onClick={handlePreferencesClick}
tabIndex={0}
aria-label="Open Preferences"
>
<IconSettings size={16} strokeWidth={1.5} aria-hidden="true" />
</button>
</ToolHint>
<ThemeDropdown>
<button
className="status-bar-button"
data-trigger="theme"
tabIndex={0}
aria-label="Change Theme"
>
<IconPalette size={16} strokeWidth={1.5} aria-hidden="true" />
</button>
</ThemeDropdown>
<ToolHint text="Notifications" toolhintId="Notifications" place="top" offset={10}>
<div className="status-bar-button">
<Notifications />
</div>
</ToolHint>
<ToolHint text="GitHub Repository" toolhintId="GitHub" place="top" offset={10}>
<button
className="status-bar-button"
onClick={() => {
window?.ipcRenderer?.openExternal('https://github.com/usebruno/bruno');
}}
tabIndex={0}
aria-label="Open GitHub Repository"
>
<IconBrandGithub size={16} strokeWidth={1.5} aria-hidden="true" />
</button>
</ToolHint>
</div>
</div>
<div className="status-bar-section">
<div className="flex items-center gap-3">
<button
className="status-bar-button"
data-trigger="search"
onClick={openGlobalSearch}
tabIndex={0}
aria-label="Global Search"
>
<div className="console-button-content">
<IconSearch size={16} strokeWidth={1.5} aria-hidden="true" />
<span className="console-label">Search</span>
</div>
</button>
<button
className="status-bar-button"
data-trigger="cookies"
onClick={() => dispatch(openCookiesModal())}
tabIndex={0}
aria-label="Open Cookies"
>
<div className="console-button-content">
<IconCookie size={16} strokeWidth={1.5} aria-hidden="true" />
<span className="console-label">Cookies</span>
</div>
</button>
<button
className={`status-bar-button ${errorCount > 0 ? 'has-errors' : ''}`}
data-trigger="dev-tools"
onClick={handleConsoleClick}
tabIndex={0}
aria-label={`Open Dev Tools${errorCount > 0 ? ` (${errorCount} errors)` : ''}`}
>
<div className="console-button-content">
<IconTool size={16} strokeWidth={1.5} aria-hidden="true" />
<span className="console-label">Dev Tools</span>
{errorCount > 0 && (
<span className="error-count-inline">{errorCount}</span>
)}
</div>
</button>
<div className="status-bar-divider"></div>
<div className="status-bar-version">
v{version}
</div>
</div>
</div>
</div>
</StyledWrapper>
);
};
export default StatusBar;