Skip to content

Commit caf9c31

Browse files
authored
Merge pull request #682 from YoungHypo/issue-chaincode-apporve-frontend
Update Frontend for Chaincode Approval Process
2 parents 1e54e05 + 829260b commit caf9c31

File tree

4 files changed

+115
-11
lines changed

4 files changed

+115
-11
lines changed

src/dashboard/src/models/chaincode.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { listChainCode, uploadChainCode, installChainCode } from '@/services/chaincode';
1+
import {
2+
listChainCode,
3+
uploadChainCode,
4+
installChainCode,
5+
approveChainCode,
6+
} from '@/services/chaincode';
27

38
export default {
49
namespace: 'chainCode',
@@ -42,6 +47,12 @@ export default {
4247
callback(response);
4348
}
4449
},
50+
*approveChainCode({ payload, callback }, { call }) {
51+
const response = yield call(approveChainCode, payload);
52+
if (callback) {
53+
callback(response);
54+
}
55+
},
4556
},
4657
reducers: {
4758
save(state, { payload }) {

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,25 @@ class ChainCode extends PureComponent {
123123
});
124124
};
125125

126+
handleApprove = (values, callback) => {
127+
const { dispatch } = this.props;
128+
129+
const payload = {
130+
channel_name: values.channel,
131+
chaincode_name: values.name,
132+
chaincode_version: values.version,
133+
sequence: parseInt(values.sequence, 10),
134+
policy: values.policy,
135+
init_flag: !!values.initFlag,
136+
};
137+
138+
dispatch({
139+
type: 'chainCode/approveChainCode',
140+
payload,
141+
callback,
142+
});
143+
};
144+
126145
handleUpload = (values, callback) => {
127146
const { dispatch } = this.props;
128147
const formData = new FormData();
@@ -194,8 +213,13 @@ class ChainCode extends PureComponent {
194213
approveModalVisible,
195214
handleApproveModalVisible: this.handleApproveModalVisible,
196215
fetchChainCodes: this.fetchChainCodes,
216+
handleApprove: this.handleApprove,
197217
approving,
198218
selectedRows: [],
219+
initFlagChange: e => {
220+
// this can be used to handle the initFlag change, currently only for demo
221+
console.log('initFlag changed:', e.target.checked);
222+
},
199223
intl,
200224
};
201225

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

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,22 @@ const ApproveForm = props => {
104104
onOk={onSubmit}
105105
onCancel={() => handleApproveModalVisible(false)}
106106
>
107-
<Form onFinish={onFinish} form={form} preserve={false}>
107+
<Form
108+
onFinish={onFinish}
109+
form={form}
110+
preserve={false}
111+
initialValues={{
112+
policy: '',
113+
initFlag: false,
114+
}}
115+
>
108116
<FormItem
109117
{...formItemLayout}
110118
label={intl.formatMessage({
111119
id: 'app.chainCode.form.approve.channel',
112120
defaultMessage: 'Please select channel',
113121
})}
114-
name="channels"
122+
name="channel"
115123
rules={[
116124
{
117125
required: true,
@@ -123,7 +131,6 @@ const ApproveForm = props => {
123131
]}
124132
>
125133
<Select
126-
mode="multiple"
127134
options={channels}
128135
tagRender={tagRender}
129136
dropdownClassName={styles.dropdownClassName}
@@ -153,6 +160,69 @@ const ApproveForm = props => {
153160
})}
154161
/>
155162
</FormItem>
163+
<FormItem
164+
{...formItemLayout}
165+
label={intl.formatMessage({
166+
id: 'app.chainCode.form.approve.version',
167+
defaultMessage: 'Version',
168+
})}
169+
name="version"
170+
rules={[
171+
{
172+
required: true,
173+
message: intl.formatMessage({
174+
id: 'app.chainCode.form.approve.version.required',
175+
defaultMessage: 'Please input version',
176+
}),
177+
},
178+
]}
179+
>
180+
<Input
181+
placeholder={intl.formatMessage({
182+
id: 'app.chainCode.form.approve.version.placeholder',
183+
defaultMessage: 'Version',
184+
})}
185+
/>
186+
</FormItem>
187+
<FormItem
188+
{...formItemLayout}
189+
label={intl.formatMessage({
190+
id: 'app.chainCode.form.approve.sequence',
191+
defaultMessage: 'Sequence',
192+
})}
193+
name="sequence"
194+
rules={[
195+
{
196+
required: true,
197+
message: intl.formatMessage({
198+
id: 'app.chainCode.form.approve.sequence.required',
199+
defaultMessage: 'Please input sequence',
200+
}),
201+
},
202+
]}
203+
>
204+
<Input
205+
placeholder={intl.formatMessage({
206+
id: 'app.chainCode.form.approve.sequence.placeholder',
207+
defaultMessage: 'Sequence',
208+
})}
209+
/>
210+
</FormItem>
211+
<FormItem
212+
{...formItemLayout}
213+
label={intl.formatMessage({
214+
id: 'app.chainCode.form.approve.endorsement_policy',
215+
defaultMessage: 'Endorsement Policy',
216+
})}
217+
name="policy"
218+
>
219+
<Input
220+
placeholder={intl.formatMessage({
221+
id: 'app.chainCode.form.approve.policy.placeholder',
222+
defaultMessage: 'Policy (optional)',
223+
})}
224+
/>
225+
</FormItem>
156226
<FormItem
157227
{...formItemLayout}
158228
label={intl.formatMessage({

src/dashboard/src/services/chaincode.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ export async function installChainCode(params) {
2020
});
2121
}
2222

23-
// export async function listApprovedChaincode(params) {
24-
// // const { channelName, orgName } = params;
25-
// // return request(`/api/v1/approvedChaincodeDefinitions/${channel_name}/${org_name}`);
26-
// return {
27-
// chaincode_names: []
28-
// };
29-
// }
23+
export async function approveChainCode(params) {
24+
return request('/api/v1/chaincodes/approve_for_my_org', {
25+
method: 'POST',
26+
data: params,
27+
});
28+
}

0 commit comments

Comments
 (0)