This repository has been archived by the owner on Jul 29, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce dashboard widget to DRY up socket sharing
- Loading branch information
1 parent
07e7285
commit 4d0d14c
Showing
4 changed files
with
26 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,24 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import socketIOClient from 'socket.io-client'; | ||
|
||
import '../styles/default.scss'; | ||
|
||
import Dashboard from '../widgets/dashboard'; | ||
import NumberWidget from '../widgets/number/widget'; | ||
import PingWidget from '../widgets/ping/widget'; | ||
import BuildStatusWidget from '../widgets/build-status/widget'; | ||
import SparklineWidget from '../widgets/sparkline/widget'; | ||
import ProgressWidget from '../widgets/progress/widget'; | ||
|
||
const socket = socketIOClient(`http://${window.location.host}`); | ||
|
||
ReactDOM.render( | ||
<div className="dashboard"> | ||
<SparklineWidget socket={socket} name="DemoUsers" title="Users" format="0.00a" /> | ||
<PingWidget socket={socket} name="GooglePing" title="API" /> | ||
<NumberWidget socket={socket} name="ReasonPRs" title="Pull Requests" /> | ||
<BuildStatusWidget socket={socket} name="DemoMaster" title="Build - Master" size="medium" /> | ||
<ProgressWidget socket={socket} name="DemoProgress" title="Sales Target" /> | ||
<NumberWidget socket={socket} name="DemoConversion" title="Conversion" metric="%" format="0.0a" /> | ||
<BuildStatusWidget socket={socket} name="DemoDevelop" title="Build - Develop" size="medium" /> | ||
</div>, | ||
<Dashboard> | ||
<SparklineWidget name="DemoUsers" title="Users" format="0.00a" /> | ||
<PingWidget name="GooglePing" title="API" /> | ||
<NumberWidget name="ReasonPRs" title="Pull Requests" /> | ||
<BuildStatusWidget name="DemoMaster" title="Build - Master" size="medium" /> | ||
<ProgressWidget name="DemoProgress" title="Sales Target" /> | ||
<NumberWidget name="DemoConversion" title="Conversion" metric="%" format="0.0a" /> | ||
<BuildStatusWidget name="DemoDevelop" title="Build - Develop" size="medium" /> | ||
</Dashboard>, | ||
document.getElementById('content'), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from 'react'; | ||
import socketIOClient from 'socket.io-client'; | ||
|
||
function renderWidgets(props) { | ||
const socket = socketIOClient(`http://${window.location.host}`); | ||
return React.Children.map(props.children, child => React.cloneElement(child, { socket })); | ||
} | ||
|
||
function Dashboard(props) { | ||
return <div className="dashboard">{renderWidgets(props)}</div>; | ||
} | ||
|
||
export default Dashboard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters