summaryrefslogtreecommitdiff
path: root/app/client/system/system.component.js
blob: 0819c2f3efe09655fd35b1a1856753a858a3b62c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { h, Component } from 'preact'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'

import Group from '../common/group.component'
import Slider from '../common/slider.component'
import Select from '../common/select.component'
import Button from '../common/button.component'

import * as systemActions from './system.actions'

class System extends Component {
  constructor(props){
    super()
  }
  render(){
    const { site, actions } = this.props
    return (
      <div className='dashboard'>
        <div className='heading'>
          <h2>{site.name} System</h2>
        </div>

        <div className='column'>
          <Group title="Diagnostics">
            <button onClick={() => actions.run('nvidia-smi')}>nvidia-smi</button>
            <button onClick={() => actions.run('ps')}>ps</button>
            <button onClick={() => actions.run('w')}>w</button>
          </Group>
          {this.renderCommandOutput()}
        </div>
      </div>
    )
  }
  renderCommandOutput(){
    const { cmd } = this.props
    let output
    if (cmd.loading) {
      output = 'Loading: ' + cmd.name
    }
    else if (cmd.loaded) {
      if (cmd.error) {
        output = 'Error: ' + cmd.name + '\n\n' + JSON.stringify(cmd.error, null, 2)
      } else {
        output = cmd.stdout
        if (cmd.stderr) {
          output += '\n\n_________________________________\n\n'
          output += cmd.stderr
        }
      }
    }
    return (
      <div>
        <div className='screen'>{output}</div>
      </div>
    )
  }
}
const mapStateToProps = state => ({
  site: state.system.site,
  cmd: state.system.cmd,
})

const mapDispatchToProps = (dispatch, ownProps) => ({
  actions: bindActionCreators(systemActions, dispatch)
})

export default connect(mapStateToProps, mapDispatchToProps)(System)