Skip to content

Commit 6a07c72

Browse files
committed
[CE-369] Implement invoke/query smart contract
Add running smart contract page for show all running chain code. Can invoke/query smart contract in running chain code detail page. Fix chain root path not clean when chain is released. Change-Id: I1ab6af5bc4023182f28e03651e30f282d5d2502e Signed-off-by: Haitao Yue <hightall@me.com>
1 parent 5162a2b commit 6a07c72

File tree

23 files changed

+1389
-14
lines changed

23 files changed

+1389
-14
lines changed

user-dashboard/src/app/assets/src/common/menu.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,19 @@ const menuData = [
2121
icon: "code-o",
2222
children: [
2323
{
24-
name: "List",
24+
name: "Templates",
2525
path: "index",
2626
},
27+
{
28+
name: "Running",
29+
path: "running",
30+
},
31+
{
32+
name: "Invoke/Query",
33+
path: "invoke-query/:id",
34+
hideInMenu: true,
35+
hideInBreadcrumb: false,
36+
},
2737
{
2838
name: "Info",
2939
path: "info/:id",

user-dashboard/src/app/assets/src/common/router.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,16 @@ export const getRouterData = app => {
130130
import("../routes/SmartContract/New/code")
131131
),
132132
},
133+
"/smart-contract/running": {
134+
component: dynamicWrapper(app, ["deploy"], () =>
135+
import("../routes/SmartContract/Running")
136+
),
137+
},
138+
"/smart-contract/invoke-query/:id": {
139+
component: dynamicWrapper(app, ["deploy"], () =>
140+
import("../routes/SmartContract/InvokeQuery")
141+
),
142+
},
133143
};
134144
// Get name from ./menu.js or just set it in the router data.
135145
const menuData = getFlatMenuData(getMenuData());
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
SPDX-License-Identifier: Apache-2.0
3+
*/
4+
import { queryDeploys, queryDeploy, operateDeploy } from "../services/deploy";
5+
6+
export default {
7+
namespace: "deploy",
8+
9+
state: {
10+
deploys: [],
11+
currentDeploy: {},
12+
total: 0,
13+
instantiatedCount: 0,
14+
instantiatingCount: 0,
15+
errorCount: 0,
16+
},
17+
18+
effects: {
19+
*fetch({ payload }, { call, put }) {
20+
const response = yield call(queryDeploys, payload);
21+
const {
22+
data,
23+
total,
24+
instantiatedCount,
25+
instantiatingCount,
26+
errorCount,
27+
} = response.data;
28+
yield put({
29+
type: "setDeploys",
30+
payload: {
31+
deploys: data,
32+
total,
33+
instantiatingCount,
34+
instantiatedCount,
35+
errorCount,
36+
},
37+
});
38+
},
39+
*queryDeploy({ payload }, { call, put }) {
40+
const response = yield call(queryDeploy, payload.id);
41+
const { deploy } = response;
42+
yield put({
43+
type: "setDeploy",
44+
payload: {
45+
currentDeploy: deploy,
46+
},
47+
});
48+
},
49+
*operateDeploy({ payload }, { call }) {
50+
const response = yield call(operateDeploy, payload);
51+
if (payload.callback) {
52+
yield call(payload.callback, {
53+
request: payload,
54+
response,
55+
});
56+
}
57+
},
58+
},
59+
60+
reducers: {
61+
setDeploys(state, action) {
62+
const {
63+
deploys,
64+
total,
65+
instantiatedCount,
66+
instantiatingCount,
67+
errorCount,
68+
} = action.payload;
69+
return {
70+
...state,
71+
deploys,
72+
total,
73+
instantiatedCount,
74+
instantiatingCount,
75+
errorCount,
76+
};
77+
},
78+
setDeploy(state, action) {
79+
const { currentDeploy } = action.payload;
80+
return {
81+
...state,
82+
currentDeploy,
83+
};
84+
},
85+
},
86+
};

user-dashboard/src/app/assets/src/models/smartContract.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export default {
1717
smartContracts: [],
1818
currentSmartContract: {},
1919
codes: [],
20+
deploys: [],
2021
newOperations: [],
2122
},
2223

@@ -51,6 +52,7 @@ export default {
5152
payload: {
5253
currentSmartContract: response.info,
5354
codes: response.codes,
55+
deploys: response.deploys,
5456
newOperations: response.newOperations,
5557
},
5658
});
@@ -78,11 +80,17 @@ export default {
7880
};
7981
},
8082
setCurrentSmartContract(state, action) {
81-
const { currentSmartContract, codes, newOperations } = action.payload;
83+
const {
84+
currentSmartContract,
85+
codes,
86+
newOperations,
87+
deploys,
88+
} = action.payload;
8289
return {
8390
...state,
8491
currentSmartContract,
8592
codes,
93+
deploys,
8694
newOperations,
8795
};
8896
},

user-dashboard/src/app/assets/src/routes/SmartContract/Info/detail.js

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
Button,
88
Table,
99
Divider,
10+
Badge,
1011
} from 'antd';
1112
import moment from 'moment';
1213
import styles from './index.less';
@@ -15,7 +16,7 @@ import styles from './index.less';
1516
export default class Detail extends Component {
1617

1718
render() {
18-
const { codes, loadingInfo, onAddNewCode, onDeploy } = this.props;
19+
const { codes, loadingInfo, onAddNewCode, onDeploy, deploys, onInvokeQuery } = this.props;
1920
const codeColumns = [
2021
{
2122
title: 'Version',
@@ -39,10 +40,76 @@ export default class Detail extends Component {
3940
),
4041
},
4142
];
43+
const deployColumns = [
44+
{
45+
title: 'Chain',
46+
dataIndex: 'chain',
47+
key: 'chain',
48+
render: text => text.name,
49+
},
50+
{
51+
title: 'Code Version',
52+
dataIndex: 'smartContractCode',
53+
key: 'smartContractCode',
54+
render: text => text.version,
55+
},
56+
{
57+
title: 'Status',
58+
dataIndex: 'status',
59+
key: 'status',
60+
render: ( text ) => {
61+
let status = "default";
62+
switch (text) {
63+
case 'installed':
64+
case 'instantiated':
65+
status = "success";
66+
break;
67+
case 'instantiating':
68+
status = "processing";
69+
break;
70+
case 'error':
71+
status = "error";
72+
break;
73+
default:
74+
break;
75+
}
76+
77+
return <Badge status={status} text={<span className={styles["status-text"]}>{text}</span>} />;
78+
},
79+
},
80+
{
81+
title: 'Deploy Time',
82+
dataIndex: 'deployTime',
83+
key: 'deployTime',
84+
render: text => moment(text).format("YYYY-MM-DD HH:mm:ss"),
85+
},
86+
{
87+
title: 'Operate',
88+
render: ( text, record ) => (
89+
<Fragment>
90+
<Button onClick={() => onInvokeQuery(record)} type="primary" icon="api" size="small" disabled={record.status !== 'instantiated'}>Invoke/Query</Button>
91+
</Fragment>
92+
),
93+
},
94+
];
4295
return (
4396
<div>
97+
<Card
98+
title="Deployment List"
99+
bordered={false}
100+
>
101+
<div className={styles.tableList}>
102+
<Table
103+
pagination={false}
104+
loading={loadingInfo}
105+
columns={deployColumns}
106+
dataSource={deploys}
107+
/>
108+
</div>
109+
</Card>
44110
<Card
45111
title="Code List"
112+
style={{marginTop: 20}}
46113
bordered={false}
47114
>
48115
<div className={styles.tableList}>

user-dashboard/src/app/assets/src/routes/SmartContract/Info/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ export default class AdvancedProfile extends Component {
126126
this.onOperationTabChange('detail');
127127
};
128128

129+
onInvokeQuery = (item) => {
130+
this.props.dispatch(routerRedux.push({
131+
pathname: `/smart-contract/invoke-query/${item._id}`,
132+
}));
133+
};
134+
129135
@Bind()
130136
@Debounce(200)
131137
setStepDirection() {
@@ -143,16 +149,18 @@ export default class AdvancedProfile extends Component {
143149
}
144150
render() {
145151
const { smartContract, chain: { chains }, loadingInfo } = this.props;
146-
const { currentSmartContract, codes, newOperations } = smartContract;
152+
const { currentSmartContract, codes, deploys, newOperations } = smartContract;
147153
const { deployStep, selectedVersion, selectedVersionId } = this.state;
148154
const versions = codes.map(code => code.version);
149155
const versionTags = versions.map(version => <Tag>{version}</Tag>);
150156

151157
const detailProps = {
152158
codes,
159+
deploys,
153160
loadingInfo,
154161
onAddNewCode: this.onAddNewCode,
155162
onDeploy: this.onClickDeploy,
163+
onInvokeQuery: this.onInvokeQuery,
156164
};
157165
const deployProps = {
158166
version: selectedVersion,

user-dashboard/src/app/assets/src/routes/SmartContract/Info/index.less

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,7 @@
107107
align-content: center;
108108
text-align: center;
109109
}
110+
111+
.status-text {
112+
text-transform: capitalize;
113+
}

0 commit comments

Comments
 (0)