Skip to content

Commit

Permalink
feat: WebUI NEO start page
Browse files Browse the repository at this point in the history
  • Loading branch information
ironAiken2 committed Nov 6, 2024
1 parent 337fc3a commit d51430b
Show file tree
Hide file tree
Showing 38 changed files with 907 additions and 551 deletions.
24 changes: 16 additions & 8 deletions react/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const ServingPage = React.lazy(() => import('./pages/ServingPage'));
const EndpointDetailPage = React.lazy(
() => import('./pages/EndpointDetailPage'),
);
// const SummaryPage = React.lazy(() => import('./pages/SummaryPage'));
const StartPage = React.lazy(() => import('./pages/StartPage'));
const EnvironmentPage = React.lazy(() => import('./pages/EnvironmentPage'));
const MyEnvironmentPage = React.lazy(() => import('./pages/MyEnvironmentPage'));
const StorageHostSettingPage = React.lazy(
Expand Down Expand Up @@ -61,9 +61,9 @@ const ComputeSessionList = React.lazy(
() => import('./components/ComputeSessionList'),
);

const RedirectToSummary = () => {
const RedirectToStart = () => {
useSuspendedBackendaiClient();
const pathName = '/summary';
const pathName = '/start';
document.dispatchEvent(
new CustomEvent('move-to-from-react', {
detail: {
Expand All @@ -72,7 +72,7 @@ const RedirectToSummary = () => {
},
}),
);
return <Navigate to="/summary" replace />;
return <Navigate to="/start" replace />;
};

const router = createBrowserRouter([
Expand Down Expand Up @@ -109,17 +109,26 @@ const router = createBrowserRouter([
children: [
{
path: '/',
element: <RedirectToSummary />,
element: <RedirectToStart />,
},
{
//for electron dev mode
path: '/build/electron-app/app/index.html',
element: <RedirectToSummary />,
element: <RedirectToStart />,
},
{
//for electron prod mode
path: '/app/index.html',
element: <RedirectToSummary />,
element: <RedirectToStart />,
},
{
path: '/start',
element: (
<BAIErrorBoundary>
<StartPage />
</BAIErrorBoundary>
),
handle: { labelKey: 'webui.menu.Start' },
},
{
path: '/summary',
Expand All @@ -134,7 +143,6 @@ const router = createBrowserRouter([
style={{ marginBottom: token.paddingContentVerticalLG }}
closable
/>
{/* <SummaryPage /> */}
</>
);
},
Expand Down
122 changes: 122 additions & 0 deletions react/src/components/ActionItemContent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import Flex from './Flex';
import { Button, Divider, Typography, theme } from 'antd';
import { useEffect, useRef, useState } from 'react';

interface StartItemContentProps {
title: string;
description?: string;
icon?: React.ReactNode;
buttonText: string;
onClick?: () => void;
themeColor?: string;
iconBgColor?: string;
}

const ActionItemContent: React.FC<StartItemContentProps> = ({
title,
description,
icon,
buttonText,
onClick,
themeColor,
iconBgColor,
}) => {
const { token } = theme.useToken();
const [needScroll, setNeedScroll] = useState<boolean>(false);
const containerRef = useRef<HTMLDivElement>(null);

useEffect(() => {
const handleResize = () => {
if (containerRef.current) {
const { clientWidth } = containerRef.current;
// Currently, the minimum width for non-scrollable content is 220px (Start an Interactive Session Card)
if (clientWidth <= 225) {
setNeedScroll(true);
} else {
setNeedScroll(false);
}
}
};
handleResize();
window.addEventListener('resize', handleResize);
return () => {
window.removeEventListener('resize', handleResize);
};
}, []);

return (
<Flex
ref={containerRef}
align="center"
justify="between"
direction="column"
style={{
height: '100%',
textAlign: 'center',
overflowY: 'scroll',
//TODO: This is a temporary fix for the padding issue. It should be served from BAIBoard.
paddingTop: token.marginMD,
}}
>
<Flex direction="column" gap={token.marginSM}>
<Flex
align="center"
justify="center"
style={{
borderRadius: 25,
width: 50,
height: 50,
//TODO: This is a temporary default background color for the icon. It should be served as a token.
backgroundColor: iconBgColor ? iconBgColor : token['green-1'],
}}
>
{icon}
</Flex>
<Flex style={{ minHeight: 60 }}>
<Typography.Text
strong
style={{
fontSize: token.fontSizeHeading4,
color: themeColor ? themeColor : token.colorPrimary,
}}
>
{title}
</Typography.Text>
</Flex>
<Typography.Text
type="secondary"
style={{ fontSize: token.fontSizeSM }}
>
{!needScroll && description}
</Typography.Text>
</Flex>
<Flex direction="column" style={{ width: '100%' }}>
{description && (
<Divider style={{ margin: token.marginSM, borderWidth: 2 }} />
)}
<Flex style={{ width: '100%', padding: `0 ${token.paddingMD}px` }}>
<Button
type="primary"
style={{
width: '100%',
height: 40,
backgroundColor: themeColor ? themeColor : token.colorPrimary,
}}
onClick={onClick}
>
<Typography.Text
style={{
fontSize: token.fontSizeHeading5,
color: token.colorWhite,
}}
>
{buttonText}
</Typography.Text>
</Button>
</Flex>
</Flex>
</Flex>
);
};

export default ActionItemContent;
40 changes: 22 additions & 18 deletions react/src/components/BAIBoard.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Flex from './Flex';
import Board, { BoardProps } from '@cloudscape-design/board-components/board';
import BoardItem from '@cloudscape-design/board-components/board-item';
import { Skeleton, Typography } from 'antd';
import { Skeleton } from 'antd';
import { createStyles } from 'antd-style';
import { Suspense } from 'react';

Expand All @@ -23,29 +22,31 @@ const useStyles = createStyles(({ css }) => {
board: css`
${defaultBoard}
`,
disableCustomize: css`
${defaultBoard}
.bai_board_handle {
disableResize: css`
.bai_board_resizer {
display: none !important;
}
.bai_board_resizer {
`,
disableMove: css`
.bai_board_handle {
display: none !important;
}
.bai_board_header {
height: var(--token-boardHeaderHeight, 55px) !important;
display: none !important;
}
`,
boardItems: css`
& > div:first-child {
border: 1px solid var(--token-colorBorder) !important ;
border: none !important ;
border-radius: var(--token-borderRadius) !important ;
background-color: var(--token-colorBgContainer) !important ;
}
& > div:first-child > div:first-child > div:first-child {
border-bottom: 1px solid var(--token-colorBorder) !important;
margin-bottom: var(--token-margin);
background-color: var(--token-colorBgContainer) !important ;
position: absolute;
z-index: 1;
}
`,
};
Expand All @@ -56,19 +57,27 @@ interface BAICustomizableGridProps {
onItemsChange: (
event: CustomEvent<BoardProps.ItemsChangeDetail<unknown>>,
) => void;
customizable?: boolean;
resizable?: boolean;
movable?: boolean;
}

const BAIBoard: React.FC<BAICustomizableGridProps> = ({
items: parsedItems,
customizable = false,
resizable = false,
movable = false,
...BoardProps
}) => {
const { styles } = useStyles();

const boardStyles = [
styles.board,
!movable && styles.disableMove,
!resizable && styles.disableResize,
].join(' ');

return (
<Board
//@ts-ignore
className={customizable ? styles.board : styles.disableCustomize}
className={boardStyles}
empty
renderItem={(item: any) => {
return (
Expand All @@ -82,11 +91,6 @@ const BAIBoard: React.FC<BAICustomizableGridProps> = ({
resizeHandleAriaLabel: '',
resizeHandleAriaDescription: '',
}}
header={
<Flex style={{ height: '100%' }} align="center">
<Typography.Text strong>{item.data.title}</Typography.Text>
</Flex>
}
>
<Suspense fallback={<Skeleton active />}>
{item.data.content}
Expand Down
6 changes: 6 additions & 0 deletions react/src/components/MainLayout/WebUISider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
FileDoneOutlined,
HddOutlined,
InfoCircleOutlined,
PlayCircleOutlined,
RocketOutlined,
SolutionOutlined,
ToolOutlined,
Expand Down Expand Up @@ -70,6 +71,11 @@ const WebUISider: React.FC<WebUISiderProps> = (props) => {
const [isOpenSignoutModal, { toggle: toggleSignoutModal }] = useToggle(false);

const generalMenu = filterEmptyItem<ItemType>([
{
label: t('webui.menu.Start'),
icon: <PlayCircleOutlined />,
key: 'start',
},
{
label: t('webui.menu.Summary'),
icon: <DashboardOutlined />,
Expand Down
92 changes: 0 additions & 92 deletions react/src/components/SummaryPageItems/SummaryItemDownloadApp.tsx

This file was deleted.

Loading

0 comments on commit d51430b

Please sign in to comment.