From 01f6c5d6f278cb9bf4c683a9d7f16ea21f3117ee Mon Sep 17 00:00:00 2001 From: Danil Kostromin Date: Thu, 28 Nov 2024 03:41:35 +0300 Subject: [PATCH] refactor(run): [results] use extracted drawer dialog for preview Signed-off-by: Danil Kostromin --- .../src/lib/result-links.container.tsx | 210 ++---------------- 1 file changed, 13 insertions(+), 197 deletions(-) diff --git a/libs/bublik/features/result-links/src/lib/result-links.container.tsx b/libs/bublik/features/result-links/src/lib/result-links.container.tsx index 8aa2a250..4ba138d3 100644 --- a/libs/bublik/features/result-links/src/lib/result-links.container.tsx +++ b/libs/bublik/features/result-links/src/lib/result-links.container.tsx @@ -1,6 +1,5 @@ /* SPDX-License-Identifier: Apache-2.0 */ /* SPDX-FileCopyrightText: 2021-2023 OKTET Labs Ltd. */ -import { useCallback, useState } from 'react'; import { Link } from 'react-router-dom'; import { @@ -8,35 +7,11 @@ import { RunDataResults, RunDetailsAPIResponse } from '@/shared/types'; -import { - getErrorMessage, - useGetLogJsonQuery, - useGetRunDetailsQuery, - useGetTreeByRunIdQuery, - usePrefetch -} from '@/services/bublik-api'; +import { useGetRunDetailsQuery, usePrefetch } from '@/services/bublik-api'; import { routes } from '@/router'; -import { - ButtonTw, - CardHeader, - cn, - DialogClose, - DialogOverlay, - dialogOverlayStyles, - DialogPortal, - DrawerContent, - DrawerRoot, - DrawerTrigger, - getBugProps, - Icon, - NewBugButton, - Skeleton -} from '@/shared/tailwind-ui'; +import { Icon } from '@/shared/tailwind-ui'; import { useUserPreferences } from '@/bublik/features/user-preferences'; -import { - LogTableContextProvider, - SessionRoot -} from '@/bublik/features/session-log'; +import { LogPreviewContainer } from '@/bublik/features/log-preview-drawer'; import { LinkToHistory } from './link-to-history'; @@ -113,181 +88,22 @@ export const ResultLinks = (props: ResultLinksProps) => { logName={result.name} resultId={resultId} runId={Number(runId)} - /> + > + + ); }; -interface LogPreviewContainerProps { - resultId: number; - runId: number; - logName: string; -} - -function LogPreviewContainer(props: LogPreviewContainerProps) { - const { resultId, runId, logName } = props; - const [open, setOpen] = useState(false); - - return ( - - - - - - - -
- {/* To fetch only on mount. Do not remove check */} - {open ? ( -
-
- -
- - - - Log - - - - - - - - -
-
-
- -
- ) : null} -
-
-
-
- ); -} - -interface NewBugProps { - runId: number; - resultId: number; -} - -function NewBug(props: NewBugProps) { - const { data: details } = useGetRunDetailsQuery(props.runId); - const { data: log } = useGetLogJsonQuery({ id: props.resultId }); - const { data: tree } = useGetTreeByRunIdQuery(String(props.runId)); - - if (!details || !tree || !log) return null; - - return ( - - ); -} - -interface LogPreviewProps { - resultId: number; -} - -function LogPreview(props: LogPreviewProps) { - const { resultId } = props; - const [page, setPage] = useState(); - const { data, error, isLoading, isFetching } = useGetLogJsonQuery({ - id: resultId, - page: typeof page !== 'undefined' ? page.toString() : undefined - }); - - const handlePageClick = useCallback( - (_: string, page: number) => { - setPage(page); - }, - [setPage] - ); - - if (isLoading) { - return ; - } - - if (error) { - return ; - } - - if (!data) { - return ; - } - - return ( -
- - - -
- ); -} - -interface LogPreviewErrorProps { - error: unknown; -} - -function LogPreviewError({ error }: LogPreviewErrorProps) { - const { description, status, title } = getErrorMessage(error); - - return ( -
-
- -
-

- {status} {title} -

-

{description}

-
-
-
- ); -} - -function LogPreviewLoading() { - return ( -
- -
- ); -} - -function LogPreviewEmpty() { - return
No log data...
; -} - export interface ActionLinksProps { runId: string; resultId: number;