-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
45 changed files
with
1,227 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import SessionDetailDrawer from './SessionDetailDrawer'; | ||
import React from 'react'; | ||
import { StringParam, useQueryParam } from 'use-query-params'; | ||
|
||
const ComputeSessionList = () => { | ||
const [sessionId, setSessionId] = useQueryParam('sessionDetail', StringParam); | ||
return ( | ||
<SessionDetailDrawer | ||
open={!sessionId} | ||
sessionId={sessionId || undefined} | ||
onClose={() => { | ||
setSessionId(null, 'replaceIn'); | ||
}} | ||
/> | ||
); | ||
}; | ||
|
||
export default ComputeSessionList; |
84 changes: 84 additions & 0 deletions
84
react/src/components/ComputeSessionNodeItems/EditableSessionName.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { EditableSessionNameFragment$key } from './__generated__/EditableSessionNameFragment.graphql'; | ||
import { EditableSessionNameMutation } from './__generated__/EditableSessionNameMutation.graphql'; | ||
import { theme } from 'antd'; | ||
import Text, { TextProps } from 'antd/es/typography/Text'; | ||
import Title, { TitleProps } from 'antd/es/typography/Title'; | ||
import graphql from 'babel-plugin-relay/macro'; | ||
import React, { useState } from 'react'; | ||
import { useFragment, useMutation } from 'react-relay'; | ||
|
||
type EditableSessionNameProps = { | ||
sessionFrgmt: EditableSessionNameFragment$key; | ||
} & ( | ||
| ({ component?: typeof Text } & Omit<TextProps, 'children'>) | ||
| ({ component: typeof Title } & Omit<TitleProps, 'children'>) | ||
); | ||
|
||
const EditableSessionName: React.FC<EditableSessionNameProps> = ({ | ||
component: Component = Text, | ||
sessionFrgmt, | ||
style, | ||
...otherProps | ||
}) => { | ||
const session = useFragment( | ||
graphql` | ||
fragment EditableSessionNameFragment on ComputeSessionNode { | ||
id | ||
name | ||
priority | ||
} | ||
`, | ||
sessionFrgmt, | ||
); | ||
const [optimisticName, setOptimisticName] = useState(session.name); | ||
const { token } = theme.useToken(); | ||
const [commitEditMutation, isPendingEditMutation] = | ||
useMutation<EditableSessionNameMutation>(graphql` | ||
mutation EditableSessionNameMutation($input: ModifyComputeSessionInput!) { | ||
modify_compute_session(input: $input) { | ||
item { | ||
id | ||
name | ||
} | ||
} | ||
} | ||
`); | ||
return ( | ||
session && ( | ||
<Component | ||
editable={ | ||
isPendingEditMutation | ||
? undefined | ||
: { | ||
onChange: (newName) => { | ||
setOptimisticName(newName); | ||
commitEditMutation({ | ||
variables: { | ||
input: { | ||
id: session.id, | ||
name: newName, | ||
// TODO: priority는 옵션이어야한다. 하지만 API 버그 때문에 유지 | ||
priority: session.priority, | ||
}, | ||
}, | ||
onCompleted(response, errors) {}, | ||
onError(error) {}, | ||
}); | ||
}, | ||
triggerType: ['icon', 'text'], | ||
} | ||
} | ||
copyable | ||
style={{ | ||
...style, | ||
color: isPendingEditMutation ? token.colorTextTertiary : style?.color, | ||
}} | ||
{...otherProps} | ||
> | ||
{isPendingEditMutation ? optimisticName : session.name} | ||
</Component> | ||
) | ||
); | ||
}; | ||
|
||
export default EditableSessionName; |
122 changes: 122 additions & 0 deletions
122
react/src/components/ComputeSessionNodeItems/SessionActionButtons.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import { useBackendAIAppLauncher } from '../../hooks/useBackendAIAppLauncher'; | ||
import TerminateSessionModal from './TerminateSessionModal'; | ||
import { | ||
SessionActionButtonsFragment$data, | ||
SessionActionButtonsFragment$key, | ||
} from './__generated__/SessionActionButtonsFragment.graphql'; | ||
import { Tooltip, Button, theme } from 'antd'; | ||
import graphql from 'babel-plugin-relay/macro'; | ||
import { TerminalIcon, PowerOffIcon } from 'lucide-react'; | ||
import { useState } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { useFragment } from 'react-relay'; | ||
|
||
interface SessionActionButtonsProps { | ||
sessionFrgmt: SessionActionButtonsFragment$key | null; | ||
} | ||
// const isRunning = (session:SessionActionButtonsFragment$data) => { | ||
// return [ | ||
// 'batch', | ||
// 'interactive', | ||
// 'inference', | ||
// 'system', | ||
// 'running', | ||
// 'others', | ||
// ].includes(session); | ||
// } | ||
|
||
const isActive = (session: SessionActionButtonsFragment$data) => { | ||
return !['TERMINATED', 'CANCELLED'].includes(session?.status || ''); | ||
}; | ||
// const isTransitional = (session: SessionActionButtonsFragment$data) => { | ||
// return [ | ||
// 'RESTARTING', | ||
// 'TERMINATING', | ||
// 'PENDING', | ||
// 'PREPARING', | ||
// 'PULLING', | ||
// ].includes(session?.status || ''); | ||
// }; | ||
|
||
const SessionActionButtons: React.FC<SessionActionButtonsProps> = ({ | ||
sessionFrgmt, | ||
}) => { | ||
const { token } = theme.useToken(); | ||
const appLauncher = useBackendAIAppLauncher(); | ||
|
||
const { t } = useTranslation(); | ||
|
||
const session = useFragment( | ||
graphql` | ||
fragment SessionActionButtonsFragment on ComputeSessionNode { | ||
id | ||
row_id @required(action: NONE) | ||
status | ||
access_key | ||
service_ports | ||
commit_status | ||
...TerminateSessionModalFragment | ||
} | ||
`, | ||
sessionFrgmt, | ||
); | ||
const [openTerminateModal, setOpenTerminateModal] = useState(false); | ||
|
||
// const isDisabledTermination = !['PENDING'].includes(session?.status || '') && session?.commit_status === 'ongoing' | ||
// ${(this._isRunning && !this._isPreparing(rowData.item.status)) || | ||
// this._isError(rowData.item.status) | ||
return ( | ||
session && ( | ||
<> | ||
{/* <Tooltip title={t('session.SeeAppDialog')}> | ||
<Button icon={<LayoutGridIcon />} onClick={()=>{ | ||
appLauncher.showLauncher({ | ||
"access-key": session?.access_key || '', | ||
"service-ports": session?.service_ports || '', | ||
}) | ||
}} /> | ||
</Tooltip> */} | ||
<Tooltip title={t('session.ExecuteTerminalApp')}> | ||
<Button | ||
disabled={!isActive(session)} | ||
icon={<TerminalIcon />} | ||
onClick={() => { | ||
appLauncher.runTerminal(session?.row_id); | ||
}} | ||
/> | ||
</Tooltip> | ||
{/* Don't put this modal to end of the return array(<></>). */} | ||
<TerminateSessionModal | ||
sessionFrgmts={[session]} | ||
open={openTerminateModal} | ||
onRequestClose={() => { | ||
setOpenTerminateModal(false); | ||
}} | ||
/> | ||
{/* | ||
<Tooltip title={t('session.SeeContainerLogs')}> | ||
<Button icon={<ScrollTextIcon />} /> | ||
</Tooltip> | ||
<Tooltip title={t('session.RequestContainerCommit')}> | ||
<Button icon={<ContainerIcon />} /> | ||
</Tooltip> */} | ||
<Tooltip title={t('session.TerminateSession')}> | ||
<Button | ||
disabled={!isActive(session)} | ||
icon={ | ||
<PowerOffIcon | ||
color={isActive(session) ? token.colorError : undefined} | ||
/> | ||
} | ||
onClick={() => { | ||
setOpenTerminateModal(true); | ||
}} | ||
/> | ||
</Tooltip> | ||
</> | ||
) | ||
); | ||
}; | ||
|
||
export default SessionActionButtons; |
49 changes: 49 additions & 0 deletions
49
react/src/components/ComputeSessionNodeItems/SessionReservation.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { useSuspendedBackendaiClient } from '../../hooks'; | ||
import BAIIntervalText from '../BAIIntervalText'; | ||
import DoubleTag from '../DoubleTag'; | ||
import { SessionReservationFragment$key } from './__generated__/SessionReservationFragment.graphql'; | ||
import graphql from 'babel-plugin-relay/macro'; | ||
import dayjs from 'dayjs'; | ||
import React from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { useFragment } from 'react-relay'; | ||
|
||
const SessionReservation: React.FC<{ | ||
sessionFrgmt: SessionReservationFragment$key; | ||
}> = ({ sessionFrgmt }) => { | ||
const baiClient = useSuspendedBackendaiClient(); | ||
const { t } = useTranslation(); | ||
const session = useFragment( | ||
graphql` | ||
fragment SessionReservationFragment on ComputeSessionNode { | ||
id | ||
created_at | ||
terminated_at | ||
} | ||
`, | ||
sessionFrgmt, | ||
); | ||
return ( | ||
<> | ||
{dayjs(session.created_at).format('lll')} | ||
<DoubleTag | ||
values={[ | ||
t('session.ElapsedTime'), | ||
<BAIIntervalText | ||
callback={() => { | ||
return session?.created_at | ||
? baiClient.utils.elapsedTime( | ||
session.created_at, | ||
session?.terminated_at, | ||
) | ||
: '-'; | ||
}} | ||
delay={1000} | ||
/>, | ||
]} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
export default SessionReservation; |
7 changes: 7 additions & 0 deletions
7
react/src/components/ComputeSessionNodeItems/SessionResourceNumbers.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import React from 'react'; | ||
|
||
const SessionResourceNumbers = () => { | ||
return <div>SessionResourceNumbers</div>; | ||
}; | ||
|
||
export default SessionResourceNumbers; |
Oops, something went wrong.