-
Notifications
You must be signed in to change notification settings - Fork 16
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
1 parent
5127a50
commit 397ceff
Showing
6 changed files
with
180 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { Box, Button, DialogContentText } from '@mui/material'; | ||
import Dialog from '@mui/material/Dialog'; | ||
import DialogActions from '@mui/material/DialogActions'; | ||
import DialogContent from '@mui/material/DialogContent'; | ||
import DialogTitle from '@mui/material/DialogTitle'; | ||
import { Fragment, memo, useCallback, useState } from 'react'; | ||
|
||
// import { useAxios } from '../common/AxiosContext'; | ||
import { IEnvironmentData } from '../environments/types'; | ||
import { EnvironmentList } from '../environments/EnvironmentList'; | ||
import { GridRowSelectionModel } from '@mui/x-data-grid'; | ||
|
||
export interface INewServerDialogProps { | ||
images: IEnvironmentData[]; | ||
} | ||
|
||
function _NewServerDialog(props: INewServerDialogProps) { | ||
// const axios = useAxios(); | ||
const [open, setOpen] = useState(false); | ||
const handleOpen = () => { | ||
setOpen(true); | ||
}; | ||
const handleClose = ( | ||
event?: any, | ||
reason?: 'backdropClick' | 'escapeKeyDown' | ||
) => { | ||
if (reason && reason === 'backdropClick') { | ||
return; | ||
} | ||
setOpen(false); | ||
}; | ||
|
||
const [rowSelectionModel, setRowSelectionModel] = | ||
useState<GridRowSelectionModel>([]); | ||
const updateSelectedRow = useCallback( | ||
(selected: GridRowSelectionModel) => { | ||
if (selected.length > 1) { | ||
setRowSelectionModel([selected[selected.length - 1]]); | ||
} else { | ||
setRowSelectionModel(selected); | ||
} | ||
}, | ||
[setRowSelectionModel] | ||
); | ||
return ( | ||
<Fragment> | ||
<Box sx={{ display: 'flex', flexDirection: 'row-reverse' }}> | ||
<Button onClick={handleOpen} variant="contained"> | ||
Create new Server | ||
</Button> | ||
</Box> | ||
<Dialog open={open} onClose={handleClose} fullWidth maxWidth={'md'}> | ||
<DialogTitle>Server Options</DialogTitle> | ||
<DialogContent> | ||
<DialogContentText>Select an environment</DialogContentText> | ||
<EnvironmentList | ||
images={props.images} | ||
hideRemoveButton={true} | ||
pageSize={10} | ||
selectable | ||
rowSelectionModel={rowSelectionModel} | ||
setRowSelectionModel={updateSelectedRow} | ||
/> | ||
</DialogContent> | ||
<DialogActions> | ||
<Button variant="contained" color="error" onClick={handleClose}> | ||
Cancel | ||
</Button> | ||
<Button | ||
variant="contained" | ||
color="primary" | ||
disabled={rowSelectionModel.length === 0} | ||
> | ||
Create Server | ||
</Button> | ||
</DialogActions> | ||
</Dialog> | ||
</Fragment> | ||
); | ||
} | ||
|
||
export const NewServerDialog = memo(_NewServerDialog); |
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,46 @@ | ||
import { Typography } from '@mui/material'; | ||
import Box from '@mui/material/Box'; | ||
import { memo, useCallback } from 'react'; | ||
|
||
import { useAxios } from '../common/AxiosContext'; | ||
import { ButtonWithConfirm } from '../common/ButtonWithConfirm'; | ||
import { API_PREFIX } from './types'; | ||
|
||
interface IRemoveServerButton { | ||
user: string; | ||
server: string; | ||
} | ||
|
||
function _RemoveServerButton(props: IRemoveServerButton) { | ||
const axios = useAxios(); | ||
|
||
const removeEnv = useCallback(async () => { | ||
const response = await axios.request({ | ||
method: 'delete', | ||
path: API_PREFIX, | ||
data: { name: props.server } | ||
}); | ||
if (response?.status === 'ok') { | ||
window.location.reload(); | ||
} else { | ||
} | ||
}, [props.server, axios]); | ||
|
||
return ( | ||
<ButtonWithConfirm | ||
buttonLabel="Stop Server" | ||
dialogTitle="Stop Server" | ||
dialogBody={ | ||
<Box> | ||
<Typography> | ||
Are you sure you want to stop the following server? | ||
</Typography> | ||
<pre>{props.server}</pre> | ||
</Box> | ||
} | ||
action={removeEnv} | ||
/> | ||
); | ||
} | ||
|
||
export const RemoveServerButton = memo(_RemoveServerButton); |
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