This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/static/js/directives/components/pages/repo-page/body.tsx

110 lines
3 KiB
TypeScript
Raw Normal View History

import * as React from "react";
2016-12-12 20:05:22 +00:00
import Build from "./build";
import Throbber from "./throbber";
2016-11-29 20:57:53 +00:00
interface IBody {
2016-12-12 20:05:22 +00:00
description: string;
api: Object;
repository: Object;
}
interface IBodyState {
currentBuild: any;
intervalId: number;
}
2016-11-29 20:57:53 +00:00
/**
* The Component for the main body of the repo page
* @param {string} description - The description of the repository
* @param {object} api - The ApiService injected from Angular
2016-12-12 20:05:22 +00:00
* @param {object} repository - The list of properties for the repository
2016-11-29 20:57:53 +00:00
*/
2016-12-12 20:05:22 +00:00
class body extends React.Component<IBody, IBodyState> {
static propTypes = {
description: React.PropTypes.string.isRequired,
2016-12-12 20:05:22 +00:00
api: React.PropTypes.object.isRequired,
repository: React.PropTypes.object.isRequired,
}
constructor(props){
super(props)
this.state = {
currentBuild: [],
intervalId: null
2016-12-12 20:05:22 +00:00
};
}
componentDidMount() {
2017-02-06 22:05:19 +00:00
let intervalId: number = window.setInterval(() => this.getBuilds(), 1000);
this.setState({
currentBuild: this.state.currentBuild,
intervalId: intervalId
});
}
comoponentDidUnmount() {
clearInterval(this.state.intervalId);
2016-12-12 20:05:22 +00:00
}
getBuilds() {
let api: any = this.props.api;
let repository: any = this.props.repository;
let params: Object = {
'repository': repository.namespace + '/' + repository.name,
'limit': 8
};
api.getRepoBuildsAsResource(params, true).get((data) => {
let builds: Array<Object> = [];
data.builds.forEach((element, i) => {
builds.push({
user: element.manual_user,
id: element.id,
display_name: element.display_name,
started: element.started,
tags: element.tags,
phase: element.phase,
trigger: element.trigger,
trigger_metadata: element.trigger_metadata
});
});
2017-02-06 22:05:19 +00:00
2016-12-12 20:05:22 +00:00
this.setState({
currentBuild: builds,
intervalId: this.state.intervalId
2016-12-12 20:05:22 +00:00
});
});
}
render () {
2016-11-29 20:57:53 +00:00
let description: string = this.props.description;
if (description === null || description === "") {
2016-11-29 20:57:53 +00:00
description = "No Description";
}
return(
<div>
<ul className="nav nav-tabs rp-tabs">
<li className="active">
<a data-target="#tab1" data-toggle="tab">Description</a>
</li>
<li>
<a data-target="#tab2" data-toggle="tab">Automated Builds</a>
</li>
</ul>
<div className="panel-body rp-panelBody">
<div className="tab-content">
<div className="tab-pane in active" id="tab1">
2016-11-29 20:57:53 +00:00
<div className="rp-description">{description}</div>
</div>
2017-02-06 22:05:19 +00:00
<div className="tab-pane" id="tab2">
2016-12-12 20:05:22 +00:00
<div className="panel-body">
<h3 className="tab-header">Repository Builds</h3>
2016-12-12 20:05:22 +00:00
<Build data={this.state.currentBuild}/>
</div>
</div>
</div>
</div>
</div>
);
}
}
2016-10-31 20:21:45 +00:00
export default body;