-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dashboard): debloat wfspec view (#1123)
- Added `getLatestWfSpecs` server actions - Uses `lhClient` RPC - Group unique `WfSpecs` with latest version tag --------- Co-authored-by: Hazim Arafa <[email protected]>
- Loading branch information
Showing
8 changed files
with
13,219 additions
and
6,337 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 33 additions & 17 deletions
50
dashboard/src/app/(authenticated)/components/tables/WfSpecTable.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,46 @@ | ||
import { WfSpecId } from 'littlehorse-client/proto' | ||
import { TagIcon } from 'lucide-react' | ||
import Link from 'next/link' | ||
import { FC, Fragment } from 'react' | ||
import { FC, Fragment, useEffect, useMemo, useState } from 'react' | ||
import { SearchResultProps } from '.' | ||
|
||
import { TagIcon } from 'lucide-react' | ||
import { Separator } from '@/components/ui/separator' | ||
import { useRouter } from 'next/navigation' | ||
import { getLatestWfSpecs } from '@/app/actions/getLatestWfSpec' | ||
import { useWhoAmI } from '@/contexts/WhoAmIContext' | ||
import { WfSpecData } from '@/types' | ||
export const WfSpecTable: FC<SearchResultProps> = ({ pages = [] }) => { | ||
const router = useRouter() | ||
const [wfSpecs, setWfSpecs] = useState<WfSpecData[]>([]) | ||
const { tenantId } = useWhoAmI() | ||
|
||
if (pages.length === 0) { | ||
return <div className="flex min-h-[360px] items-center justify-center text-center italic">No WfSpecs</div> | ||
} | ||
|
||
useEffect(() => { | ||
if (!tenantId) return | ||
const wfSpecNames = pages.flatMap(page => page.results).map(wfSpec => wfSpec.name) | ||
getLatestWfSpecs(tenantId, wfSpecNames).then(setWfSpecs) | ||
}, [pages, tenantId]) | ||
|
||
return ( | ||
<div className="py-4"> | ||
{pages.map((page, i) => ( | ||
<Fragment key={i}> | ||
{page.results.map(({ name, majorVersion, revision }: WfSpecId) => ( | ||
<div key={`${name}.${majorVersion}.${revision}`} className="my-2 flex gap-2"> | ||
<Link className="underline hover:no-underline" href={`/wfSpec/${name}/${majorVersion}.${revision}`}> | ||
{name} | ||
</Link> | ||
<div className="flex max-h-[600px] flex-col overflow-auto"> | ||
{wfSpecs.map(wfSpec => ( | ||
<Fragment key={wfSpec.name}> | ||
<button | ||
className="flex items-center gap-3 rounded-md px-2 py-2 hover:bg-gray-100" | ||
key={wfSpec.name} | ||
onClick={() => router.push(`/wfSpec/${wfSpec.name}/${wfSpec.latestVersion}`)} | ||
> | ||
<p>{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" />v{majorVersion}.{revision} | ||
<TagIcon className="h-4 w-4 fill-none stroke-gray-500 stroke-1" /> | ||
Latest: v{wfSpec.latestVersion} | ||
</div> | ||
</div> | ||
))} | ||
</Fragment> | ||
))} | ||
</button> | ||
<Separator /> | ||
</Fragment> | ||
))} | ||
</div> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use server' | ||
|
||
import { WfSpecId } from 'littlehorse-client/proto' | ||
import { lhClient } from '../lhClient' | ||
import { WfSpecData } from '@/types' | ||
|
||
export async function getLatestWfSpecs(tenantId: string, wfSpecNames: string[]): Promise<WfSpecData[]> { | ||
const client = await lhClient({ tenantId }) | ||
const specMap = new Map<string, WfSpecData>() | ||
|
||
await Promise.all( | ||
wfSpecNames.map(async name => { | ||
if (!specMap.has(name)) { | ||
const wf = await client.getLatestWfSpec({ name }) | ||
specMap.set(name, { | ||
name, | ||
latestVersion: `${wf?.id?.majorVersion}.${wf?.id?.revision}`, | ||
}) | ||
} | ||
}) | ||
) | ||
|
||
return Array.from(specMap.values()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use client' | ||
|
||
import * as React from 'react' | ||
import * as SeparatorPrimitive from '@radix-ui/react-separator' | ||
|
||
import { cn } from '@/components/utils' | ||
|
||
const Separator = React.forwardRef< | ||
React.ElementRef<typeof SeparatorPrimitive.Root>, | ||
React.ComponentPropsWithoutRef<typeof SeparatorPrimitive.Root> | ||
>(({ className, orientation = 'horizontal', decorative = true, ...props }, ref) => ( | ||
<SeparatorPrimitive.Root | ||
ref={ref} | ||
decorative={decorative} | ||
orientation={orientation} | ||
className={cn('shrink-0 bg-border', orientation === 'horizontal' ? 'h-[1px] w-full' : 'h-full w-[1px]', className)} | ||
{...props} | ||
/> | ||
)) | ||
Separator.displayName = SeparatorPrimitive.Root.displayName | ||
|
||
export { Separator } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters