Skip to content

Commit

Permalink
refactor(dashboard): SelectionLink for listed item page redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
bryson-g committed Dec 14, 2024
1 parent 30e0cb4 commit f2d2d0d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
9 changes: 6 additions & 3 deletions dashboard/src/app/[tenantId]/components/LinkWithTenant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import NextLink from 'next/link'
import { useParams } from 'next/navigation'
import { ComponentProps } from 'react'

const LinkWithTenant = ({ linkStyle, ...props }: ComponentProps<typeof NextLink> & { linkStyle?: boolean }) => {
const LinkWithTenant = ({ linkStyle, href, ...props }: ComponentProps<typeof NextLink> & { linkStyle?: boolean }) => {
const { tenantId } = useParams()

return (
<NextLink
{...props}
href={`/${tenantId}${props.href}`}
className={cn(props.className, { 'text-blue-500 underline': linkStyle })}
href={`/${tenantId}${href}`}
className={cn(props.className, {
'[&>*:first-child]:text-blue-500 [&>*:first-child]:hover:underline': linkStyle,
})}
/>
)
}
Expand Down
32 changes: 32 additions & 0 deletions dashboard/src/app/[tenantId]/components/SelectionLink.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { WfSpecData } from '@/types'
import LinkWithTenant from './LinkWithTenant'

import { Fragment } from 'react'
import { TagIcon } from 'lucide-react'
import { Separator } from '@/components/ui/separator'

export const SelectionLink = ({
href,
key,
children,
...props
}: { href: string | undefined } & Omit<React.ComponentProps<typeof LinkWithTenant>, 'href'>) => {
return href !== undefined ? (
<Fragment key={key}>
<LinkWithTenant
className="flex items-center gap-3 rounded-md px-2 py-2 hover:bg-gray-100"
href={href}
linkStyle={href !== undefined}
{...props}
>
{children}
</LinkWithTenant>
<Separator />
</Fragment>
) : (
<Fragment key={key}>
<div className="flex items-center gap-3 rounded-md px-2 py-2 hover:bg-gray-100">{children}</div>
<Separator />
</Fragment>
)
}
11 changes: 4 additions & 7 deletions dashboard/src/app/[tenantId]/components/tables/WfSpecTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { TagIcon } from 'lucide-react'
import { useParams, useRouter } from 'next/navigation'
import { FC, Fragment, useEffect, useState } from 'react'
import { SearchResultProps } from '.'
import LinkWithTenant from '../LinkWithTenant'
import { SelectionLink } from '../SelectionLink'

export const WfSpecTable: FC<SearchResultProps> = ({ pages = [] }) => {
const router = useRouter()
Expand All @@ -26,16 +26,13 @@ export const WfSpecTable: FC<SearchResultProps> = ({ pages = [] }) => {
<div className="flex max-h-[600px] flex-col overflow-auto">
{wfSpecs.map(wfSpec => (
<Fragment key={wfSpec.name}>
<LinkWithTenant
className="flex items-center gap-3 rounded-md px-2 py-2 hover:bg-gray-100"
href={`/wfSpec/${wfSpec.name}/${wfSpec.latestVersion}`}
>
<p>{wfSpec.name}</p>
<SelectionLink href={`/wfSpec/${wfSpec.name}/${wfSpec.latestVersion}`}>
<p className="group">{wfSpec.name}</p>
<div className="flex items-center gap-2 rounded bg-blue-200 px-2 font-mono text-sm text-gray-500">
<TagIcon className="h-4 w-4 fill-none stroke-gray-500 stroke-1" />
Latest: v{wfSpec.latestVersion}
</div>
</LinkWithTenant>
</SelectionLink>
<Separator />
</Fragment>
))}
Expand Down

0 comments on commit f2d2d0d

Please sign in to comment.