From 8494ebf397115a86ad222417d0a66baa08e5721a Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Thu, 4 Aug 2022 10:56:10 -0700 Subject: Web: fix tabs on project page This corrects the tab titles on the project page which currently typically just say "master", "master", "master", ... because they all display the default branch of the project stanza. Instead, use the branch of the source context for the project stanza, or, if the project stanza is not from the current project, then use the name of its project. This causes them to appear like: "openstack/project-config", "master", "stable/diablo", ... Also, update the entire Project page component hierarchy to use hooks instead of classes. Update the styling on the H2 element so that we can have the refresh icon share the same vertical space (so that we don't have large amounts of wasted vertical space at the top of each page. Change-Id: I863e0eb4a7f20ee6363e596e61cc49b2cbc22953 --- web/src/containers/project/Project.jsx | 79 +++++++------------ web/src/containers/project/ProjectVariant.jsx | 106 +++++++++++++------------- 2 files changed, 83 insertions(+), 102 deletions(-) (limited to 'web/src/containers') diff --git a/web/src/containers/project/Project.jsx b/web/src/containers/project/Project.jsx index c355b6af7..993d4d927 100644 --- a/web/src/containers/project/Project.jsx +++ b/web/src/containers/project/Project.jsx @@ -1,4 +1,5 @@ // Copyright 2018 Red Hat, Inc +// Copyright 2022 Acme Gating, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); you may // not use this file except in compliance with the License. You may obtain @@ -12,68 +13,44 @@ // License for the specific language governing permissions and limitations // under the License. -import * as React from 'react' +import React, { useState } from 'react' import PropTypes from 'prop-types' import { - Nav, - NavItem, - TabContainer, - TabPane, - TabContent, -} from 'patternfly-react' + Tabs, + Tab, +} from '@patternfly/react-core' import ProjectVariant from './ProjectVariant' -class Project extends React.Component { - static propTypes = { - project: PropTypes.object.isRequired, - } - - state = { - variantIdx: 0, - } +function Project(props) { + const [variantIdx, setVariantIdx] = useState(0) + const { project } = props - renderVariantTitle (variant, selected) { - let title = variant.default_branch - if (selected) { - title = {title} - } + function renderVariantTitle (variant) { + let title = variant.source_context.project === project.name ? + variant.source_context.branch : variant.source_context.project return title } - render () { - const { project } = this.props - const { variantIdx } = this.state + return ( + + setVariantIdx(tabIndex)} + isBox> + {project.configs.map((variant, idx) => ( + + + + ))} + + + ) +} - return ( - -

{project.canonical_name}

- -
- - - - {project.configs[variantIdx] && ( - - )} - - -
-
-
- ) - } +Project.propTypes = { + project: PropTypes.object.isRequired, } export default Project diff --git a/web/src/containers/project/ProjectVariant.jsx b/web/src/containers/project/ProjectVariant.jsx index 74be10a55..51a093a32 100644 --- a/web/src/containers/project/ProjectVariant.jsx +++ b/web/src/containers/project/ProjectVariant.jsx @@ -18,64 +18,68 @@ import { connect } from 'react-redux' import { Link } from 'react-router-dom' -class ProjectVariant extends React.Component { - static propTypes = { - tenant: PropTypes.object, - variant: PropTypes.object.isRequired - } +function ProjectVariant(props) { + const { tenant, variant } = props + const rows = [] - render () { - const { tenant, variant } = this.props - const rows = [] + rows.push({label: 'Merge mode', value: variant.merge_mode}) - rows.push({label: 'Merge mode', value: variant.merge_mode}) + if (variant.templates.length > 0) { + const templateList = ( + + ) + rows.push({label: 'Templates', value: templateList}) + } - if (variant.templates.length > 0) { - const templateList = ( + variant.pipelines.forEach(pipeline => { + // TODO: either adds job link anchor to load the right variant + // and/or show the job variant config in a modal? + const jobList = ( + + {pipeline.queue_name && ( +

Queue: {pipeline.queue_name}

)} - ) - rows.push({label: 'Templates', value: templateList}) - } +
+ ) + rows.push({label: pipeline.name + ' jobs', value: jobList}) + }) - variant.pipelines.forEach(pipeline => { - // TODO: either adds job link anchor to load the right variant - // and/or show the job variant config in a modal? - const jobList = ( - - {pipeline.queue_name && ( -

Queue: {pipeline.queue_name}

)} - -
- ) - rows.push({label: pipeline.name + ' jobs', value: jobList}) - }) + return ( +
+ + + {rows.map(item => ( + + + + + ))} + +
{item.label}{item.value}
+
+ ) +} - return ( -
- - - {rows.map(item => ( - - - - - ))} - -
{item.label}{item.value}
-
- ) +ProjectVariant.propTypes = { + tenant: PropTypes.object, + variant: PropTypes.object.isRequired +} + +function mapStateToProps(state) { + return { + tenant: state.tenant, } } -export default connect(state => ({tenant: state.tenant}))(ProjectVariant) +export default connect(mapStateToProps)(ProjectVariant) -- cgit v1.2.1