-
Notifications
You must be signed in to change notification settings - Fork 251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: fe/config du monitor #1752
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
0cf056f
move field parsing to network util
ajhollid b015f7b
destructure var, build form to update monitor
ajhollid 89a542e
Add a config route for DU
ajhollid 2db41d3
simpler differentiation between creating and updating
ajhollid f72dd79
fix incorrect field parsing
ajhollid dc84bd8
fix loading condtitional, correct row renderng
ajhollid ab16ab0
implement cconfig using create component
ajhollid 074824f
add delete dialog, state, and header
ajhollid 9344ebc
Simpler differentiation
ajhollid 82c9a73
Add a method for deleting status pages when a monitor is deleted
ajhollid ca6e400
add delete checks method
ajhollid 508c838
delete checks and status pages on monitor delete
ajhollid 1ed6112
Add todo comment
ajhollid 84bbcc8
fix confirmation dialog messags
ajhollid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
33 changes: 33 additions & 0 deletions
33
Client/src/Pages/DistributedUptime/Create/Hooks/useCreateDistributedUptimeMonitor.jsx
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,33 @@ | ||
import { useState } from "react"; | ||
import { networkService } from "../../../../main"; | ||
import { useSelector } from "react-redux"; | ||
import { createToast } from "../../../../Utils/toastUtils"; | ||
|
||
const useCreateDistributedUptimeMonitor = ({ isCreate, monitorId }) => { | ||
const { authToken, user } = useSelector((state) => state.auth); | ||
|
||
const [isLoading, setIsLoading] = useState(false); | ||
const [networkError, setNetworkError] = useState(false); | ||
const createDistributedUptimeMonitor = async ({ form }) => { | ||
setIsLoading(true); | ||
try { | ||
if (isCreate) { | ||
await networkService.createMonitor({ authToken, monitor: form }); | ||
} else { | ||
await networkService.updateMonitor({ authToken, monitor: form, monitorId }); | ||
} | ||
|
||
return true; | ||
} catch (error) { | ||
setNetworkError(true); | ||
createToast({ body: error?.response?.data?.msg ?? error.message }); | ||
return false; | ||
} finally { | ||
setIsLoading(false); | ||
} | ||
}; | ||
|
||
return [createDistributedUptimeMonitor, isLoading, networkError]; | ||
}; | ||
|
||
export { useCreateDistributedUptimeMonitor }; |
32 changes: 32 additions & 0 deletions
32
Client/src/Pages/DistributedUptime/Create/Hooks/useMonitorFetch.jsx
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,32 @@ | ||
import { useEffect, useState } from "react"; | ||
import { networkService } from "../../../../main"; | ||
import { createToast } from "../../../../Utils/toastUtils"; | ||
|
||
export const useMonitorFetch = ({ authToken, monitorId, isCreate }) => { | ||
const [networkError, setNetworkError] = useState(false); | ||
const [isLoading, setIsLoading] = useState(true); | ||
const [monitor, setMonitor] = useState(undefined); | ||
|
||
useEffect(() => { | ||
const fetchMonitors = async () => { | ||
try { | ||
if (isCreate) return; | ||
const res = await networkService.getUptimeDetailsById({ | ||
authToken: authToken, | ||
monitorId: monitorId, | ||
normalize: true, | ||
}); | ||
setMonitor(res?.data?.data ?? {}); | ||
} catch (error) { | ||
setNetworkError(true); | ||
createToast({ body: error.message }); | ||
} finally { | ||
setIsLoading(false); | ||
} | ||
}; | ||
fetchMonitors(); | ||
}, [authToken, monitorId, isCreate]); | ||
return [monitor, isLoading, networkError]; | ||
}; | ||
|
||
export default useMonitorFetch; |
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
91 changes: 91 additions & 0 deletions
91
Client/src/Pages/DistributedUptime/Details/Components/ControlsHeader/index.jsx
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,91 @@ | ||
// Components | ||
import { Box, Stack, Typography, Button } from "@mui/material"; | ||
import Image from "../../../../../Components/Image"; | ||
import SettingsIcon from "../../../../../assets/icons/settings-bold.svg?react"; | ||
|
||
//Utils | ||
import { useTheme } from "@mui/material/styles"; | ||
import { useNavigate } from "react-router-dom"; | ||
import { useLocation } from "react-router-dom"; | ||
import PropTypes from "prop-types"; | ||
|
||
const Controls = ({ isDeleteOpen, setIsDeleteOpen, isDeleting, monitorId }) => { | ||
const theme = useTheme(); | ||
const navigate = useNavigate(); | ||
|
||
return ( | ||
<Stack | ||
direction="row" | ||
gap={theme.spacing(2)} | ||
> | ||
<Box> | ||
<Button | ||
variant="contained" | ||
color="error" | ||
onClick={() => setIsDeleteOpen(!isDeleteOpen)} | ||
loading={isDeleting} | ||
> | ||
Delete | ||
</Button> | ||
</Box> | ||
<Box> | ||
<Button | ||
variant="contained" | ||
color="secondary" | ||
onClick={() => { | ||
navigate(`/distributed-uptime/configure/${monitorId}`); | ||
}} | ||
sx={{ | ||
px: theme.spacing(5), | ||
"& svg": { | ||
mr: theme.spacing(3), | ||
"& path": { | ||
stroke: theme.palette.secondary.contrastText, | ||
}, | ||
}, | ||
}} | ||
> | ||
<SettingsIcon /> Configure | ||
</Button> | ||
</Box> | ||
</Stack> | ||
); | ||
}; | ||
|
||
Controls.propTypes = { | ||
isDeleting: PropTypes.bool, | ||
monitorId: PropTypes.string, | ||
isDeleteOpen: PropTypes.bool.isRequired, | ||
setIsDeleteOpen: PropTypes.func.isRequired, | ||
}; | ||
|
||
const ControlsHeader = ({ isDeleting, isDeleteOpen, setIsDeleteOpen, monitorId }) => { | ||
const theme = useTheme(); | ||
|
||
return ( | ||
<Stack | ||
alignSelf="flex-start" | ||
direction="row" | ||
width="100%" | ||
gap={theme.spacing(2)} | ||
justifyContent="flex-end" | ||
alignItems="flex-end" | ||
> | ||
<Controls | ||
isDeleting={isDeleting} | ||
isDeleteOpen={isDeleteOpen} | ||
setIsDeleteOpen={setIsDeleteOpen} | ||
monitorId={monitorId} | ||
/> | ||
</Stack> | ||
); | ||
}; | ||
|
||
ControlsHeader.propTypes = { | ||
monitorId: PropTypes.string, | ||
isDeleting: PropTypes.bool, | ||
isDeleteOpen: PropTypes.bool.isRequired, | ||
setIsDeleteOpen: PropTypes.func.isRequired, | ||
}; | ||
|
||
export default ControlsHeader; |
27 changes: 27 additions & 0 deletions
27
Client/src/Pages/DistributedUptime/Details/Hooks/useDeleteMonitor.jsx
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,27 @@ | ||
import { useSelector } from "react-redux"; | ||
import { useState } from "react"; | ||
import { networkService } from "../../../../main"; | ||
import { createToast } from "../../../../Utils/toastUtils"; | ||
|
||
const useDeleteMonitor = ({ monitorId }) => { | ||
const [isLoading, setIsLoading] = useState(false); | ||
const { authToken } = useSelector((state) => state.auth); | ||
const deleteMonitor = async () => { | ||
try { | ||
setIsLoading(true); | ||
await networkService.deleteMonitorById({ authToken, monitorId }); | ||
return true; | ||
} catch (error) { | ||
createToast({ | ||
body: error.message, | ||
}); | ||
return false; | ||
} finally { | ||
setIsLoading(false); | ||
} | ||
}; | ||
|
||
return [deleteMonitor, isLoading]; | ||
}; | ||
|
||
export { useDeleteMonitor }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Knees weak from missing cleanup and retries!
The fetch logic needs some improvements:
Here's how to make it stronger:
📝 Committable suggestion