Skip to content

Commit

Permalink
add Filter by Hash functionality to Ticket History view
Browse files Browse the repository at this point in the history
  • Loading branch information
bgptr committed Dec 13, 2021
1 parent 362aae9 commit 39f3d56
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 4 deletions.
Expand Up @@ -92,6 +92,7 @@ const selectTicketTypeFromFilter = (filter) => {

const MyTickets = ({ toggleIsLegacy }) => {
const {
intl,
tickets,
tsDate,
noMoreTickets,
Expand All @@ -113,6 +114,7 @@ const MyTickets = ({ toggleIsLegacy }) => {
const [selectedSortOrderKey, setSortOrderKey] = useState(
ticketsFilter.listDirection
);
const [searchText, setSearchText] = useState(ticketsFilter.search);

const onChangeFilter = (filter) => {
const newFilter = { ...ticketsFilter, ...filter };
Expand All @@ -129,11 +131,18 @@ const MyTickets = ({ toggleIsLegacy }) => {
setSortOrderKey(type.value);
};

const onChangeSearchText = (searchText) => {
onChangeFilter({ search: searchText });
setSearchText(searchText);
};
const loadMoreThreshold = 90 + Math.max(0, window.innerHeight - 765);

return (
<TicketListPage
{...{
intl,
searchText,
onChangeSearchText,
selectedTicketTypeKey,
selectedSortOrderKey,
loadMoreThreshold,
Expand Down
Expand Up @@ -10,11 +10,10 @@
}

.ticketsButtons {
text-align: right;
margin-right: 20px;
margin-left: auto;
display: flex;
align-items: center;
line-height: 1.2rem;
padding-top: 0.5rem;
}

.subtitle {
Expand Down
26 changes: 25 additions & 1 deletion app/components/views/TicketsPage/MyTicketsTab/Page.jsx
@@ -1,4 +1,4 @@
import { FormattedMessage as T } from "react-intl";
import { FormattedMessage as T, defineMessages } from "react-intl";
import { Tooltip, Paginator } from "pi-ui";
import InfiniteScroll from "react-infinite-scroller";
import {
Expand All @@ -9,8 +9,19 @@ import {
import { TxHistory, Subtitle } from "shared";
import { EyeFilterMenu, QRModalButton } from "buttons";
import styles from "./MyTicketsTab.module.css";
import { TextInput } from "inputs";

const messages = defineMessages({
filterByHashPlaceholder: {
id: "txhistory.filterByHashPlaceholder",
defaultMessage: "Filter by Hash"
}
});

const subtitleMenu = ({
intl,
searchText,
onChangeSearchText,
sortTypes,
ticketTypes,
selectedSortOrderKey,
Expand All @@ -24,6 +35,13 @@ const subtitleMenu = ({
prepareQRs
}) => (
<div className={styles.ticketsButtons}>
<TextInput
id="filterByHashInput"
type="text"
placeholder={intl.formatMessage(messages.filterByHashPlaceholder)}
value={searchText}
onChange={(e) => onChangeSearchText(e.target.value)}
/>
<Tooltip
contentClassName={styles.sortByTooltip}
content={<T id="tickets.sortby.tooltip" m="Sort By" />}>
Expand Down Expand Up @@ -84,6 +102,9 @@ const subtitleMenu = ({
);

const TicketListPage = ({
intl,
searchText,
onChangeSearchText,
tickets,
noMoreTickets,
getTickets,
Expand Down Expand Up @@ -112,6 +133,9 @@ const TicketListPage = ({
title={<T id="mytickets.subtitle" m="My Tickets" />}
className={styles.subtitle}
children={subtitleMenu({
intl,
searchText,
onChangeSearchText,
sortTypes,
ticketTypes,
selectedSortOrderKey,
Expand Down
3 changes: 3 additions & 0 deletions app/components/views/TicketsPage/MyTicketsTab/hooks.js
Expand Up @@ -6,8 +6,10 @@ import * as ta from "actions/TransactionActions";
import { UNMINED, IMMATURE, LIVE } from "constants";
import { isEqual } from "lodash";
import QRCode from "qrcode";
import { useIntl } from "react-intl";

export const useTicketsList = () => {
const intl = useIntl();
const dispatch = useDispatch();

// selectors
Expand Down Expand Up @@ -76,6 +78,7 @@ export const useTicketsList = () => {
}, [tickets, qrHashes]);

return {
intl,
tickets,
tsDate,
noMoreTickets,
Expand Down
5 changes: 5 additions & 0 deletions app/selectors.js
Expand Up @@ -865,6 +865,11 @@ export const filteredStakeTxs = createSelector(
(transactions, filter) => {
const filteredTxs = Object.keys(transactions)
.map((hash) => transactions[hash])
.filter((v) =>
filter.search
? v.txHash.toLowerCase().includes(filter.search.toLowerCase())
: true
)
.filter((v) => (filter.status ? filter.status === v.status : true));

return filteredTxs;
Expand Down

0 comments on commit 39f3d56

Please sign in to comment.