Skip to content

Commit

Permalink
feat(front): show artifacts if 1st or build branch is master (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
ekelen authored May 18, 2020
1 parent 8a3ba02 commit b9f883b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
47 changes: 41 additions & 6 deletions web/src/ui/components/Build/BuildAndMrContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
AlertCircle,
Calendar,
Link as LinkIcon,
ChevronDown,
ChevronUp,
} from 'react-feather'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faGithub } from '@fortawesome/free-brands-svg-icons'
Expand All @@ -21,14 +23,19 @@ import ArtifactRow from './ArtifactRow'
import AnchorLink from '../AnchorLink/AnchorLink'
import Tag from '../../Tag/Tag'

import { MR_STATE, BUILD_STATE, BRANCH } from '../../../constants'
import { MR_STATE, BUILD_STATE } from '../../../constants'
import { getRelativeTime, getTimeLabel } from '../../../util/date'
import { getIsArr, getStrEquNormalized } from '../../../util/getters'
import { getIsArr } from '../../../util/getters'

import './Build.scss'

const BuildAndMergeRequest = ({ build, mr, isDetailed }) => {
const BuildAndMergeRequest = ({
build, mr, isDetailed, isMaster,
}) => {
const [messageExpanded, toggleMessageExpanded] = useState(false)
const [showingArtifacts, toggleShowingArtifacts] = useState(
isDetailed || isMaster,
)

const {
theme,
Expand Down Expand Up @@ -246,6 +253,35 @@ const BuildAndMergeRequest = ({ build, mr, isDetailed }) => {
/>
)

const artifactsMessagePrefix = showingArtifacts ? 'hide' : 'show'

const artifactsMessage = getIsArr(buildHasArtifacts)
? `${artifactsMessagePrefix} ${buildHasArtifacts.length} artifact${
buildHasArtifacts.length > 1 ? 's' : ''
}`
: ''

const ArtifactsCount = () => getIsArr(buildHasArtifacts) && (
<Tag
text={artifactsMessage}
classes={['btn-info-tag']}
title={artifactsMessage}
icon={
showingArtifacts ? (
<ChevronUp color={blockTitle} />
) : (
<ChevronDown color={blockTitle} />
)
}
styles={tagStyle({
name: theme.name,
state: null,
cursor: 'pointer',
})}
onClick={() => toggleShowingArtifacts(!showingArtifacts)}
/>
)

const SharableBuildLink = (
<AnchorLink target={`?build_id=${buildId}`}>
<LinkIcon size={16} />
Expand Down Expand Up @@ -281,6 +317,7 @@ const BuildAndMergeRequest = ({ build, mr, isDetailed }) => {
{BuildDriver}
{BuildUpdatedAt}
{BuildCreatedAt}
{buildHasArtifacts && <ArtifactsCount />}
</div>
</div>
{isDetailed && (
Expand All @@ -290,9 +327,7 @@ const BuildAndMergeRequest = ({ build, mr, isDetailed }) => {
</div>
)}
</div>
{isDetailed
&& getIsArr(buildHasArtifacts)
&& getStrEquNormalized(buildBranch, BRANCH.MASTER)
{showingArtifacts
&& buildHasArtifacts.map((artifact) => (
<ArtifactRow
artifact={artifact}
Expand Down
1 change: 1 addition & 0 deletions web/src/ui/components/Build/BuildContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ const BuildContainer = ({ build, toCollapse, children }) => {
build: state.builds[b],
mr: buildHasMr,
isDetailed: i === 0,
isMaster,
}}
key={i}
/>
Expand Down

0 comments on commit b9f883b

Please sign in to comment.