Skip to content

Commit

Permalink
feat: Session list NEO
Browse files Browse the repository at this point in the history
  • Loading branch information
yomybaby committed Jan 6, 2025
1 parent 059d576 commit 2cb5723
Show file tree
Hide file tree
Showing 15 changed files with 527 additions and 50 deletions.
6 changes: 3 additions & 3 deletions react/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ const UserCredentialsPage = React.lazy(
() => import('./pages/UserCredentialsPage'),
);

const ComputeSessionList = React.lazy(
() => import('./components/ComputeSessionList'),
const ComputeSessionListPage = React.lazy(
() => import('./pages/ComputeSessionListPage'),
);
const AgentSummaryPage = React.lazy(() => import('./pages/AgentSummaryPage'));

Expand Down Expand Up @@ -142,7 +142,7 @@ const router = createBrowserRouter([
handle: { labelKey: 'webui.menu.Sessions' },
element: (
<BAIErrorBoundary>
<ComputeSessionList />
<ComputeSessionListPage />
</BAIErrorBoundary>
),
},
Expand Down
2 changes: 1 addition & 1 deletion react/src/components/BAILink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const useStyles = createStyles(({ css, token }) => ({
}));

interface BAILinkProps extends LinkProps {
type: 'hover';
type?: 'hover';
}
const BAILink: React.FC<BAILinkProps> = ({ type, ...linkProps }) => {
const { styles } = useStyles();
Expand Down
2 changes: 1 addition & 1 deletion react/src/components/BAIPropertyFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function trimFilterValue(filterValue: string): string {
}

export function mergeFilterValues(
filterStrings: Array<string | undefined>,
filterStrings: Array<string | undefined | null>,
operator: string = '&',
) {
const mergedFilter = _.join(
Expand Down
51 changes: 36 additions & 15 deletions react/src/components/BAITable.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { useDebounce } from 'ahooks';
import { GetProps, Table } from 'antd';
import { ConfigProvider, GetProps, Table } from 'antd';
import { createStyles } from 'antd-style';
import { ColumnsType, ColumnType } from 'antd/es/table';
import { TableProps } from 'antd/lib';
import { ComponentToken } from 'antd/lib/table/style';
import _ from 'lodash';
import { useEffect, useMemo, useRef, useState } from 'react';
import { Resizable, ResizeCallbackData } from 'react-resizable';
Expand All @@ -23,6 +24,11 @@ const useStyles = createStyles(({ token, css }) => ({
whitespace: 'pre';
wordwrap: 'break-word';
}
thead.ant-table-thead > tr > th.ant-table-cell {
font-weight: 500;
color: ${token.colorTextTertiary};
}
`,
}));

Expand Down Expand Up @@ -94,6 +100,7 @@ const ResizableTitle = (
interface BAITableProps<RecordType extends object = any>
extends TableProps<RecordType> {
resizable?: boolean;
tableComponentToken?: ComponentToken;
}

const columnKeyOrIndexKey = (column: any, index: number) =>
Expand All @@ -110,6 +117,7 @@ const BAITable = <RecordType extends object = any>({
resizable = false,
columns,
components,
tableComponentToken,
...tableProps
}: BAITableProps<RecordType>) => {
const { styles } = useStyles();
Expand Down Expand Up @@ -145,22 +153,35 @@ const BAITable = <RecordType extends object = any>({
}, [resizable, columns, resizedColumnWidths]);

return (
<Table
sortDirections={['descend', 'ascend', 'descend']}
showSorterTooltip={false}
className={resizable ? styles.resizableTable : ''}
components={
resizable
? _.merge(components || {}, {
header: {
cell: ResizableTitle,
<ConfigProvider
theme={
tableComponentToken
? {
components: {
Table: tableComponentToken,
},
})
: components
}
: undefined
}
columns={mergedColumns}
{...tableProps}
/>
>
<Table
size="small"
sortDirections={['descend', 'ascend', 'descend']}
showSorterTooltip={false}
className={resizable ? styles.resizableTable : ''}
components={
resizable
? _.merge(components || {}, {
header: {
cell: ResizableTitle,
},
})
: components
}
columns={mergedColumns}
{...tableProps}
/>
</ConfigProvider>
);
};

Expand Down
11 changes: 0 additions & 11 deletions react/src/components/ComputeSessionList.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { convertBinarySizeUnit } from '../../helper';
import { useResourceSlotsDetails } from '../../hooks/backendai';
import { SessionOccupiedSlotFragment$key } from './__generated__/SessionOccupiedSlotFragment.graphql';
import { Divider, Typography } from 'antd';
import graphql from 'babel-plugin-relay/macro';
import _ from 'lodash';
import React from 'react';
import { useFragment } from 'react-relay';

interface OccupiedSlotViewProps {
sessionFrgmt: SessionOccupiedSlotFragment$key;
type: 'cpu' | 'mem' | 'accelerator';
}
const SessionOccupiedSlot: React.FC<OccupiedSlotViewProps> = ({
type,
sessionFrgmt,
}) => {
const { deviceMetadata } = useResourceSlotsDetails();
const session = useFragment(
graphql`
fragment SessionOccupiedSlotFragment on ComputeSessionNode {
id
occupied_slots
}
`,
sessionFrgmt,
);

const occupiedSlots = JSON.parse(session.occupied_slots || '{}');

if (type === 'cpu') {
return occupiedSlots.cpu ?? '-';
} else if (type === 'mem') {
const mem = occupiedSlots.mem ?? '-';
return mem === '-' ? mem : convertBinarySizeUnit(mem, 'G')?.number + ' GiB';
} else if (type === 'accelerator') {
const occupiedAccelerators = _.omit(occupiedSlots, ['cpu', 'mem']);
return _.isEmpty(occupiedAccelerators)
? '-'
: _.map(occupiedAccelerators, (value, key) => {
return (
<>
<Typography.Text>{value}</Typography.Text>
<Divider type="vertical" />
<Typography.Text>
{deviceMetadata?.[key]?.human_readable_name}
</Typography.Text>
</>
);
});
}
};

export default SessionOccupiedSlot;
33 changes: 18 additions & 15 deletions react/src/components/ComputeSessionNodeItems/SessionReservation.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { formatDurationAsDays } from '../../helper';
import { useSuspendedBackendaiClient } from '../../hooks';

Check warning on line 2 in react/src/components/ComputeSessionNodeItems/SessionReservation.tsx

View workflow job for this annotation

GitHub Actions / coverage

'useSuspendedBackendaiClient' is defined but never used
import BAIIntervalView from '../BAIIntervalView';
import DoubleTag from '../DoubleTag';
Expand All @@ -10,8 +11,8 @@ import { useFragment } from 'react-relay';

const SessionReservation: React.FC<{
sessionFrgmt: SessionReservationFragment$key;
}> = ({ sessionFrgmt }) => {
const baiClient = useSuspendedBackendaiClient();
mode?: 'simple-elapsed' | 'detail';
}> = ({ sessionFrgmt, mode = 'detail' }) => {
const { t } = useTranslation();
const session = useFragment(
graphql`
Expand All @@ -25,25 +26,27 @@ const SessionReservation: React.FC<{
);
return (
<>
{dayjs(session.created_at).format('lll')}
{mode !== 'simple-elapsed' && dayjs(session.created_at).format('lll')}
<BAIIntervalView
key={session.id}
callback={() => {
return session?.created_at
? baiClient.utils.elapsedTime(
session.created_at,
session?.terminated_at,
)
? formatDurationAsDays(session.created_at, session?.terminated_at)
: '-';
}}
delay={1000}
render={(intervalValue) => (
<DoubleTag
values={[
{ label: t('session.ElapsedTime') },
{ label: intervalValue },
]}
/>
)}
render={(intervalValue) =>
mode === 'simple-elapsed' ? (
intervalValue
) : (
<DoubleTag
values={[
{ label: t('session.ElapsedTime') },
{ label: intervalValue },
]}
/>
)
}
/>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useFragment } from 'react-relay';

interface SessionStatusTagProps {
sessionFrgmt?: SessionStatusTagFragment$key | null;
showInfo?: boolean;
}
const statusTagColor = {
//prepare
Expand Down Expand Up @@ -51,6 +52,7 @@ const statusInfoTagColor = {
};
const SessionStatusTag: React.FC<SessionStatusTagProps> = ({
sessionFrgmt,
showInfo,
}) => {
const session = useFragment(
graphql`
Expand All @@ -66,7 +68,7 @@ const SessionStatusTag: React.FC<SessionStatusTagProps> = ({
const { token } = theme.useToken();

return session ? (
_.isEmpty(session.status_info) ? (
_.isEmpty(session.status_info) || !showInfo ? (
<Tag
color={
session.status ? _.get(statusTagColor, session.status) : undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ const TerminateSessionModal: React.FC<TerminateSessionModalProps> = ({
`,
sessionFrgmt,
);

const [isForce, setIsForce] = useState(false);
const userRole = useCurrentUserRole();

Expand Down
2 changes: 1 addition & 1 deletion react/src/components/SessionDetailContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ const SessionDetailContent: React.FC<{
label={t('session.Status')}
contentStyle={{ display: 'flex', gap: token.marginSM }}
>
<SessionStatusTag sessionFrgmt={session} />
<SessionStatusTag sessionFrgmt={session} showInfo />
{/* <Button type="text" icon={<TriangleAlertIcon />} /> */}
</Descriptions.Item>
<Descriptions.Item label={t('session.SessionType')}>
Expand Down
Loading

0 comments on commit 2cb5723

Please sign in to comment.