fix(striker-ui): link server list preview to VNC

main
Tsu-ba-me 3 years ago
parent e3b5688779
commit 6dfa7e6b70
  1. 39
      striker-ui/components/Display/FullSize.tsx
  2. 33
      striker-ui/components/Display/Preview.tsx
  3. 8
      striker-ui/pages/index.tsx
  4. 19
      striker-ui/pages/server/index.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 dynamic from 'next/dynamic';
import { import {
Box, Box,
Button, Button,
IconButton, IconButton,
IconButtonProps,
Menu, Menu,
MenuItem, MenuItem,
Typography, Typography,
@ -92,22 +93,32 @@ const StyledDiv = styled('div')(() => ({
const VncDisplay = dynamic(() => import('./VncDisplay'), { ssr: false }); const VncDisplay = dynamic(() => import('./VncDisplay'), { ssr: false });
interface FullSizeProps { type FullSizeOptionalProps = {
setMode: Dispatch<SetStateAction<boolean>>; onClickCloseButton?: IconButtonProps['onClick'];
};
type FullSizeProps = FullSizeOptionalProps & {
serverUUID: string; serverUUID: string;
serverName: string | string[] | undefined; serverName: string | string[] | undefined;
} };
interface VncConnectionProps { type VncConnectionProps = {
protocol: string; protocol: string;
forward_port: number; forward_port: number;
} };
const FullSize = ({ const FULL_SIZE_DEFAULT_PROPS: Required<
setMode, Omit<FullSizeOptionalProps, 'onClickCloseButton'>
> &
Pick<FullSizeOptionalProps, 'onClickCloseButton'> = {
onClickCloseButton: undefined,
};
const FullSize: FC<FullSizeProps> = ({
onClickCloseButton,
serverUUID, serverUUID,
serverName, serverName,
}: FullSizeProps): JSX.Element => { }): JSX.Element => {
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null); const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
const rfb = useRef<typeof RFB>(); const rfb = useRef<typeof RFB>();
const hostname = useRef<string | undefined>(undefined); const hostname = useRef<string | undefined>(undefined);
@ -196,9 +207,13 @@ const FullSize = ({
className={classes.closeButton} className={classes.closeButton}
style={{ color: TEXT }} style={{ color: TEXT }}
component="span" component="span"
onClick={() => { onClick={(
...args: Parameters<
Exclude<IconButtonProps['onClick'], undefined>
>
) => {
handleClickClose(); handleClickClose();
setMode(true); onClickCloseButton?.call(null, ...args);
}} }}
> >
<CloseIcon /> <CloseIcon />
@ -270,4 +285,6 @@ const FullSize = ({
); );
}; };
FullSize.defaultProps = FULL_SIZE_DEFAULT_PROPS;
export default FullSize; export default FullSize;

@ -1,12 +1,9 @@
import { FC, ReactNode, useEffect, useState } from 'react';
import { import {
Dispatch, Box,
FC, IconButton as MUIIconButton,
ReactNode, IconButtonProps as MUIIconButtonProps,
SetStateAction, } from '@mui/material';
useEffect,
useState,
} from 'react';
import { Box, IconButton as MUIIconButton } from '@mui/material';
import { import {
DesktopWindows as DesktopWindowsIcon, DesktopWindows as DesktopWindowsIcon,
PowerOffOutlined as PowerOffOutlinedIcon, PowerOffOutlined as PowerOffOutlinedIcon,
@ -15,7 +12,7 @@ import {
import API_BASE_URL from '../../lib/consts/API_BASE_URL'; import API_BASE_URL from '../../lib/consts/API_BASE_URL';
import { BORDER_RADIUS, GREY } from '../../lib/consts/DEFAULT_THEME'; 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 { InnerPanel, InnerPanelHeader, Panel, PanelHeader } from '../Panels';
import { BodyText, HeaderText } from '../Text'; import { BodyText, HeaderText } from '../Text';
@ -26,23 +23,28 @@ type PreviewOptionalProps = {
isFetchPreview?: boolean; isFetchPreview?: boolean;
isShowControls?: boolean; isShowControls?: boolean;
isUseInnerPanel?: boolean; isUseInnerPanel?: boolean;
onClickConnectButton?: IconButtonProps['onClick'];
onClickPreview?: MUIIconButtonProps['onClick'];
serverName?: string; serverName?: string;
setMode?: Dispatch<SetStateAction<boolean>> | null;
}; };
type PreviewProps = PreviewOptionalProps & { type PreviewProps = PreviewOptionalProps & {
serverUUID: string; serverUUID: string;
}; };
const PREVIEW_DEFAULT_PROPS: Required<PreviewOptionalProps> = { const PREVIEW_DEFAULT_PROPS: Required<
Omit<PreviewOptionalProps, 'onClickConnectButton' | 'onClickPreview'>
> &
Pick<PreviewOptionalProps, 'onClickConnectButton' | 'onClickPreview'> = {
externalPreview: '', externalPreview: '',
headerEndAdornment: null, headerEndAdornment: null,
isExternalPreviewStale: false, isExternalPreviewStale: false,
isFetchPreview: true, isFetchPreview: true,
isShowControls: true, isShowControls: true,
isUseInnerPanel: false, isUseInnerPanel: false,
onClickConnectButton: undefined,
onClickPreview: undefined,
serverName: '', serverName: '',
setMode: null,
}; };
const PreviewPanel: FC<{ isUseInnerPanel: boolean }> = ({ const PreviewPanel: FC<{ isUseInnerPanel: boolean }> = ({
@ -78,9 +80,10 @@ const Preview: FC<PreviewProps> = ({
isFetchPreview = PREVIEW_DEFAULT_PROPS.isFetchPreview, isFetchPreview = PREVIEW_DEFAULT_PROPS.isFetchPreview,
isShowControls = PREVIEW_DEFAULT_PROPS.isShowControls, isShowControls = PREVIEW_DEFAULT_PROPS.isShowControls,
isUseInnerPanel = PREVIEW_DEFAULT_PROPS.isUseInnerPanel, isUseInnerPanel = PREVIEW_DEFAULT_PROPS.isUseInnerPanel,
onClickPreview: previewClickHandler,
serverName, serverName,
serverUUID, serverUUID,
setMode, onClickConnectButton: connectButtonClickHandle = previewClickHandler,
}) => { }) => {
const [isPreviewStale, setIsPreviewStale] = useState<boolean>(false); const [isPreviewStale, setIsPreviewStale] = useState<boolean>(false);
const [preview, setPreview] = useState<string>(''); const [preview, setPreview] = useState<string>('');
@ -130,7 +133,7 @@ const Preview: FC<PreviewProps> = ({
<Box> <Box>
<MUIIconButton <MUIIconButton
component="span" component="span"
onClick={() => setMode?.call(null, false)} onClick={previewClickHandler}
sx={{ sx={{
borderRadius: BORDER_RADIUS, borderRadius: BORDER_RADIUS,
color: GREY, color: GREY,
@ -161,7 +164,7 @@ const Preview: FC<PreviewProps> = ({
</Box> </Box>
{isShowControls && ( {isShowControls && (
<Box> <Box>
<IconButton onClick={() => setMode?.call(null, false)}> <IconButton onClick={connectButtonClickHandle}>
<DesktopWindowsIcon /> <DesktopWindowsIcon />
</IconButton> </IconButton>
</Box> </Box>

@ -75,10 +75,12 @@ const createServerPreviewContainer = (
isShowControls={false} isShowControls={false}
isUseInnerPanel isUseInnerPanel
key={`server-preview-${serverUUID}`} key={`server-preview-${serverUUID}`}
serverUUID={serverUUID} onClickPreview={() => {
setMode={() => { router.push(
router.push(`/server?uuid=${serverUUID}&server_name=${serverName}`); `/server?uuid=${serverUUID}&server_name=${serverName}&vnc=1`,
);
}} }}
serverUUID={serverUUID}
/> />
), ),
)} )}

@ -1,4 +1,4 @@
import { useState } from 'react'; import { useEffect, useState } from 'react';
import { useRouter } from 'next/router'; import { useRouter } from 'next/router';
import Head from 'next/head'; import Head from 'next/head';
import { Box } from '@mui/material'; import { Box } from '@mui/material';
@ -35,10 +35,17 @@ const Server = (): JSX.Element => {
const [previewMode, setPreviewMode] = useState<boolean>(true); const [previewMode, setPreviewMode] = useState<boolean>(true);
const router = useRouter(); 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 serverUUID: string = uuid?.toString() || '';
const serverName: string = server_name?.toString() || ''; const serverName: string = server_name?.toString() || '';
useEffect(() => {
if (isConnectVNC) {
setPreviewMode(false);
}
}, [isConnectVNC]);
return ( return (
<StyledDiv> <StyledDiv>
<Head> <Head>
@ -48,7 +55,9 @@ const Server = (): JSX.Element => {
{previewMode ? ( {previewMode ? (
<Box className={classes.preview}> <Box className={classes.preview}>
<Preview <Preview
setMode={setPreviewMode} onClickPreview={() => {
setPreviewMode(false);
}}
serverName={serverName} serverName={serverName}
serverUUID={serverUUID} serverUUID={serverUUID}
/> />
@ -56,7 +65,9 @@ const Server = (): JSX.Element => {
) : ( ) : (
<Box className={classes.fullView}> <Box className={classes.fullView}>
<FullSize <FullSize
setMode={setPreviewMode} onClickCloseButton={() => {
setPreviewMode(true);
}}
serverUUID={serverUUID} serverUUID={serverUUID}
serverName={serverName} serverName={serverName}
/> />

Loading…
Cancel
Save