// Copyright 2019 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 React, { useState } from 'react'
import PropTypes from 'prop-types'
import { connect, useDispatch } from 'react-redux'
import { Link } from 'react-router-dom'
import {
Button,
Flex,
FlexItem,
List,
ListItem,
Title,
Modal,
ModalVariant,
} from '@patternfly/react-core'
import {
CodeIcon,
CodeBranchIcon,
OutlinedCommentDotsIcon,
CubeIcon,
FingerprintIcon,
StreamIcon,
OutlinedCalendarAltIcon,
OutlinedClockIcon,
RedoAltIcon,
} from '@patternfly/react-icons'
import * as moment from 'moment'
import 'moment-duration-format'
import { buildExternalLink, IconProperty } from '../../Misc'
import { BuildResultBadge, BuildResultWithIcon } from './Misc'
import { enqueue, enqueue_ref } from '../../api'
import { addNotification, addApiError } from '../../actions/notifications'
import { ChartModal } from '../charts/ChartModal'
import BuildsetGanttChart from '../charts/GanttChart'
function Buildset({ buildset, timezone, tenant, user, preferences }) {
const buildset_link = buildExternalLink(buildset)
const [isGanttChartModalOpen, setIsGanttChartModalOpen] = useState(false)
function renderBuildTimes() {
const firstStartBuild = buildset.builds.reduce((prev, cur) =>
!cur.start_time || prev.start_time < cur.start_time ? prev : cur
)
const lastEndBuild = buildset.builds.reduce((prev, cur) =>
!cur.end_time || prev.end_time > cur.end_time ? prev : cur
)
const totalDuration =
(moment.utc(lastEndBuild.end_time).tz(timezone) -
moment.utc(firstStartBuild.start_time).tz(timezone)) /
1000
const overallDuration =
(moment.utc(lastEndBuild.end_time).tz(timezone) -
moment.utc(
buildset.event_timestamp != null
? buildset.event_timestamp : firstStartBuild.start_time
).tz(timezone)
) / 1000
const buildLink = (build) => (
{build.job_name}
)
const firstStartLink = buildLink(firstStartBuild)
const lastEndLink = buildLink(lastEndBuild)
return (
Please confirm that you want to re-enqueue all jobs {changeInfo} on project {buildset.project} on pipeline {buildset.pipeline}.
(started{' '}
{moment
.utc(firstStartBuild.start_time)
.tz(timezone)
.format('YYYY-MM-DD HH:mm:ss')}
)
Ending build
{lastEndLink}
(ended{' '}
{moment
.utc(lastEndBuild.end_time)
.tz(timezone)
.format('YYYY-MM-DD HH:mm:ss')}
)
}
/>
{buildset.message}