From 9208470ba29d9d76ce19d730385894d609cb7d69 Mon Sep 17 00:00:00 2001 From: Xiao Ran Date: Fri, 3 Nov 2023 13:14:37 -0500 Subject: [PATCH 1/2] Added the approve form. Signed-off-by: Xiao Ran --- .../src/pages/ChainCode/ChainCode.js | 24 ++- .../src/pages/ChainCode/forms/ApproveForm.js | 168 ++++++++++++++++++ 2 files changed, 190 insertions(+), 2 deletions(-) create mode 100644 src/dashboard/src/pages/ChainCode/forms/ApproveForm.js diff --git a/src/dashboard/src/pages/ChainCode/ChainCode.js b/src/dashboard/src/pages/ChainCode/ChainCode.js index bdf9d9482..c03128441 100644 --- a/src/dashboard/src/pages/ChainCode/ChainCode.js +++ b/src/dashboard/src/pages/ChainCode/ChainCode.js @@ -8,6 +8,7 @@ import { PlusOutlined, UploadOutlined, FunctionOutlined, DownOutlined } from '@a import PageHeaderWrapper from '@/components/PageHeaderWrapper'; import StandardTable from '@/components/StandardTable'; import { Form } from 'antd/lib/index'; +import ApproveForm from '@/pages/ChainCode/forms/ApproveForm'; import styles from './styles.less'; const FormItem = Form.Item; @@ -156,6 +157,7 @@ const UploadChainCode = props => { chainCode, loadingChainCodes: loading.effects['chainCode/listChainCode'], uploading: loading.effects['chainCode/uploadChainCode'], + approving: loading.effects['chainCode/approveChainCode'], })) class ChainCode extends PureComponent { state = { @@ -163,6 +165,7 @@ class ChainCode extends PureComponent { formValues: {}, newFile: '', modalVisible: false, + approveModalVisible: false, }; componentDidMount() { @@ -214,6 +217,12 @@ class ChainCode extends PureComponent { }); }; + handleApproveModalVisible = visible => { + this.setState({ + approveModalVisible: !!visible, + }); + }; + handleUpload = (values, callback) => { const { dispatch } = this.props; const formData = new FormData(); @@ -240,12 +249,13 @@ class ChainCode extends PureComponent { }; render() { - const { selectedRows, modalVisible, newFile } = this.state; + const { selectedRows, modalVisible, newFile, approveModalVisible } = this.state; const { chainCode: { chainCodes, paginations }, loadingChainCodes, intl, uploading, + approving, } = this.props; const formProps = { @@ -259,6 +269,15 @@ class ChainCode extends PureComponent { intl, }; + const approveFormProps = { + approveModalVisible, + handleApproveModalVisible: this.handleApproveModalVisible, + fetchChainCodes: this.fetchChainCodes, + approving, + selectedRows: [], + intl, + }; + const menu = record => ( @@ -333,7 +352,7 @@ class ChainCode extends PureComponent { })} - + this.handleApproveModalVisible(true)}> {intl.formatMessage({ id: 'app.chainCode.table.operate.approve', defaultMessage: 'Approve', @@ -402,6 +421,7 @@ class ChainCode extends PureComponent { /> + ); diff --git a/src/dashboard/src/pages/ChainCode/forms/ApproveForm.js b/src/dashboard/src/pages/ChainCode/forms/ApproveForm.js new file mode 100644 index 000000000..beae57931 --- /dev/null +++ b/src/dashboard/src/pages/ChainCode/forms/ApproveForm.js @@ -0,0 +1,168 @@ +import React, { useState, useEffect } from 'react'; +import { injectIntl, useIntl } from 'umi'; +import { Modal, message, Select, Form, Tag, Input, Checkbox } from 'antd'; +import { listChannel } from '@/services/channel'; +import styles from '../styles.less'; + +const FormItem = Form.Item; + +const ApproveForm = props => { + const [form] = Form.useForm(); + const intl = useIntl(); + const [channels, setChannels] = useState(); + const { + approveModalVisible, + handleApprove, + handleApproveModalVisible, + approving, + fetchChainCodes, + initFlagChange, + } = props; + + useEffect(() => { + async function fecthData() { + const response = await listChannel(); + setChannels(response.data.data); + } + fecthData(); + }, []); + + const approveCallback = response => { + if (response.status !== 'successful') { + message.error( + intl.formatMessage({ + id: 'app.operator.chainCode.form.approve.fail', + defaultMessage: 'Approve chaincode failed', + }) + ); + } else { + message.success( + intl.formatMessage({ + id: 'app.operator.chainCode.form.approve.success', + defaultMessage: 'Approve chaincode succeed', + }) + ); + form.resetFields(); + handleApproveModalVisible(); + fetchChainCodes(); + } + }; + + const onSubmit = () => { + form.submit(); + }; + + const onFinish = values => { + handleApprove(values, approveCallback); + }; + + const formItemLayout = { + labelCol: { + xs: { span: 24 }, + sm: { span: 11 }, + }, + wrapperCol: { + xs: { span: 24 }, + sm: { span: 12 }, + md: { span: 10 }, + }, + }; + + // eslint-disable-next-line no-shadow + const tagRender = props => { + const { label, closable, onClose } = props; + const onPreventMouseDown = event => { + event.preventDefault(); + event.stopPropagation(); + }; + return ( + + {label} + + ); + }; + + return ( + handleApproveModalVisible(false)} + > +
+ + + + + + +
+
+ ); +}; + +export default injectIntl(ApproveForm); From 07f30bbb6345fd41845a36f25506970aacec89c8 Mon Sep 17 00:00:00 2001 From: Xiao Ran Date: Fri, 17 Nov 2023 12:19:05 -0600 Subject: [PATCH 2/2] Changed the message ids. Signed-off-by: Xiao Ran --- .../src/pages/ChainCode/forms/ApproveForm.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/dashboard/src/pages/ChainCode/forms/ApproveForm.js b/src/dashboard/src/pages/ChainCode/forms/ApproveForm.js index beae57931..113520193 100644 --- a/src/dashboard/src/pages/ChainCode/forms/ApproveForm.js +++ b/src/dashboard/src/pages/ChainCode/forms/ApproveForm.js @@ -31,14 +31,14 @@ const ApproveForm = props => { if (response.status !== 'successful') { message.error( intl.formatMessage({ - id: 'app.operator.chainCode.form.approve.fail', + id: 'app.chainCode.form.approve.fail', defaultMessage: 'Approve chaincode failed', }) ); } else { message.success( intl.formatMessage({ - id: 'app.operator.chainCode.form.approve.success', + id: 'app.chainCode.form.approve.success', defaultMessage: 'Approve chaincode succeed', }) ); @@ -92,7 +92,7 @@ const ApproveForm = props => { { { { required: true, message: intl.formatMessage({ - id: 'app.operator.chainCode.form.approve.channel', + id: 'app.chainCode.form.approve.channel', defaultMessage: 'Please select channel', }), }, @@ -129,7 +129,7 @@ const ApproveForm = props => { { { required: true, message: intl.formatMessage({ - id: 'app.operator.chainCode.form.approve.specifyName', + id: 'app.chainCode.form.approve.specifyName', defaultMessage: 'Name for chaincode', }), }, @@ -145,7 +145,7 @@ const ApproveForm = props => { > @@ -153,7 +153,7 @@ const ApproveForm = props => {