Skip to content

Commit 074f9be

Browse files
committed
feat: update search on feeds table
1 parent ea4a10b commit 074f9be

File tree

4 files changed

+22
-10
lines changed

4 files changed

+22
-10
lines changed

apps/insights/src/components/PriceComponentsCard/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ export const ResolvedPriceComponentsCard = <
200200
}
201201
}
202202
},
203+
(items) => items,
203204
{
204205
defaultPageSize: 50,
205206
defaultSort: "name",

apps/insights/src/components/PriceFeeds/price-feeds-card.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,25 @@ import type {
1414
} from "@pythnetwork/component-library/Table";
1515
import { Table } from "@pythnetwork/component-library/Table";
1616
import { useLogger } from "@pythnetwork/component-library/useLogger";
17-
import { useQueryState, parseAsString } from "nuqs";
17+
import { matchSorter } from "match-sorter";
18+
import { parseAsString, useQueryState } from "nuqs";
1819
import type { ReactNode } from "react";
1920
import { Suspense, useCallback, useMemo } from "react";
20-
import { useFilter, useCollator } from "react-aria";
21+
import { useCollator } from "react-aria";
2122

22-
import styles from "./price-feeds-card.module.scss";
2323
import { useQueryParamFilterPagination } from "../../hooks/use-query-param-filter-pagination";
2424
import { Cluster } from "../../services/pyth";
2525
import { AssetClassBadge } from "../AssetClassBadge";
2626
import { FeedKey } from "../FeedKey";
2727
import {
28-
SKELETON_WIDTH,
29-
LivePrice,
3028
LiveConfidence,
29+
LivePrice,
3130
LiveValue,
31+
SKELETON_WIDTH,
3232
} from "../LivePrices";
3333
import { PriceFeedTag } from "../PriceFeedTag";
3434
import { PriceName } from "../PriceName";
35+
import styles from "./price-feeds-card.module.scss";
3536

3637
type Props = {
3738
id: string;
@@ -56,7 +57,6 @@ export const PriceFeedsCard = ({ priceFeeds, ...props }: Props) => (
5657
const ResolvedPriceFeedsCard = ({ priceFeeds, ...props }: Props) => {
5758
const logger = useLogger();
5859
const collator = useCollator();
59-
const filter = useFilter({ sensitivity: "base", usage: "search" });
6060
const [assetClass, setAssetClass] = useQueryState(
6161
"assetClass",
6262
parseAsString.withDefault(""),
@@ -83,14 +83,19 @@ const ResolvedPriceFeedsCard = ({ priceFeeds, ...props }: Props) => {
8383
mkPageLink,
8484
} = useQueryParamFilterPagination(
8585
feedsFilteredByAssetClass,
86-
(priceFeed, search) => filter.contains(priceFeed.displaySymbol, search),
86+
() => true,
8787
(a, b, { column, direction }) => {
8888
const field = column === "assetClass" ? "assetClass" : "displaySymbol";
8989
return (
9090
(direction === "descending" ? -1 : 1) *
9191
collator.compare(a[field], b[field])
9292
);
9393
},
94+
(items, search) => {
95+
return matchSorter(items, search, {
96+
keys: ["displaySymbol", "symbol", "description", "key"],
97+
});
98+
},
9499
{ defaultSort: "priceFeedName" },
95100
);
96101

apps/insights/src/components/Publishers/publishers-card.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ const ResolvedPublishersCard = ({
124124
}
125125
}
126126
},
127+
(items) => items,
127128
{ defaultSort: "ranking" },
128129
);
129130

apps/insights/src/hooks/use-query-param-filter-pagination.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ import { useCallback, useMemo } from "react";
1414

1515
export const useQueryParamFilterPagination = <T>(
1616
items: T[],
17-
predicate: (item: T, term: string) => boolean,
17+
predicate: (item: T, search: string) => boolean,
1818
doSort: (a: T, b: T, descriptor: SortDescriptor) => number,
19+
doMutate: (items: T[], search: string) => T[],
1920
options?: {
2021
defaultPageSize?: number | undefined;
2122
defaultSort?: string | undefined;
@@ -100,9 +101,13 @@ export const useQueryParamFilterPagination = <T>(
100101
[filteredItems, sortDescriptor, doSort],
101102
);
102103

104+
const mutatedItems = useMemo(() => {
105+
return doMutate(sortedItems, search);
106+
}, [doMutate, sortedItems, search]);
107+
103108
const paginatedItems = useMemo(
104-
() => sortedItems.slice((page - 1) * pageSize, page * pageSize),
105-
[page, pageSize, sortedItems],
109+
() => mutatedItems.slice((page - 1) * pageSize, page * pageSize),
110+
[page, pageSize, mutatedItems],
106111
);
107112

108113
const numPages = useMemo(

0 commit comments

Comments
 (0)