This repository has been archived by the owner on Sep 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
10 changed files
with
408 additions
and
18 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
75 changes: 75 additions & 0 deletions
75
ts/webui/src/components/modals/tensorboard/TensorboardDialog.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,75 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { PrimaryButton, Dialog, DialogType, DialogFooter } from '@fluentui/react'; | ||
|
||
function TensorboardDialog(props): any { | ||
const { isReaptedStartTensorboard, onHideDialog, item, isShowTensorboardDetail, errorMessage } = props; | ||
|
||
const dialogContentProps = { | ||
type: DialogType.normal, | ||
title: `${isShowTensorboardDetail ? item.id : 'TensorBoard'}` | ||
}; | ||
|
||
function gotoTensorboard(): void { | ||
const hostname = window.location.hostname; | ||
const protocol = window.location.protocol; | ||
window.open(`${protocol}//${hostname}:${item.port}`); | ||
onHideDialog(); | ||
} | ||
|
||
const startTensorboard = isReaptedStartTensorboard ? ( | ||
<div> | ||
You had started this tensorBoard with these trials: | ||
<span className='bold'>{item.trialJobIdList.join(', ')}</span>. | ||
<div className='line-height'> | ||
Its tensorBoard id: <span className='bold'>{item.id}</span> | ||
</div> | ||
</div> | ||
) : ( | ||
<div> | ||
You are starting a new TensorBoard with trials: | ||
<span className='bold'>{item.trialJobIdList.join(', ')}</span>. | ||
<div className='line-height'> | ||
TensorBoard id: <span className='bold'>{item.id}</span> | ||
</div> | ||
</div> | ||
); | ||
|
||
return ( | ||
<Dialog hidden={false} dialogContentProps={dialogContentProps} modalProps={{ className: 'dialog' }}> | ||
{errorMessage.error ? ( | ||
<div> | ||
<span>Failed to start tensorBoard! Error message: {errorMessage.message}</span>. | ||
</div> | ||
) : isShowTensorboardDetail ? ( | ||
<div> | ||
This tensorBoard with trials: <span className='bold'>{item.trialJobIdList.join(', ')}</span>. | ||
</div> | ||
) : ( | ||
startTensorboard | ||
)} | ||
{errorMessage.error ? ( | ||
<DialogFooter> | ||
<PrimaryButton onClick={onHideDialog} text='Close' /> | ||
</DialogFooter> | ||
) : ( | ||
<DialogFooter> | ||
<PrimaryButton | ||
onClick={gotoTensorboard} | ||
text={`${isShowTensorboardDetail ? 'See tensorBoard' : 'Ok'}`} | ||
/> | ||
</DialogFooter> | ||
)} | ||
</Dialog> | ||
); | ||
} | ||
|
||
TensorboardDialog.propTypes = { | ||
isReaptedStartTensorboard: PropTypes.bool, | ||
isShowTensorboardDetail: PropTypes.bool, | ||
onHideDialog: PropTypes.func, | ||
item: PropTypes.object, | ||
errorMessage: PropTypes.object | ||
}; | ||
|
||
export default TensorboardDialog; |
144 changes: 144 additions & 0 deletions
144
ts/webui/src/components/modals/tensorboard/TensorboardUI.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,144 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import axios from 'axios'; | ||
import { DefaultButton, IContextualMenuProps } from '@fluentui/react'; | ||
import { MANAGER_IP } from '../../../static/const'; | ||
import { disableTensorboard, getTensorboardMenu } from '../../../static/function'; | ||
import { Tensorboard } from '../../../static/interface'; | ||
import TensorboardDialog from './TensorboardDialog'; | ||
|
||
function TensorboardUI(props): any { | ||
let refreshTensorboard = 0; | ||
const { selectedRowIds } = props; | ||
const [queryTensorboardList, setQueryTensorboardList] = useState([]); | ||
const [isReaptedStartTensorboard, setReaptedTensorboard] = useState(false); | ||
const [tensorboardPanelVisible, setTensorboardPanelVisible] = useState(false); | ||
const [isShowTensorboardDetail, setIsShowTensorboardDetail] = useState(false); | ||
const [selectedTensorboard, setSelectedTensorboard] = useState({}); | ||
const [errorMessage, setErrorMessage] = useState({}); | ||
const [timerList, setTimerList] = useState([0]); | ||
|
||
function startTrialTensorboard(): void { | ||
const { selectedRowIds } = props; | ||
if (selectedRowIds.length > 0) { | ||
setIsShowTensorboardDetail(false); | ||
const result = queryTensorboardList.filter( | ||
(item: Tensorboard) => item.trialJobIdList.join(',') === selectedRowIds.join(',') | ||
); | ||
if (result.length > 0) { | ||
setReaptedTensorboard(true); | ||
setSelectedTensorboard(result[0]); | ||
setTensorboardPanelVisible(true); | ||
} else { | ||
const startTensorboard = axios.post(`${MANAGER_IP}/tensorboard`, { trials: selectedRowIds.join(',') }); | ||
startTensorboard | ||
.then(res => { | ||
if (res.status === 200) { | ||
setSelectedTensorboard(res.data); | ||
closeTimer(); | ||
queryAllTensorboard(); | ||
setErrorMessage({ error: false, message: '' }); | ||
setTensorboardPanelVisible(true); | ||
} | ||
}) | ||
.catch(error => { | ||
setErrorMessage({ | ||
error: true, | ||
message: error.message || 'Tensorboard start failed' | ||
}); | ||
setTensorboardPanelVisible(true); | ||
}); | ||
setReaptedTensorboard(false); | ||
} | ||
} else { | ||
alert('Please select trials first!'); | ||
} | ||
} | ||
|
||
function queryAllTensorboard(): void { | ||
const queryTensorboard = axios.get(`${MANAGER_IP}/tensorboard-tasks`); | ||
queryTensorboard.then(res => { | ||
if (res.status === 200) { | ||
setQueryTensorboardList(res.data); | ||
if (res.data.length !== 0) { | ||
refreshTensorboard = window.setTimeout(queryAllTensorboard, 10000); | ||
const storeTimerList = timerList; | ||
storeTimerList.push(refreshTensorboard); | ||
setTimerList(storeTimerList); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
function closeTimer(): void { | ||
timerList.forEach(item => { | ||
window.clearTimeout(item); | ||
}); | ||
} | ||
|
||
function stopAllTensorboard(): void { | ||
const delTensorboard = axios.delete(`${MANAGER_IP}/tensorboard-tasks`); | ||
delTensorboard.then(res => { | ||
if (res.status === 200) { | ||
setQueryTensorboardList([]); | ||
closeTimer(); | ||
} | ||
}); | ||
} | ||
|
||
function seeTensorboardWebportal(item: Tensorboard): void { | ||
setSelectedTensorboard(item); | ||
setIsShowTensorboardDetail(true); | ||
setTensorboardPanelVisible(true); | ||
} | ||
|
||
const isDisableTensorboardBtn = disableTensorboard(selectedRowIds, queryTensorboardList); | ||
const tensorboardMenu: IContextualMenuProps = getTensorboardMenu( | ||
queryTensorboardList, | ||
stopAllTensorboard, | ||
seeTensorboardWebportal | ||
); | ||
|
||
useEffect(() => { | ||
queryAllTensorboard(); | ||
// clear timer when component is unmounted | ||
return function closeTimer(): void { | ||
timerList.forEach(item => { | ||
window.clearTimeout(item); | ||
}); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<React.Fragment> | ||
<DefaultButton | ||
text='TensorBoard' | ||
className='elementMarginLeft' | ||
split | ||
splitButtonAriaLabel='See 2 options' | ||
aria-roledescription='split button' | ||
menuProps={tensorboardMenu} | ||
onClick={(): void => startTrialTensorboard()} | ||
disabled={isDisableTensorboardBtn} | ||
/> | ||
{queryTensorboardList.length !== 0 ? <span className='circle'>{queryTensorboardList.length}</span> : null} | ||
{tensorboardPanelVisible && ( | ||
<TensorboardDialog | ||
isReaptedStartTensorboard={isReaptedStartTensorboard} | ||
isShowTensorboardDetail={isShowTensorboardDetail} | ||
errorMessage={errorMessage} | ||
item={selectedTensorboard} | ||
onHideDialog={(): void => { | ||
setTensorboardPanelVisible(false); | ||
}} | ||
/> | ||
)} | ||
</React.Fragment> | ||
); | ||
} | ||
|
||
TensorboardUI.propTypes = { | ||
selectedRowIds: PropTypes.array | ||
}; | ||
|
||
export default TensorboardUI; |
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
Oops, something went wrong.