From 1d606ea20db13f0477262065b4e81f06d650315e Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Fri, 1 Dec 2023 15:29:42 -0500 Subject: [PATCH] fix(striker-ui): allow open VNC connection in new tab from dashboard --- striker-ui/components/Display/Preview.tsx | 70 ++++++++++++++++------- striker-ui/pages/index.tsx | 17 ++---- 2 files changed, 54 insertions(+), 33 deletions(-) diff --git a/striker-ui/components/Display/Preview.tsx b/striker-ui/components/Display/Preview.tsx index 7b9af5e9..8c5b1dc8 100644 --- a/striker-ui/components/Display/Preview.tsx +++ b/striker-ui/components/Display/Preview.tsx @@ -27,6 +27,7 @@ type PreviewOptionalProps = { externalPreview?: string; externalTimestamp?: number; headerEndAdornment?: ReactNode; + hrefPreview?: string; isExternalLoading?: boolean; isExternalPreviewStale?: boolean; isFetchPreview?: boolean; @@ -43,12 +44,19 @@ type PreviewProps = PreviewOptionalProps & { }; const PREVIEW_DEFAULT_PROPS: Required< - Omit + Omit< + PreviewOptionalProps, + 'hrefPreview' | 'onClickConnectButton' | 'onClickPreview' + > > & - Pick = { + Pick< + PreviewOptionalProps, + 'hrefPreview' | 'onClickConnectButton' | 'onClickPreview' + > = { externalPreview: '', externalTimestamp: 0, headerEndAdornment: null, + hrefPreview: undefined, isExternalLoading: false, isExternalPreviewStale: false, isFetchPreview: true, @@ -90,6 +98,7 @@ const Preview: FC = ({ externalPreview = PREVIEW_DEFAULT_PROPS.externalPreview, externalTimestamp = PREVIEW_DEFAULT_PROPS.externalTimestamp, headerEndAdornment, + hrefPreview, isExternalLoading = PREVIEW_DEFAULT_PROPS.isExternalLoading, isExternalPreviewStale = PREVIEW_DEFAULT_PROPS.isExternalPreviewStale, isFetchPreview = PREVIEW_DEFAULT_PROPS.isFetchPreview, @@ -153,6 +162,44 @@ const Preview: FC = ({ ], ); + const iconButton = useMemo(() => { + if (isPreviewLoading) { + return ; + } + + const disabled = !preview; + const sx: MUIIconButtonProps['sx'] = { + borderRadius: BORDER_RADIUS, + color: GREY, + padding: 0, + }; + + if (hrefPreview) { + return ( + + {previewButtonContent} + + ); + } + + return ( + + {previewButtonContent} + + ); + }, [ + hrefPreview, + isPreviewLoading, + preview, + previewButtonContent, + previewClickHandler, + ]); + useEffect(() => { if (isFetchPreview) { (async () => { @@ -195,24 +242,7 @@ const Preview: FC = ({ :first-child': { flexGrow: 1 } }}> {/* Box wrapper below is required to keep external preview size sane. */} - - {isPreviewLoading ? ( - - ) : ( - - {previewButtonContent} - - )} - + {iconButton} {isShowControls && preview && ( diff --git a/striker-ui/pages/index.tsx b/striker-ui/pages/index.tsx index b4d7986b..3b727915 100644 --- a/striker-ui/pages/index.tsx +++ b/striker-ui/pages/index.tsx @@ -1,7 +1,6 @@ import { Add as AddIcon } from '@mui/icons-material'; import { Box, Divider, Grid } from '@mui/material'; import Head from 'next/head'; -import { NextRouter, useRouter } from 'next/router'; import { FC, useEffect, useRef, useState } from 'react'; import API_BASE_URL from '../lib/consts/API_BASE_URL'; @@ -28,10 +27,7 @@ type ServerListItem = ServerOverviewMetadata & { timestamp: number; }; -const createServerPreviewContainer = ( - servers: ServerListItem[], - router: NextRouter, -) => ( +const createServerPreviewContainer = (servers: ServerListItem[]) => ( , ]} + hrefPreview={`/server?uuid=${serverUUID}&server_name=${serverName}&server_state=${serverState}&vnc=1`} isExternalLoading={loading} isExternalPreviewStale={isScreenshotStale} isFetchPreview={false} isShowControls={false} isUseInnerPanel - onClickPreview={() => { - router.push( - `/server?uuid=${serverUUID}&server_name=${serverName}&server_state=${serverState}&vnc=1`, - ); - }} serverState={serverState} serverUUID={serverUUID} /> @@ -129,7 +121,6 @@ const filterServers = (allServers: ServerListItem[], searchTerm: string) => const Dashboard: FC = () => { const componentMountedRef = useRef(true); - const router = useRouter(); const [allServers, setAllServers] = useState([]); const [excludeServers, setExcludeServers] = useState([]); @@ -244,11 +235,11 @@ const Dashboard: FC = () => { value={inputSearchTerm} /> - {createServerPreviewContainer(includeServers, router)} + {createServerPreviewContainer(includeServers)} {includeServers.length > 0 && ( )} - {createServerPreviewContainer(excludeServers, router)} + {createServerPreviewContainer(excludeServers)} )}