Skip to content

Commit

Permalink
refactor: set default page to start instead of summary page
Browse files Browse the repository at this point in the history
  • Loading branch information
lizable authored and agatha197 committed Aug 30, 2024
1 parent 2b694bb commit 19bbcdb
Show file tree
Hide file tree
Showing 17 changed files with 37 additions and 48 deletions.
14 changes: 7 additions & 7 deletions react/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ const InteractiveLoginPage = React.lazy(
);
const ImportAndRunPage = React.lazy(() => import('./pages/ImportAndRunPage'));

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

const router = createBrowserRouter([
Expand Down Expand Up @@ -110,17 +110,17 @@ 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',
Expand All @@ -140,7 +140,7 @@ const router = createBrowserRouter([
</>
);
},
handle: { labelKey: 'webui.menu.Summary' },
handle: { labelKey: 'start' },
},
{
path: '/job',
Expand Down
1 change: 0 additions & 1 deletion react/src/components/BAIMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ConfigProvider, Menu, MenuProps, theme } from 'antd';
import _ from 'lodash';
import React from 'react';

interface BAIMenuProps extends MenuProps {
Expand Down
3 changes: 1 addition & 2 deletions react/src/components/MainLayout/MainLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import BAIErrorBoundary from '../BAIErrorBoundary';
import BAISider from '../BAISider';
import Flex from '../Flex';
import ForceTOTPChecker from '../ForceTOTPChecker';
import NetworkStatusBanner from '../NetworkStatusBanner';
import PasswordChangeRequestAlert from '../PasswordChangeRequestAlert';
import { DRAWER_WIDTH } from '../WEBUINotificationDrawer';
import WebUIHeader from './WebUIHeader';
import WebUISider from './WebUISider';
import { App, Button, Layout, Space, theme } from 'antd';
import { App, Layout, theme } from 'antd';
import { atom, useSetAtom } from 'jotai';
import { Suspense, useEffect, useLayoutEffect, useRef, useState } from 'react';
import { useNavigate, Outlet } from 'react-router-dom';
Expand Down
8 changes: 2 additions & 6 deletions react/src/components/MainLayout/WebUIHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useCustomThemeConfig } from '../../helper/customThemeConfig';
import { useCurrentDomainValue } from '../../hooks';
import { useSuspendedBackendaiClient, useWebUINavigate } from '../../hooks';
import { useWebUINavigate } from '../../hooks';
import {
useCurrentProjectValue,
useSetCurrentProject,
Expand All @@ -16,12 +16,9 @@ import { DRAWER_WIDTH } from '../WEBUINotificationDrawer';
import WebUIThemeToggleButton from '../WebUIThemeToggleButton';
// @ts-ignore
import rawCss from './WebUIHeader.css?raw';
import { MenuOutlined } from '@ant-design/icons';
import { theme, Button, Typography, Grid } from 'antd';
import _ from 'lodash';
import { theme, Typography, Grid } from 'antd';
import { Suspense, useState, useTransition } from 'react';
import { useTranslation } from 'react-i18next';
import { useMatches } from 'react-router-dom';

export interface WebUIHeaderProps extends FlexProps {
onClickMenuIcon?: () => void;
Expand All @@ -38,7 +35,6 @@ const WebUIHeader: React.FC<WebUIHeaderProps> = ({
const currentDomainName = useCurrentDomainValue();
const currentProject = useCurrentProjectValue();
const setCurrentProject = useSetCurrentProject();
const matches = useMatches();
const { y: scrolled } = useScrollBreakPoint(
{
y: 1,
Expand Down
7 changes: 2 additions & 5 deletions react/src/components/MainLayout/WebUISider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@ import TrailsIcon from '../icons/TrailsIcon';
import { PluginPage, WebUIPluginType } from './MainLayout';
import {
ApiOutlined,
BarChartOutlined,
BarsOutlined,
CloudUploadOutlined,
ControlOutlined,
DashboardOutlined,
ExportOutlined,
FileDoneOutlined,
HddOutlined,
InfoCircleOutlined,
PlayCircleOutlined,
RocketOutlined,
SolutionOutlined,
ToolOutlined,
UserOutlined,
Expand All @@ -32,7 +31,6 @@ import { useToggle } from 'ahooks';
import { theme, MenuProps, Typography } from 'antd';
import { ItemType } from 'antd/lib/menu/interface';
import _ from 'lodash';
import { PlayIcon } from 'lucide-react';
import React from 'react';
import { useTranslation } from 'react-i18next';
import { useLocation } from 'react-router-dom';
Expand Down Expand Up @@ -62,7 +60,6 @@ const WebUISider: React.FC<WebUISiderProps> = (props) => {
const location = useLocation();
const baiClient = useSuspendedBackendaiClient();

const isHideAgents = baiClient?._config?.hideAgents ?? true;
const fasttrackEndpoint = baiClient?._config?.fasttrackEndpoint ?? null;
const blockList = baiClient?._config?.blockList ?? null;
const inactiveList = baiClient?._config?.inactiveList ?? null;
Expand Down Expand Up @@ -408,7 +405,7 @@ const WebUISider: React.FC<WebUISiderProps> = (props) => {
<BAIMenu
isAdminMenu={true}
selectedKeys={[
location.pathname.split('/')[1] || 'summary',
location.pathname.split('/')[1] || 'start',
// TODO: After matching first path of 'storage-settings' and 'agent', remove this code
location.pathname.split('/')[1] === 'storage-settings' ? 'agent' : '',
// TODO: After 'SessionListPage' is completed and used as the main page, remove this code
Expand Down
4 changes: 2 additions & 2 deletions react/src/components/UserDropdownMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ const UserProfileSettingModal = React.lazy(
() => import('./UserProfileSettingModal'),
);

interface UserDropdownMenu {
interface UserDropdownMenuProps {
iconColor?: string;
color?: string;
}

const UserDropdownMenu: React.FC<UserDropdownMenu> = ({ ...props }) => {
const UserDropdownMenu: React.FC<UserDropdownMenuProps> = ({ ...props }) => {
const { t } = useTranslation();
const { token } = theme.useToken();
const [userInfo] = useCurrentUserInfo();
Expand Down
5 changes: 1 addition & 4 deletions react/src/components/icons/SessionsIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { ReactComponent as logo } from './Sessions.svg';
import Icon from '@ant-design/icons';
import {
CustomIconComponentProps,
IconComponentProps,
} from '@ant-design/icons/lib/components/Icon';
import { CustomIconComponentProps } from '@ant-design/icons/lib/components/Icon';

interface SessionsIconProps
extends Omit<CustomIconComponentProps, 'width' | 'height' | 'fill'> {}
Expand Down
5 changes: 1 addition & 4 deletions react/src/components/icons/TrailsIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { ReactComponent as logo } from './Trails.svg';
import Icon from '@ant-design/icons';
import {
CustomIconComponentProps,
IconComponentProps,
} from '@ant-design/icons/lib/components/Icon';
import { CustomIconComponentProps } from '@ant-design/icons/lib/components/Icon';

interface TrailsIconProps
extends Omit<CustomIconComponentProps, 'width' | 'height' | 'fill'> {}
Expand Down
6 changes: 1 addition & 5 deletions react/src/pages/StartPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import BatchSessionIcon from '../components/icons/BatchSessionIcon';
import ExampleStartIcon from '../components/icons/ExampleStart';
import InteractiveSessionIcon from '../components/icons/InteractiveSession';
import ModelServiceIcon from '../components/icons/ModelServiceIcon';
import URLStartIcon from '../components/icons/URLStartIcon';
import { useWebUINavigate } from '../hooks';
import { FolderAddOutlined } from '@ant-design/icons';
import React from 'react';
Expand Down Expand Up @@ -107,10 +106,7 @@ const StartPage: React.FC<StartPageProps> = (props) => {
secondary
icon={
// FIXME: workaround for displaying proper icon
<img
src="react/src/components/icons/URLStart.svg"
alt="URL start"
></img>
<img src="/resources/icons/URLStart.svg" alt="URL start"></img>
// <URLStartIcon />
}
title={
Expand Down
7 changes: 7 additions & 0 deletions resources/icons/URLStart.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/backend-ai-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const navigate =
}
let page;
if (['/', 'build', '/build', 'app', '/app'].includes(path)) {
page = 'summary';
page = 'start';
} else if (path[0] === '/') {
page = path.slice(1);
} else {
Expand Down Expand Up @@ -85,7 +85,7 @@ const loadPage =
(page, params: Record<string, unknown> = {}) =>
(dispatch) => {
switch (page) {
case 'summary':
case 'start':
import('./components/backend-ai-summary-view.js').then((module) => {
// TODO: after page changing?
});
Expand Down
6 changes: 3 additions & 3 deletions src/components/backend-ai-error-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ export default class BackendAIErrorView extends BackendAIPage {
* @param {string} url - page to redirect from the current page.
*/
_moveTo(url = '') {
const page = url !== '' ? url : 'summary';
globalThis.history.pushState({}, '', '/summary');
const page = url !== '' ? url : 'start';
globalThis.history.pushState({}, '', '/start');
store.dispatch(navigate(decodeURIComponent('/' + page), {}));
document.dispatchEvent(
new CustomEvent('react-navigate', {
Expand All @@ -98,7 +98,7 @@ export default class BackendAIErrorView extends BackendAIPage {
fullwidth
id="go-to-summary"
label="${_t('button.GoBackToSummaryPage')}"
@click="${() => this._moveTo('summary')}"
@click="${() => this._moveTo('start')}"
></mwc-button>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/components/backend-ai-permission-denied-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export default class BackendAIPermissionDeniedView extends BackendAIPage {
* @param {string} url - page to redirect from the current page.
*/
_moveTo(url = '') {
const page = url !== '' ? url : 'summary';
const page = url !== '' ? url : 'start';
globalThis.history.pushState({}, '', '/summary');
store.dispatch(navigate(decodeURIComponent('/' + page), {}));
}
Expand All @@ -135,7 +135,7 @@ export default class BackendAIPermissionDeniedView extends BackendAIPage {
fullwidth
id="go-to-summary"
label="${_t('button.GoBackToSummaryPage')}"
@click="${() => this._moveTo('summary')}"
@click="${() => this._moveTo('start')}"
></mwc-button>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/backend-ai-storage-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@ export default class BackendAiStorageList extends BackendAIPage {
* @param {string} url - page to redirect from the current page.
*/
_moveTo(url = '') {
const page = url !== '' ? url : 'summary';
const page = url !== '' ? url : 'start';
// globalThis.history.pushState({}, '', page);
store.dispatch(navigate(decodeURIComponent(page), {}));

Expand Down
2 changes: 1 addition & 1 deletion src/components/backend-ai-storage-proxy-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export default class BackendAIStorageProxyList extends BackendAIPage {
* @param {string} url - page to redirect from the current page.
*/
_moveTo(url = '') {
const page = url !== '' ? url : 'summary';
const page = url !== '' ? url : 'start';
// globalThis.history.pushState({}, '', page);
store.dispatch(navigate(decodeURIComponent(page), {}));

Expand Down
2 changes: 1 addition & 1 deletion src/components/backend-ai-summary-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ export default class BackendAISummary extends BackendAIPage {
* @param {string} search
*/
_moveTo(url = '', search: string | undefined = undefined) {
const page = url !== '' ? url : 'summary';
const page = url !== '' ? url : 'start';
// globalThis.history.pushState({}, '', page);
store.dispatch(navigate(decodeURIComponent(page), {}));

Expand Down
5 changes: 3 additions & 2 deletions src/components/backend-ai-webui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ export default class BackendAIWebUI extends connect(store)(LitElement) {
@property({ type: Number }) sidepanelWidth = 250;
@property({ type: Object }) supports = Object();
@property({ type: Array }) availablePages = [
'summary',
// 'summary',
'start',
'verify-email',
'change-password',
'job',
Expand Down Expand Up @@ -719,7 +720,7 @@ export default class BackendAIWebUI extends connect(store)(LitElement) {
*/
_loadPageElement() {
if (this._page === 'index.html' || this._page === '') {
this._page = 'summary';
this._page = 'start';
navigate(decodeURIComponent('/'));
}
}
Expand Down

0 comments on commit 19bbcdb

Please sign in to comment.