Skip to content

Commit

Permalink
fix: clear params filter pools
Browse files Browse the repository at this point in the history
  • Loading branch information
DinhTran committed Apr 17, 2024
1 parent 5b73657 commit 56f13a1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
25 changes: 17 additions & 8 deletions src/components/DelegationPool/DelegationList/index.tsx
Expand Up @@ -37,10 +37,15 @@ const DelegationLists: React.FC = () => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [tickerNameSearch]);

Object.keys(pageInfo).forEach((key) => {
if (pageInfo[key] === "" || pageInfo[key] === undefined) {
delete pageInfo[key];
}
});

const fetchData = useFetchList<Delegators>(
API.DELEGATION.POOL_LIST,
{
search,
isShowRetired: isShowRetired,
...pageInfo
},
Expand All @@ -50,6 +55,10 @@ const DelegationLists: React.FC = () => {

const fromPath = history.location.pathname as SpecialPath;

const handleBlankSort = () => {
history.replace({ search: stringify({ ...pageInfo, page: 1, sort: undefined }) });
};

useEffect(() => {
if (fetchData.initialized) {
history.replace({ search: stringify({ ...pageInfo }), state: undefined });
Expand Down Expand Up @@ -99,7 +108,7 @@ const DelegationLists: React.FC = () => {
minWidth: "120px",
render: (r) => <Box component={"span"}>{r.poolSize != null ? formatADAFull(r.poolSize) : t("common.N/A")}</Box>,
sort: ({ columnKey, sortValue }) => {
sortValue ? setSort(`${columnKey},${sortValue}`) : setSort("");
sortValue ? setSort(`${columnKey},${sortValue}`) : handleBlankSort();
}
},
{
Expand All @@ -112,7 +121,7 @@ const DelegationLists: React.FC = () => {
minWidth: "120px",
render: (r) => <Box component={"span"}>{formatADAFull(r.pledge)}</Box>,
sort: ({ columnKey, sortValue }) => {
sortValue ? setSort(`${columnKey},${sortValue}`) : setSort("");
sortValue ? setSort(`${columnKey},${sortValue}`) : handleBlankSort();
}
},
{
Expand All @@ -128,7 +137,7 @@ const DelegationLists: React.FC = () => {
t("common.N/A")
),
sort: ({ columnKey, sortValue }) => {
sortValue ? setSort(`${columnKey},${sortValue}`) : setSort("");
sortValue ? setSort(`${columnKey},${sortValue}`) : handleBlankSort();
}
},
{
Expand All @@ -137,7 +146,7 @@ const DelegationLists: React.FC = () => {
minWidth: "120px",
render: (r) => <Box component={"span"}>{r.epochBlock || 0}</Box>,
sort: ({ columnKey, sortValue }) => {
sortValue ? setSort(`${columnKey},${sortValue}`) : setSort("");
sortValue ? setSort(`${columnKey},${sortValue}`) : handleBlankSort();
}
},
{
Expand All @@ -146,7 +155,7 @@ const DelegationLists: React.FC = () => {
key: "lifetimeBlock",
render: (r) => <Box component={"span"}>{r.lifetimeBlock || 0}</Box>,
sort: ({ columnKey, sortValue }) => {
sortValue ? setSort(`${columnKey},${sortValue}`) : setSort("");
sortValue ? setSort(`${columnKey},${sortValue}`) : handleBlankSort();
}
},
{
Expand All @@ -162,7 +171,7 @@ const DelegationLists: React.FC = () => {
t("common.N/A")
),
sort: ({ columnKey, sortValue }) => {
sortValue ? setSort(`${columnKey},${sortValue}`) : setSort("");
sortValue ? setSort(`${columnKey},${sortValue}`) : handleBlankSort();
}
},
{
Expand All @@ -172,7 +181,7 @@ const DelegationLists: React.FC = () => {
render: (r) =>
r.governanceParticipationRate != null ? `${formatPercent(r.governanceParticipationRate)}` : t("common.N/A"),
sort: ({ columnKey, sortValue }) => {
sortValue ? setSort(`${columnKey},${sortValue}`) : setSort("");
sortValue ? setSort(`${columnKey},${sortValue}`) : handleBlankSort();
}
}
];
Expand Down
6 changes: 4 additions & 2 deletions src/components/commons/CustomFilterMultiRange/index.tsx
Expand Up @@ -48,6 +48,8 @@ interface PoolResponse {
maxGovParticipationRate?: number;
}

const defaultParams = { page: 0, size: 50, sort: "" };

const CustomFilterMultiRange: React.FC = () => {
const theme = useTheme();
const { t } = useTranslation();
Expand Down Expand Up @@ -106,7 +108,7 @@ const CustomFilterMultiRange: React.FC = () => {
setExpanded(false);
setOpen(false);
setFilterParams({ ...initParams });
history.replace({ search: stringify({ page: 0, size: 50, sort: "" }), state: undefined });
history.replace({ search: stringify(defaultParams), state: undefined });
};

const handleFilter = () => {
Expand Down Expand Up @@ -477,7 +479,7 @@ const CustomFilterMultiRange: React.FC = () => {
onClick={() => {
handleFilter();
}}
disabled={!isDisableFilter}
disabled={JSON.stringify(defaultParams) === JSON.stringify(filterParams) && !isDisableFilter}
>
{t("common.applyFilters")}
</ApplyFilterButton>
Expand Down

0 comments on commit 56f13a1

Please sign in to comment.