Skip to content

Commit c31ea7d

Browse files
committed
4031: Adds data to production component
1 parent 693a7bc commit c31ea7d

7 files changed

Lines changed: 178 additions & 9 deletions

File tree

package-lock.json

Lines changed: 63 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"jest-image-snapshot": "^4.2.0",
6262
"lazy.js": "^0.5.1",
6363
"lodash": "^4.17.20",
64+
"millify": "^6.1.0",
6465
"ogr2ogr": "^2.0.0",
6566
"pg": "^7.18.2",
6667
"prop-types": "^15.7.2",
Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,89 @@
11
import React from 'react';
2-
import { Box, Typography } from '@material-ui/core';
2+
import { Box, Typography, Grid } from '@material-ui/core';
33
import { makeStyles } from '@material-ui/core/styles'
4+
import millify from 'millify'
5+
import oilIconUrl from '../../../images/icons/icon-oil.svg';
6+
import gasIconUrl from '../../../images/icons/icon-gas.svg';
7+
import coalIconUrl from '../../../images/icons/icon-coal.svg';
8+
import PercentDifference from '../../utils/PercentDifference';
9+
import { getFiscalYear } from '../../utils/nrrdUtils'
410

511
const useStyles = makeStyles({
612
h3: {
713
marginTop: '0.5rem',
814
marginBottom: '1rem',
915
textAlign: 'center'
10-
},
16+
}
1117
})
1218

1319

14-
export default function FYProductionSummary() {
20+
export default function FYProductionSummary({ currentFYData, prevFYData }) {
1521
const classes = useStyles()
1622

23+
const currentOil = currentFYData.find((i) => i.commodity === 'Oil');
24+
const currentGas = currentFYData.find((i) => i.commodity === 'Gas');
25+
const currentCoal = currentFYData.find((i) => i.commodity === 'Coal');
26+
27+
const previousOil = prevFYData.find((i) => i.commodity === 'Oil');
28+
const previousGas = prevFYData.find((i) => i.commodity === 'Gas');
29+
const previousCoal = prevFYData.find((i) => i.commodity === 'Coal');
30+
1731
return (
1832
<Box bgcolor="primary.main" mb={2} pt={0.5} pb={2} pl={3} pr={3} borderRadius={10}>
1933
<Typography variant="h3" className={classes.h3}>
2034
Production
2135
</Typography>
36+
<Grid container spacing={1}>
37+
<Grid item>
38+
<img src={oilIconUrl} alt="Logo" width={30}/>
39+
</Grid>
40+
<Grid item>
41+
<Typography component="strong" variant='inherit'>
42+
Oil: { millify(currentOil.volume, { precision: 1 }).replace('M', ' million')} { currentOil.unit_abbr }
43+
</Typography>
44+
</Grid>
45+
<Grid item style={{ marginLeft: "auto" }}>
46+
<Typography variant='inherit'>
47+
<PercentDifference
48+
currentAmount={currentOil.volume}
49+
previousAmount={previousOil.volume} /> from FY{ (getFiscalYear() - 1) % 100 }
50+
</Typography>
51+
</Grid>
52+
</Grid>
53+
<Grid container spacing={1}>
54+
<Grid item>
55+
<img src={gasIconUrl} alt="Logo" width={30}/>
56+
</Grid>
57+
<Grid item>
58+
<Typography component="strong" variant='inherit'>
59+
Gas: { millify(currentGas.volume, { precision: 1 }).replace('B', ' billion')} { currentGas.unit_abbr }
60+
</Typography>
61+
</Grid>
62+
<Grid item style={{ marginLeft: "auto" }}>
63+
<Typography variant='inherit'>
64+
<PercentDifference
65+
currentAmount={currentGas.volume}
66+
previousAmount={previousGas.volume} /> from FY{ (getFiscalYear() - 1) % 100 }
67+
</Typography>
68+
</Grid>
69+
</Grid>
70+
<Grid container spacing={1}>
71+
<Grid item>
72+
<img src={coalIconUrl} alt="Logo" width={30}/>
73+
</Grid>
74+
<Grid item>
75+
<Typography component="strong" variant='inherit'>
76+
Coal: { millify(currentCoal.volume, { precision: 1 }).replace('M', ' million')} { currentCoal.unit_abbr }
77+
</Typography>
78+
</Grid>
79+
<Grid item style={{ marginLeft: "auto" }}>
80+
<Typography variant='inherit'>
81+
<PercentDifference
82+
currentAmount={currentCoal.volume}
83+
previousAmount={previousCoal.volume} /> from FY{ (getFiscalYear() - 1) % 100 }
84+
</Typography>
85+
</Grid>
86+
</Grid>
2287
</Box>
2388
)
2489
}

src/components/sections/LandingPageSidebar/LandingPageSidebar.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,43 @@ import FyAtAGlance from '../FYAtAGlance'
33
import { FYProductionSummary } from '../FYProductionSummary';
44
import { LPMonthlyFactSheet } from '../LPMonthlyFactsheet'
55
import { WhatsNew } from '../WhatsNew';
6+
import { gql, useQuery } from '@apollo/client';
7+
8+
const atAGlanceQuery = gql`
9+
query FYDataAtAGlance {
10+
productionCurrFy: curr_fy_production_summary_v {
11+
commodity
12+
unit_abbr
13+
volume
14+
}
15+
16+
productionPrevFy: prev_fy_production_summary_v {
17+
commodity
18+
unit_abbr
19+
volume
20+
}
21+
22+
max_fy_month_by_dataset_v {
23+
fiscal_month
24+
dataset
25+
}
26+
}
27+
`
628

729
export default function LandingPageSidebar() {
30+
const { loading, error, data } = useQuery(atAGlanceQuery);
31+
32+
if (loading) return <p>Loading...</p>;
33+
if (error) return <p>Error: {error.message}</p>;
34+
35+
console.log(data)
836
return(
937
<>
1038
<FyAtAGlance />
1139

12-
<FYProductionSummary />
40+
<FYProductionSummary
41+
currentFYData={ data.productionCurrFy }
42+
prevFYData={ data.productionPrevFy }/>
1343

1444
<LPMonthlyFactSheet />
1545

src/components/utils/PercentDifference/PercentDifference.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@ const useStyles = makeStyles(theme => ({
3333
const PercentDifference = ({ currentAmount, previousAmount }) => {
3434
const classes = useStyles()
3535
const percentChange = (currentAmount < previousAmount ? -1 : 1) * (Math.abs(currentAmount - previousAmount) / Math.abs(previousAmount)) * 100
36+
3637
let icon
37-
if (percentChange > 0) {
38+
if (Math.round(percentChange) > 0) {
3839
icon = <ArrowUpwardIcon className={classes.trendIconUp} alt="Arrow pointing up indicating an increase." />
3940
}
40-
else if (percentChange < 0) {
41+
else if (Math.round(percentChange) < 0) {
4142
icon = <ArrowDownwardIcon className={classes.trendIconDown} alt="Arrow pointing down indicating a decrease." />
4243
}
43-
else if (percentChange === 0) {
44+
else if (Math.round(percentChange) === 0) {
4445
icon = <ArrowForwardIcon className={classes.trendIconDown} alt="Arrow pointing right indicating no change." />
4546
}
4647

src/images/icons/icon-gas.svg

Lines changed: 9 additions & 0 deletions
Loading

src/pages/index.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { Tabtastic, TabtasticTab } from '../components/layouts/Tabtastic'
1919
width: "100%",
2020
padding: "0 0 10px",
2121
}}>
22-
<Container maxWidth="lg">
22+
<Container maxWidth={false}>
2323
<Grid container spacing={0}>
2424
<Grid item xs={12} md={12}>
2525
<Typography variant="h2" component="h1">About natural resources revenue data</Typography>
@@ -40,7 +40,7 @@ import { Tabtastic, TabtasticTab } from '../components/layouts/Tabtastic'
4040
</Grid>
4141
</Container>
4242
</Box>
43-
<Container maxWidth="lg">
43+
<Container maxWidth={false}>
4444
<Box mb={2}>
4545
<Grid container spacing={2}>
4646
<Grid item xs={12} lg={8}>

0 commit comments

Comments
 (0)