Browse Source

Merge "web: add labels page"

tags/3.4.0
Zuul 5 months ago
parent
commit
98b1fc77d2
3 changed files with 96 additions and 0 deletions
  1. 4
    0
      web/src/api.js
  2. 86
    0
      web/src/pages/Labels.jsx
  3. 6
    0
      web/src/routes.js

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

@@ -140,6 +140,9 @@ function fetchJob (apiPrefix, jobName) {
140 140
 function fetchJobs (apiPrefix) {
141 141
   return Axios.get(apiUrl + apiPrefix + 'jobs')
142 142
 }
143
+function fetchLabels (apiPrefix) {
144
+  return Axios.get(apiUrl + apiPrefix + 'labels')
145
+}
143 146
 
144 147
 export {
145 148
   getHomepageUrl,
@@ -153,6 +156,7 @@ export {
153 156
   fetchProjects,
154 157
   fetchJob,
155 158
   fetchJobs,
159
+  fetchLabels,
156 160
   fetchTenants,
157 161
   fetchInfo
158 162
 }

+ 86
- 0
web/src/pages/Labels.jsx View File

@@ -0,0 +1,86 @@
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
+
20
+import { fetchLabels } from '../api'
21
+
22
+
23
+class LabelsPage extends React.Component {
24
+  static propTypes = {
25
+    tenant: PropTypes.object
26
+  }
27
+
28
+  state = {
29
+    labels: null
30
+  }
31
+
32
+  updateData () {
33
+    fetchLabels(this.props.tenant.apiPrefix).then(response => {
34
+      this.setState({labels: response.data})
35
+    })
36
+  }
37
+
38
+  componentDidMount () {
39
+    document.title = 'Zuul Labels'
40
+    if (this.props.tenant.name) {
41
+      this.updateData()
42
+    }
43
+  }
44
+
45
+  componentDidUpdate (prevProps) {
46
+    if (this.props.tenant.name !== prevProps.tenant.name) {
47
+      this.updateData()
48
+    }
49
+  }
50
+
51
+  render () {
52
+    const { labels } = this.state
53
+    if (!labels) {
54
+      return (<p>Loading...</p>)
55
+    }
56
+
57
+    const headerFormat = value => <Table.Heading>{value}</Table.Heading>
58
+    const cellFormat = value => <Table.Cell>{value}</Table.Cell>
59
+    const columns = []
60
+    const myColumns = ['name']
61
+    myColumns.forEach(column => {
62
+      let formatter = cellFormat
63
+      let prop = column
64
+      columns.push({
65
+        header: {label: column, formatters: [headerFormat]},
66
+        property: prop,
67
+        cell: {formatters: [formatter]}
68
+      })
69
+    })
70
+    return (
71
+      <Table.PfProvider
72
+        striped
73
+        bordered
74
+        hover
75
+        columns={columns}
76
+      >
77
+        <Table.Header/>
78
+        <Table.Body
79
+          rows={labels}
80
+          rowKey="name"
81
+        />
82
+      </Table.PfProvider>)
83
+  }
84
+}
85
+
86
+export default connect(state => ({tenant: state.tenant}))(LabelsPage)

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

@@ -18,6 +18,7 @@ import ProjectPage from './pages/Project'
18 18
 import ProjectsPage from './pages/Projects'
19 19
 import JobPage from './pages/Job'
20 20
 import JobsPage from './pages/Jobs'
21
+import LabelsPage from './pages/Labels'
21 22
 import BuildPage from './pages/Build'
22 23
 import BuildsPage from './pages/Builds'
23 24
 import ConfigErrorsPage from './pages/ConfigErrors'
@@ -44,6 +45,11 @@ const routes = () => [
44 45
     to: '/jobs',
45 46
     component: JobsPage
46 47
   },
48
+  {
49
+    title: 'Labels',
50
+    to: '/labels',
51
+    component: LabelsPage
52
+  },
47 53
   {
48 54
     title: 'Builds',
49 55
     to: '/builds',

Loading…
Cancel
Save