// Copyright 2021 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 { connect } from 'react-redux' import PropTypes from 'prop-types' import { EmptyState, EmptyStateIcon, EmptyStateVariant, PageSection, PageSectionVariants, Title, Flex, FlexItem, List, ListItem, } from '@patternfly/react-core' import { LockIcon, BuildIcon, CubeIcon, CodeIcon, HashtagIcon, OutlinedClockIcon, OutlinedCommentDotsIcon, TrashIcon, } from '@patternfly/react-icons' import { IconProperty } from '../Misc' import { Link } from 'react-router-dom' import * as moment from 'moment' import { fetchAutohold } from '../actions/autoholds' import { EmptyPage } from '../containers/Errors' import { Fetching } from '../containers/Fetching' import HeldBuildList from '../containers/autohold/HeldBuildList' // This is hard-coded in zuul/executor/server.py#3035 const EXPIRED_HOLD_REQUEST_TTL = 24 * 60 * 60 class AutoholdPage extends React.Component { static propTypes = { match: PropTypes.object.isRequired, tenant: PropTypes.object.isRequired, autohold: PropTypes.object, isFetching: PropTypes.bool.isRequired, fetchAutohold: PropTypes.func.isRequired, preferences: PropTypes.object, } updateData = () => { if (!this.props.autohold) { this.props.fetchAutohold( this.props.tenant, this.props.match.params.requestId ) } } componentDidMount() { document.title = 'Zuul Autohold Request' if (this.props.tenant.name) { this.updateData() } } componentDidUpdate(prevProps) { if (this.props.tenant.name !== prevProps.tenant.name) { this.updateData() } } render() { const { autohold, isFetching, tenant } = this.props // Initial page load if (autohold === undefined || isFetching) { return } // Fetching finished, but no autohold found if (!autohold) { return ( ) } // Return the build list or an empty state if no builds triggered the autohold. const buildsContent = autohold.nodes.length > 0 ? ( ) : ( <> {/* Using an hr above the empty state ensures that the space between heading (builds) and empty state is filled and the empty state doesn't look like it's lost in space. */}
This autohold request has not triggered yet. ) const node_expiration = (autohold.node_expiration === 0) ? 'Indefinitely' : moment.duration(autohold.node_expiration, 'seconds').humanize() console.log(autohold.expired) const elapsed = autohold.expired ? (Date.now() / 1000 - autohold.expired) : false console.log(elapsed) const timeToDeletion = autohold.node_expiration + EXPIRED_HOLD_REQUEST_TTL - elapsed console.log(timeToDeletion) let deletionInfo, deletionInfoMsg if (autohold.node_expiration !== 0 && elapsed) { deletionInfoMsg = timeToDeletion > 0 ? (<> Deletion scheduled in {moment.duration(timeToDeletion, 'seconds').humanize()} ) : This request is scheduled to be deleted automatically. deletionInfo = } value={deletionInfoMsg} /> } else { deletionInfo = <> } return ( <> Autohold Request {autohold.id} } value={ <> Project {autohold.project} } /> } value={ <> Filter {autohold.ref_filter} } /> } value={ <> Job {autohold.job} } /> } value={ <> Trigger Count {autohold.current_count} out of {autohold.max_count} } /> } value={ <> Hold Duration {node_expiration} } /> } value={ <> Reason:
{autohold.reason}
} /> {deletionInfo}
<BuildIcon style={{ marginRight: 'var(--pf-global--spacer--sm)', verticalAlign: '-0.1em', }} />{' '} Held Builds {buildsContent} ) } } function mapStateToProps(state) { return { autohold: state.autoholds.autohold, tenant: state.tenant, isFetching: state.autoholds.isFetching, preferences: state.preferences, } } const mapDispatchToProps = { fetchAutohold } export default connect(mapStateToProps, mapDispatchToProps)(AutoholdPage)