fix broken lookup link in metadata explorer

This commit is contained in:
Victor Oliva
2025-03-10 12:13:52 +01:00
parent 2620169ce0
commit 1e3dcd51e5
3 changed files with 32 additions and 7 deletions
+26 -5
View File
@@ -1,10 +1,13 @@
import { FC } from "react"
import {
LinkProps,
Path,
NavigateFunction,
NavigateOptions,
Link as RouterLink,
Location as RouterLocation,
To,
useLocation,
useNavigate as useRouterNavigate,
} from "react-router-dom"
export const getHashParams = (location?: Location | RouterLocation) => {
@@ -29,9 +32,8 @@ export const setHashParams = (
}
const persistingKeys = ["networkId", "endpoint"]
export const Link: FC<LinkProps & React.RefAttributes<HTMLAnchorElement>> = (
props,
) => {
const usePersistKeys = () => {
const location = useLocation()
const originalParams = getHashParams(location)
@@ -46,7 +48,7 @@ export const Link: FC<LinkProps & React.RefAttributes<HTMLAnchorElement>> = (
return "#" + parsedParams.toString()
}
const persistKeys = (to: Partial<Path> | string): Partial<Path> | string => {
return (to: To): To => {
if (typeof to === "string") {
const idx = to.indexOf("#")
return (idx < 0 ? to : to.slice(0, idx)) + appendParams(to.slice(idx))
@@ -59,5 +61,24 @@ export const Link: FC<LinkProps & React.RefAttributes<HTMLAnchorElement>> = (
}
: to
}
}
export const Link: FC<LinkProps & React.RefAttributes<HTMLAnchorElement>> = (
props,
) => {
const persistKeys = usePersistKeys()
return <RouterLink {...props} to={persistKeys(props.to)} />
}
export const useNavigate = (): NavigateFunction => {
const persistKeys = usePersistKeys()
const navigate = useRouterNavigate()
return (toOrDelta: number | To, options?: NavigateOptions) => {
if (typeof toOrDelta === "number") {
return navigate(toOrDelta)
}
return navigate(persistKeys(toOrDelta), options)
}
}
+4 -1
View File
@@ -235,7 +235,10 @@ const GenericLookupNode: FC<PropsWithChildren<{ entry: V14Entry }>> = ({
<div className="flex flex-col gap-2 w-full py-2">
<div>
<div className="flex gap-2 items-center">
<Link to={`editor/${entry.id}`} className="hover:text-polkadot-400">
<Link
to={`/metadata/lookup/editor/${entry.id}`}
className="hover:text-polkadot-400"
>
<Edit size={20} />
</Link>
<h4 className="font-bold">Type: {entry.def.tag}</h4>
+2 -1
View File
@@ -3,11 +3,12 @@ import { ButtonGroup } from "@/components/ButtonGroup"
import { JsonDisplay } from "@/components/JsonDisplay"
import { LoadingMetadata } from "@/components/Loading"
import { withSubscribe } from "@/components/withSuspense"
import { useNavigate } from "@/hashParams"
import { lookup$, metadata$ } from "@/state/chains/chain.state"
import { getTypeComplexity } from "@/utils/shape"
import { useStateObservable } from "@react-rxjs/core"
import { useState } from "react"
import { Route, Routes, useNavigate, useParams } from "react-router-dom"
import { Route, Routes, useParams } from "react-router-dom"
import { Extrinsic } from "./Extrinsic"
import { Lookup, LookupContext } from "./Lookup"
import { Pallets } from "./Pallets"