Skip to content

Commit

Permalink
src: introducing func comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Sinclert committed Jul 24, 2018
1 parent 8930d6c commit 77a8a7a
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions reana-ui/src/components/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ const TOKEN = 'yCmoYC08hwqp7hFhpgwUUS6fIG8OflCvakCUKDi5cVE';
const POOLING_PERIOD = 5;


export default class TableSortable extends Component {
export default class SortTable extends Component {

/**
* Variables defining the state of the table
*/
state = {
column: null,
data: [],
Expand All @@ -44,6 +47,9 @@ export default class TableSortable extends Component {
};


/**
* Transforms millisecond into a 'HH MM SS' string format
*/
static msToTime(millis) {

let seconds = Math.floor((millis / 1000) % 60);
Expand All @@ -58,8 +64,13 @@ export default class TableSortable extends Component {
}


/**
* Parses API data into displayable data
*/
static parseData(data) {

if (!Array.isArray(data)) return [];

data.forEach((workflow) => {

let info = workflow['name'].split('.');
Expand All @@ -68,20 +79,26 @@ export default class TableSortable extends Component {

let date = new Date(workflow['created']);
workflow['created'] = date.getFullYear() + '-' + date.getMonth() + '-' + date.getDate();
workflow['duration'] = TableSortable.msToTime(Date.now() - date.getTime());
workflow['duration'] = SortTable.msToTime(Date.now() - date.getTime());
});

return data;
}


/**
* Gets data from the specified API
*/
getData() {
fetch(URL + 'access_token=' + TOKEN)
.then(response => response.json())
.then(data => this.setState({ data: _.sortBy(TableSortable.parseData(data), [this.state.column])}));
.then(data => this.setState({ data: _.sortBy(SortTable.parseData(data), [this.state.column])}));
}


/**
* Default runnable method when the component is loaded
*/
componentDidMount() {
this.getData();
this.setState({
Expand All @@ -90,6 +107,9 @@ export default class TableSortable extends Component {
}


/**
* Performs the sorting when a column header is clicked
*/
handleSort = clickedColumn => () => {

const { column, data, direction } = this.state;
Expand Down

0 comments on commit 77a8a7a

Please sign in to comment.