-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
146 additions
and
7 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
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 |
---|---|---|
|
@@ -99,4 +99,5 @@ | |
- average_daily_transactions_in_last_week | ||
- created_at | ||
- updated_at | ||
- nodes_summary | ||
filter: {} |
4 changes: 4 additions & 0 deletions
4
hasura/migrations/1619390533943_alter_table_public_stat_add_column_nodes_summary/down.sql
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,4 @@ | ||
-- Could not auto-generate a down migration. | ||
-- Please write an appropriate down migration for the SQL below: | ||
-- alter table "public"."stat" add column "nodes_summary" jsonb | ||
null default jsonb_build_object(); |
2 changes: 2 additions & 0 deletions
2
hasura/migrations/1619390533943_alter_table_public_stat_add_column_nodes_summary/up.sql
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,2 @@ | ||
alter table "public"."stat" add column "nodes_summary" jsonb | ||
null default jsonb_build_object(); |
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,83 @@ | ||
/* eslint camelcase: 0 */ | ||
import React, { memo, useEffect, useState } from 'react' | ||
import PropTypes from 'prop-types' | ||
import Card from '@material-ui/core/Card' | ||
import Grid from '@material-ui/core/Grid' | ||
import CardContent from '@material-ui/core/CardContent' | ||
import Typography from '@material-ui/core/Typography' | ||
import LinearProgress from '@material-ui/core/LinearProgress' | ||
import { useQuery } from '@apollo/react-hooks' | ||
|
||
import { NODES_SUMMARY_QUERY } from '../gql' | ||
|
||
const BodyGraphValue = ({ loading, value }) => { | ||
if (loading) return <LinearProgress /> | ||
|
||
return ( | ||
<Typography component="p" variant="h6"> | ||
{value} | ||
</Typography> | ||
) | ||
} | ||
|
||
BodyGraphValue.propTypes = { | ||
loading: PropTypes.bool, | ||
value: PropTypes.number | ||
} | ||
|
||
BodyGraphValue.defaultProps = { | ||
value: 0, | ||
loading: false | ||
} | ||
|
||
const NodesSummary = ({ t }) => { | ||
const { data, loading } = useQuery(NODES_SUMMARY_QUERY) | ||
const [total, setTotal] = useState() | ||
const [nodes, setNodes] = useState() | ||
|
||
useEffect(() => { | ||
if (!data?.stats) { | ||
return | ||
} | ||
|
||
const { total, ...nodes } = data?.stats[0]?.nodes_summary | ||
|
||
setTotal(total) | ||
setNodes(nodes) | ||
}, [data]) | ||
|
||
return ( | ||
<> | ||
<Grid item xs={12}> | ||
<Card> | ||
<CardContent> | ||
<Typography>{`${t('total')} ${t('nodes')}`}</Typography> | ||
<BodyGraphValue value={total} loading={loading} /> | ||
</CardContent> | ||
</Card> | ||
</Grid> | ||
|
||
{nodes && | ||
Object.keys(nodes).map((type) => ( | ||
<Grid item xs={12} key={type}> | ||
<Card> | ||
<CardContent> | ||
<Typography>{`${t(type)} ${t('nodes')}`}</Typography> | ||
<BodyGraphValue value={nodes[type] || 0} loading={loading} /> | ||
</CardContent> | ||
</Card> | ||
</Grid> | ||
))} | ||
</> | ||
) | ||
} | ||
|
||
NodesSummary.propTypes = { | ||
t: PropTypes.func | ||
} | ||
|
||
NodesSummary.defaultProps = { | ||
t: (text) => text | ||
} | ||
|
||
export default memo(NodesSummary) |
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
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
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