Add project and issue links in card

This commit is contained in:
wpetit 2019-12-13 13:31:27 +01:00
parent b087e50292
commit 477f221b24
1 changed files with 21 additions and 6 deletions

View File

@ -1,8 +1,13 @@
import React from 'react'; import React from 'react';
const issueURLPattern = /(^https?:\/\/([^\/]))$/i;
export class IssueCard extends React.PureComponent { export class IssueCard extends React.PureComponent {
render() { render() {
const { card } = this.props; const { card } = this.props;
const issueURLInfo = extractInfoFromIssueURL(card.issue.url);
const projectURL = `${issueURLInfo.baseURL}/${issueURLInfo.owner}/${issueURLInfo.projectName}`;
const issueURL = `${projectURL}/issues/${card.issue.number}`;
return ( return (
<div className="kanboard-card"> <div className="kanboard-card">
<div className="box"> <div className="box">
@ -30,10 +35,10 @@ export class IssueCard extends React.PureComponent {
</div> </div>
<div className="level is-mobile" style={{marginTop:'1rem'}}> <div className="level is-mobile" style={{marginTop:'1rem'}}>
<div className="level-left"> <div className="level-left">
<small className="level-item"><a href="#">{card.project}</a></small> <small className="level-item"><a href={projectURL}>{card.project}</a></small>
</div> </div>
<div className="level-right"> <div className="level-right">
<a className="level-item" target="_blank" href={card.issue.url.replace('/api/v1/repos', '')}> <a className="level-item" target="_blank" href={issueURL}>
<span className="icon is-small has-text-info"> <span className="icon is-small has-text-info">
<i className="fas fa-search" aria-hidden="true"></i> <i className="fas fa-search" aria-hidden="true"></i>
</span> </span>
@ -45,3 +50,13 @@ export class IssueCard extends React.PureComponent {
); );
} }
} }
function extractInfoFromIssueURL(issueURL) {
const pattern = /^(https?:\/\/[^\/]+)\/api\/v1\/repos\/([^\/]+)\/([^\/]+)\/.*$/;
const matches = pattern.exec(issueURL);
return {
baseURL: matches[1],
owner: matches[2],
projectName: matches[3],
};
}