Skip to content

Commit

Permalink
refactor: update to support ipfs-cluster-api@0.0.9
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Vaibhav Saini <vasa@towardsblockchain.com>
  • Loading branch information
vasa-develop committed May 29, 2019
1 parent 27da187 commit 65e8687
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
17 changes: 10 additions & 7 deletions src/pages/dashboard/data/index.js
Expand Up @@ -2,10 +2,9 @@ import React, { Component, Fragment } from 'react'
import statsActions from '../../../redux/cluster/actions'
import { connect } from 'react-redux'
import formatBytes from '../../../utils/formatBytes'
import { Input, Card, Avatar, Button } from 'antd'
const { Meta } = Card;

import ipfs from '../../../utils/ipfs-http-client'
import { Input, Card, Avatar, Button, Empty } from 'antd'
const { Meta } = Card
//import ipfs from '../../../utils/ipfs-http-client'

class Devices extends Component {

Expand Down Expand Up @@ -54,7 +53,7 @@ class Devices extends Component {
folders: []
};

cluster.pins && cluster.pins[0].Hash ? cluster.pins.map((pin) => {
cluster.pins && cluster.pins[0] ? cluster.pins.map((pin) => {
return pin.isDir ? fileStructure.folders.push(pin.Hash['/']) : fileStructure.files.push(pin.Hash['/'])
}) : []

Expand All @@ -68,6 +67,8 @@ class Devices extends Component {
</Card>
})

files.length == 0 ? files = <Empty /> : null

var folders = fileStructure.folders.map((folder, index) => {
return <Card key={index} style={{ width: 490, marginTop: 16 }} loading={false}>
<Meta
Expand All @@ -78,6 +79,8 @@ class Devices extends Component {
</Card>
})

folders.length == 0 ? folders = <Empty /> : null

return (
<Fragment>
<h3><b>Cluster ID</b></h3>
Expand All @@ -87,11 +90,11 @@ class Devices extends Component {
<br /><br />

<h4><b>Folders</b></h4>
{ folders }
{ folders || <Empty /> }

<br /><br />
<h4><b>Files</b></h4>
{ files }
{ files || <Empty /> }
</Fragment>
)
}
Expand Down
6 changes: 4 additions & 2 deletions src/pages/dashboard/stats/index.js
Expand Up @@ -41,9 +41,9 @@ class Devices extends Component {

render() {

var { cluster } = this.props
var { cluster } = this.props

var freespace = cluster.monitor ? formatBytes(cluster.monitor.freespace[0].value, 3) : ""
var freespace = cluster.health ? formatBytes(cluster.health.metrics.freespace[0].value, 3) : ""

var peerList = cluster.peers ? cluster.peers.map((peer, index) => {
return <Card key={index} style={{ width: 490, marginTop: 16 }} loading={!cluster.peers}>
Expand Down Expand Up @@ -100,12 +100,14 @@ class Devices extends Component {
<Input placeholder="new node multihash" />
<br/><br/>
<Button type="primary" shape="round" icon="plus" size={"large"}>Add</Button>
&nbsp;&nbsp;<span>Feature in development</span>
</div>
<div className="col-sm">
<h5>Remove a Cluster peer</h5>
<Input placeholder="node multihash" />
<br/><br/>
<Button type="danger" shape="round" icon="minus" size={"large"}>Remove</Button>
&nbsp;&nbsp;<span>Feature in development</span>
</div>
</div>
</div>
Expand Down
22 changes: 9 additions & 13 deletions src/redux/cluster/actions.js
Expand Up @@ -63,12 +63,10 @@ const getAllStats = payload => dispatch => {
ipfsCluster.id(),
ipfsCluster.status(),
ipfsCluster.health.graph(),
//ipfsCluster.health.metrics(name, [options]),
ipfsCluster.monitor('freespace'),
ipfsCluster.monitor('ping'),
ipfsCluster.health.metrics('freespace'),
ipfsCluster.health.metrics('ping'),
ipfsCluster.peers.ls(),
ipfsCluster.pins.ls(),
ipfsCluster.allocations({ filter: 'all'})
ipfsCluster.pin.ls(),
];
Promise.all(promises)
.then(stats => {
Expand All @@ -77,15 +75,13 @@ const getAllStats = payload => dispatch => {
status: stats[1],
health: {
graph: stats[2],
metrics: null
},
monitor: {
freespace: stats[3],
ping: stats[4]
metrics: {
freespace: stats[3],
ping: stats[4]
}
},
peers: stats[5],
pins: stats[6],
allocations: stats[7]
}

dispatch({
Expand All @@ -109,8 +105,8 @@ const getFileStructure = payload => dispatch => {

let promises = [
ipfsCluster.id(),
ipfsCluster.monitor('freespace'),
ipfsCluster.pins.ls()
ipfsCluster.health.metrics('freespace'),
ipfsCluster.pin.ls()
]
Promise.all(promises)
.then((data) => {
Expand Down

0 comments on commit 65e8687

Please sign in to comment.