Skip to content

Commit bdaaaf6

Browse files
authored
Adds frontend support for notifications (#334)
* adds frontend support for notifications * js lint fixes
1 parent 4923be0 commit bdaaaf6

File tree

5 files changed

+83
-0
lines changed

5 files changed

+83
-0
lines changed

pkg/server/handler.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,15 @@ func (ctrl *Controller) renderIndexPage(w http.ResponseWriter, _ *http.Request)
386386
"LatestVersionInfo": updates.LatestVersionJSON(),
387387
"ExtraMetadata": extraMetadataStr,
388388
"BaseURL": ctrl.config.BaseURL,
389+
"NotificationText": ctrl.NotificationText(),
389390
})
390391
}
391392

393+
func (ctrl *Controller) NotificationText() string {
394+
// TODO: implement backend support for alert text
395+
return ""
396+
}
397+
392398
func mustExecute(t *template.Template, w io.Writer, v interface{}) {
393399
if err := t.Execute(w, v); err != nil {
394400
panic(err)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import React, { useState, useEffect } from "react";
2+
import { connect } from "react-redux";
3+
import "react-dom";
4+
5+
import { withShortcut } from "react-keybind";
6+
import Modal from "react-modal";
7+
import clsx from "clsx";
8+
9+
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
10+
import { faExclamationTriangle } from "@fortawesome/free-solid-svg-icons";
11+
12+
function Notifications(props) {
13+
const { notificationText } = window;
14+
15+
const [hidden, setHidden] = useState(notificationText === "");
16+
17+
return (
18+
<div className={clsx("notifications", { hidden })}>
19+
<div className="notifications-container">
20+
<div className="notification-icon">
21+
<FontAwesomeIcon icon={faExclamationTriangle} />
22+
</div>
23+
<div className="notification-body">{notificationText}</div>
24+
<div
25+
className="notification-close-btn"
26+
onClick={function () {
27+
setHidden(true);
28+
}}
29+
/>
30+
</div>
31+
</div>
32+
);
33+
}
34+
35+
export default connect((x) => x, {})(Notifications);

webapp/javascript/index.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import PyroscopeApp from "./components/PyroscopeApp";
1111
import ComparisonApp from "./components/ComparisonApp";
1212
import ComparisonDiffApp from "./components/ComparisonDiffApp";
1313
import Sidebar from "./components/Sidebar";
14+
import Notifications from "./components/Notifications";
1415

1516
import history from "./util/history";
1617

@@ -39,6 +40,7 @@ ReactDOM.render(
3940
<ComparisonDiffApp />
4041
</Route>
4142
</Switch>
43+
<Notifications />
4244
</ShortcutProvider>
4345
</Router>
4446
{showFps ? <FPSStats left="auto" top="auto" bottom={2} right={2} /> : ""}

webapp/sass/profile.scss

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,3 +679,42 @@ $sidebar-tooltip-color: #777;
679679
.main-wrapper {
680680
margin-left: $sidebar-size;
681681
}
682+
683+
.notifications {
684+
position: fixed;
685+
top: 58px;
686+
right: 15px;
687+
688+
&.hidden {
689+
display: none;
690+
}
691+
692+
.notifications-container {
693+
display: flex;
694+
overflow: hidden;
695+
background-color: rgb(78, 81, 90);
696+
border-radius: 4px;
697+
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
698+
699+
.notification-icon {
700+
padding: 15px;
701+
background-color: #c43028bb;
702+
}
703+
704+
.notification-body {
705+
padding: 15px;
706+
max-width: 30vw;
707+
}
708+
.notification-close-btn {
709+
text-align: center;
710+
font-weight: bold;
711+
cursor: pointer;
712+
background-color: rgba(0,0,0,0.1);
713+
padding: 15px;
714+
&::before {
715+
content: '×';
716+
display: inline;
717+
}
718+
}
719+
}
720+
}

webapp/templates/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<body>
1818
<div id="root"></div>
1919
<script type="text/javascript">window.initialState = {{ .InitialState }};</script>
20+
<script type="text/javascript">window.notificationText = "{{ .NotificationText }}";</script>
2021
<script type="text/javascript">window.buildInfo = {{ .BuildInfo }};</script>
2122
<script type="text/javascript">window.latestVersionInfo = {{ .LatestVersionInfo }};</script>
2223
<script src="/assets/app.<%= webpack.hash %>.js" type="text/javascript"></script>

0 commit comments

Comments
 (0)