Skip to content

Commit c0de903

Browse files
saksham1203ArchanaArige
authored andcommitted
Display chaincode metadata in chaincodes tab
Signed-off-by: saksham1203 <[email protected]>
1 parent 58c49ad commit c0de903

File tree

11 files changed

+314
-57
lines changed

11 files changed

+314
-57
lines changed

client/src/components/Lists/Chaincodes.js

Lines changed: 59 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,49 @@ import { withStyles } from '@material-ui/core/styles';
77
import matchSorter from 'match-sorter';
88
import Dialog from '@material-ui/core/Dialog';
99
import ReactTable from '../Styled/Table';
10-
import ChaincodeForm from '../Forms/ChaincodeForm';
11-
import ChaincodeModal from '../View/ChaincodeModal';
1210
import { chaincodeListType } from '../types';
11+
import ChaincodeMetaDataView from '../View/ChaincodeMetaDataView';
1312

14-
const styles = theme => ({
15-
hash: {
16-
whiteSpace: 'nowrap',
17-
overflow: 'hidden',
18-
textOverflow: 'ellipsis',
19-
maxWidth: 60,
20-
letterSpacing: '2px'
21-
}
22-
});
13+
const styles = theme => {
14+
const { type } = theme.palette;
15+
const dark = type === 'dark';
16+
return {
17+
hash: {
18+
'&, & li, & ul': {
19+
overflow: 'visible !important'
20+
}
21+
},
22+
partialHash: {
23+
textAlign: 'center',
24+
position: 'relative !important',
25+
'&:hover $fullHash': {
26+
display: 'block',
27+
position: 'absolute !important',
28+
padding: '4px 4px',
29+
backgroundColor: dark ? '#5e558e' : '#000000',
30+
marginTop: -30,
31+
marginLeft: -215,
32+
borderRadius: 8,
33+
color: '#ffffff',
34+
opacity: dark ? 1 : undefined
35+
},
36+
'&:hover $lastFullHash': {
37+
display: 'block',
38+
position: 'absolute !important',
39+
padding: '4px 4px',
40+
backgroundColor: dark ? '#5e558e' : '#000000',
41+
marginTop: -30,
42+
marginLeft: -415,
43+
borderRadius: 8,
44+
color: '#ffffff',
45+
opacity: dark ? 1 : undefined
46+
}
47+
},
48+
fullHash: {
49+
display: 'none'
50+
}
51+
};
52+
};
2353

2454
export class Chaincodes extends Component {
2555
constructor(props) {
@@ -31,27 +61,31 @@ export class Chaincodes extends Component {
3161
};
3262
}
3363

34-
handleDialogOpen = () => {
64+
handleDialogOpen = async tid => {
65+
await this.props.getChaincodeMetaData(tid);
3566
this.setState({ dialogOpen: true });
3667
};
3768

3869
handleDialogClose = () => {
3970
this.setState({ dialogOpen: false });
4071
};
4172

42-
sourceDialogOpen = chaincode => {
43-
this.setState({ chaincode });
44-
this.setState({ sourceDialog: true });
45-
};
46-
47-
sourceDialogClose = () => {
48-
this.setState({ sourceDialog: false });
49-
};
50-
5173
reactTableSetup = classes => [
5274
{
5375
Header: 'Chaincode Name',
5476
accessor: 'chaincodename',
77+
className: classes.hash,
78+
Cell: row => (
79+
<span>
80+
<a
81+
data-command="transaction-partial-hash"
82+
className={classes.partialHash}
83+
onClick={() => this.handleDialogOpen(row.value)}
84+
href="#/chaincodes"
85+
>{row.value}
86+
</a>
87+
</span>
88+
),
5589
filterMethod: (filter, rows) =>
5690
matchSorter(
5791
rows,
@@ -112,13 +146,10 @@ export class Chaincodes extends Component {
112146
];
113147

114148
render() {
115-
const { chaincodeList, classes } = this.props;
149+
const { chaincodeList, chaincodeMetaData, classes } = this.props;
116150
const { dialogOpen, sourceDialog, chaincode } = this.state;
117151
return (
118152
<div>
119-
{/* <Button className="button" onClick={() => this.handleDialogOpen()}>
120-
Add Chaincode
121-
</Button> */}
122153
<ReactTable
123154
data={chaincodeList}
124155
columns={this.reactTableSetup(classes)}
@@ -133,18 +164,9 @@ export class Chaincodes extends Component {
133164
fullWidth
134165
maxWidth="md"
135166
>
136-
<ChaincodeForm />
137-
</Dialog>
138-
<Dialog
139-
open={sourceDialog}
140-
onClose={this.sourceDialogClose}
141-
fullWidth
142-
maxWidth="md"
143-
>
144-
<ChaincodeModal
145-
chaincode={chaincode}
146-
classes={classes}
147-
onClose={this.sourceDialogClose}
167+
<ChaincodeMetaDataView
168+
chaincodeMetaData={chaincodeMetaData}
169+
onClose={this.handleDialogClose}
148170
/>
149171
</Dialog>
150172
</div>

client/src/components/Lists/Chaincodes.spec.js

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import React from 'react';
77
import ReactTable from '../Styled/Table';
88
import { Chaincodes } from './Chaincodes';
9+
import ChaincodeMetaDataView from '../View/ChaincodeMetaDataView';//s
910

1011
jest.useFakeTimers();
1112

@@ -33,6 +34,7 @@ const setup = () => {
3334
txCount: '36',
3435
},
3536
getChaincodes: jest.fn(),
37+
getChaincodeMetaData: jest.fn()
3638
};
3739

3840
const chaincode = {
@@ -149,18 +151,38 @@ describe('Chaincodes', () => {
149151
expect(wrapper.find(ReactTable).find('TrGroupComponent').length).toBe(1);
150152
});
151153

152-
test('handleDialogOpen sets state to true', () => {
153-
const { wrapper } = setup();
154-
wrapper.instance().handleDialogOpen();
155-
expect(wrapper.state('dialogOpen')).toBe(true);
156-
});
157-
158-
test('handleDialogClose sets state to false', () => {
159-
const { wrapper } = setup();
160-
wrapper.setState({ dialogOpen: true });
161-
wrapper.instance().handleDialogClose();
162-
expect(wrapper.state('dialogOpen')).toBe(false);
163-
});
154+
test('Modal for ChaincodeMetaDataView View should not exist', () => {
155+
const { wrapper } = setup();
156+
expect(wrapper.find(ChaincodeMetaDataView).exists()).toBe(false);
157+
});
158+
159+
test('Modal for ChaincodeMetaDataView View should exist', () => {
160+
const { wrapper } = setup();
161+
wrapper.setState({ dialogOpen: true });
162+
wrapper.update();
163+
expect(wrapper.find(ChaincodeMetaDataView).exists()).toBe(true);
164+
});
165+
166+
test('handleDialogOpen should set dialogOpen to true', async () => {
167+
const { wrapper } = setup();
168+
await wrapper
169+
.instance()
170+
.handleDialogOpen(
171+
'basic'
172+
);
173+
expect(wrapper.state('dialogOpen')).toBe(true);
174+
wrapper.update();
175+
expect(wrapper.find(ChaincodeMetaDataView).exists()).toBe(true);
176+
});
177+
178+
test('handleDialogClose should set dialogOpen to false', () => {
179+
const { wrapper } = setup();
180+
wrapper.setState({ dialogOpen: true });
181+
wrapper.update();
182+
wrapper.instance().handleDialogClose();
183+
wrapper.update();
184+
expect(wrapper.state('dialogOpen')).toBe(false);
185+
});
164186

165187
test('sourceDialogOpen', () => {
166188
const { wrapper, chaincode } = setup();

client/src/components/Main.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
peerStatusType,
2828
blockRangeSearchType,
2929
blockListSearchType,
30+
chaincodeMetaDataType,
3031
transactionType,
3132
transactionByOrgType,
3233
transactionListType
@@ -50,6 +51,7 @@ const {
5051
peerListSelector,
5152
txnListSelector,
5253
blockSearchSelector,
54+
chaincodeMetaDataSelector,
5355
transactionSelector,
5456
transactionListSelector,
5557
blockRangeSearchSelector,
@@ -88,7 +90,8 @@ export const Main = props => {
8890
txnList,
8991
blockSearch,
9092
peerStatus,
91-
txnList,//s
93+
chaincodeMetaData,
94+
getChaincodeMetaData,
9295
transaction,
9396
transactionByOrg,
9497
transactionList,
@@ -126,7 +129,9 @@ export const Main = props => {
126129
transaction
127130
};
128131
const chaincodeViewProps = {
129-
chaincodeList
132+
chaincodeList,
133+
chaincodeMetaData,
134+
getChaincodeMetaData
130135
};
131136

132137
const channelsViewProps = {
@@ -253,6 +258,7 @@ Main.propTypes = {
253258
txnList: txnListType.isRequired,
254259
blockSearch: blockSearchType.isRequired,
255260
peerStatus: peerStatusType.isRequired,
261+
chaincodeMetaData: chaincodeMetaDataType.isRequired,
256262
transaction: transactionType.isRequired,
257263
transactionByOrg: transactionByOrgType.isRequired,
258264
transactionList: transactionListType.isRequired
@@ -269,6 +275,7 @@ const connectedComponent = connect(
269275
txnList: txnListSelector(state),
270276
blockSearch: blockSearchSelector(state),
271277
peerStatus: peerStatusSelector(state),
278+
chaincodeMetaData: chaincodeMetaDataSelector(state),
272279
transaction: transactionSelector(state),
273280
transactionByOrg: transactionByOrgSelector(state),
274281
transactionList: transactionListSelector(state),
@@ -290,7 +297,8 @@ const connectedComponent = connect(
290297
getBlockListSearch: tableOperations.blockListSearch,
291298
getBlockRangeSearch: tableOperations.blockRangeSearch,
292299
getTransactionListSearch: tableOperations.transactionListSearch,
293-
getTxnList: tableOperations.txnList
300+
getTxnList: tableOperations.txnList,
301+
getChaincodeMetaData: tableOperations.chaincodeMetaData,
294302
}
295303
)(Main);
296304
export default withStyles(styles)(connectedComponent);

0 commit comments

Comments
 (0)