Browse Source

Merge "web: add nodes page"

tags/3.4.0
Zuul 5 months ago
parent
commit
144ab10ba7
3 changed files with 120 additions and 0 deletions
  1. 4
    0
      web/src/api.js
  2. 110
    0
      web/src/pages/Nodes.jsx
  3. 6
    0
      web/src/routes.js

+ 4
- 0
web/src/api.js View File

@@ -143,6 +143,9 @@ function fetchJobs (apiPrefix) {
143 143
 function fetchLabels (apiPrefix) {
144 144
   return Axios.get(apiUrl + apiPrefix + 'labels')
145 145
 }
146
+function fetchNodes (apiPrefix) {
147
+  return Axios.get(apiUrl + apiPrefix + 'nodes')
148
+}
146 149
 
147 150
 export {
148 151
   getHomepageUrl,
@@ -157,6 +160,7 @@ export {
157 160
   fetchJob,
158 161
   fetchJobs,
159 162
   fetchLabels,
163
+  fetchNodes,
160 164
   fetchTenants,
161 165
   fetchInfo
162 166
 }

+ 110
- 0
web/src/pages/Nodes.jsx View File

@@ -0,0 +1,110 @@
1
+// Copyright 2018 Red Hat, Inc
2
+//
3
+// Licensed under the Apache License, Version 2.0 (the "License"); you may
4
+// not use this file except in compliance with the License. You may obtain
5
+// a copy of the License at
6
+//
7
+//      http://www.apache.org/licenses/LICENSE-2.0
8
+//
9
+// Unless required by applicable law or agreed to in writing, software
10
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+// License for the specific language governing permissions and limitations
13
+// under the License.
14
+
15
+import * as React from 'react'
16
+import PropTypes from 'prop-types'
17
+import { connect } from 'react-redux'
18
+import { Table } from 'patternfly-react'
19
+import * as moment from 'moment'
20
+
21
+import { fetchNodes } from '../api'
22
+
23
+
24
+class NodesPage extends React.Component {
25
+  static propTypes = {
26
+    tenant: PropTypes.object
27
+  }
28
+
29
+  state = {
30
+    nodes: null
31
+  }
32
+
33
+  updateData () {
34
+    fetchNodes(this.props.tenant.apiPrefix).then(response => {
35
+      this.setState({nodes: response.data})
36
+    })
37
+  }
38
+
39
+  componentDidMount () {
40
+    document.title = 'Zuul Nodes'
41
+    if (this.props.tenant.name) {
42
+      this.updateData()
43
+    }
44
+  }
45
+
46
+  componentDidUpdate (prevProps) {
47
+    if (this.props.tenant.name !== prevProps.tenant.name) {
48
+      this.updateData()
49
+    }
50
+  }
51
+
52
+  render () {
53
+    const { nodes } = this.state
54
+    if (!nodes) {
55
+      return (<p>Loading...</p>)
56
+    }
57
+
58
+    const headerFormat = value => <Table.Heading>{value}</Table.Heading>
59
+    const cellFormat = value => <Table.Cell>{value}</Table.Cell>
60
+    const cellPreFormat = value => (
61
+      <Table.Cell style={{fontFamily: 'Menlo,Monaco,Consolas,monospace'}}>
62
+        {value}
63
+      </Table.Cell>)
64
+    const cellAgeFormat = value => (
65
+      <Table.Cell style={{fontFamily: 'Menlo,Monaco,Consolas,monospace'}}>
66
+        {moment.unix(value).fromNow()}
67
+      </Table.Cell>)
68
+
69
+    const columns = []
70
+    const myColumns = [
71
+      'id', 'label', 'connection', 'server', 'provider', 'state',
72
+      'age', 'comment'
73
+    ]
74
+    myColumns.forEach(column => {
75
+      let formatter = cellFormat
76
+      let prop = column
77
+      if (column === 'label') {
78
+        prop = 'type'
79
+      } else if (column === 'connection') {
80
+        prop = 'connection_type'
81
+      } else if (column === 'server') {
82
+        prop = 'external_id'
83
+        formatter = cellPreFormat
84
+      } else if (column === 'age') {
85
+        prop = 'state_time'
86
+        formatter = cellAgeFormat
87
+      }
88
+      columns.push({
89
+        header: {label: column, formatters: [headerFormat]},
90
+        property: prop,
91
+        cell: {formatters: [formatter]}
92
+      })
93
+    })
94
+    return (
95
+      <Table.PfProvider
96
+        striped
97
+        bordered
98
+        hover
99
+        columns={columns}
100
+      >
101
+        <Table.Header/>
102
+        <Table.Body
103
+          rows={nodes}
104
+          rowKey="id"
105
+        />
106
+      </Table.PfProvider>)
107
+  }
108
+}
109
+
110
+export default connect(state => ({tenant: state.tenant}))(NodesPage)

+ 6
- 0
web/src/routes.js View File

@@ -19,6 +19,7 @@ import ProjectsPage from './pages/Projects'
19 19
 import JobPage from './pages/Job'
20 20
 import JobsPage from './pages/Jobs'
21 21
 import LabelsPage from './pages/Labels'
22
+import NodesPage from './pages/Nodes'
22 23
 import BuildPage from './pages/Build'
23 24
 import BuildsPage from './pages/Builds'
24 25
 import ConfigErrorsPage from './pages/ConfigErrors'
@@ -50,6 +51,11 @@ const routes = () => [
50 51
     to: '/labels',
51 52
     component: LabelsPage
52 53
   },
54
+  {
55
+    title: 'Nodes',
56
+    to: '/nodes',
57
+    component: NodesPage
58
+  },
53 59
   {
54 60
     title: 'Builds',
55 61
     to: '/builds',

Loading…
Cancel
Save