-
Notifications
You must be signed in to change notification settings - Fork 0
Add: Dashboard #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
n00b-coder9
wants to merge
7
commits into
master
Choose a base branch
from
faiz-dashboard-ui
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Add: Dashboard #16
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
24d6129
add: recent urls component with logic
n00b-coder9 a7ac86c
added charts to dashboard
n00b-coder9 fd5ad3a
Add: Line Chart and Pie Charts
n00b-coder9 db58d05
fixed trivial issues
n00b-coder9 947b9cc
fixed some ui issues and upgraded to highcharts
n00b-coder9 a173253
fixed minor issues
n00b-coder9 70770c6
fixed minor issues
n00b-coder9 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,83 @@ | ||
| import React from 'react'; | ||
| import Highcharts from 'highcharts/highstock'; | ||
| import HighchartsReact from 'highcharts-react-official'; | ||
| import { useSelector } from 'react-redux'; | ||
|
|
||
| /** | ||
| * Line Chart component | ||
| * This renders a line chart plotting the no of clicks made per day | ||
| */ | ||
|
|
||
| // The component to render the line chart | ||
Rishav-Agarwal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| function LineChart() { | ||
| // Retreive the selected Url | ||
| const selectedUrl = useSelector((state) => state.urls.selectedUrl); | ||
| const clicks = selectedUrl ? selectedUrl.clicks : []; | ||
|
|
||
| // Group the Clicks according to date | ||
| const groups = clicks.reduce((groups, click) => { | ||
| // Retrieve the Date from clicked time | ||
| const date = click.time.split('T')[0]; | ||
| if (!groups[date]) { | ||
| groups[date] = []; | ||
| } | ||
| groups[date].push(click); | ||
| return groups; | ||
| }, {}); | ||
| // Generate an array according to the groups made | ||
| const groupArrays = Object.keys(groups).map((date) => { | ||
| return { | ||
| date, | ||
| clicks: groups[date], | ||
| }; | ||
| }); | ||
|
|
||
| // Data to be passed to the chart | ||
| const options = { | ||
| chart: { | ||
| reflow: 'true', | ||
| BackgroundColor: '#fbfbfb', | ||
| plotBorderWidth: null, | ||
| plotShadow: false, | ||
| type: 'line', | ||
| }, | ||
| title: { | ||
| text: 'Clicks by Date ', | ||
| align: 'left', | ||
| }, | ||
| xAxis: { | ||
| title: { | ||
| text: 'Date', | ||
| }, | ||
| categories: groupArrays.map((groups) => groups.date), | ||
| }, | ||
| yAxis: { | ||
| title: { | ||
| text: 'Clicks', | ||
| }, | ||
| }, | ||
| series: [{ | ||
| name: 'Clicks', | ||
| data: groupArrays.map((groups) => groups.clicks.length), | ||
| }], | ||
| }; | ||
|
|
||
| return ( | ||
| <div style={{ | ||
| display: 'flex', | ||
| flexGrow: 1, | ||
| flexBasis: '30%', | ||
| }}> | ||
| <div style={{ | ||
| width: '100% !important', | ||
| backgroundColor: '#fbfbfb', | ||
| }}> | ||
|
|
||
| <HighchartsReact | ||
| highcharts={Highcharts} | ||
| options={options} /> | ||
| </div> | ||
| </div>); | ||
| } | ||
|
|
||
| export default LineChart; | ||
This file contains hidden or 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,157 @@ | ||
| import HighchartsReact from 'highcharts-react-official'; | ||
| import Highcharts from 'highcharts/highstock'; | ||
| import PropTypes from 'prop-types'; | ||
| import React from 'react'; | ||
| import { useSelector } from 'react-redux'; | ||
|
|
||
| /** | ||
| * This is the Pie Chart component | ||
| * This has two variants | ||
| * 1. This plots the no of clicks made in the last month per location on a pieChart | ||
| * 2. This plots the no of clicks made in the last month per url on a pieChart | ||
| * @usage Just import it and pass a variant prop | ||
Rishav-Agarwal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * whose value should be `CLICKS_BY_LOCATION` for 1 else `CLICKS_BY_URLS` for 2 | ||
| * @example <PieChart variant = `CLICKS_BY_LOCATION`||`CLICKS_BY_URLS`/> | ||
| */ | ||
|
|
||
| export default function PieChart(props) { | ||
| const { variant } = props; | ||
|
|
||
| const urls = useSelector((state) => state.urls.urls); | ||
| const selectedUrl = useSelector((state) => state.urls.selectedUrl); | ||
| const clicks = selectedUrl ? selectedUrl.clicks : []; | ||
| let options = null; | ||
|
|
||
| // Check if the variant is one needing location | ||
| if (variant === 'CLICKS_BY_LOCATION') { | ||
| const groups = clicks.reduce((groups, click) => { | ||
| const location = click.location.city + ',' + click.location.state; | ||
| if (!groups[location]) { | ||
| groups[location] = []; | ||
| } | ||
| const date1 = new Date(); | ||
| const date2 = new Date(click.time.split('T')[0]); | ||
| const diffDays = Math.ceil((date1 - date2) / (1000 * 60 * 60 * 24)); | ||
| if (diffDays <= 31) { | ||
| groups[location].push(click); | ||
| } | ||
| return groups; | ||
| }, {}); | ||
| const groupArrays = Object.keys(groups).map((location) => { | ||
| return { | ||
| name: location, | ||
| y: groups[location].length, | ||
| }; | ||
| }); | ||
| options = { | ||
| chart: { | ||
| plotBackgroundColor: '#fbfbfb', | ||
| plotBorderWidth: null, | ||
| plotShadow: false, | ||
| type: 'pie', | ||
| }, | ||
| legend: { | ||
| layout: 'vertical', | ||
| align: 'right', | ||
| verticalAlign: 'middle', | ||
| }, | ||
| title: { | ||
| text: 'Clicks by Location', | ||
| align: 'left', | ||
| }, | ||
| tooltip: { | ||
| pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>', | ||
| }, | ||
| plotOptions: { | ||
| pie: { | ||
| dataLabels: { | ||
| enabled: true, | ||
| format: '<b>{point.name}<b/>:{point.percentage:.1f} %', | ||
| }, | ||
| }, | ||
| }, | ||
| series: [{ | ||
| name: 'Clicks', | ||
| colorByPoint: true, | ||
| data: groupArrays, | ||
| }], | ||
| }; | ||
| } else if (variant === 'CLICKS_BY_URLS') { | ||
| const groups = urls.reduce((groups, url) => { | ||
| const clicks = url.clicks ? url.clicks : []; | ||
| const title = url.title ? url.title : url.shortUrl; | ||
| for (const click of clicks) { | ||
| const date1 = new Date(); | ||
| const date2 = new Date(click.time.split('T')[0]); | ||
| const diffDays = Math.ceil((date1 - date2) / (1000 * 60 * 60 * 24)); | ||
| if (!groups[title]) { | ||
| groups[title] = []; | ||
| } | ||
| if (diffDays <= 31) { | ||
| groups[title].push(click); | ||
| } | ||
| } | ||
| return groups; | ||
| }, {}); | ||
| const groupArrays = Object.keys(groups).map((title) => { | ||
| return { | ||
| name: title, | ||
| y: groups[title].length, | ||
| }; | ||
| }); | ||
| options = { | ||
| chart: { | ||
| plotBackgroundColor: '#fbfbfb', | ||
| plotBorderWidth: null, | ||
| plotShadow: false, | ||
| type: 'pie', | ||
| }, | ||
| legend: { | ||
| layout: 'vertical', | ||
| align: 'right', | ||
| verticalAlign: 'middle', | ||
| }, | ||
| title: { | ||
| text: 'Clicks last month', | ||
| align: 'left', | ||
| }, | ||
| tooltip: { | ||
| pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>', | ||
| }, | ||
| plotOptions: { | ||
| pie: { | ||
| dataLabels: { | ||
| enabled: true, | ||
| format: '<b>{point.name}<b/>:{point.percentage:.1f} %', | ||
| }, | ||
| }, | ||
| }, | ||
| series: [{ | ||
| name: 'Clicks', | ||
| colorByPoint: true, | ||
| data: groupArrays, | ||
| }], | ||
| }; | ||
| } | ||
| return ( | ||
| <div style={{ | ||
| display: 'flex', | ||
| flexGrow: 1, | ||
| height: '40%', | ||
| }}> | ||
| <div style={{ | ||
| width: '100% !important', | ||
| backgroundColor: '#fbfbfb', | ||
| }}> | ||
| <HighchartsReact | ||
| highcharts={Highcharts} | ||
| options={options} | ||
| /> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| PieChart.propTypes = { | ||
| variant: PropTypes.string, | ||
| }; | ||
This file contains hidden or 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,61 @@ | ||
| import { | ||
| Card, | ||
| CardActions, | ||
| CardHeader, | ||
| makeStyles, | ||
| useMediaQuery, | ||
| useTheme, | ||
| } from '@material-ui/core'; | ||
| import React from 'react'; | ||
| import UrlList from './UrlList'; | ||
|
|
||
| // Create styles for the component | ||
| const useStyles = makeStyles((theme) => ({ | ||
Rishav-Agarwal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| container: { | ||
| display: 'flex', | ||
| flexGrow: 1, | ||
| flexBasis: '50%', | ||
| }, | ||
| })); | ||
|
|
||
| // Url Container component | ||
| const UrlContainer = (props) => { | ||
| const theme = useTheme(); | ||
| const classes = useStyles(); | ||
| const mediaMinSm = useMediaQuery(theme.breakpoints.up('sm')); | ||
|
|
||
| return ( | ||
Rishav-Agarwal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <div className={classes.container}> | ||
| <Card style={{ | ||
| flex: 1, | ||
| height: '90%', | ||
| }}> | ||
| <CardHeader | ||
| title = 'My Urls' | ||
| style={{ | ||
| width: '100%', | ||
| height: '10%', | ||
| color: 'white', | ||
| background: 'black', | ||
| }} /> | ||
| <CardActions style={{ | ||
| display: 'flex', | ||
| flexDirection: 'column', | ||
| height: '70%', | ||
| }}> | ||
| <div | ||
| style={{ | ||
| display: 'flex', | ||
| flexDirection: 'column', | ||
| paddingTop: '4px', | ||
| paddingBottom: mediaMinSm ? '16px' : '6px', | ||
| width: '100%', | ||
| }}> | ||
| <UrlList /> | ||
| </div> | ||
| </CardActions> | ||
| </Card> | ||
| </div>); | ||
| }; | ||
|
|
||
| export default UrlContainer; | ||
This file contains hidden or 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,10 @@ | ||
| .item{ | ||
| cursor: 'pointer'; | ||
| height: '12%'; | ||
| } | ||
| .active{ | ||
| display: flex; | ||
| width: '100%'; | ||
| background-color: slategray; | ||
| color: white; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't required anymore. We discussed, right?