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 authored and yomybaby committed Nov 15, 2024
1 parent b082f8a commit 752f0d5
Show file tree
Hide file tree
Showing 40 changed files with 927 additions and 552 deletions.
1 change: 1 addition & 0 deletions react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"@cloudscape-design/board-components": "3.0.60",
"@codemirror/language": "^6.10.2",
"@melloware/react-logviewer": "^5.2.4",
"@react-hook/resize-observer": "^2.0.2",
"@storybook/test": "^8.2.8",
"@tanstack/react-query": "^5.51.15",
"@testing-library/jest-dom": "^6.4.8",
Expand Down
34 changes: 33 additions & 1 deletion react/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
108 changes: 108 additions & 0 deletions react/src/components/ActionItemContent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import Flex from './Flex';
import useResizeObserver from '@react-hook/resize-observer';
import { Button, Divider, Typography, theme } from 'antd';
import { useEffect, useRef, useState } from 'react';

Check warning on line 4 in react/src/components/ActionItemContent.tsx

View workflow job for this annotation

GitHub Actions / coverage

'useEffect' is defined but never used

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);

useResizeObserver(containerRef, (entry) => {
entry.contentRect.width <= 200 ? setNeedScroll(true) : setNeedScroll(false);
});

return (
<Flex
ref={containerRef}
align="center"
justify="between"
direction="column"
style={{
height: '100%',
textAlign: 'center',
overflowY: 'auto',
//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
Loading

0 comments on commit 752f0d5

Please sign in to comment.