diff --git a/striker-ui/components/Display/FullSize.tsx b/striker-ui/components/Display/FullSize.tsx index 15f8fe2b..ff75f1d6 100644 --- a/striker-ui/components/Display/FullSize.tsx +++ b/striker-ui/components/Display/FullSize.tsx @@ -1,9 +1,10 @@ -import { useState, useRef, useEffect, Dispatch, SetStateAction } from 'react'; +import { useState, useRef, useEffect, FC } from 'react'; import dynamic from 'next/dynamic'; import { Box, Button, IconButton, + IconButtonProps, Menu, MenuItem, Typography, @@ -92,22 +93,32 @@ const StyledDiv = styled('div')(() => ({ const VncDisplay = dynamic(() => import('./VncDisplay'), { ssr: false }); -interface FullSizeProps { - setMode: Dispatch>; +type FullSizeOptionalProps = { + onClickCloseButton?: IconButtonProps['onClick']; +}; + +type FullSizeProps = FullSizeOptionalProps & { serverUUID: string; serverName: string | string[] | undefined; -} +}; -interface VncConnectionProps { +type VncConnectionProps = { protocol: string; forward_port: number; -} +}; -const FullSize = ({ - setMode, +const FULL_SIZE_DEFAULT_PROPS: Required< + Omit +> & + Pick = { + onClickCloseButton: undefined, +}; + +const FullSize: FC = ({ + onClickCloseButton, serverUUID, serverName, -}: FullSizeProps): JSX.Element => { +}): JSX.Element => { const [anchorEl, setAnchorEl] = useState(null); const rfb = useRef(); const hostname = useRef(undefined); @@ -196,9 +207,13 @@ const FullSize = ({ className={classes.closeButton} style={{ color: TEXT }} component="span" - onClick={() => { + onClick={( + ...args: Parameters< + Exclude + > + ) => { handleClickClose(); - setMode(true); + onClickCloseButton?.call(null, ...args); }} > @@ -270,4 +285,6 @@ const FullSize = ({ ); }; +FullSize.defaultProps = FULL_SIZE_DEFAULT_PROPS; + export default FullSize; diff --git a/striker-ui/components/Display/Preview.tsx b/striker-ui/components/Display/Preview.tsx index 4f79c491..a56a9ca1 100644 --- a/striker-ui/components/Display/Preview.tsx +++ b/striker-ui/components/Display/Preview.tsx @@ -1,12 +1,9 @@ +import { FC, ReactNode, useEffect, useState } from 'react'; import { - Dispatch, - FC, - ReactNode, - SetStateAction, - useEffect, - useState, -} from 'react'; -import { Box, IconButton as MUIIconButton } from '@mui/material'; + Box, + IconButton as MUIIconButton, + IconButtonProps as MUIIconButtonProps, +} from '@mui/material'; import { DesktopWindows as DesktopWindowsIcon, PowerOffOutlined as PowerOffOutlinedIcon, @@ -15,7 +12,7 @@ import { import API_BASE_URL from '../../lib/consts/API_BASE_URL'; import { BORDER_RADIUS, GREY } from '../../lib/consts/DEFAULT_THEME'; -import IconButton from '../IconButton'; +import IconButton, { IconButtonProps } from '../IconButton'; import { InnerPanel, InnerPanelHeader, Panel, PanelHeader } from '../Panels'; import { BodyText, HeaderText } from '../Text'; @@ -26,23 +23,28 @@ type PreviewOptionalProps = { isFetchPreview?: boolean; isShowControls?: boolean; isUseInnerPanel?: boolean; + onClickConnectButton?: IconButtonProps['onClick']; + onClickPreview?: MUIIconButtonProps['onClick']; serverName?: string; - setMode?: Dispatch> | null; }; type PreviewProps = PreviewOptionalProps & { serverUUID: string; }; -const PREVIEW_DEFAULT_PROPS: Required = { +const PREVIEW_DEFAULT_PROPS: Required< + Omit +> & + Pick = { externalPreview: '', headerEndAdornment: null, isExternalPreviewStale: false, isFetchPreview: true, isShowControls: true, isUseInnerPanel: false, + onClickConnectButton: undefined, + onClickPreview: undefined, serverName: '', - setMode: null, }; const PreviewPanel: FC<{ isUseInnerPanel: boolean }> = ({ @@ -78,9 +80,10 @@ const Preview: FC = ({ isFetchPreview = PREVIEW_DEFAULT_PROPS.isFetchPreview, isShowControls = PREVIEW_DEFAULT_PROPS.isShowControls, isUseInnerPanel = PREVIEW_DEFAULT_PROPS.isUseInnerPanel, + onClickPreview: previewClickHandler, serverName, serverUUID, - setMode, + onClickConnectButton: connectButtonClickHandle = previewClickHandler, }) => { const [isPreviewStale, setIsPreviewStale] = useState(false); const [preview, setPreview] = useState(''); @@ -130,7 +133,7 @@ const Preview: FC = ({ setMode?.call(null, false)} + onClick={previewClickHandler} sx={{ borderRadius: BORDER_RADIUS, color: GREY, @@ -161,7 +164,7 @@ const Preview: FC = ({ {isShowControls && ( - setMode?.call(null, false)}> + diff --git a/striker-ui/pages/index.tsx b/striker-ui/pages/index.tsx index f0acd0ac..778fc754 100644 --- a/striker-ui/pages/index.tsx +++ b/striker-ui/pages/index.tsx @@ -75,10 +75,12 @@ const createServerPreviewContainer = ( isShowControls={false} isUseInnerPanel key={`server-preview-${serverUUID}`} - serverUUID={serverUUID} - setMode={() => { - router.push(`/server?uuid=${serverUUID}&server_name=${serverName}`); + onClickPreview={() => { + router.push( + `/server?uuid=${serverUUID}&server_name=${serverName}&vnc=1`, + ); }} + serverUUID={serverUUID} /> ), )} diff --git a/striker-ui/pages/server/index.tsx b/striker-ui/pages/server/index.tsx index c77b502a..be7cdd0a 100644 --- a/striker-ui/pages/server/index.tsx +++ b/striker-ui/pages/server/index.tsx @@ -1,4 +1,4 @@ -import { useState } from 'react'; +import { useEffect, useState } from 'react'; import { useRouter } from 'next/router'; import Head from 'next/head'; import { Box } from '@mui/material'; @@ -35,10 +35,17 @@ const Server = (): JSX.Element => { const [previewMode, setPreviewMode] = useState(true); const router = useRouter(); - const { uuid, server_name } = router.query; + const { server_name, uuid, vnc } = router.query; + const isConnectVNC: boolean = (vnc?.toString() || '').length > 0; const serverUUID: string = uuid?.toString() || ''; const serverName: string = server_name?.toString() || ''; + useEffect(() => { + if (isConnectVNC) { + setPreviewMode(false); + } + }, [isConnectVNC]); + return ( @@ -48,7 +55,9 @@ const Server = (): JSX.Element => { {previewMode ? ( { + setPreviewMode(false); + }} serverName={serverName} serverUUID={serverUUID} /> @@ -56,7 +65,9 @@ const Server = (): JSX.Element => { ) : ( { + setPreviewMode(true); + }} serverUUID={serverUUID} serverName={serverName} />