@@ -12,10 +12,12 @@ import {
1212 graphql ,
1313 useFragment ,
1414 useRelayEnvironment ,
15+ useSubscription ,
1516} from 'react-relay' ;
1617import { useNavigate } from 'react-router-dom' ;
1718import { BAIComputeSessionNodeNotificationItemFragment$key } from 'src/__generated__/BAIComputeSessionNodeNotificationItemFragment.graphql' ;
1819import { BAIComputeSessionNodeNotificationItemRefreshQuery } from 'src/__generated__/BAIComputeSessionNodeNotificationItemRefreshQuery.graphql' ;
20+ import { useSuspendedBackendaiClient } from 'src/hooks' ;
1921import {
2022 NotificationState ,
2123 useSetBAINotification ,
@@ -35,6 +37,7 @@ const BAIComputeSessionNodeNotificationItem: React.FC<
3537 const { closeNotification } = useSetBAINotification ( ) ;
3638 const { t } = useTranslation ( ) ;
3739 const navigate = useNavigate ( ) ;
40+ const baiClient = useSuspendedBackendaiClient ( ) ;
3841 const node = useFragment (
3942 graphql `
4043 fragment BAIComputeSessionNodeNotificationItemFragment on ComputeSessionNode {
@@ -49,24 +52,6 @@ const BAIComputeSessionNodeNotificationItem: React.FC<
4952 sessionFrgmt ,
5053 ) ;
5154
52- // TODO: delete this when Status subscription is implemented
53- const [ delay , setDelay ] = useState < number | null > ( null ) ;
54- UNSAFE_useAutoRefreshInterval ( node ?. id || '' , delay ) ;
55- useEffect ( ( ) => {
56- if (
57- ! node ?. status ||
58- node ?. status === 'TERMINATED' ||
59- node ?. status === 'CANCELLED'
60- ) {
61- setDelay ( null ) ;
62- } else if ( node ?. status === 'RUNNING' ) {
63- setDelay ( 15000 ) ;
64- } else {
65- setDelay ( 3000 ) ;
66- }
67- } , [ node ?. status ] ) ;
68- // ---
69-
7055 useUpdateEffect ( ( ) => {
7156 if ( node ?. status === 'TERMINATED' || node ?. status === 'CANCELLED' ) {
7257 setTimeout ( ( ) => {
@@ -77,46 +62,56 @@ const BAIComputeSessionNodeNotificationItem: React.FC<
7762
7863 return (
7964 node && (
80- < BAINotificationItem
81- title = {
82- < BAIText ellipsis >
83- { t ( 'general.Session' ) } :
84- < BAILink
85- style = { {
86- fontWeight : 'normal' ,
87- } }
88- title = { node . name || '' }
89- onClick = { ( ) => {
90- navigate (
91- `/session${ node . row_id ? `?${ new URLSearchParams ( { sessionDetail : node . row_id } ) . toString ( ) } ` : '' } ` ,
92- ) ;
93- closeNotification ( notification . key ) ;
94- } }
95- >
96- { node . name }
97- </ BAILink >
98- </ BAIText >
99- }
100- description = {
101- < BAIFlex justify = "between" >
102- < SessionStatusTag
103- sessionFrgmt = { node || null }
104- showQueuePosition = { false }
105- showTooltip = { false }
106- />
107- < SessionActionButtons
108- compact
109- size = "small"
110- sessionFrgmt = { node || null }
111- hiddenButtonKeys = { [ 'containerCommit' ] }
112- primaryAppOption = { primaryAppOption }
113- />
114- </ BAIFlex >
115- }
116- footer = {
117- showDate ? dayjs ( notification . created ) . format ( 'lll' ) : undefined
118- }
119- />
65+ < >
66+ < BAINotificationItem
67+ title = {
68+ < BAIText ellipsis >
69+ { t ( 'general.Session' ) } :
70+ < BAILink
71+ style = { {
72+ fontWeight : 'normal' ,
73+ } }
74+ title = { node . name || '' }
75+ onClick = { ( ) => {
76+ navigate (
77+ `/session${ node . row_id ? `?${ new URLSearchParams ( { sessionDetail : node . row_id } ) . toString ( ) } ` : '' } ` ,
78+ ) ;
79+ closeNotification ( notification . key ) ;
80+ } }
81+ >
82+ { node . name }
83+ </ BAILink >
84+ </ BAIText >
85+ }
86+ description = {
87+ < BAIFlex justify = "between" >
88+ < SessionStatusTag
89+ sessionFrgmt = { node || null }
90+ showQueuePosition = { false }
91+ showTooltip = { false }
92+ />
93+ < SessionActionButtons
94+ compact
95+ size = "small"
96+ sessionFrgmt = { node || null }
97+ hiddenButtonKeys = { [ 'containerCommit' ] }
98+ primaryAppOption = { primaryAppOption }
99+ />
100+ </ BAIFlex >
101+ }
102+ footer = {
103+ showDate ? dayjs ( notification . created ) . format ( 'lll' ) : undefined
104+ }
105+ />
106+ { baiClient . isManagerVersionCompatibleWith ( '25.16.0' ) && node . row_id ? (
107+ < SessionStatusRefresherUsingSubscription sessionRowId = { node . row_id } />
108+ ) : node . row_id && node . status ? (
109+ < UNSAFE_SessionStatusRefresher
110+ id = { node . row_id }
111+ status = { node . status }
112+ />
113+ ) : null }
114+ </ >
120115 )
121116 ) ;
122117} ;
@@ -146,3 +141,48 @@ const UNSAFE_useAutoRefreshInterval = (
146141 ) . toPromise ( ) ;
147142 } , delay ) ;
148143} ;
144+
145+ const SessionStatusRefresherUsingSubscription : React . FC < {
146+ sessionRowId ?: string ;
147+ } > = ( { sessionRowId } ) => {
148+ useSubscription ( {
149+ subscription : graphql `
150+ subscription BAIComputeSessionNodeNotificationItemSubscription(
151+ $session_id: ID!
152+ ) {
153+ schedulingEventsBySession(sessionId: $session_id) {
154+ reason
155+ session {
156+ status
157+ ...SessionNodesFragment
158+ ...SessionDetailContentFragment
159+ ...SessionActionButtonsFragment
160+ }
161+ }
162+ }
163+ ` ,
164+ variables : { session_id : sessionRowId } ,
165+ } ) ;
166+ return null ;
167+ } ;
168+
169+ const UNSAFE_SessionStatusRefresher : React . FC < {
170+ id : string ;
171+ status : string ;
172+ } > = ( { id, status } ) => {
173+ // TODO: delete this when Status subscription is implemented
174+ const [ delay , setDelay ] = useState < number | null > ( null ) ;
175+ UNSAFE_useAutoRefreshInterval ( id || '' , delay ) ;
176+ useEffect ( ( ) => {
177+ if ( ! status || status === 'TERMINATED' || status === 'CANCELLED' ) {
178+ setDelay ( null ) ;
179+ } else if ( status === 'RUNNING' ) {
180+ setDelay ( 15000 ) ;
181+ } else {
182+ setDelay ( 3000 ) ;
183+ }
184+ } , [ status ] ) ;
185+ // ---
186+
187+ return null ;
188+ } ;
0 commit comments