From f4e9c81846694b1e96f944db22cbb438be5a60a1 Mon Sep 17 00:00:00 2001 From: Taras Oliynyk <49455800+OliynykPro@users.noreply.github.com> Date: Mon, 18 Dec 2023 18:33:13 +0200 Subject: [PATCH] fix: change attestations sort by date logic and small fixes (#476) Co-authored-by: Taras Oliynyk --- .../DataTable/components/TdHandler/index.tsx | 34 +++++++++++++++++++ .../components/TdHandler/interface.ts | 6 ++++ explorer/src/components/Pagination/index.tsx | 3 +- explorer/src/components/SortByDate/index.tsx | 20 ++++------- explorer/src/components/ui/table.tsx | 8 +++-- .../src/constants/columns/attestation.tsx | 5 ++- explorer/src/constants/columns/module.tsx | 15 ++++---- explorer/src/constants/columns/schema.tsx | 5 ++- explorer/src/index.css | 32 ----------------- explorer/src/pages/Attestations/index.tsx | 8 +++-- 10 files changed, 76 insertions(+), 60 deletions(-) create mode 100644 explorer/src/components/DataTable/components/TdHandler/index.tsx create mode 100644 explorer/src/components/DataTable/components/TdHandler/interface.ts diff --git a/explorer/src/components/DataTable/components/TdHandler/index.tsx b/explorer/src/components/DataTable/components/TdHandler/index.tsx new file mode 100644 index 00000000..d54eac44 --- /dev/null +++ b/explorer/src/components/DataTable/components/TdHandler/index.tsx @@ -0,0 +1,34 @@ +import { ChevronRight } from "lucide-react"; + +import { Link } from "@/components/Link"; + +import { ITdHandler } from "./interface"; + +export const TdHandler: React.FC = ({ value, valueUrl, to, isTextLeft = false }) => { + return ( +
+ {valueUrl ? ( + + {value} + + ) : ( +

+ {value} +

+ )} + + + +
+ ); +}; diff --git a/explorer/src/components/DataTable/components/TdHandler/interface.ts b/explorer/src/components/DataTable/components/TdHandler/interface.ts new file mode 100644 index 00000000..191ebfff --- /dev/null +++ b/explorer/src/components/DataTable/components/TdHandler/interface.ts @@ -0,0 +1,6 @@ +export interface ITdHandler { + to: string; + value: string; + valueUrl?: string; + isTextLeft?: boolean; +} diff --git a/explorer/src/components/Pagination/index.tsx b/explorer/src/components/Pagination/index.tsx index 85b0fdf3..141000fb 100644 --- a/explorer/src/components/Pagination/index.tsx +++ b/explorer/src/components/Pagination/index.tsx @@ -75,11 +75,10 @@ export const Pagination = ({ itemsCount, handlePage }: IPaginationProps) => { changePage(event.target.value)} - className="w-12 h-8 px-2 border text-xs font-semibold text-zinc-950 text-center outline-none border-slate-200 focus:border-slate-400 rounded-lg" + className="w-16 h-8 px-2 border text-xs font-semibold text-zinc-950 text-center outline-none border-slate-200 focus:border-slate-400 rounded-lg" /> {`of ${displayAmountWithComma(totalPages)}`} diff --git a/explorer/src/components/SortByDate/index.tsx b/explorer/src/components/SortByDate/index.tsx index 84aa04e2..e0566306 100644 --- a/explorer/src/components/SortByDate/index.tsx +++ b/explorer/src/components/SortByDate/index.tsx @@ -1,3 +1,4 @@ +import { t } from "i18next"; import { ArrowDownUp } from "lucide-react"; import { useSearchParams } from "react-router-dom"; @@ -11,24 +12,17 @@ export const SortByDate: React.FC = () => { const handleSort = () => { const currentSearchParams = new URLSearchParams(searchParams); - if (sort === null) { - currentSearchParams.set(EQueryParams.SORT_BY_DATE, ETableSorting.ASC); - } else if (sort === ETableSorting.ASC) { - currentSearchParams.set(EQueryParams.SORT_BY_DATE, ETableSorting.DESC); - } else { - currentSearchParams.delete(EQueryParams.SORT_BY_DATE); - } + sort === null + ? currentSearchParams.set(EQueryParams.SORT_BY_DATE, ETableSorting.ASC) + : currentSearchParams.delete(EQueryParams.SORT_BY_DATE); + setSearchParams(currentSearchParams); }; return (
- Issued - + {t("attestation.list.columns.issued")} +
); }; diff --git a/explorer/src/components/ui/table.tsx b/explorer/src/components/ui/table.tsx index 1e814b48..44717e63 100644 --- a/explorer/src/components/ui/table.tsx +++ b/explorer/src/components/ui/table.tsx @@ -4,7 +4,7 @@ import { cn } from "@/utils"; const Table = React.forwardRef>( ({ className, ...props }, ref) => ( -
+
), @@ -34,7 +34,11 @@ TableFooter.displayName = "TableFooter"; const TableRow = React.forwardRef>( ({ className, ...props }, ref) => ( - + ), ); TableRow.displayName = "TableRow"; diff --git a/explorer/src/constants/columns/attestation.tsx b/explorer/src/constants/columns/attestation.tsx index 08c5f939..4900d7d9 100644 --- a/explorer/src/constants/columns/attestation.tsx +++ b/explorer/src/constants/columns/attestation.tsx @@ -5,6 +5,7 @@ import moment from "moment"; import { Address } from "viem"; import { hexToNumber } from "viem/utils"; +import { TdHandler } from "@/components/DataTable/components/TdHandler"; import { HelperIndicator } from "@/components/HelperIndicator"; import { Link } from "@/components/Link"; import { SortByDate } from "@/components/SortByDate"; @@ -77,7 +78,9 @@ export const columns = ({ sortByDate = true }: Partial = {}): Colu header: () => (sortByDate ? :

{t("attestation.list.columns.issued")}

), cell: ({ row }) => { const timestamp: number = row.getValue("attestedDate"); - return

{moment.unix(timestamp).fromNow()}

; + const id = row.original.id; + + return ; }, }, ]; diff --git a/explorer/src/constants/columns/module.tsx b/explorer/src/constants/columns/module.tsx index 69bc4a2d..1da6ec80 100644 --- a/explorer/src/constants/columns/module.tsx +++ b/explorer/src/constants/columns/module.tsx @@ -2,6 +2,7 @@ import { ColumnDef } from "@tanstack/react-table"; import { Module } 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 { ColumnsOptions } from "@/interfaces/components"; @@ -38,14 +39,14 @@ export const columns = (): ColumnDef[] => [ header: () =>

{t("module.list.columns.contractAddress")}

, cell: ({ row }) => { const address = row.original.moduleAddress; + const id = row.original.id; + return ( - - {cropString(address)} - + ); }, }, diff --git a/explorer/src/constants/columns/schema.tsx b/explorer/src/constants/columns/schema.tsx index 359873ee..81de05ab 100644 --- a/explorer/src/constants/columns/schema.tsx +++ b/explorer/src/constants/columns/schema.tsx @@ -2,6 +2,7 @@ import { ColumnDef } from "@tanstack/react-table"; import { Schema } 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 { ColumnsOptions } from "@/interfaces/components"; @@ -49,7 +50,9 @@ export const columns = (): ColumnDef[] => [ header: () =>

{t("schema.list.columns.schema")}

, cell: ({ row }) => { const schema = row.getValue("schema") as string; - return

{schema}

; + const id = row.original.id; + + return ; }, }, ]; diff --git a/explorer/src/index.css b/explorer/src/index.css index 72cfe7f2..1b17f72b 100644 --- a/explorer/src/index.css +++ b/explorer/src/index.css @@ -148,36 +148,4 @@ .sort-arrows.asc path:nth-child(4) { stroke: var(--grey-400); } - - .table-row-transition { - transition: all cubic-bezier(0, 0.52, 1, 1) 1s; - - td:last-child { - display: flex; - justify-content: flex-end; - position: relative; - transition: transform .5s; - - &:after { - content: '\203A'; - position: absolute; - opacity: 0; - top: 15px; - right: 15px; - transition: 0.5s; - scale: 2; - } - } - } - - .table-row-transition:hover { - td:last-child { - transform: translateX(-20px); - - &:after { - right: 5px; - opacity: 1; - } - } - } } \ No newline at end of file diff --git a/explorer/src/pages/Attestations/index.tsx b/explorer/src/pages/Attestations/index.tsx index 399d6fba..26c1063f 100644 --- a/explorer/src/pages/Attestations/index.tsx +++ b/explorer/src/pages/Attestations/index.tsx @@ -1,5 +1,6 @@ import { OrderDirection } from "@verax-attestation-registry/verax-sdk/lib/types/.graphclient"; import { useRef, useState } from "react"; +import { useSearchParams } from "react-router-dom"; import useSWR from "swr"; import { DataTable } from "@/components/DataTable"; @@ -8,6 +9,7 @@ import { ITEMS_PER_PAGE_DEFAULT, ZERO } from "@/constants"; import { attestationColumnsOption, columns, skeletonAttestations } from "@/constants/columns/attestation"; import { columnsSkeleton } from "@/constants/columns/skeleton"; import { EQueryParams } from "@/enums/queryParams"; +import { ETableSorting } from "@/enums/tableSorting"; import { SWRKeys } from "@/interfaces/swr/enum"; import { useNetworkContext } from "@/providers/network-provider/context"; import { getItemsByPage, pageBySearchParams } from "@/utils/paginationUtils"; @@ -25,8 +27,9 @@ export const Attestations: React.FC = () => { () => sdk.attestation.getAttestationIdCounter() as Promise, ); + const [searchParams] = useSearchParams(); + const totalItems = attestationsCount ?? ZERO; - const searchParams = new URLSearchParams(window.location.search); const page = pageBySearchParams(searchParams, totalItems); const sortByDateDirection = searchParams.get(EQueryParams.SORT_BY_DATE); @@ -40,7 +43,7 @@ export const Attestations: React.FC = () => { skip, undefined, "attestedDate", - sortByDateDirection as OrderDirection, + (sortByDateDirection as OrderDirection) || ETableSorting.DESC, ), ); @@ -49,6 +52,7 @@ export const Attestations: React.FC = () => { }; const columnsSkeletonRef = useRef(columnsSkeleton(columns(), attestationColumnsOption)); + const data = isLoading ? { columns: columnsSkeletonRef.current, list: skeletonAttestations() } : { columns: columns(), list: attestationsList || [] };