Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the commit form demo #596

Merged
merged 1 commit into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 22 additions & 55 deletions src/dashboard/src/pages/ChainCode/ChainCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import PageHeaderWrapper from '@/components/PageHeaderWrapper';
import StandardTable from '@/components/StandardTable';
import { Form } from 'antd/lib/index';
import ApproveForm from '@/pages/ChainCode/forms/ApproveForm';
import CommitForm from './forms/CommitForm';
import styles from './styles.less';
import InstallForm from './forms/InstallForm';

const FormItem = Form.Item;

Expand Down Expand Up @@ -159,15 +159,16 @@ const UploadChainCode = props => {
loadingChainCodes: loading.effects['chainCode/listChainCode'],
uploading: loading.effects['chainCode/uploadChainCode'],
approving: loading.effects['chainCode/approveChainCode'],
committing: loading.effects['chainCode/commitChainCode'],
}))
class ChainCode extends PureComponent {
state = {
selectedRows: [],
formValues: {},
newFile: '',
modalVisible: false,
installModalVisible: false,
approveModalVisible: false,
commitModalVisible: false,
};

componentDidMount() {
Expand Down Expand Up @@ -219,21 +220,15 @@ class ChainCode extends PureComponent {
});
};

handleInstallModalVisible = visible => {
this.setState({
installModalVisible: !!visible,
});
};

handleApproveModalVisible = visible => {
this.setState({
approveModalVisible: !!visible,
});
};

setOperatedRow = row => {
handleCommitModalVisible = visible => {
this.setState({
operatedRow: row,
commitModalVisible: !!visible,
});
};

Expand All @@ -254,21 +249,6 @@ class ChainCode extends PureComponent {
});
};

handleInstall = (values, callback) => {
const { dispatch } = this.props;
const { operatedRow } = this.state;
const { node } = values;
const formData = new FormData();
formData.append('peer_uuid', node);
formData.append('chaincode_package', operatedRow.package_id);

dispatch({
type: 'chainCode/installChainCode',
payload: formData,
callback,
});
};

onUploadChainCode = () => {
this.handleModalVisible(true);
};
Expand All @@ -283,16 +263,15 @@ class ChainCode extends PureComponent {
modalVisible,
newFile,
approveModalVisible,
installModalVisible,
operatedRow,
commitModalVisible,
} = this.state;
const {
chainCode: { chainCodes, paginations },
loadingChainCodes,
intl,
uploading,
installing,
approving,
committing,
} = this.props;

const formProps = {
Expand All @@ -306,15 +285,6 @@ class ChainCode extends PureComponent {
intl,
};

const installFormProps = {
installModalVisible,
handleInstallModalVisible: this.handleInstallModalVisible,
fetchChainCodes: this.fetchChainCodes,
installing,
operatedRow,
handleInstall: this.handleInstall,
};

const approveFormProps = {
approveModalVisible,
handleApproveModalVisible: this.handleApproveModalVisible,
Expand All @@ -324,6 +294,15 @@ class ChainCode extends PureComponent {
intl,
};

const commitFormProps = {
commitModalVisible,
handleCommitModalVisible: this.handleCommitModalVisible,
fetchChainCodes: this.fetchChainCodes,
committing,
selectedRows: [],
intl,
};

const menu = record => (
<Menu>
<Menu.Item>
Expand Down Expand Up @@ -359,7 +338,7 @@ class ChainCode extends PureComponent {
id: 'app.chainCode.table.header.packageID',
defaultMessage: 'PackageID',
}),
dataIndex: 'package_id',
dataIndex: 'packageID',
ellipsis: true,
},
{
Expand Down Expand Up @@ -391,12 +370,7 @@ class ChainCode extends PureComponent {
// eslint-disable-next-line no-unused-vars
render: (text, record) => (
<Fragment>
<a
onClick={() => {
this.handleInstallModalVisible(true);
this.setOperatedRow(record);
}}
>
<a>
{intl.formatMessage({
id: 'app.chainCode.table.operate.install',
defaultMessage: 'Install',
Expand All @@ -410,7 +384,7 @@ class ChainCode extends PureComponent {
})}
</a>
<Divider type="vertical" />
<a>
<a onClick={() => this.handleCommitModalVisible(true)}>
{intl.formatMessage({
id: 'app.chainCode.table.operate.commit',
defaultMessage: 'Commit',
Expand All @@ -425,14 +399,7 @@ class ChainCode extends PureComponent {
// TODO: remove dummy data after API is connected
const dummyList = [
{
package_id: 'cc1v1:cc7bb5f50a53c207f68d37e9423c32f968083282e5ffac00d41ffc5768dc1873',
description: 'chaincode demo',
version: 'v1',
language: 'golang',
approve: false,
},
{
package_id: 'cc2v1:cc7bb5f50a53c207f68d37e9423c32f968083282e5ffac00d41ffc5768dc1873',
packageID: 'cc1v1:cc7bb5f50a53c207f68d37e9423c32f968083282e5ffac00d41ffc5768dc1873',
description: 'chaincode demo',
version: 'v1',
language: 'golang',
Expand Down Expand Up @@ -479,9 +446,9 @@ class ChainCode extends PureComponent {
/>
</div>
</Card>
<InstallForm {...installFormProps} />
<ApproveForm {...approveFormProps} />
<UploadChainCode {...formProps} />
<ApproveForm {...approveFormProps} />
<CommitForm {...commitFormProps} />
</PageHeaderWrapper>
);
}
Expand Down
Loading