From 3dd149ede92a550fa84955269c1dca9c52bab94a Mon Sep 17 00:00:00 2001 From: Hazim Arafa Date: Mon, 27 May 2024 13:11:02 -0700 Subject: [PATCH] feat(dashboard): taskRun Table * fix: unnecessary code * fix: no avatar when not authenticated * fix: valid way to detect auth disabled * feat: init search for taskRun * feat: table task def init * feat: finish taskRun table I will rewrite this with the new decided frontend design system. I just wanted to push what I already wrote * fix: update table cols * fix: filter `UNRECOGNIZED` * fix: return all taskRuns by default * chore: rename nodeRunName -> nodeName * fix: mistyped emoji & extra css * revert: "chore: rename nodeRunName -> nodeName" This reverts commit bb4f4dca9dbefd5b58568b34605a6633ca473fd5. --- .../NodeTypes/UserTask/UserTask.tsx | 2 +- .../taskDef/[name]/actions/searchTaskRun.ts | 53 ++++++++ .../taskDef/[name]/components/TaskDef.tsx | 126 +++++++++++++++++- .../[...props]/components/UserTaskDef.tsx | 2 +- 4 files changed, 180 insertions(+), 3 deletions(-) create mode 100644 dashboard/src/app/(authenticated)/taskDef/[name]/actions/searchTaskRun.ts diff --git a/dashboard/src/app/(authenticated)/(diagram)/components/NodeTypes/UserTask/UserTask.tsx b/dashboard/src/app/(authenticated)/(diagram)/components/NodeTypes/UserTask/UserTask.tsx index 34f636c38..6d3c2292c 100644 --- a/dashboard/src/app/(authenticated)/(diagram)/components/NodeTypes/UserTask/UserTask.tsx +++ b/dashboard/src/app/(authenticated)/(diagram)/components/NodeTypes/UserTask/UserTask.tsx @@ -18,7 +18,7 @@ const Node: FC = ({ data, selected }) => { <>
-
+

UserTask

=> { + const client = await lhClient({ tenantId }) + const requestWithBookmark = bookmarkAsString ? { ...req, bookmark: Buffer.from(bookmarkAsString, 'base64') } : req + const taskRunIdList: TaskRunIdList = await client.searchTaskRun(requestWithBookmark) + const hydrateWithTaskRunDetails = (): Promise[] => { + return taskRunIdList.results.map(async (taskRunId: TaskRunId) => { + const taskRun = await client.getTaskRun({ + wfRunId: taskRunId.wfRunId, + taskGuid: taskRunId.taskGuid, + }) + const nodeRun = await client.getNodeRun(taskRun.id!) + + return { + taskRun, + nodeRun, + } + }) + } + + const taskRunWithDetails: runDetails[] = await Promise.all(hydrateWithTaskRunDetails()) + + return { + ...taskRunIdList, + bookmarkAsString: taskRunIdList.bookmark?.toString('base64'), + resultsWithDetails: taskRunWithDetails, + } +} diff --git a/dashboard/src/app/(authenticated)/taskDef/[name]/components/TaskDef.tsx b/dashboard/src/app/(authenticated)/taskDef/[name]/components/TaskDef.tsx index 92dad1027..6e9ed34dc 100644 --- a/dashboard/src/app/(authenticated)/taskDef/[name]/components/TaskDef.tsx +++ b/dashboard/src/app/(authenticated)/taskDef/[name]/components/TaskDef.tsx @@ -1,6 +1,15 @@ +'use client' import { Navigation } from '@/app/(authenticated)/components/Navigation' +import { concatWfRunIds, localDateTimeToUTCIsoString, utcToLocalDateTime } from '@/app/utils' +import { useWhoAmI } from '@/contexts/WhoAmIContext' +import { Field, Input, Label } from '@headlessui/react' +import { ArrowPathIcon } from '@heroicons/react/24/outline' +import { useInfiniteQuery } from '@tanstack/react-query' +import { TaskStatus } from 'littlehorse-client/dist/proto/common_enums' import { TaskDef as TaskDefProto } from 'littlehorse-client/dist/proto/task_def' -import { FC } from 'react' +import Link from 'next/link' +import { FC, Fragment, useState } from 'react' +import { PaginatedTaskRunList, searchTaskRun } from '../actions/searchTaskRun' import { Details } from './Details' import { InputVars } from './InputVars' @@ -8,11 +17,126 @@ type Props = { spec: TaskDefProto } export const TaskDef: FC = ({ spec }) => { + const [selectedStatus, setSelectedStatus] = useState('ALL') + const [createdAfter, setCreatedAfter] = useState('') + const [createdBefore, setCreatedBefore] = useState('') + const { tenantId } = useWhoAmI() + + const { isPending, data, hasNextPage, fetchNextPage } = useInfiniteQuery({ + queryKey: ['taskRun', selectedStatus, tenantId, 10, createdAfter, createdBefore], + initialPageParam: undefined, + getNextPageParam: (lastPage: PaginatedTaskRunList) => lastPage.bookmarkAsString, + queryFn: async ({ pageParam }) => { + return await searchTaskRun({ + tenantId, + bookmarkAsString: pageParam, + limit: 10, + status: selectedStatus == 'ALL' ? undefined : selectedStatus, + taskDefName: spec.id?.name || '', + earliestStart: createdAfter ? localDateTimeToUTCIsoString(createdAfter) : undefined, + latestStart: createdBefore ? localDateTimeToUTCIsoString(createdBefore) : undefined, + }) + }, + }) return ( <>
+
+
+

Related Task Run's:

+ +
+
+ + + ) => setCreatedAfter(e.target.value)} + className="focus:shadow-outline ml-3 w-full appearance-none rounded border px-3 py-2 leading-tight shadow focus:outline-none" + /> + + + + + ) => setCreatedBefore(e.target.value)} + className="focus:shadow-outline ml-4 w-full appearance-none rounded border px-3 py-2 leading-tight shadow focus:outline-none" + /> + +
+ + {isPending ? ( +
+ +
+ ) : ( +
+ + + + + + + + + + {data?.pages.map((page, i) => ( + + {page.resultsWithDetails.length > 0 ? ( + page.resultsWithDetails.map(({ taskRun }) => { + return ( + + + + + + + ) + }) + ) : ( + + + + )} + + ))} + +
+ WfRun Id + + Task GUID + + Creation Date +
+ + {concatWfRunIds(taskRun.id?.wfRunId!)} + + {taskRun.id?.taskGuid} + {taskRun.scheduledAt ? utcToLocalDateTime(taskRun.scheduledAt) : 'N/A'} +
No data
+
+ )} ) } diff --git a/dashboard/src/app/(authenticated)/userTaskDef/[...props]/components/UserTaskDef.tsx b/dashboard/src/app/(authenticated)/userTaskDef/[...props]/components/UserTaskDef.tsx index ea7a51875..ce68d5975 100644 --- a/dashboard/src/app/(authenticated)/userTaskDef/[...props]/components/UserTaskDef.tsx +++ b/dashboard/src/app/(authenticated)/userTaskDef/[...props]/components/UserTaskDef.tsx @@ -77,7 +77,7 @@ export const UserTaskDef: FC = ({ spec }) => {
-

Related User Task Run's:

+

Related User Task Runs:

{userTaskPossibleStatuses.map(status => (