Skip to content

Commit e5945e8

Browse files
Components and styles refactor.
Change text on search bar.
1 parent b88a0a0 commit e5945e8

File tree

27 files changed

+137
-246
lines changed

27 files changed

+137
-246
lines changed

examples/explorer/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ A simple Cardano Explorer using Reactjs, React-bootstrap and Relay to use with J
77
- Transaction search by Hash.
88
- Block search by hash.
99
- Block search by chain length.
10+
- Epoch search by Epoch number.
1011
- Block table showing all blocks ordered from more recents to older.
1112

1213
# What does this explorer not have (and should have)?
1314

14-
- Search by Epoch number.
1515
- Logging tool.
1616
- Automated tests.
1717
- Complete responsiveness.

examples/explorer/src/App.scss

Lines changed: 0 additions & 5 deletions
This file was deleted.

examples/explorer/src/components/Addresses/AddressInfo/AddressInfo.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const AddressInfo = ({ address }) => {
1414
}
1515

1616
return (
17-
<div className="addressInfo">
17+
<div className="entityInfoTable">
1818
<h2>Address</h2>
1919
<div className="keyValueTable">
2020
<Table striped bordered hover responsive>
Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1 @@
11
@import '../../../generalStyling.scss';
2-
3-
.addressInfo {
4-
display: flex;
5-
flex-direction: column;
6-
align-items: center;
7-
width: 100%;
8-
}

examples/explorer/src/components/Addresses/FullAddressInfo/FullAddressInfo.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import './fullAddressInfo.scss';
1111
const FullAddressInfo = ({ address }) => {
1212
const { transactions } = address;
1313
return (
14-
<div className="fullAddressInfo">
14+
<div className="entityInfoContainer">
1515
<AddressInfo {...{ address }} />
1616
<TransactionTable {...{ transactions, showBlocks: true }} />
1717
</div>
Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1 @@
11
@import '../../../generalStyling.scss';
2-
3-
.fullAddressInfo {
4-
display: flex;
5-
overflow: hidden;
6-
flex-direction: column;
7-
justify-content: center;
8-
align-items: center;
9-
box-shadow: 0px 0px 6px 1px grey;
10-
padding: 1%;
11-
width: 80%;
12-
}

examples/explorer/src/components/Blocks/BlockInfo/BlockInfo.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import BlockLink from '../../Commons/BlockLink/BlockLink';
99
import EpochLink from '../../Commons/EpochLink/EpochLink';
1010

1111
const BlockInfo = ({ block }) => (
12-
<div className="blockInfo">
12+
<div className="entityInfoTable">
1313
<h2>Block</h2>
1414
<div className="keyValueTable">
1515
<Table striped bordered hover responsive>
Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1 @@
11
@import '../../../generalStyling.scss';
2-
3-
.blockInfo {
4-
display: flex;
5-
flex-direction: column;
6-
align-items: center;
7-
width: 100%;
8-
}

examples/explorer/src/components/Blocks/BlockPagedTable/BlockPagedTable.jsx

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,21 @@
11
import React, { useState } from 'react';
22
import Pagination from 'react-bootstrap/Pagination';
33

4+
import graphql from 'babel-plugin-relay/macro';
5+
import { createFragmentContainer } from 'react-relay';
6+
47
import BlockTable from '../BlockTable/BlockTable';
58
import { TABLE_PAGE_SIZE } from '../../../helpers/constants';
69
import { blocksFromBlockConnection } from '../../../helpers/blockHelper';
710

8-
const BlockPagedTable = ({ data, relay }) => {
9-
const [start, setStart] = useState(1);
10-
const blocks = blocksFromBlockConnection(data.blocks);
11-
const { pageInfo } = data.blocks;
12-
13-
const handlePageChange = (vars, callback) => {
14-
relay.refetch(
15-
{
16-
first: vars.first || null,
17-
last: vars.last || null,
18-
after: vars.after || null,
19-
before: vars.before || null
20-
},
21-
error => {
22-
if (error) {
23-
console.error(error); // eslint-disable-line no-console
24-
}
25-
callback();
26-
}
27-
);
28-
};
11+
/**
12+
* This component receives a BlockConnection and a function to refetch data
13+
* and renders a paged table.
14+
*/
15+
const BlockPagedTable = ({ blockConnection, handlePageChange }) => {
16+
const [start, setStart] = useState();
17+
const { pageInfo } = blockConnection;
18+
const blocks = blocksFromBlockConnection(blockConnection);
2919

3020
const openPreviousPage = () => {
3121
handlePageChange({ before: pageInfo.startCursor, last: TABLE_PAGE_SIZE }, () =>
@@ -65,4 +55,22 @@ const BlockPagedTable = ({ data, relay }) => {
6555
);
6656
};
6757

68-
export default BlockPagedTable;
58+
export default createFragmentContainer(BlockPagedTable, {
59+
blockConnection: graphql`
60+
fragment BlockPagedTable_blockConnection on BlockConnection {
61+
edges {
62+
cursor
63+
node {
64+
...BlockTable_blocks
65+
}
66+
}
67+
pageInfo {
68+
hasNextPage
69+
hasPreviousPage
70+
endCursor
71+
startCursor
72+
}
73+
totalCount
74+
}
75+
`
76+
});

examples/explorer/src/components/Blocks/EpochBlockTable/EpochBlockTable.jsx

Lines changed: 6 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
1-
import React, { useState } from 'react';
2-
import Pagination from 'react-bootstrap/Pagination';
1+
import React from 'react';
32

43
import graphql from 'babel-plugin-relay/macro';
54
import { createRefetchContainer } from 'react-relay';
65

7-
import BlockTable from '../BlockTable/BlockTable';
8-
import { TABLE_PAGE_SIZE } from '../../../helpers/constants';
9-
import { blocksFromBlockConnection } from '../../../helpers/blockHelper';
6+
import BlockPagedTable from '../BlockPagedTable/BlockPagedTable';
107

11-
// TODO: Think on some way of extract shared code between EpochBlockTable and BlockPagedTable
128
const EpochBlockTable = ({ epoch, relay }) => {
13-
const [start, setStart] = useState(1);
149
if (!epoch.blocks) {
1510
return null;
1611
}
17-
18-
const blocks = blocksFromBlockConnection(epoch.blocks);
19-
const { pageInfo } = epoch.blocks;
20-
12+
const blockConnection = epoch.blocks;
2113
const handlePageChange = (vars, callback) => {
2214
relay.refetch(
2315
{
@@ -36,40 +28,10 @@ const EpochBlockTable = ({ epoch, relay }) => {
3628
);
3729
};
3830

39-
const openPreviousPage = () => {
40-
handlePageChange({ before: pageInfo.startCursor, last: TABLE_PAGE_SIZE }, () =>
41-
setStart(start - TABLE_PAGE_SIZE)
42-
);
43-
};
44-
45-
const openNextPage = () => {
46-
handlePageChange({ after: pageInfo.endCursor, first: TABLE_PAGE_SIZE }, () =>
47-
setStart(start + TABLE_PAGE_SIZE)
48-
);
49-
};
50-
51-
const openLastPage = () => {
52-
handlePageChange({ last: TABLE_PAGE_SIZE }, () => setStart(start - TABLE_PAGE_SIZE));
53-
};
54-
55-
const openFirstPage = () => {
56-
handlePageChange({ first: TABLE_PAGE_SIZE }, () => setStart(0));
57-
};
58-
5931
return (
6032
<>
61-
<BlockTable {...{ blocks }} />
62-
<Pagination>
63-
<Pagination.Item onClick={openLastPage} disabled={!pageInfo.hasNextPage}>
64-
Last
65-
</Pagination.Item>
66-
<Pagination.Prev onClick={openNextPage} disabled={!pageInfo.hasNextPage} />
67-
<Pagination.Ellipsis disabled />
68-
<Pagination.Next onClick={openPreviousPage} disabled={!pageInfo.hasPreviousPage} />
69-
<Pagination.Item onClick={openFirstPage} disabled={!pageInfo.hasPreviousPage}>
70-
First
71-
</Pagination.Item>
72-
</Pagination>
33+
<h2>Blocks</h2>
34+
<BlockPagedTable {...{ handlePageChange, blockConnection }} />
7335
</>
7436
);
7537
};
@@ -87,19 +49,7 @@ export default createRefetchContainer(
8749
) {
8850
id
8951
blocks(first: $first, last: $last, after: $after, before: $before) {
90-
edges {
91-
cursor
92-
node {
93-
...BlockTable_blocks
94-
}
95-
}
96-
pageInfo {
97-
hasNextPage
98-
hasPreviousPage
99-
endCursor
100-
startCursor
101-
}
102-
totalCount
52+
...BlockPagedTable_blockConnection
10353
}
10454
}
10555
`

0 commit comments

Comments
 (0)