// Copyright 2018 Red Hat, Inc // // 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 // a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the // License for the specific language governing permissions and limitations // under the License. import * as React from 'react' import PropTypes from 'prop-types' import { connect } from 'react-redux' import { Link } from 'react-router-dom' import ReactJson from 'react-json-view' import { DescriptionList, DescriptionListTerm, DescriptionListGroup, DescriptionListDescription, List, ListItem, ListVariant, } from '@patternfly/react-core' import { AnsibleTowerIcon, BanIcon, CatalogIcon, ClipboardCheckIcon, ClusterIcon, CodeBranchIcon, CodeIcon, ConnectedIcon, DisconnectedIcon, ExternalLinkAltIcon, FlagIcon, HistoryIcon, InfrastructureIcon, LockIcon, LockedIcon, OutlinedClockIcon, PackageIcon, RedoIcon, WrenchIcon } from '@patternfly/react-icons' import SourceContext from '../SourceContext' import Nodeset from './Nodeset' import Role from './Role' import JobProject from './JobProject' import JobDescriptionCard from './JobDescriptionCard' class JobVariant extends React.Component { static propTypes = { parent: PropTypes.object, tenant: PropTypes.object, variant: PropTypes.object.isRequired, preferences: PropTypes.object, } renderStatus (variant) { const status = [{ icon: variant.voting ? : , name: variant.voting ? 'Voting' : 'Non-voting' }] if (variant.abstract) { status.push({ icon: , name: 'Abstract' }) } if (variant.final) { status.push({ icon: , name: 'Final' }) } if (variant.post_review) { status.push({ icon: , name: 'Post review' }) } if (variant.protected) { status.push({ icon: , name: 'Protected' }) } return ( {status.map((item, idx) => ( {item.name} ))} ) } render () { const { tenant, variant } = this.props const rows = [] const jobInfos = [ 'source_context', 'builds', 'status', 'parent', 'attempts', 'timeout', 'semaphores', 'nodeset', 'nodeset_alternatives', 'variables', 'override_checkout', ] jobInfos.forEach(key => { let label = key let nice_label = key let value = variant[key] if (label === 'source_context' && value) { value = ( ) nice_label = ( Defined at) } if (label === 'builds') { value = ( Job flags) } if (!value) { return } if (label === 'attempts') { nice_label = ( Retry attempts) } if (label === 'timeout') { value = ({value} seconds) nice_label = ( Timeout) } if (label === 'semaphores') { if (value.length === 0) { value = (none) } else { value = ( ) } nice_label = ( Semaphores) } if (label === 'nodeset') { value = ( ) nice_label = ( Required nodes) } if (label === 'nodeset_alternatives') { value = value.map((alt, idx) => { return (<> {(idx > 0 ? or:<>)} ) }) nice_label = ( Required nodes) } if (label === 'parent') { value = (  {value} ) nice_label = ( Parent) } if (label === 'variables') { value = ( ) nice_label = ( Job variables) } if (label === 'description') { value = (
{value}
) nice_label = ( Description) } rows.push({label: nice_label, value: value}) }) const jobInfosList = [ 'required_projects', 'dependencies', 'files', 'irrelevant_files', 'roles' ] jobInfosList.forEach(key => { let label = key let nice_label = key let values = variant[key] if (values.length === 0) { return } const items = ( {values.map((value, idx) => { let item if (label === 'required_projects') { nice_label = 'Required Projects' item = } else if (label === 'roles') { nice_label = ( Uses roles from) item = } else if (label === 'dependencies') { nice_label = ( Job dependencies) if (value['soft']) { item = value['name'] + ' (soft)' } else { item = value['name'] } } else if (label === 'irrelevant_files') { nice_label = ( Irrelevant files matchers) item = value } else if (label === 'files') { nice_label = (Files matchers) item = value } else { item = value } return ( {item} ) })} ) rows.push({label: nice_label, value: items}) }) return ( {rows.map((item, idx) => ( {item.label} {item.value} ))} ) } } export default connect(state => ({ tenant: state.tenant, preferences: state.preferences, }))(JobVariant)