From 9032e0570f6fa6f0f62737a448290ab39848ca6e Mon Sep 17 00:00:00 2001 From: Artyom Zaporozhets Date: Sat, 20 Sep 2025 12:28:08 +0300 Subject: [PATCH 1/4] #27: fix links and render coordinates --- src/components/ui/common-table.tsx | 4 +- src/pages/SearchResults.tsx | 67 ++++++++++++++++-------------- 2 files changed, 38 insertions(+), 33 deletions(-) diff --git a/src/components/ui/common-table.tsx b/src/components/ui/common-table.tsx index b9a942e..543c334 100644 --- a/src/components/ui/common-table.tsx +++ b/src/components/ui/common-table.tsx @@ -1,4 +1,4 @@ -import React, { ReactElement } from "react"; +import React, { ReactElement, ReactNode } from "react"; import classNames from "classnames"; import { Hint } from "./hint"; @@ -6,7 +6,7 @@ export type CellPrimitive = ReactElement | string | number; export interface Column { name: string; - renderCell?: (value: CellPrimitive) => ReactElement; + renderCell?: (value: CellPrimitive) => ReactNode; hint?: ReactElement; } diff --git a/src/pages/SearchResults.tsx b/src/pages/SearchResults.tsx index f3a8b98..ab7a443 100644 --- a/src/pages/SearchResults.tsx +++ b/src/pages/SearchResults.tsx @@ -11,6 +11,7 @@ import { ErrorPage, ErrorPageHomeButton } from "../components/ui/error-page"; import { useDataFetching } from "../hooks/useDataFetching"; import { querySimpleApiV1QuerySimpleGet } from "../clients/backend/sdk.gen"; import { QuerySimpleResponse } from "../clients/backend/types.gen"; +import { Link } from "../components/ui/link"; function searchHandler(navigate: NavigateFunction) { return function f(query: string) { @@ -18,6 +19,35 @@ function searchHandler(navigate: NavigateFunction) { }; } +function renderRightAscension( + value: React.ReactElement | string | number, +): React.ReactNode { + const raDegrees = + typeof value === "number" ? value : parseFloat(value as string); + if (isNaN(raDegrees)) return "N/A"; + const totalSeconds = raDegrees * 240; + const hours = Math.floor(totalSeconds / 3600); + const minutes = Math.floor((totalSeconds % 3600) / 60); + const seconds = (totalSeconds % 60).toFixed(2); + return `${hours}h ${minutes}m ${seconds}s`; +} + +function renderDeclination( + value: React.ReactElement | string | number, +): React.ReactNode { + const decDegrees = + typeof value === "number" ? value : parseFloat(value as string); + if (isNaN(decDegrees)) return "N/A"; + const sign = decDegrees < 0 ? "-" : "+"; + const absDec = Math.abs(decDegrees); + const degrees = Math.floor(absDec); + const minutesFloat = (absDec - degrees) * 60; + const minutes = Math.floor(minutesFloat); + const seconds = (minutesFloat - minutes) * 60; + return `${sign}${degrees}° ${minutes}' ${seconds.toFixed(2)}"`; +} + + function pageChangeHandler( navigate: NavigateFunction, query: string, @@ -48,33 +78,12 @@ function SearchResults({ { name: "PGC", renderCell: (value: React.ReactElement | string | number) => ( - - {value} - - ), - }, - { - name: "Name", - renderCell: (value: React.ReactElement | string | number) => ( - {value || "N/A"} - ), - }, - { - name: "RA (deg)", - renderCell: (value: React.ReactElement | string | number) => ( - - {typeof value === "number" ? value.toFixed(6) : value} - - ), - }, - { - name: "Dec (deg)", - renderCell: (value: React.ReactElement | string | number) => ( - - {typeof value === "number" ? value.toFixed(6) : value} - + {value} ), }, + { name: "Name" }, + { name: "RA", renderCell: renderRightAscension }, + { name: "Dec", renderCell: renderDeclination }, ]; if (results.objects.length > 0) { @@ -85,14 +94,10 @@ function SearchResults({ data={results.objects.map((object) => ({ PGC: object.pgc, Name: object.catalogs.designation?.name || "N/A", - "RA (deg)": object.catalogs.coordinates?.equatorial.ra || 0, - "Dec (deg)": object.catalogs.coordinates?.equatorial.dec || 0, + RA: object.catalogs.coordinates?.equatorial.ra || 0, + Dec: object.catalogs.coordinates?.equatorial.dec || 0, }))} className="w-full" - onRowClick={(row) => { - const pgc = row.PGC as number; - navigate(`/object/${pgc}`); - }} />
+ + Page {page + 1} (showing {records.length} records) + + +
+ ); +} diff --git a/src/pages/CrossmatchResults.tsx b/src/pages/CrossmatchResults.tsx index 97e2c11..44f956e 100644 --- a/src/pages/CrossmatchResults.tsx +++ b/src/pages/CrossmatchResults.tsx @@ -21,6 +21,7 @@ import { Loading } from "../components/ui/loading"; import { ErrorPage } from "../components/ui/error-page"; import { Link } from "../components/ui/link"; import { useDataFetching } from "../hooks/useDataFetching"; +import { Pagination } from "../components/ui/pagination"; interface CrossmatchFiltersProps { tableName: string | null; @@ -244,27 +245,17 @@ export function CrossmatchResultsPage(): ReactElement { function Content(): ReactElement { if (loading) return ; if (error) return ; + if (!data?.records) return ; return ( <> -
- - - Page {page + 1} (showing {data?.records.length} records) - - -
+ ); } diff --git a/src/pages/SearchResults.tsx b/src/pages/SearchResults.tsx index eb5ef82..936bb8b 100644 --- a/src/pages/SearchResults.tsx +++ b/src/pages/SearchResults.tsx @@ -13,6 +13,7 @@ import { querySimpleApiV1QuerySimpleGet } from "../clients/backend/sdk.gen"; import { QuerySimpleResponse } from "../clients/backend/types.gen"; import { Link } from "../components/ui/link"; import { Declination, RightAscension } from "../components/ui/astronomy"; +import { Pagination } from "../components/ui/pagination"; function searchHandler(navigate: NavigateFunction) { return function f(query: string) { @@ -76,9 +77,13 @@ function SearchResults({ }, ]; + function handlePageChange(newPage: number): void { + pageChangeHandler(navigate, query, pageSize, newPage); + } + if (results.objects.length > 0) { return ( -
+ <> ({ @@ -89,28 +94,13 @@ function SearchResults({ }))} className="w-full" /> -
- - Page {page} - -
-
+ + ); } @@ -158,7 +148,7 @@ export function SearchResultsPage(): ReactElement { const navigate = useNavigate(); const query = searchParams.get("q") || ""; const page = parseInt(searchParams.get("page") || "1"); - const pageSize = parseInt(searchParams.get("pagesize") || "10"); + const pageSize = parseInt(searchParams.get("pagesize") || "25"); useEffect(() => { document.title = `${query} | HyperLEDA`; From c12032f156a7153f818d15c1f50858e0237949df Mon Sep 17 00:00:00 2001 From: Artyom Zaporozhets Date: Sat, 20 Sep 2025 13:20:09 +0300 Subject: [PATCH 4/4] rename stuff --- src/components/ui/astronomy.tsx | 26 +++++++-------- src/components/ui/catalog-data.tsx | 52 +++++++++++++++--------------- 2 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/components/ui/astronomy.tsx b/src/components/ui/astronomy.tsx index b04e383..bc1bc43 100644 --- a/src/components/ui/astronomy.tsx +++ b/src/components/ui/astronomy.tsx @@ -1,18 +1,18 @@ import React, { ReactElement, ReactNode } from "react"; -interface ValueProps { +interface QuantityProps { value: string | number; unit?: string; className?: string; spaced?: boolean; } -export function Value({ +export function Quantity({ value, unit, className, spaced = true, -}: ValueProps): React.ReactElement { +}: QuantityProps): React.ReactElement { return ( {value} @@ -28,22 +28,22 @@ export function Value({ ); } -interface ValueWithErrorProps { +interface QuantityWithErrorProps { children: ReactNode; error: number; unit?: string; decimalPlaces?: number; } -export function ValueWithError({ +export function QuantityWithError({ children, error, unit, decimalPlaces = 2, -}: ValueWithErrorProps): ReactElement { +}: QuantityWithErrorProps): ReactElement { return (
- {children} ± + {children} ±
); } @@ -68,9 +68,9 @@ export function RightAscension({ return ( - {" "} - {" "} - + {" "} + {" "} + ); } @@ -93,9 +93,9 @@ export function Declination({ return ( {sign} - {" "} - {" "} - + {" "} + {" "} + ); } diff --git a/src/components/ui/catalog-data.tsx b/src/components/ui/catalog-data.tsx index 3a2c54e..ee2c0a4 100644 --- a/src/components/ui/catalog-data.tsx +++ b/src/components/ui/catalog-data.tsx @@ -4,8 +4,8 @@ import { Catalogs, Schema } from "../../clients/backend/types.gen"; import { Declination, RightAscension, - Value, - ValueWithError, + Quantity, + QuantityWithError, } from "./astronomy"; interface CatalogDataProps { @@ -35,12 +35,12 @@ export function CatalogData({ data.push({ Parameter: "Equatorial RA", Value: ( - - + ), }); } @@ -49,12 +49,12 @@ export function CatalogData({ data.push({ Parameter: "Equatorial Dec", Value: ( - - + ), }); } @@ -63,29 +63,29 @@ export function CatalogData({ { Parameter: "Galactic l", Value: ( - - - + ), }, { Parameter: "Galactic b", Value: ( - - - + ), }, ); @@ -95,9 +95,9 @@ export function CatalogData({ data.push({ Parameter: "Redshift z", Value: ( - + {catalogs.redshift.z?.toFixed(5) || "N/A"} - + ), }); } @@ -107,57 +107,57 @@ export function CatalogData({ { Parameter: "Heliocentric Velocity", Value: ( - - - + ), }, { Parameter: "Local Group Velocity", Value: ( - - - + ), }, { Parameter: "CMB (old) Velocity", Value: ( - - - + ), }, { Parameter: "CMB Velocity", Value: ( - - - + ), }, );