-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Portals are missing from search results (#510)
- Loading branch information
1 parent
096498b
commit 0bdf34f
Showing
12 changed files
with
162 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { ColumnDef } from "@tanstack/react-table"; | ||
import { Portal } from "@verax-attestation-registry/verax-sdk"; | ||
import { t } from "i18next"; | ||
|
||
import { TdHandler } from "@/components/DataTable/components/TdHandler"; | ||
import { HelperIndicator } from "@/components/HelperIndicator"; | ||
import { Link } from "@/components/Link"; | ||
import { toPortalById } from "@/routes/constants"; | ||
import { cropString } from "@/utils/stringUtils"; | ||
|
||
import { links } from "../index"; | ||
|
||
export const columns = ({ chainId }: { chainId: number }): ColumnDef<Portal>[] => [ | ||
{ | ||
accessorKey: "name", | ||
header: () => ( | ||
<div className="flex items-center gap-2.5"> | ||
<HelperIndicator type="portal" /> | ||
{t("portal.list.columns.name")} | ||
</div> | ||
), | ||
cell: ({ row }) => { | ||
const name = row.getValue("name") as string; | ||
const id = row.original.id; | ||
|
||
return ( | ||
<Link to={toPortalById(id)} className="hover:underline" onClick={(e) => e.stopPropagation()}> | ||
{name} | ||
</Link> | ||
); | ||
}, | ||
}, | ||
{ | ||
accessorKey: "description", | ||
header: () => t("portal.list.columns.description"), | ||
cell: ({ row }) => { | ||
const description = row.getValue("description") as string; | ||
return <p className="max-w-[300px] overflow-hidden text-ellipsis">{description}</p>; | ||
}, | ||
}, | ||
{ | ||
accessorKey: "owner", | ||
header: () => <p>{t("portal.list.columns.owner")}</p>, | ||
cell: ({ row }) => { | ||
const address = row.original.ownerAddress; | ||
const id = row.original.id; | ||
|
||
return ( | ||
<TdHandler | ||
valueUrl={chainId ? `${links[chainId].address}/${address}` : "#"} | ||
value={cropString(address)} | ||
to={toPortalById(id)} | ||
/> | ||
); | ||
}, | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
explorer/src/pages/Search/components/SearchPortals/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { t } from "i18next"; | ||
import useSWR from "swr"; | ||
|
||
import { DataTable } from "@/components/DataTable"; | ||
import { columns } from "@/constants/columns/portal"; | ||
import { SWRKeys } from "@/interfaces/swr/enum"; | ||
import { useNetworkContext } from "@/providers/network-provider/context"; | ||
import { APP_ROUTES } from "@/routes/constants"; | ||
|
||
import { loadPortalList } from "./loadPortalList"; | ||
import { SearchComponentProps } from "../interfaces"; | ||
import { SearchWrapper } from "../SearchWrapper"; | ||
|
||
export const SearchPortals: React.FC<SearchComponentProps> = ({ getSearchData, parsedString, search }) => { | ||
const { | ||
sdk: { portal }, | ||
network: { chain }, | ||
} = useNetworkContext(); | ||
|
||
const { data } = useSWR( | ||
`${SWRKeys.GET_PORTAL_LIST}/${SWRKeys.SEARCH}/${search}/${chain.id}`, | ||
async () => loadPortalList(portal, parsedString), | ||
{ | ||
shouldRetryOnError: false, | ||
revalidateAll: false, | ||
onSuccess: (successData) => getSearchData(successData.length, true), | ||
onError: () => getSearchData(0, true), | ||
}, | ||
); | ||
|
||
if (!data || !data.length) return null; | ||
return ( | ||
<SearchWrapper title={t("portal.title")} items={data.length}> | ||
<DataTable columns={columns({ chainId: chain.id })} data={data} link={APP_ROUTES.PORTAL_BY_ID} /> | ||
</SearchWrapper> | ||
); | ||
}; |
26 changes: 26 additions & 0 deletions
26
explorer/src/pages/Search/components/SearchPortals/loadPortalList.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import PortalDataMapper from "@verax-attestation-registry/verax-sdk/lib/types/src/dataMapper/PortalDataMapper"; | ||
|
||
import { ITEMS_PER_PAGE_DEFAULT } from "@/constants"; | ||
import { ResultParseSearch } from "@/interfaces/components"; | ||
import { isNotNullOrUndefined } from "@/utils"; | ||
|
||
export const loadPortalList = async (portal: PortalDataMapper, parsedString: Partial<ResultParseSearch>) => { | ||
const [listByName, listByDescription] = parsedString.nameOrDescription | ||
? await Promise.all([ | ||
portal.findBy(ITEMS_PER_PAGE_DEFAULT, undefined, { | ||
name_contains_nocase: parsedString.nameOrDescription, | ||
}), | ||
portal.findBy(ITEMS_PER_PAGE_DEFAULT, undefined, { | ||
description_contains_nocase: parsedString.nameOrDescription, | ||
}), | ||
]) | ||
: []; | ||
|
||
const listByIds = ( | ||
parsedString.address ? await Promise.all(parsedString.address.map((id) => portal.findOneById(id))) : [] | ||
).filter(isNotNullOrUndefined); | ||
|
||
const result = [...(listByIds || []), ...(listByName || []), ...(listByDescription || [])]; | ||
|
||
return result; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters