Skip to content

Commit

Permalink
feat(front): add quick links to PRs in card titles (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
ekelen authored May 8, 2020
1 parent 7a3c396 commit ed995d4
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 12 deletions.
74 changes: 63 additions & 11 deletions web/src/ui/components/BuildCard/BuildCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
faAlignLeft,
faHammer,
faPencilAlt,
faFile,
} from '@fortawesome/free-solid-svg-icons';

import {ThemeContext} from '../../../store/ThemeStore';
Expand Down Expand Up @@ -62,15 +63,14 @@ const BuildCard = ({build, toCollapse}) => {
has_project: {id: buildProjectUrl = ''} = {},
} = build || {};

const COMMIT_LEN = 7;
const MESSAGE_LEN = 280;
const isMaster = buildBranch && buildBranch.toUpperCase() === 'MASTER';
const {has_mergerequest: buildHasMr = false} = build;

const timeSinceUpdated = getRelativeTime(buildUpdatedAt);
const timeSinceCreated = getRelativeTime(buildCreatedAt);

const COMMIT_LEN = 7;
const MESSAGE_LEN = 280;

const colorInteractiveText = {
color: theme.text.blockTitle,
};
Expand All @@ -79,30 +79,81 @@ const BuildCard = ({build, toCollapse}) => {
color: theme.text.sectionText,
};

const mrDisplayShortId = mrShortId && <>{`#${mrShortId}`}</>;
const mrDisplayId = mrDisplayShortId || <>{mrId}</>;

const buildDisplayShortId = buildShortId && <>{`#${buildShortId}`}</>;
const buildDisplayId = buildDisplayShortId || <>{buildId}</>;

const CardTitleMasterNoMr = isMaster && <>Master - build {buildDisplayId}</>;
const CardTitleMasterWithMr = isMaster && buildHasMr && <>Master</>;
const CardTitlePullWithMr = !isMaster && mrShortId && (
<>
Pull{' '}
<u>
<a href={mrId}>{mrDisplayId}</a>
</u>
</>
);
const CardDefaultTitle = <>Build {buildDisplayId}</>;

const CardSubtitleMasterWithMr = isMaster && buildHasMr && (
<>
Merge{' '}
<u>
<a href={mrId}>{mrDisplayId}</a>
</u>
</>
);
const CardSubtitlePullWithMr = !isMaster && mrShortId && <>{mrTitle}</>;
const CardSubtitleDefault = '';

const CardTitle = (
<div className="card-title">
<div className="short-card-title">
{mrShortId
? 'Pull ' + mrShortId
: buildShortId
? (isMaster ? 'Master ' : 'Build ') + buildShortId
: ''}
{CardTitleMasterWithMr ||
CardTitleMasterNoMr ||
CardTitlePullWithMr ||
CardDefaultTitle}
</div>
<div className="card-mr-subtitle" style={colorPlainText}>
{mrTitle ? mrTitle : ''}
{CardSubtitleMasterWithMr ||
CardSubtitlePullWithMr ||
CardSubtitleDefault}
</div>
</div>
);

const CardIcon = isMaster ? (
const CardIconMasterWithMr = isMaster && buildHasMr && (
<div className="card-left-icon rotate-merge">
<GitCommit color={theme.icon.masterGreen} />
</div>
) : (
);
const CardIconMasterNoMr = isMaster && !buildHasMr && (
<div className="card-left-icon rotate-merge">
<GitCommit color={theme.text.sectionText} />
</div>
);
const CardIconPullHasMr = !isMaster && buildHasMr && (
<div className="card-left-icon">
<GitMerge color={theme.icon.branchPurple} />
</div>
);
const CardIconDefault = (
<div className="card-left-icon rotate-merge">
<GitCommit color={theme.text.sectionText} />
{/* <FontAwesomeIcon icon={faFile} color={theme.text.sectionText} /> */}
</div>
);

const CardIcon = (
<>
{CardIconMasterWithMr ||
CardIconPullHasMr ||
CardIconMasterNoMr ||
CardIconDefault}
</>
);

const CommitIcon = mrCommitUrl ? (
<a
Expand Down Expand Up @@ -138,6 +189,7 @@ const BuildCard = ({build, toCollapse}) => {
</div>
);

// TODO: Parse line breaks in message
const BuildMessage = !buildMessage ? (
''
) : buildMessage.length < MESSAGE_LEN ? (
Expand Down
5 changes: 4 additions & 1 deletion web/src/ui/components/Header/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import './Header.scss';

const Header = () => {
const {theme} = useContext(ThemeContext);
const {state, updateState} = useContext(ResultContext);
const {state} = useContext(ResultContext);

return (
<div className={'Header'} style={{backgroundColor: theme.bg.page}}>
Expand All @@ -24,6 +24,9 @@ const Header = () => {
<Filters />
</ActionWidgets>
)}
{process.env.YOLO_UI_TEST && (
<pre style={{padding: 0, margin: 0}}>UI Test</pre>
)}
</div>
);
};
Expand Down

0 comments on commit ed995d4

Please sign in to comment.