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

Add sorting on mempool page #129

Merged
merged 1 commit into from
Nov 11, 2021
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import React from 'react';
import queryString from 'query-string';
import { FormattedMessage } from 'react-intl';
import { RouteComponentProps, withRouter } from 'react-router-dom';
import { Link, RouteComponentProps, withRouter } from 'react-router-dom';

import {
SortDirectionAscIcon,
SortDirectionDescIcon,
SortDirectionIcon,
} from '../../common/icons/common.icons';

import './unconfirmed-transactions-table-header.scss';

Expand All @@ -15,7 +22,16 @@ class UnconfirmedTransactionsTableHeader extends React.Component<
</div>

<div className="bi-blocks-table__cell bi-table__cell">
<FormattedMessage id="components.unconfirmed-transactions.creation-timestamp" />
<Link
className={this.getSortDirectionClassName('creationtimestamp')}
to={`/mempool?${this.getSortLink('creationtimestamp')}`}
>
<FormattedMessage id="components.unconfirmed-transactions.creation-timestamp" />

<SortDirectionIcon className="bi-blocks-table-header__sort-icon" />
<SortDirectionAscIcon className="bi-blocks-table-header__sort-icon bi-blocks-table-header__sort-icon--asc" />
<SortDirectionDescIcon className="bi-blocks-table-header__sort-icon bi-blocks-table-header__sort-icon--desc" />
</Link>
</div>

<div className="bi-blocks-table__cell bi-table__cell">
Expand All @@ -27,11 +43,63 @@ class UnconfirmedTransactionsTableHeader extends React.Component<
</div>

<div className="bi-blocks-table__cell bi-table__cell">
<FormattedMessage id="common.block.size" />
<Link
className={this.getSortDirectionClassName('size')}
to={`/mempool?${this.getSortLink('size')}`}
>
<FormattedMessage id="common.block.size" />

<SortDirectionIcon className="bi-blocks-table-header__sort-icon" />
<SortDirectionAscIcon className="bi-blocks-table-header__sort-icon bi-blocks-table-header__sort-icon--asc" />
<SortDirectionDescIcon className="bi-blocks-table-header__sort-icon bi-blocks-table-header__sort-icon--desc" />
</Link>
</div>
</div>
);
}

private getSortDirectionClassName(sortedColumn: string): string {
const { sortBy, sortDirection } = queryString.parse(
this.props.history.location.search
);
const classNames = [
'bi-blocks-table-header__sort',
'u-word-wrap u-word-wrap--ellipsis',
];

if (sortBy === sortedColumn && sortDirection) {
classNames.push(`bi-blocks-table-header__sort--${sortDirection}`);
}

return classNames.join(' ');
}

private getSortLink(sortedColumn: string): string {
const params = queryString.parse(this.props.history.location.search);

const { sortBy, sortDirection } = params;

let newSortDirection: string | null = 'asc';
if (sortBy === sortedColumn && sortDirection === 'desc') {
return queryString.stringify({
...params,
offset: undefined,
sortBy: undefined,
sortDirection: undefined,
});
}

if (sortBy === sortedColumn && sortDirection !== 'desc') {
newSortDirection = 'desc';
}

return queryString.stringify({
...params,
offset: undefined,
sortBy: sortedColumn,
sortDirection: newSortDirection,
});
}
}

export const UnconfirmedTransactionsTableHeaderComponent = withRouter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class UnconfirmedTransactions extends React.PureComponent<IDataProps> {
sortDirection = ['asc', 'desc'].includes(sortDirection)
? sortDirection
: null;
sortBy = ['creationTimestamp', 'size'].includes(sortBy) ? sortBy : null;
sortBy = ['creationtimestamp', 'size'].includes(sortBy) ? sortBy : null;

return {
limit,
Expand Down