import React, { Component } from 'react'; import { Link, withRouter } from 'react-router-dom'; import { withI18n } from '@lingui/react'; import { CardBody, Button, TextList, TextListItem, TextListItemVariants, TextListVariants } from '@patternfly/react-core'; import styled from 'styled-components'; import { t } from '@lingui/macro'; import ContentError from '../../../components/ContentError'; import ContentLoading from '../../../components/ContentLoading'; import { ChipGroup, Chip } from '../../../components/Chip'; import { DetailList, Detail } from '../../../components/DetailList'; import { JobTemplatesAPI } from '../../../api'; import { toTitleCase } from '../../../util/strings'; const ButtonGroup = styled.div` display: flex; justify-content: flex-end; margin-top: 20px; & > :not(:first-child){ margin-left: 20px; } `; class JobTemplateDetail extends Component { constructor (props) { super(props); this.state = { contentError: false, hasContentLoading: true, instanceGroups: [] }; this.readInstanceGroups = this.readInstanceGroups.bind(this); } componentDidMount () { this.readInstanceGroups(); } async readInstanceGroups () { const { match } = this.props; try { const { data } = await JobTemplatesAPI.readInstanceGroups(match.params.id); this.setState({ instanceGroups: [...data.results] }); } catch { this.setState({ contentError: true }); } finally { this.setState({ hasContentLoading: false }); } } render () { const { template: { allow_simultaneous, become_enabled, created, description, diff_mode, forks, host_config_key, job_slice_count, job_tags, job_type, inventory, name, limit, modified, playbook, project, skip_tags, timeout, summary_fields, use_fact_cache, url, verbosity }, hasTemplateLoading, i18n, match, } = this.props; const { instanceGroups, hasContentLoading, contentError } = this.state; const verbosityOptions = [ { verbosity: 0, details: i18n._(t`0 (Normal)`) }, { verbosity: 1, details: i18n._(t`1 (Verbose)`) }, { verbosity: 2, details: i18n._(t`2 (More Verbose)`) }, { verbosity: 3, details: i18n._(t`3 (Debug)`) }, { verbosity: 4, details: i18n._(t`4 (Connection Debug)`) }, { verbosity: 5, details: i18n._(t`5 (WinRM Debug)`) }, ]; const verbosityDetails = verbosityOptions.filter( option => option.verbosity === verbosity ); const generateCallBackUrl = `${window.location.origin + url}callback/`; const isInitialized = !hasTemplateLoading && !hasContentLoading; const credentialType = (c) => (c === 'aws' || c === 'ssh' ? c.toUpperCase() : toTitleCase(c)); const renderOptionsField = become_enabled || host_config_key || allow_simultaneous || use_fact_cache; const renderOptions = ( {become_enabled && ( {i18n._(t`Enable Privilege Escalation`)} )} {host_config_key && ( {i18n._(t`Allow Provisioning Callbacks`)} )} {allow_simultaneous && ( {i18n._(t`Enable Concurrent Jobs`)} )} {use_fact_cache && ( {i18n._(t`Use Fact Cache`)} )} ); if (contentError) { return (); } if (hasContentLoading) { return (); } return ( isInitialized && ( {inventory && ( )} {project && ( )} {host_config_key && ( )} {renderOptionsField && ( )} {(summary_fields.credentials && summary_fields.credentials.length > 0) && ( {summary_fields.credentials.map(c => ( {c.kind ? credentialType(c.kind) : i18n._(t`Cloud`)} : {` ${c.name}`} )) } )} /> )} {(summary_fields.labels && summary_fields.labels.results.length > 0) && ( {summary_fields.labels.results.map(l => ( {l.name} )) } )} /> )} {(instanceGroups.length > 0) && ( {instanceGroups.map(ig => ( {ig.name} ))} )} /> )} {(job_tags && job_tags.length > 0) && ( {job_tags.split(',').map(jobTag => ( {jobTag} )) } )} /> )} {(skip_tags && skip_tags.length > 0) && ( {skip_tags.split(',').map(skipTag => ( {skipTag} )) } )} /> )} {summary_fields.user_capabilities.edit && ( )} ) ); } } export { JobTemplateDetail as _JobTemplateDetail }; export default withI18n()(withRouter(JobTemplateDetail));