-
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.
Merge branch 'master' into refactor-test-utils
- Loading branch information
Showing
21 changed files
with
479 additions
and
119 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
19 changes: 19 additions & 0 deletions
19
dashboard/src/app/[tenantId]/(diagram)/components/ExternalLinkButton.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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Button } from '@/components/ui/button' | ||
import LinkWithTenant from '@/app/[tenantId]/components/LinkWithTenant' | ||
import { ExternalLinkIcon } from 'lucide-react' | ||
import { ComponentProps } from 'react' | ||
import { cn } from '@/components/utils' | ||
|
||
type ExternalLinkButtonProps = { | ||
href: string | ||
label: string | ||
target?: string | ||
} & ComponentProps<typeof Button> | ||
|
||
export const ExternalLinkButton = ({ href, label, target, className, ...props }: ExternalLinkButtonProps) => ( | ||
<Button variant="link" className={cn('h-5 w-fit p-0 text-xs', className)} {...props}> | ||
<LinkWithTenant href={href} target={target} className="flex gap-1"> | ||
{label} <ExternalLinkIcon className="h-4 w-4" /> | ||
</LinkWithTenant> | ||
</Button> | ||
) |
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
29 changes: 17 additions & 12 deletions
29
dashboard/src/app/[tenantId]/(diagram)/components/NodeTypes/UserTask/UserTask.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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { TagIcon } from 'lucide-react' | ||
import { FC } from 'react' | ||
import { Versions } from '../userTaskDef/[...props]/components/Versions' | ||
|
||
export type DetailsProps = { | ||
itemHeader: string | ||
header: string | ||
version?: number[] | ||
status?: string | ||
description?: Record<string, string | React.ReactNode> | ||
} | ||
|
||
export const Details: FC<DetailsProps> = ({ itemHeader, header, version, status, description }) => { | ||
return ( | ||
<div> | ||
<div className="mb-4"> | ||
<span className="italic">{itemHeader}</span> | ||
<h1 className="block text-2xl font-bold">{header}</h1> | ||
<div className="flex flex-row gap-2 text-sm text-gray-500"> | ||
{version && version.length > 1 ? ( | ||
<div className="flex items-center gap-2"> | ||
<TagIcon className="h-5 w-5" /> | ||
{version[0]} | ||
</div> | ||
) : null} | ||
</div> | ||
{description && | ||
Object.entries(description).map(([key, value]) => ( | ||
<div key={key}> | ||
<b>{key}</b>: {value} | ||
</div> | ||
))} | ||
{status && <div className="italic text-gray-400">{status}</div>} | ||
</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 |
---|---|---|
@@ -1,11 +1,18 @@ | ||
'use client' | ||
import { cn } from '@/components/utils' | ||
import NextLink from 'next/link' | ||
import { useParams } from 'next/navigation' | ||
import { ComponentProps } from 'react' | ||
|
||
const LinkWithTenant = ({ ...props }: ComponentProps<typeof NextLink>) => { | ||
const LinkWithTenant = ({ linkStyle, ...props }: ComponentProps<typeof NextLink> & { linkStyle?: boolean }) => { | ||
const { tenantId } = useParams() | ||
return <NextLink {...props} href={`/${tenantId}${props.href}`} /> | ||
return ( | ||
<NextLink | ||
{...props} | ||
href={`/${tenantId}${props.href}`} | ||
className={cn(props.className, { 'text-blue-500 underline': linkStyle })} | ||
/> | ||
) | ||
} | ||
|
||
export default LinkWithTenant |
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
1 change: 1 addition & 0 deletions
1
dashboard/src/app/[tenantId]/userTaskDef/[...props]/components/Versions.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
88 changes: 88 additions & 0 deletions
88
dashboard/src/app/[tenantId]/userTaskDef/audit/[...ids]/AuditTable.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 |
---|---|---|
@@ -0,0 +1,88 @@ | ||
'use client' | ||
import { useState } from 'react' | ||
import { Table, TableBody, TableCaption, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table' | ||
import { | ||
Pagination, | ||
PaginationContent, | ||
PaginationItem, | ||
PaginationLink, | ||
PaginationNext, | ||
PaginationPrevious, | ||
} from '@/components/ui/pagination' | ||
import { UserTaskEvent } from 'littlehorse-client/proto' | ||
|
||
type AuditTableProps = { | ||
events: UserTaskEvent[] | ||
} | ||
|
||
export function AuditTable({ events }: AuditTableProps) { | ||
const [currentPage, setCurrentPage] = useState(1) | ||
const itemsPerPage = 10 | ||
|
||
const allEvents = events.filter(event => event.saved !== undefined).reverse() | ||
|
||
const totalPages = Math.ceil(allEvents.length / itemsPerPage) | ||
const startIndex = (currentPage - 1) * itemsPerPage | ||
const paginatedEvents = allEvents.slice(startIndex, startIndex + itemsPerPage) | ||
|
||
return ( | ||
<div className="mx-auto w-full max-w-2xl border-blue-300"> | ||
<Table> | ||
<TableCaption className="mb-2">Audit Log</TableCaption> | ||
<TableHeader> | ||
<TableRow> | ||
<TableHead>Saved At</TableHead> | ||
<TableHead>Saved By</TableHead> | ||
</TableRow> | ||
</TableHeader> | ||
<TableBody> | ||
{paginatedEvents.map(event => ( | ||
<TableRow key={`${event.time}`}> | ||
<TableCell>{new Date(event.time ?? 'N/A').toLocaleString()}</TableCell> | ||
<TableCell> {event.saved?.userId}</TableCell> | ||
</TableRow> | ||
))} | ||
</TableBody> | ||
</Table> | ||
|
||
{totalPages > 1 && ( | ||
<Pagination className="mt-4"> | ||
<PaginationContent> | ||
<PaginationItem> | ||
<PaginationPrevious | ||
href="#" | ||
onClick={e => { | ||
e.preventDefault() | ||
if (currentPage > 1) setCurrentPage(currentPage - 1) | ||
}} | ||
/> | ||
</PaginationItem> | ||
{[...Array(totalPages)].map((_, index) => ( | ||
<PaginationItem key={index + 1}> | ||
<PaginationLink | ||
href="#" | ||
isActive={currentPage === index + 1} | ||
onClick={e => { | ||
e.preventDefault() | ||
setCurrentPage(index + 1) | ||
}} | ||
> | ||
{index + 1} | ||
</PaginationLink> | ||
</PaginationItem> | ||
))} | ||
<PaginationItem> | ||
<PaginationNext | ||
href="#" | ||
onClick={e => { | ||
e.preventDefault() | ||
if (currentPage < totalPages) setCurrentPage(currentPage + 1) | ||
}} | ||
/> | ||
</PaginationItem> | ||
</PaginationContent> | ||
</Pagination> | ||
)} | ||
</div> | ||
) | ||
} |
54 changes: 54 additions & 0 deletions
54
dashboard/src/app/[tenantId]/userTaskDef/audit/[...ids]/page.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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { getUserTaskRun } from '@/app/actions/getUserTaskRun' | ||
import { Metadata } from 'next' | ||
import { notFound } from 'next/navigation' | ||
import { ClientError, Status } from 'nice-grpc-common' | ||
import { Details } from '@/app/[tenantId]/components/Details' | ||
import LinkWithTenant from '@/app/[tenantId]/components/LinkWithTenant' | ||
import { AuditTable } from './AuditTable' | ||
import Link from 'next/link' | ||
import { Button } from '@/components/ui/button' | ||
|
||
type Props = { params: { ids: string[]; tenantId: string } } | ||
|
||
export default async function Page({ params: { ids, tenantId } }: Props) { | ||
const [wfRunId, userTaskGuid] = ids | ||
|
||
try { | ||
const userTaskRun = await getUserTaskRun(tenantId, wfRunId, userTaskGuid) | ||
|
||
return ( | ||
<div> | ||
<Details | ||
itemHeader={'UserTaskRun'} | ||
header={userTaskRun.userTaskDefId?.name ?? 'N/A'} | ||
version={[userTaskRun.userTaskDefId?.version ?? -1]} | ||
description={{ | ||
wfRunId: ( | ||
<Button variant="link" className="p-0" asChild> | ||
<LinkWithTenant href={`/wfRun/${wfRunId}`}>{wfRunId}</LinkWithTenant> | ||
</Button> | ||
), | ||
userTaskRunId: userTaskGuid, | ||
}} | ||
/> | ||
{userTaskRun.events.some(event => event.saved !== undefined) ? ( | ||
<AuditTable events={userTaskRun.events} /> | ||
) : ( | ||
<div className="mt-20 w-full text-center"> | ||
<p className="text-center text-xl font-bold">No save history found.</p> | ||
<p className="text-center text-primary/50">This UserTaskRun has not been saved since it was created.</p> | ||
</div> | ||
)} | ||
</div> | ||
) | ||
} catch (error) { | ||
if (error instanceof ClientError && error.code === Status.NOT_FOUND) return notFound() | ||
throw error | ||
} | ||
} | ||
|
||
export async function generateMetadata({ params: { ids } }: Props): Promise<Metadata> { | ||
return { | ||
title: `UserTask Audit ${ids[1]} | Littlehorse`, | ||
} | ||
} |
Oops, something went wrong.