Skip to content

Commit

Permalink
sort peers subpage
Browse files Browse the repository at this point in the history
  • Loading branch information
mjadach-iv committed Dec 2, 2024
1 parent aa6036e commit 7fe7f2a
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 18 deletions.
7 changes: 5 additions & 2 deletions src/future-hopr-lib-components/PeerInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import { generateBase64Jazz } from '../../utils/functions';
import CopyIcon from '@mui/icons-material/ContentCopy';
import LaunchIcon from '@mui/icons-material/Launch';


interface Props {
peerId?: string;
nodeAddress?: string;
shortenPeerId?: boolean;
}

const Container = styled.div`
Expand All @@ -32,8 +34,9 @@ const PeersInfo: React.FC<Props> = (props) => {

const getAliasByPeerId = (peerId: string): string => {
const shortPeerId = peerId && `${peerId.substring(0, 6)}...${peerId.substring(peerId.length - 8, peerId.length)}`;
if (aliases && peerId && peerIdToAliasLink[peerId]) return `${peerIdToAliasLink[peerId]} (${shortPeerId})`;
return shortPeerId;
const displayPeerId = props.shortenPeerId ? shortPeerId : peerId;
if (aliases && peerId && peerIdToAliasLink[peerId]) return `${peerIdToAliasLink[peerId]} (${displayPeerId})`;
return displayPeerId;
};

const noCopyPaste = !(
Expand Down
8 changes: 6 additions & 2 deletions src/future-hopr-lib-components/Table/table-pro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ const STextField = styled(TextField)`
interface Props {
data: {
[key: string]: string | number | JSX.Element;
id: string;
id: string | number;
actions: JSX.Element;
}[];
id?: string;
Expand Down Expand Up @@ -325,7 +325,8 @@ export default function CustomPaginationActionsTable(props: Props) {
<CustomTableRow
row={row}
header={props.header}
key={row.id}
id={`${props.id}_row_${row.id}`}
key={`${props.id}_row_${row.id}`}
onRowClick={props.onRowClick}
/>
))}
Expand All @@ -352,10 +353,12 @@ export default function CustomPaginationActionsTable(props: Props) {
}

const CustomTableRow = ({
id,
row,
header,
onRowClick,
}: {
id: string;
row: Props['data'][0];
header: Props['header'];
onRowClick?: Function;
Expand All @@ -376,6 +379,7 @@ const CustomTableRow = ({
return (
<TableRow
key={row.id}
id={id}
onClick={() => {
onRowClick && onRowClick(row);
}}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/node/channelsIncoming.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,12 @@ function ChannelsPage() {

return {
id: (index + 1).toString(),
number: parseInt(id),
key: id,
node: (
<PeersInfo
peerId={peerId}
nodeAddress={peerAddress}
shortenPeerId
/>
),
peerAddress: getAliasByPeerAddress(peerAddress as string),
Expand Down
4 changes: 2 additions & 2 deletions src/pages/node/channelsOutgoing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,13 @@ function ChannelsPage() {
const peerId = getPeerIdFromPeerAddress(peerAddress as string);

return {
id: index.toString(),
id: (index+1).toString(),
key: id,
number: parseInt(id),
node: (
<PeersInfo
peerId={peerId}
nodeAddress={peerAddress}
shortenPeerId
/>
),
peerAddress: getAliasByPeerAddress(peerAddress as string),
Expand Down
39 changes: 28 additions & 11 deletions src/pages/node/peers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function PeersPage() {

const header = [
{
key: 'number',
key: 'id',
name: '#',
},
{
Expand Down Expand Up @@ -117,20 +117,37 @@ function PeersPage() {
},
];

const noCopyPaste = !(
window.location.protocol === 'https:' ||
window.location.hostname === 'localhost' ||
window.location.hostname === '127.0.0.1'
);
const peersWithAliases = (peers?.connected || []).filter(peer => aliases && peer.peerId && peerIdToAliasLink[peer.peerId]) ;
const peersWithAliasesSorted = peersWithAliases.sort((a, b) => {
if (getAliasByPeerId(b.peerId).toLowerCase() > getAliasByPeerId(a.peerId).toLowerCase()) {
return -1;
}
if (getAliasByPeerId(b.peerId).toLowerCase() < getAliasByPeerId(a.peerId).toLowerCase()) {
return 1;
}
return 0
});
const peersWithoutAliases = (peers?.connected || []).filter(peer => aliases && peer.peerId && !peerIdToAliasLink[peer.peerId]) ;
const peersWithoutAliasesSorted = peersWithoutAliases.sort((a, b) => {
if (b.peerId > a.peerId) {
return -1;
}
if (b.peerId < a.peerId) {
return 1;
}
return 0
});

const peersSorted = [...peersWithAliasesSorted, ...peersWithoutAliasesSorted]

const parsedTableData = Object.entries(peers?.connected ?? {}).map(([id, peer]) => {
const parsedTableData = peersSorted.map((peer, index)=>{
return {
id: id,
number: parseInt(id),
id: index+1,
node: (
<PeersInfo
peerId={peer.peerId}
nodeAddress={peer.peerAddress}
shortenPeerId
/>
),
peerId: getAliasByPeerId(peer.peerId),
Expand Down Expand Up @@ -163,8 +180,8 @@ function PeersPage() {
<SendMessageModal peerId={peer.peerId} />
</>
),
};
});
}
})

return (
<Section
Expand Down

0 comments on commit 7fe7f2a

Please sign in to comment.