Skip to content
This repository was archived by the owner on Aug 24, 2019. It is now read-only.

Commit 729cb7f

Browse files
committed
add deployment list
1 parent 2fa7aae commit 729cb7f

File tree

9 files changed

+119
-8
lines changed

9 files changed

+119
-8
lines changed

src/actions/actionTypes.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ export const CLOSE_POP_ADD_APP = 'CLOSE_POP_ADD_APP';
8181
export const POP_ADD_APP_INPUT = 'POP_ADD_APP_INPUT';
8282
export const REQUEST_ADD_PRODUCTS = 'REQUEST_ADD_PRODUCTS';
8383
export const RECEIVE_ADD_PRODUCTS = 'RECEIVE_ADD_PRODUCTS';
84+
export const REQUEST_PRODUCTS_DEPLOYMENTS = 'REQUEST_PRODUCTS_DEPLOYMENTS';
85+
export const RECEIVE_PRODUCTS_DEPLOYMENTS = 'RECEIVE_PRODUCTS_DEPLOYMENTS';
8486
/*========= end productsActions ===========*/
8587

8688
/*========= begin msgStackActions ===========*/

src/actions/productsActions.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,28 @@ export function addProducts(appName) {
7373
});
7474
};
7575
}
76+
77+
export function requestDeployments(appName) {
78+
return {
79+
type: types.REQUEST_PRODUCTS_DEPLOYMENTS,
80+
payload: appName
81+
}
82+
}
83+
84+
export function receiveDeployments(appName, data) {
85+
return {
86+
type: types.RECEIVE_PRODUCTS_DEPLOYMENTS,
87+
payload: {appName, ...data}
88+
}
89+
}
90+
91+
export function fetchDeployments(appName) {
92+
return (dispatch) => {
93+
dispatch(requestDeployments(appName));
94+
return restApi.getDeployments(appName)
95+
.then(data => {
96+
checkResponseAuth(dispatch, data);
97+
dispatch(receiveDeployments(appName, data));
98+
});
99+
};
100+
}

src/components/Product/Product.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,18 @@
1111
min-height: 480px;
1212
max-width: var(--max-content-width);
1313
}
14+
15+
table{
16+
font-size: 1.2em;
17+
width: 100%;
18+
text-align: center;
19+
}
20+
21+
li {
22+
list-style: none;
23+
}
24+
25+
li a {
26+
text-decoration: none;
27+
color: inherit;
28+
}

src/components/Product/Product.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@ import Link from '../Link';
1010
class Product extends Component {
1111
static propTypes = {
1212
appName: PropTypes.string,
13+
items: PropTypes.array
1314
};
1415

1516
static defaultProps = {
1617
appName: '',
18+
items: [],
1719
};
1820

1921
constructor() {
2022
super();
23+
this.renderRow = this.renderRow.bind(this);
2124
}
2225

2326
render() {
@@ -46,11 +49,37 @@ class Product extends Component {
4649
</tr>
4750
</thead>
4851
<tbody>
52+
{
53+
this.props.items.length > 0 ?
54+
_.map(this.props.items, (item, index) => self.renderRow(item, index))
55+
:
56+
<tr>
57+
<td colSpan="6" >{tipText}</td>
58+
</tr>
59+
}
4960
</tbody>
5061
</Table>
5162
</div>
5263
</div>
5364
);
5465
}
66+
67+
renderRow(rowData, index) {
68+
const deployName = _.get(rowData, 'name');
69+
return (
70+
<tr key={index}>
71+
<td>
72+
<Link to={`/apps/${this.props.appName}/${deployName}`}>{deployName}</Link>
73+
</td>
74+
<td style={{ textAlign: 'left' }}>
75+
{_.get(rowData, 'key')}
76+
</td>
77+
<td></td>
78+
<td></td>
79+
<td></td>
80+
<td />
81+
</tr>
82+
);
83+
}
5584
}
5685
export default withStyles(s)(Product);

src/containers/ProductContainer.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,20 @@ class ProductContainer extends Component {
2828
}
2929
}
3030
render() {
31-
const {products, appName, actions } = this.props;
31+
const {deployments, appName, actions } = this.props;
3232
return (
33-
<Product appName={appName} />
33+
<Product
34+
appName={appName}
35+
items={_.get(deployments, `rs.${appName}`)}
36+
/>
3437
);
3538
}
3639
}
3740

3841
function mapStateToProps(state, ownProps) {
3942
return {
4043
'auth': _.get(state, 'auth', {}),
41-
'products': _.get(state, 'products', {})
44+
'deployments': _.get(state, 'deployments', {})
4245
};
4346
}
4447

src/network/RestApi.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,22 @@ class RestApi {
4141
.then(this.jsonDecode);
4242
}
4343

44+
getDeployments(appName) {
45+
return this.get(`/apps/${appName}/deployments`)
46+
.then(data=>{
47+
if (data.httpCode == 200) {
48+
var rs = this.jsonDecode(data);
49+
if (_.get(rs, 'status') != "ERROR") {
50+
return {status:"OK", httpCode: data.httpCode, results: rs};
51+
} else {
52+
return rs;
53+
}
54+
} else {
55+
return {status:"ERROR", httpCode: data.httpCode, errorCode: 0, errorMessage: data.text};
56+
}
57+
});
58+
}
59+
4460
addProducts(appName) {
4561
return this.post('/apps', {name:appName})
4662
.then(data=>{

src/reducers/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {users, login, password} from './users';
55
import {register} from './registers';
66
import {auth, accessKeys} from './auth';
77
import {routes} from './routes';
8-
import {products, addProducts} from './products';
8+
import {products, addProducts, deployments} from './products';
99
import {msgStack} from './msgStack';
1010

1111
const appReducer = combineReducers({
@@ -18,6 +18,7 @@ const appReducer = combineReducers({
1818
routes,
1919
products,
2020
addProducts,
21+
deployments,
2122
msgStack,
2223
});
2324

src/reducers/products.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {
88
POP_ADD_APP_INPUT,
99
REQUEST_ADD_PRODUCTS,
1010
RECEIVE_ADD_PRODUCTS,
11+
REQUEST_PRODUCTS_DEPLOYMENTS,
12+
RECEIVE_PRODUCTS_DEPLOYMENTS,
1113
} from '../actions/actionTypes';
1214

1315
export function products(state = {}, action) {
@@ -16,7 +18,6 @@ export function products(state = {}, action) {
1618
return Object.assign({}, state, {isFetching: true});
1719

1820
case RECEIVE_PRODUCTS:
19-
2021
return Object.assign({}, state, {
2122
isFetching: false,
2223
rs: _.get(action, 'payload.apps')
@@ -27,6 +28,23 @@ export function products(state = {}, action) {
2728
}
2829
}
2930

31+
export function deployments(state = {rs:{}}, action) {
32+
let payload = _.get(action, 'payload');
33+
switch (action.type) {
34+
case REQUEST_PRODUCTS_DEPLOYMENTS:
35+
return Object.assign({}, state, {isFetching: true});
36+
37+
case RECEIVE_PRODUCTS_DEPLOYMENTS:
38+
var data = Object.assign({}, state, {isFetching: false});
39+
var appName = _.get(payload, 'appName');
40+
_.set(data, `rs.${appName}`, _.get(payload, 'results.deployments'));
41+
return data;
42+
43+
default :
44+
return state;
45+
}
46+
}
47+
3048
export function addProducts(state = {}, action) {
3149
let payload = action.payload;
3250
switch (action.type) {

src/routes/apps/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
import React from 'react';
33
import LayoutContainer from '../../containers/LayoutContainer';
4-
import { getProducts } from '../../actions/productsActions';
4+
import { getProducts, fetchDeployments} from '../../actions/productsActions';
55
import _ from 'lodash';
66

77
const apps = {
@@ -48,10 +48,12 @@ const appDetails = {
4848
path: '/apps/:appName',
4949

5050
async action({store, params}) {
51+
var appName = _.get(params, 'appName');
5152
if (process.env.BROWSER) {
52-
53+
setTimeout(() => {
54+
store.dispatch(fetchDeployments(appName));
55+
}, 100);
5356
}
54-
var appName = _.get(params, 'appName');
5557
const ProductContainer = await require.ensure([], require => require('../../containers/ProductContainer').default, 'product');
5658
return {
5759
title: `${appName} 详情`,

0 commit comments

Comments
 (0)