From a5b6e66e22d1806aca7befd49aeccb9c41a53d2e Mon Sep 17 00:00:00 2001 From: Ali BARIN Date: Wed, 10 Aug 2022 20:59:29 +0200 Subject: [PATCH] feat: add header with id, name, date in Execution --- .../src/graphql/queries/get-execution.ts | 3 +- .../src/components/ExecutionHeader/index.tsx | 59 +++++++++++++++++++ .../web/src/graphql/queries/get-execution.ts | 17 ++++++ packages/web/src/pages/Execution/index.tsx | 26 ++++---- 4 files changed, 89 insertions(+), 16 deletions(-) create mode 100644 packages/web/src/components/ExecutionHeader/index.tsx create mode 100644 packages/web/src/graphql/queries/get-execution.ts diff --git a/packages/backend/src/graphql/queries/get-execution.ts b/packages/backend/src/graphql/queries/get-execution.ts index 0b6e149e..f687d5df 100644 --- a/packages/backend/src/graphql/queries/get-execution.ts +++ b/packages/backend/src/graphql/queries/get-execution.ts @@ -16,7 +16,8 @@ const getExecution = async ( steps: true } }) - .findById(params.executionId); + .findById(params.executionId) + .throwIfNotFound(); return execution; }; diff --git a/packages/web/src/components/ExecutionHeader/index.tsx b/packages/web/src/components/ExecutionHeader/index.tsx new file mode 100644 index 00000000..2db8e37f --- /dev/null +++ b/packages/web/src/components/ExecutionHeader/index.tsx @@ -0,0 +1,59 @@ +import * as React from 'react'; +import { DateTime } from 'luxon'; +import Stack from '@mui/material/Stack'; +import Box from '@mui/material/Box'; +import Tooltip from '@mui/material/Tooltip'; +import Typography from '@mui/material/Typography'; +import type { IExecution } from '@automatisch/types'; + +type ExecutionHeaderProps = { + execution: IExecution; +}; + +function ExecutionName(props: Pick) { + return ( + {props.name} + ); +} + +function ExecutionId(props: Pick) { + return ( + + + Execution ID: {props.id} + + + ); +} + +function ExecutionDate(props: Pick) { + const createdAt = DateTime.fromMillis( + parseInt(props.createdAt, 10) + ); + const relativeCreatedAt = createdAt.toRelative(); + + return ( + + {relativeCreatedAt} + + ); +} + +export default function ExecutionHeader(props: ExecutionHeaderProps): React.ReactElement { + const { execution } = props; + + if (!execution) return ; + + return ( + + + + + + + + + + + ); +} diff --git a/packages/web/src/graphql/queries/get-execution.ts b/packages/web/src/graphql/queries/get-execution.ts new file mode 100644 index 00000000..22303351 --- /dev/null +++ b/packages/web/src/graphql/queries/get-execution.ts @@ -0,0 +1,17 @@ +import { gql } from '@apollo/client'; + +export const GET_EXECUTION = gql` + query GetExecution($executionId: String!) { + getExecution(executionId: $executionId) { + id + testRun + createdAt + updatedAt + flow { + id + name + active + } + } + } +`; diff --git a/packages/web/src/pages/Execution/index.tsx b/packages/web/src/pages/Execution/index.tsx index 0c4ffcf0..ee2410d0 100644 --- a/packages/web/src/pages/Execution/index.tsx +++ b/packages/web/src/pages/Execution/index.tsx @@ -4,15 +4,17 @@ import { useQuery } from '@apollo/client'; import Grid from '@mui/material/Grid'; import type { IExecutionStep } from '@automatisch/types'; +import ExecutionHeader from 'components/ExecutionHeader'; import ExecutionStep from 'components/ExecutionStep'; import Container from 'components/Container'; +import { GET_EXECUTION } from 'graphql/queries/get-execution'; import { GET_EXECUTION_STEPS } from 'graphql/queries/get-execution-steps'; type ExecutionParams = { executionId: string; }; -const EXECUTION_PER_PAGE = 5; +const EXECUTION_PER_PAGE = 100; const getLimitAndOffset = (page: number) => ({ limit: EXECUTION_PER_PAGE, @@ -21,25 +23,19 @@ const getLimitAndOffset = (page: number) => ({ export default function Execution(): React.ReactElement { const { executionId } = useParams() as ExecutionParams; - const { data, fetchMore } = useQuery(GET_EXECUTION_STEPS, { variables: { executionId, ...getLimitAndOffset(1) } }); + const { data: execution } = useQuery(GET_EXECUTION, { variables: { executionId } }); + const { data } = useQuery(GET_EXECUTION_STEPS, { variables: { executionId, ...getLimitAndOffset(1) } }); - const { edges, pageInfo } = data?.getExecutionSteps || {}; + const { edges } = data?.getExecutionSteps || {}; const executionSteps: IExecutionStep[] = edges?.map((edge: { node: IExecutionStep }) => edge.node); - React.useEffect(() => { - if (pageInfo?.currentPage < pageInfo?.totalPages) { - fetchMore({ - variables: { - executionId, - ...getLimitAndOffset(pageInfo.currentPage + 1), - } - }); - } - }, [executionId, fetchMore, pageInfo]); - return ( - + + + {executionSteps?.map((executionStep) => ( ))}