Skip to content

Commit d5eef56

Browse files
committed
update dashboard components for commiting
Signed-off-by: YoungHypo <[email protected]>
1 parent ae81505 commit d5eef56

File tree

4 files changed

+159
-141
lines changed

4 files changed

+159
-141
lines changed

src/dashboard/src/models/chaincode.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
uploadChainCode,
44
installChainCode,
55
approveChainCode,
6+
commitChainCode,
67
} from '@/services/chaincode';
78

89
export default {
@@ -53,6 +54,12 @@ export default {
5354
callback(response);
5455
}
5556
},
57+
*commitChainCode({ payload, callback }, { call }) {
58+
const response = yield call(commitChainCode, payload);
59+
if (callback) {
60+
callback(response);
61+
}
62+
},
5663
},
5764
reducers: {
5865
save(state, { payload }) {

src/dashboard/src/pages/ChainCode/ChainCode.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,25 @@ class ChainCode extends PureComponent {
142142
});
143143
};
144144

145+
handleCommit = (values, callback) => {
146+
const { dispatch } = this.props;
147+
148+
const payload = {
149+
channel_name: values.channel,
150+
chaincode_name: values.name,
151+
chaincode_version: values.version,
152+
sequence: parseInt(values.sequence, 10),
153+
policy: values.policy,
154+
init_flag: !!values.initFlag,
155+
};
156+
157+
dispatch({
158+
type: 'chainCode/commitChainCode',
159+
payload,
160+
callback,
161+
});
162+
};
163+
145164
handleUpload = (values, callback) => {
146165
const { dispatch } = this.props;
147166
const formData = new FormData();
@@ -226,9 +245,9 @@ class ChainCode extends PureComponent {
226245
const commitFormProps = {
227246
commitModalVisible,
228247
handleCommitModalVisible: this.handleCommitModalVisible,
248+
handleCommit: this.handleCommit,
229249
fetchChainCodes: this.fetchChainCodes,
230250
committing,
231-
selectedRows: [],
232251
intl,
233252
};
234253

src/dashboard/src/pages/ChainCode/forms/CommitForm.js

Lines changed: 125 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,38 @@
11
import React, { useState, useEffect } from 'react';
22
import { injectIntl, useIntl } from 'umi';
3-
import { Modal, message, Select, Form, Tag, Checkbox } from 'antd';
4-
import StandardTable from '@/components/StandardTable';
5-
// import { listChannel } from '@/services/channel'
6-
import { listOrganization } from '@/services/organization';
7-
// import { listApprovedChaincode } from '@/services/chaincode';
3+
import { Modal, message, Select, Form, Tag, Checkbox, Input } from 'antd';
4+
import { listChannel } from '@/services/channel';
85
import styles from '../styles.less';
96

107
const FormItem = Form.Item;
11-
// const initialState = [
12-
// { label: 'mychannel1', value: 'mychannel1', disabled: true },
13-
// { label: 'mychannel2', value: 'mychannel2' },
14-
// { label: 'mychannel3', value: 'mychannel3' },
15-
// ];
168

179
const CommitForm = props => {
1810
const [form] = Form.useForm();
1911
const intl = useIntl();
20-
const [orgs, setOrgs] = useState();
21-
const [approvedOrgs, setApprovedOrgs] = useState();
22-
// const [channels, setChannels] = useState();
12+
const [channels, setChannels] = useState();
2313
const {
24-
chaincodeName = '',
2514
commitModalVisible,
2615
handleCommit,
2716
handleCommitModalVisible,
28-
Committing,
17+
committing,
2918
fetchChainCodes,
30-
selectedRows,
3119
initFlagChange,
3220
} = props;
3321

3422
useEffect(() => {
35-
async function fecthData() {
36-
// const channelResponse = await listChannel();
37-
// setChannels(channelResponse.data.data);
38-
const orgResponse = await listOrganization();
39-
setOrgs(orgResponse.data.data);
23+
async function fetchData() {
24+
try {
25+
const response = await listChannel();
26+
const newChannels = Object.keys(response.data.data).map(item => ({
27+
label: response.data.data[item].name,
28+
value: response.data.data[item].name,
29+
}));
30+
setChannels(newChannels);
31+
} catch (error) {
32+
console.error('Failed to fetch data:', error);
33+
}
4034
}
41-
fecthData();
35+
fetchData();
4236
}, []);
4337

4438
const commitCallback = response => {
@@ -102,155 +96,146 @@ const CommitForm = props => {
10296
);
10397
};
10498

105-
const handleTableChange = pagination => {
106-
const { dispatch } = props;
107-
const { current, pageSize } = pagination;
108-
const params = {
109-
page: current,
110-
per_page: pageSize,
111-
};
112-
dispatch({
113-
type: 'chainCode/listChainCode',
114-
payload: params,
115-
});
116-
};
117-
118-
const handleChannelChange = () => {
119-
const filteredOrgs = orgs.map(org => {
120-
// const response = await listApprovedChaincode({ channels_name: value[0], org_name: org["name"] });
121-
// const chaincode_names = response.data.chaincode_names;
122-
const chaincodeNames = [];
123-
return chaincodeName in chaincodeNames
124-
? {
125-
name: org.name,
126-
status: 'Approved',
127-
}
128-
: {
129-
name: org.name,
130-
status: 'Unapproved',
131-
};
132-
});
133-
setApprovedOrgs(filteredOrgs);
134-
};
135-
136-
// const dummyList = [
137-
// {
138-
// name: 'org1.cello.com',
139-
// status: 'Approved',
140-
// },
141-
// {
142-
// name: 'org2.cello.com',
143-
// status: 'Approved',
144-
// },
145-
// {
146-
// name: 'org3.cello.com',
147-
// status: 'Unapproved',
148-
// },
149-
// ];
150-
151-
const dummyChannel = [
152-
{
153-
id: '89cab0f6-47a8-4335-b217-7ec39cfcf65f',
154-
name: 'channel1',
155-
network: {
156-
id: 'bfb3484d-dc5c-4cc4-8be0-0251eefd2c57',
157-
name: 'test1',
158-
},
159-
organizations: [
160-
{
161-
id: '76ebf68b-019f-45ff-abef-67e3a3d1752f',
162-
name: 'org1.cello.com',
163-
},
164-
],
165-
create_ts: '2021-12-10T05:52:30.931971Z',
166-
},
167-
];
168-
169-
const dummyPagination = {
170-
total: 0,
171-
current: 1,
172-
pageSize: 10,
173-
};
174-
175-
const columns = [
176-
{
177-
title: intl.formatMessage({
178-
id: 'app.operator.chainCode.form.commit.header.name',
179-
defaultMessage: 'Organization Name',
180-
}),
181-
dataIndex: 'name',
182-
},
183-
{
184-
title: intl.formatMessage({
185-
id: 'app.operator.chainCode.form.commit.header.status',
186-
defaultMessage: 'Approvement Status',
187-
}),
188-
dataIndex: 'status',
189-
},
190-
];
191-
19299
return (
193100
<Modal
194101
destroyOnClose
195102
title={intl.formatMessage({
196103
id: 'app.operator.chainCode.form.commit.header.title',
197104
defaultMessage: 'Commit Chaincode',
198105
})}
199-
confirmLoading={Committing}
106+
confirmLoading={committing}
200107
open={commitModalVisible}
201108
onOk={onSubmit}
202109
onCancel={() => handleCommitModalVisible(false)}
203110
>
204-
<Form onFinish={onFinish} form={form} preserve={false}>
111+
<Form
112+
onFinish={onFinish}
113+
form={form}
114+
preserve={false}
115+
initialValues={{
116+
initFlag: false,
117+
}}
118+
>
205119
<FormItem
206120
{...formItemLayout}
207121
label={intl.formatMessage({
208122
id: 'app.operator.chainCode.form.commit.channels',
209-
defaultMessage: 'Please select channels',
123+
defaultMessage: 'Please select channel',
210124
})}
211-
name="channels"
125+
name="channel"
126+
rules={[
127+
{
128+
required: true,
129+
message: intl.formatMessage({
130+
id: 'app.operator.chainCode.form.commit.channels',
131+
defaultMessage: 'Please select channel',
132+
}),
133+
},
134+
]}
212135
>
213136
<Select
214-
mode="multiple"
215-
// options={channels}
216-
onChange={handleChannelChange}
217-
options={dummyChannel.map(c => {
218-
return {
219-
value: c.name,
220-
label: c.name,
221-
};
222-
})}
137+
options={channels}
223138
tagRender={tagRender}
224139
dropdownClassName={styles.dropdownClassName}
225140
/>
226141
</FormItem>
227142
<FormItem
228143
{...formItemLayout}
229144
label={intl.formatMessage({
230-
id: 'app.operator.chainCode.form.initFlag',
145+
id: 'app.chainCode.form.approve.specifyName',
146+
defaultMessage: 'Name for chaincode',
147+
})}
148+
name="name"
149+
rules={[
150+
{
151+
required: true,
152+
message: intl.formatMessage({
153+
id: 'app.chainCode.form.approve.specifyName',
154+
defaultMessage: 'Name for chaincode',
155+
}),
156+
},
157+
]}
158+
>
159+
<Input
160+
placeholder={intl.formatMessage({
161+
id: 'app.chainCode.form.approve.name',
162+
defaultMessage: 'Name',
163+
})}
164+
/>
165+
</FormItem>
166+
<FormItem
167+
{...formItemLayout}
168+
label={intl.formatMessage({
169+
id: 'app.chainCode.form.approve.version',
170+
defaultMessage: 'Version',
171+
})}
172+
name="version"
173+
rules={[
174+
{
175+
required: true,
176+
message: intl.formatMessage({
177+
id: 'app.chainCode.form.approve.version.required',
178+
defaultMessage: 'Please input version',
179+
}),
180+
},
181+
]}
182+
>
183+
<Input
184+
placeholder={intl.formatMessage({
185+
id: 'app.chainCode.form.approve.version.placeholder',
186+
defaultMessage: 'Version',
187+
})}
188+
/>
189+
</FormItem>
190+
<FormItem
191+
{...formItemLayout}
192+
label={intl.formatMessage({
193+
id: 'app.chainCode.form.approve.sequence',
194+
defaultMessage: 'Sequence',
195+
})}
196+
name="sequence"
197+
rules={[
198+
{
199+
required: true,
200+
message: intl.formatMessage({
201+
id: 'app.chainCode.form.approve.sequence.required',
202+
defaultMessage: 'Please input sequence',
203+
}),
204+
},
205+
]}
206+
>
207+
<Input
208+
placeholder={intl.formatMessage({
209+
id: 'app.chainCode.form.approve.sequence.placeholder',
210+
defaultMessage: 'Sequence',
211+
})}
212+
/>
213+
</FormItem>
214+
<FormItem
215+
{...formItemLayout}
216+
label={intl.formatMessage({
217+
id: 'app.chainCode.form.approve.endorsement_policy',
218+
defaultMessage: 'Endorsement Policy',
219+
})}
220+
name="policy"
221+
>
222+
<Input
223+
placeholder={intl.formatMessage({
224+
id: 'app.chainCode.form.approve.policy.placeholder',
225+
defaultMessage: 'Policy (optional)',
226+
})}
227+
/>
228+
</FormItem>
229+
<FormItem
230+
{...formItemLayout}
231+
label={intl.formatMessage({
232+
id: 'app.chainCode.form.initFlag',
231233
defaultMessage: '--init-required flag',
232234
})}
233235
name="initFlag"
234236
>
235237
<Checkbox onChange={initFlagChange} />
236238
</FormItem>
237-
<div className={styles.tableList}>
238-
<StandardTable
239-
selectedRows={selectedRows}
240-
rowKey="id"
241-
// data={{
242-
// list: chainCodes,
243-
// pagination,
244-
// }}
245-
data={{
246-
// list: dummyList,
247-
list: approvedOrgs,
248-
pagination: dummyPagination,
249-
}}
250-
columns={columns}
251-
onChange={handleTableChange}
252-
/>
253-
</div>
254239
</Form>
255240
</Modal>
256241
);

src/dashboard/src/services/chaincode.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,10 @@ export async function approveChainCode(params) {
2626
data: params,
2727
});
2828
}
29+
30+
export async function commitChainCode(params) {
31+
return request('/api/v1/chaincodes/commit', {
32+
method: 'POST',
33+
data: params,
34+
});
35+
}

0 commit comments

Comments
 (0)