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

fix: Search filters fix #2087

Merged
merged 1 commit into from
Apr 18, 2024
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
11 changes: 11 additions & 0 deletions src/contexts/Filters/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,14 @@ export const FiltersProvider = ({ children }: { children: ReactNode }) => {
if (o === 'default') {
newOrders = [...orders].filter((order) => order.key !== g);
} else if (orders.length) {
// Attempt to replace the order record if it exists.
newOrders = [...orders].map((order) =>
order.key !== g ? order : { ...order, order: o }
);
// If order for this key does not exist, add it.
if (newOrders.find(({ key }) => key === g) === undefined) {
newOrders.push({ key: g, order: o });
}
} else {
newOrders = [{ key: g, order: o }];
}
Expand All @@ -151,9 +156,15 @@ export const FiltersProvider = ({ children }: { children: ReactNode }) => {
const setSearchTerm = (g: string, t: string) => {
let newSearchTerms = [];
if (orders.length) {
// Attempt to replace the search term if it exists.
newSearchTerms = [...searchTerms].map((term) =>
term.key !== g ? term : { ...term, searchTerm: t }
);

// If search term for this key does not exist, add it.
if (newSearchTerms.find(({ key }) => key === g) === undefined) {
newSearchTerms.push({ key: g, searchTerm: t });
}
} else {
newSearchTerms = [{ key: g, searchTerm: t }];
}
Expand Down
1 change: 1 addition & 0 deletions src/library/PoolList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export const PoolList = ({

const handleSearchChange = (e: FormEvent<HTMLInputElement>) => {
const newValue = e.currentTarget.value;

let filteredPools: BondedPool[] = Object.assign(poolsDefault);
filteredPools = applyFilter(includes, excludes, filteredPools);
filteredPools = poolSearchFilter(filteredPools, newValue);
Expand Down
2 changes: 1 addition & 1 deletion src/library/ValidatorList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ export const ValidatorListInner = ({
index === self.findIndex((i) => i.address === value.address)
);

setValidators(filteredValidators);
setPage(1);
setValidators(filteredValidators);
setIsSearching(e.currentTarget.value !== '');
setSearchTerm('validators', newValue);
};
Expand Down
Loading