Skip to content

Commit

Permalink
Merge pull request #3408 from cardano-foundation/fix/MET-2035-search-…
Browse files Browse the repository at this point in the history
…suggestion-list-is-not-working

fix: MET-2035 fix search suggestion
  • Loading branch information
Sotatek-TaiTruong committed May 4, 2024
2 parents 00a60ee + 97193e6 commit 4fa5867
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ const DelegationDetailInfo: React.FC<IDelegationDetailInfo> = ({ data, loading,
) : (
<TruncateSubTitleContainer>
<DynamicEllipsisText
value={data?.poolName || poolId}
value={data?.poolName || data?.poolName || poolId}
sxFirstPart={{ maxWidth: width > 600 ? "calc(100% - 130px)" : "calc(100% - 50px)" }}
postfix={5}
isNoLimitPixel={true}
Expand Down
6 changes: 0 additions & 6 deletions src/components/DelegationPool/DelegationList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ const DelegationLists: React.FC = () => {
history.replace({ search: stringify({ ...pageInfo, page: 1, sort: undefined }) });
};

useEffect(() => {
if (fetchData.initialized) {
history.replace({ search: stringify({ ...pageInfo }), state: undefined });
}
}, [fetchData.initialized, history]);

const columns: Column<Delegators>[] = [
{
title: <div data-testid="poolList.poolNameTitle">{t("glossary.pool")}</div>,
Expand Down
59 changes: 45 additions & 14 deletions src/components/commons/Layout/Header/HeaderSearch/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { HeaderSearchIconComponent } from "src/commons/resources";
import { details, routers } from "src/commons/routers";
import { API } from "src/commons/utils/api";
import defaultAxios from "src/commons/utils/axios";
import { API_ADA_HANDLE_API } from "src/commons/utils/constants";
import { API_ADA_HANDLE_API, FF_GLOBAL_IS_CONWAY_ERA } from "src/commons/utils/constants";
import { getShortHash } from "src/commons/utils/helper";
import CustomIcon from "src/components/commons/CustomIcon";

Expand Down Expand Up @@ -52,7 +52,8 @@ const URL_FETCH_DETAIL = {
txs: (trx: string) => `${API.TRANSACTION.DETAIL}/${trx}`,
addresses: (address: string) => `${API.ADDRESS.DETAIL}/${address}`,
stake: (stake: string) => `${API.STAKE.DETAIL}/${stake}`,
policies: (policy: string) => `${API.SCRIPTS_SEARCH}/${policy}`
policies: (policy: string) => `${API.SCRIPTS_SEARCH}/${policy}`,
dreps: (dreps: string) => `${API.DREP_OVERVIEW.replace(":drepId", dreps)}`
};

interface Props extends RouteComponentProps {
Expand All @@ -65,6 +66,7 @@ interface IResponseSearchAll {
epoch?: number;
block?: string;
tx?: string;
drep?: string;
token?: {
name: string;
fingerprint: string;
Expand Down Expand Up @@ -173,6 +175,12 @@ const HeaderSearch: React.FC<Props> = ({ home, callback, setShowErrorMobile, his
label: t("filter.scriptHash"),
paths: [routers.SMART_CONTRACT, routers.NATIVE_SCRIPT_DETAIL, routers.NATIVE_SCRIPTS_AND_SC],
detail: details.policyDetail
},
{
value: "dreps",
label: t("filter.dreps"),
paths: [routers.DREPS, routers.DREP_DETAILS],
detail: details.drep
}
];

Expand Down Expand Up @@ -202,7 +210,13 @@ const HeaderSearch: React.FC<Props> = ({ home, callback, setShowErrorMobile, his
setADAHanldeOption(isEmpty(adaHanlde) ? undefined : adaHanlde);
setDataSearchAll(res?.data);
const keyDetail = getKeyIfOnlyOneNonNullResult(res?.data);
if (!res?.data?.validPoolName && !res?.data?.validTokenName && keyDetail === "" && isEmpty(adaHanlde)) {
if (
!res?.data?.validPoolName &&
!res?.data?.validTokenName &&
keyDetail === "" &&
!(Object.keys(filteredData).length > 0) &&
isEmpty(adaHanlde)
) {
throw new Error();
}
if (adaHanlde && adaHanlde !== null) {
Expand Down Expand Up @@ -261,7 +275,7 @@ const HeaderSearch: React.FC<Props> = ({ home, callback, setShowErrorMobile, his

setShowOption(true);
setLoading(false);
} catch {
} catch (error) {
showResultNotFound();
setLoading(false);
}
Expand Down Expand Up @@ -289,6 +303,9 @@ const HeaderSearch: React.FC<Props> = ({ home, callback, setShowErrorMobile, his
case "tx":
history.push(details.transaction(data?.tx as string));
return;
case "drep":
history.push(details.drep(data?.drep as string));
return;
case "script":
if (data?.script?.nativeScript) {
history.push(details.nativeScriptDetail(data?.script?.scriptHash as string));
Expand Down Expand Up @@ -335,8 +352,9 @@ const HeaderSearch: React.FC<Props> = ({ home, callback, setShowErrorMobile, his
search.query = query.trim();
const url =
filter === "tokens"
? `${API.TOKEN.LIST}?page=0&size=${RESULT_SIZE}&${stringify(search)}`
: `${API.DELEGATION.POOL_LIST}?${stringify(search)}`;
? `${API.TOKEN.LIST}?page=0&size=${RESULT_SIZE}&${stringify({ query: query })}`
: `${API.DELEGATION.POOL_LIST}?${stringify({ query: query })}&page=0&size=${RESULT_SIZE}`;

const res = await defaultAxios.get(url);
setTotalResult(res?.data && res.data?.totalItems ? res.data?.totalItems : 0);

Expand All @@ -352,9 +370,9 @@ const HeaderSearch: React.FC<Props> = ({ home, callback, setShowErrorMobile, his
callback?.();
} else {
if (res.data?.totalItems === 1) {
history.push(details.delegation(search.query));
history.push(details.delegation(res.data.data[0].poolId || ""));
} else {
history.push(`${routers.DELEGATION_POOLS}?${stringify(search)}`, {
history.push(`${routers.DELEGATION_POOLS}?${stringify({ page: 1, size: 50, query: query })}`, {
tickerNameSearch: (search.query || "").toLocaleLowerCase()
});
}
Expand All @@ -365,7 +383,7 @@ const HeaderSearch: React.FC<Props> = ({ home, callback, setShowErrorMobile, his
setShowOption(true);
}
setLoading(false);
} catch {
} catch (error) {
showResultNotFound();
setLoading(false);
}
Expand Down Expand Up @@ -559,6 +577,12 @@ const HeaderSearch: React.FC<Props> = ({ home, callback, setShowErrorMobile, his
callback?.();
return;
}
if (option?.value === "dreps") {
history.push(details.drep(search.trim()));
handleSetSearchValueDefault();
callback?.();
return;
}

if (search) {
const params = { search, filter: filterParams || (filter !== "all" ? filter : undefined) };
Expand Down Expand Up @@ -620,11 +644,18 @@ const HeaderSearch: React.FC<Props> = ({ home, callback, setShowErrorMobile, his
}
}}
>
{options.map(({ value, label }) => (
<SelectOption data-testid="filter-options" key={value} value={value} home={home ? 1 : 0}>
{label}
</SelectOption>
))}
{options
.filter((i) => {
if (!FF_GLOBAL_IS_CONWAY_ERA) {
return i.value !== "dreps";
}
return i;
})
.map(({ value, label }) => (
<SelectOption data-testid="filter-options" key={value} value={value} home={home ? 1 : 0}>
{label}
</SelectOption>
))}
</StyledSelect>
<StyledInput
data-testid="search-bar"
Expand Down
1 change: 1 addition & 0 deletions src/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"filter.blocks": "Blocks",
"filter.transactions": "Transactions",
"filter.tokens": "Tokens",
"filter.dreps": "Dreps",
"filter.address": "Addresses",
"filter.pools": "Pools",
"filter.ADAHanlde": "ADA Handle",
Expand Down
1 change: 1 addition & 0 deletions src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type FilterParams =
| "delegations/pool-detail-header"
| "lifecycle"
| "policies"
| "dreps"
| "delegations/pool-list?search="
| "ADAHanlde";
interface SearchParams {
Expand Down

0 comments on commit 4fa5867

Please sign in to comment.