Skip to content

Commit 0122984

Browse files
committed
refactor: Endpoint list loading state management
1 parent f71c345 commit 0122984

File tree

3 files changed

+64
-93
lines changed

3 files changed

+64
-93
lines changed

react/src/App.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import AnnouncementAlert from './components/AnnouncementAlert';
2+
import BAICard from './components/BAICard';
23
import BAIErrorBoundary, { ErrorView } from './components/BAIErrorBoundary';
34
import {
45
DefaultProvidersForReactRoot,
@@ -15,6 +16,7 @@ import VFolderListPage from './pages/VFolderListPage';
1516
import { Skeleton, theme } from 'antd';
1617
import React, { Suspense } from 'react';
1718
import { FC } from 'react';
19+
import { useTranslation } from 'react-i18next';
1820
import {
1921
IndexRouteObject,
2022
RouterProvider,
@@ -176,14 +178,13 @@ const router = createBrowserRouter([
176178
const [experimentalNeoSessionList] = useBAISettingUserState(
177179
'experimental_neo_session_list',
178180
);
181+
const { t } = useTranslation();
179182

180183
return experimentalNeoSessionList ? (
181184
<BAIErrorBoundary>
182185
<Suspense
183186
fallback={
184-
<Flex direction="column" style={{ maxWidth: 700 }}>
185-
<Skeleton active />
186-
</Flex>
187+
<BAICard title={t('webui.menu.Sessions')} loading />
187188
}
188189
>
189190
<ComputeSessionListPage />

react/src/components/EndpointList.tsx

Lines changed: 14 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ import {
44
filterNonNullItems,
55
transformSorterToOrderString,
66
} from '../helper';
7-
import {
8-
useSuspendedBackendaiClient,
9-
useUpdatableState,
10-
useWebUINavigate,
11-
} from '../hooks';
7+
import { useSuspendedBackendaiClient, useWebUINavigate } from '../hooks';
128
import { useCurrentUserInfo, useCurrentUserRole } from '../hooks/backendai';
139
import { useBAIPaginationOptionState } from '../hooks/reactPaginationQueryOptions';
1410
// import { getSortOrderByName } from '../hooks/reactPaginationQueryOptions';
@@ -29,23 +25,16 @@ import {
2925
CheckOutlined,
3026
CloseOutlined,
3127
DeleteOutlined,
32-
LoadingOutlined,
33-
ReloadOutlined,
3428
SettingOutlined,
3529
} from '@ant-design/icons';
36-
import { useRafInterval, useToggle } from 'ahooks';
30+
import { useToggle } from 'ahooks';
3731
import { Button, Typography, theme, Radio, App, Tooltip } from 'antd';
3832
import { ColumnType } from 'antd/lib/table';
3933
import graphql from 'babel-plugin-relay/macro';
4034
import { default as dayjs } from 'dayjs';
4135
import _ from 'lodash';
4236
import { InfoIcon } from 'lucide-react';
43-
import React, {
44-
PropsWithChildren,
45-
useState,
46-
useTransition,
47-
startTransition as startTransitionWithoutPendingState,
48-
} from 'react';
37+
import React, { PropsWithChildren, useState, useTransition } from 'react';
4938
import { useTranslation } from 'react-i18next';
5039
import { useLazyLoadQuery } from 'react-relay';
5140
import { Link } from 'react-router-dom';
@@ -75,8 +64,15 @@ type LifecycleStage = 'created&destroying' | 'destroyed';
7564

7665
interface EndpointListProps extends PropsWithChildren {
7766
style?: React.CSSProperties;
67+
fetchKey?: string;
68+
onDeleted?: (endpoint: Endpoint) => void;
7869
}
79-
const EndpointList: React.FC<EndpointListProps> = ({ style, children }) => {
70+
const EndpointList: React.FC<EndpointListProps> = ({
71+
style,
72+
fetchKey,
73+
onDeleted,
74+
children,
75+
}) => {
8076
const { t } = useTranslation();
8177
const { token } = theme.useToken();
8278
const { message, modal } = App.useApp();
@@ -98,11 +94,8 @@ const EndpointList: React.FC<EndpointListProps> = ({ style, children }) => {
9894
? `lifecycle_stage == "created" | lifecycle_stage == "destroying"`
9995
: `lifecycle_stage == "${selectedLifecycleStage}"`;
10096

101-
const [isRefetchPending, startRefetchTransition] = useTransition();
10297
const [isFilterPending, startFilterTransition] = useTransition();
10398
const [isPendingPageChange, startPageChangeTransition] = useTransition();
104-
const [servicesFetchKey, updateServicesFetchKey] =
105-
useUpdatableState('initial-fetch');
10699
const [optimisticDeletingId, setOptimisticDeletingId] = useState<
107100
string | null
108101
>();
@@ -212,9 +205,7 @@ const EndpointList: React.FC<EndpointListProps> = ({ style, children }) => {
212205
row.endpoint_id &&
213206
terminateModelServiceMutation.mutate(row?.endpoint_id, {
214207
onSuccess: (res) => {
215-
startRefetchTransition(() => {
216-
updateServicesFetchKey();
217-
});
208+
onDeleted?.(row);
218209
// FIXME: temporally refer to mutate input to message
219210
if (res.success) {
220211
message.success(
@@ -318,12 +309,6 @@ const EndpointList: React.FC<EndpointListProps> = ({ style, children }) => {
318309
const [hiddenColumnKeys, setHiddenColumnKeys] =
319310
useHiddenColumnKeysSetting('EndpointListPage');
320311

321-
useRafInterval(() => {
322-
startTransitionWithoutPendingState(() => {
323-
updateServicesFetchKey();
324-
});
325-
}, 7000);
326-
327312
const { endpoint_list: modelServiceList } =
328313
useLazyLoadQuery<EndpointListQuery>(
329314
graphql`
@@ -388,7 +373,7 @@ const EndpointList: React.FC<EndpointListProps> = ({ style, children }) => {
388373
},
389374
{
390375
fetchPolicy: 'network-only',
391-
fetchKey: servicesFetchKey,
376+
fetchKey,
392377
},
393378
);
394379

@@ -506,34 +491,12 @@ const EndpointList: React.FC<EndpointListProps> = ({ style, children }) => {
506491
</>
507492
)}
508493
</Flex>
509-
<Flex direction="row" gap={'xs'}>
510-
<Flex gap={'xs'}>
511-
<Button
512-
icon={<ReloadOutlined />}
513-
loading={isRefetchPending}
514-
onClick={() => {
515-
startRefetchTransition(() => updateServicesFetchKey());
516-
}}
517-
/>
518-
<Button
519-
type="primary"
520-
onClick={() => {
521-
webuiNavigate('/service/start');
522-
}}
523-
>
524-
{t('modelService.StartService')}
525-
</Button>
526-
</Flex>
527-
</Flex>
528494
</Flex>
529495
<Flex direction="column" align="stretch">
530496
<BAITable
531497
neoStyle
532498
size="small"
533-
loading={{
534-
spinning: isFilterPending || isPendingPageChange,
535-
indicator: <LoadingOutlined />,
536-
}}
499+
loading={isFilterPending || isPendingPageChange}
537500
scroll={{ x: 'max-content' }}
538501
rowKey={'endpoint_id'}
539502
dataSource={filterNonNullItems(modelServiceList?.items)}

react/src/pages/ServingPage.tsx

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1+
import BAICard from '../components/BAICard';
2+
import BAIFetchKeyButton from '../components/BAIFetchKeyButton';
13
import Flex from '../components/Flex';
24
import { filterEmptyItem } from '../helper';
3-
import { Card, Skeleton, theme } from 'antd';
5+
import { useUpdatableState, useWebUINavigate } from '../hooks';
6+
import { ReloadOutlined } from '@ant-design/icons';
7+
import { Button, Card, Skeleton, theme } from 'antd';
48
import React, { Suspense } from 'react';
59
import { useTranslation } from 'react-i18next';
610
import { StringParam, useQueryParam, withDefault } from 'use-query-params';
711

812
// FIXME: need to apply filtering type of service later
913
type TabKey = 'services' | 'chatting'; // "running" | "finished" | "others";
1014

11-
const EndpointListPage = React.lazy(() => import('./EndpointListPage'));
15+
const EndpointList = React.lazy(() => import('../components/EndpointList'));
1216

1317
interface ServingPageProps {}
1418

@@ -17,34 +21,36 @@ const tabParam = withDefault(StringParam, 'services');
1721
const ServingPage: React.FC<ServingPageProps> = ({ ...props }) => {
1822
const { t } = useTranslation();
1923
const { token } = theme.useToken();
20-
const [curTabKey, setCurTabKey] = useQueryParam('tab', tabParam, {
21-
updateType: 'replace',
22-
});
24+
const webuiNavigate = useWebUINavigate();
25+
26+
const [fetchKey, updateFetchKey] = useUpdatableState('initial-fetch');
2327

24-
const tabList = filterEmptyItem([
25-
{ key: 'services', label: t('modelService.Services') },
26-
// FIXME: need to apply filtering type of service later
27-
// {
28-
// key: "running",
29-
// label: t("session.Running"),
30-
// },
31-
// {
32-
// key: "finished",
33-
// label: t("session.Finished"),
34-
// },
35-
// {
36-
// key: "others",
37-
// label: t("session.Others"),
38-
// },
39-
]);
4028
return (
4129
<Flex direction="column" align="stretch" gap={'md'}>
42-
<Card
43-
activeTabKey={curTabKey}
44-
onTabChange={(key) => {
45-
setCurTabKey(key as TabKey);
46-
}}
47-
tabList={tabList}
30+
<BAICard
31+
title={t('modelService.Services')}
32+
extra={
33+
<Flex direction="row" gap={'xs'}>
34+
<Flex gap={'xs'}>
35+
<BAIFetchKeyButton
36+
value={fetchKey}
37+
onChange={() => {
38+
updateFetchKey();
39+
// startRefetchTransition(() => updateServicesFetchKey());
40+
}}
41+
autoUpdateDelay={7000}
42+
/>
43+
<Button
44+
type="primary"
45+
onClick={() => {
46+
webuiNavigate('/service/start');
47+
}}
48+
>
49+
{t('modelService.StartService')}
50+
</Button>
51+
</Flex>
52+
</Flex>
53+
}
4854
styles={{
4955
body: {
5056
padding: 0,
@@ -53,18 +59,19 @@ const ServingPage: React.FC<ServingPageProps> = ({ ...props }) => {
5359
},
5460
}}
5561
>
56-
{curTabKey === 'services' ? (
57-
<Suspense
58-
fallback={<Skeleton active style={{ padding: token.paddingMD }} />}
59-
>
60-
<EndpointListPage
61-
style={{
62-
padding: token.paddingMD,
63-
}}
64-
/>
65-
</Suspense>
66-
) : null}
67-
</Card>
62+
<Suspense
63+
fallback={<Skeleton active style={{ padding: token.paddingMD }} />}
64+
>
65+
<EndpointList
66+
style={{
67+
padding: token.paddingMD,
68+
}}
69+
onDeleted={() => {
70+
updateFetchKey();
71+
}}
72+
/>
73+
</Suspense>
74+
</BAICard>
6875
</Flex>
6976
);
7077
};

0 commit comments

Comments
 (0)