-
Notifications
You must be signed in to change notification settings - Fork 107
/
serviceVersionsBlockWithData.jsx
69 lines (56 loc) · 1.78 KB
/
serviceVersionsBlockWithData.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import fetchJsonp from 'fetch-jsonp';
import semverDiff from 'semver-diff';
import { appInfoSelector } from 'controllers/appInfo';
import { ServiceVersionsBlock } from './serviceVersionsBlock';
@connect((state) => ({
appInfo: appInfoSelector(state),
}))
export class ServiceVersionsBlockWithData extends Component {
static propTypes = {
appInfo: PropTypes.object,
};
static defaultProps = {
appInfo: {},
};
state = {
services: {},
};
componentWillMount() {
fetchJsonp('https://status.reportportal.io/versions', {
jsonpCallback: 'jsonp',
})
.then((res) => res.json())
.then((latestServiceVersions) =>
this.setState({
services: this.calculateServices(latestServiceVersions),
}),
);
}
calculateServices = (latestServiceVersions) => {
const services = {};
const { appInfo } = this.props;
Object.keys(appInfo).forEach((serviceKey) => {
const serviceValue = appInfo[serviceKey];
if (!(serviceValue && serviceValue.build)) return false;
const currentVersion = serviceValue.build.version;
if (!currentVersion) return false;
const latestVersion = latestServiceVersions[serviceValue.build.repo];
services[serviceKey] = {
name: serviceValue.build.name,
version: serviceValue.build.version,
newVersion: latestVersion || null,
repo: serviceValue.build.repo || null,
isDeprecated:
serviceValue.build.repo && latestVersion && semverDiff(currentVersion, latestVersion),
};
return true;
});
return services;
};
render() {
return <ServiceVersionsBlock services={this.state.services} />;
}
}