Skip to content

Commit

Permalink
feat: embed jaeger ui in cardinal editor
Browse files Browse the repository at this point in the history
  • Loading branch information
rmrt1n committed Oct 17, 2024
1 parent 72af65b commit ef969a5
Show file tree
Hide file tree
Showing 24 changed files with 1,691 additions and 521 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@sentry/react": "^8.28.0",
"@sentry/vite-plugin": "^2.22.4",
"@tanstack/react-query": "^5.28.14",
"@tanstack/react-router": "^1.26.9",
"@tanstack/react-router": "^1.70.0",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.0",
"lucide-react": "^0.334.0",
Expand All @@ -41,7 +41,7 @@
},
"devDependencies": {
"@biomejs/biome": "1.9.3",
"@tanstack/router-vite-plugin": "^1.26.8",
"@tanstack/router-vite-plugin": "^1.69.1",
"@types/node": "^20.12.4",
"@types/react": "^18.2.74",
"@types/react-dom": "^18.2.24",
Expand Down
870 changes: 675 additions & 195 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EntityCard } from '@/components/entity-views'
import { EntityCard } from '@/components/cardinal/entity-views'
import {
Accordion,
AccordionContent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { SidebarQueries } from './queries'
const builtinMessages = new Set([routeMsgCreatePersona, routeMsgAuthorizePersonaAddress])
const builtinQueries = new Set([routeQryPersonaSigner, routeQryReceiptsList])

export function Sidebar() {
export function CardinalSidebar() {
const cardinal = useCardinal()
const { data, isError, error } = useQuery(worldQueryOptions(cardinal))
const { toast } = useToast()
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
172 changes: 120 additions & 52 deletions src/components/header.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,79 @@
import * as Sentry from '@sentry/react'
import { useQueryClient } from '@tanstack/react-query'
import { Bell, BellOff, RefreshCw } from 'lucide-react'
import { Bell, BellOff, ExternalLink, RefreshCw } from 'lucide-react'
import { useEffect, useState } from 'react'

import logoDark from '@/assets/world-dark.svg'
import logoLight from '@/assets/world-light.svg'
import { Button } from '@/components/ui/button'
import { Button, buttonVariants } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
import { useToast } from '@/components/ui/use-toast'
import { useCardinal } from '@/lib/cardinal-provider'
import { worldQueryOptions } from '@/lib/query-options'
import { cn, errorToast } from '@/lib/utils'
import { Link, useRouterState } from '@tanstack/react-router'

const links = [
{ title: 'Cardinal', href: '/cardinal' },
{ title: 'Jaeger', href: '/jaeger' },
]

export function Header() {
const { cardinalUrl, setCardinalUrl, isCardinalConnected, notifications, setNotifications } =
useCardinal()
const [fetching, setFetching] = useState(false)
const queryClient = useQueryClient()
const { toast } = useToast()
const routerState = useRouterState({
select: (state) => state.location,
})
const location = routerState.pathname

useEffect(() => {
const feedback = Sentry.getFeedback()
const unsubscribe = feedback?.attachTo('#feedback-btn')
return unsubscribe
}, [])

return (
<header className="border-b">
<nav className="flex items-center justify-between px-3 h-12">
<div className="flex items-center gap-2">
<img src={logoLight} width={32} height={32} className="dark:hidden" />
<img src={logoDark} width={32} height={32} className="hidden dark:block" />
{links.map((link) => (
<Link
key={link.href}
to={link.href}
className={cn(
buttonVariants({ variant: location === link.href ? 'default' : 'outline' }),
'px-4 py-2 h-8',
)}
>
{link.title}
</Link>
))}
</div>
<div className="flex items-center gap-2">
{location === '/cardinal' ? (
<CardinalUrl />
) : location === '/jaeger' ? (
<JaegerUrl />
) : (
// unreachable or 404
<></>
)}
<Button id="feedback-btn" variant="outline" className="h-8 gap-2">
Give Feedback
</Button>
</div>
</nav>
</header>
)
}

function CardinalUrl() {
const { cardinalUrl, setCardinalUrl, isCardinalConnected, notifications, setNotifications } =
useCardinal()
const [fetching, setFetching] = useState(false)
const queryClient = useQueryClient()
const { toast } = useToast()

const refetchWorld = async () => {
setFetching(true)
try {
Expand All @@ -36,50 +85,69 @@ export function Header() {
}

return (
<header className="border-b">
<nav className="flex items-center justify-between px-3 h-12">
<img src={logoLight} width={32} height={32} className="dark:hidden" />
<img src={logoDark} width={32} height={32} className="hidden dark:block" />
<div className="flex items-center gap-2">
<div
className={cn(
'size-2 rounded-full flex-shrink-0',
isCardinalConnected ? 'bg-green-500' : 'bg-red-500',
)}
/>
<label htmlFor="host" className="flex-shrink-0 text-xs text-muted-foreground">
Cardinal URL
</label>
<Input
id="host"
placeholder="localhost:4040"
value={cardinalUrl}
onChange={(e) => setCardinalUrl(e.target.value)}
className="h-8"
/>
<Button
variant="outline"
size="icon"
className="size-8 flex-shrink-0"
title="Refresh world"
onClick={() => void refetchWorld()}
>
<RefreshCw size={16} className={cn(fetching && 'animate-spin')} />
</Button>
<Button
variant="outline"
size="icon"
className="size-8 flex-shrink-0"
title="Toggle notifications"
onClick={() => setNotifications(!notifications)}
>
{notifications ? <Bell size={17} /> : <BellOff size={17} />}
</Button>
<Button id="feedback-btn" variant="outline" className="h-8 gap-2">
Give Feedback
</Button>
</div>
</nav>
</header>
<div className="flex items-center gap-2">
<div
className={cn(
'size-2 rounded-full flex-shrink-0',
isCardinalConnected ? 'bg-green-500' : 'bg-red-500',
)}
/>
<label htmlFor="host" className="flex-shrink-0 text-xs text-muted-foreground">
Cardinal URL
</label>
<Input
id="host"
placeholder="localhost:4040"
value={cardinalUrl}
onChange={(e) => setCardinalUrl(e.target.value)}
className="h-8"
/>
<Button
variant="outline"
size="icon"
className="size-8 flex-shrink-0"
title="Refresh world"
onClick={() => void refetchWorld()}
>
<RefreshCw size={16} className={cn(fetching && 'animate-spin')} />
</Button>
<Button
variant="outline"
size="icon"
className="size-8 flex-shrink-0"
title="Toggle notifications"
onClick={() => setNotifications(!notifications)}
>
{notifications ? <Bell size={17} /> : <BellOff size={17} />}
</Button>
</div>
)
}

function JaegerUrl() {
const { jaegerUrl, setJaegerUrl } = useCardinal()

return (
<div className="flex items-center gap-2">
<label htmlFor="host" className="flex-shrink-0 text-xs text-muted-foreground">
Jaeger URL
</label>
<Input
id="host"
placeholder="localhost:16686"
value={jaegerUrl}
onChange={(e) => setJaegerUrl(e.target.value)}
className="h-8"
/>
<a
href={jaegerUrl}
target="_blank"
className={cn(buttonVariants({ variant: 'outline', size: 'icon' }), 'size-8 flex-shrink-0')}
title="Open full Jaeger UI"
rel="noreferrer"
>
<ExternalLink size={17} />
</a>
</div>
)
}
Loading

0 comments on commit ef969a5

Please sign in to comment.