-
Notifications
You must be signed in to change notification settings - Fork 31
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
[Netmanager] Added maintenance banner, fixed sidebar, use skip for pagination #2300
Changes from 7 commits
3a26acf
fdebe17
2a7597d
3caa5ec
2297030
6e7eeac
89362b9
f92c09d
86fdb64
2826c40
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { useState, useEffect } from 'react'; | ||
import { getMaintenanceStatusApi } from 'views/apis/authService'; | ||
|
||
export const useMaintenanceStatus = () => { | ||
const [maintenance, setMaintenance] = useState(null); | ||
const [loading, setLoading] = useState(true); | ||
const [error, setError] = useState(null); | ||
|
||
useEffect(() => { | ||
const checkMaintenanceStatus = async () => { | ||
try { | ||
const response = await getMaintenanceStatusApi(); | ||
setMaintenance(response.maintenance); | ||
} catch (err) { | ||
setError(err); | ||
} finally { | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
checkMaintenanceStatus(); | ||
// Check every 5 minutes | ||
const interval = setInterval(checkMaintenanceStatus, 5 * 60 * 1000); | ||
return () => clearInterval(interval); | ||
}, []); | ||
|
||
return { maintenance, loading, error }; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React from 'react'; | ||
import { makeStyles } from '@material-ui/styles'; | ||
import { Alert } from '@material-ui/lab'; | ||
import { useMaintenanceStatus } from 'utils/hooks/useMaintenanceStatus'; | ||
import { formatDateString } from '../../../utils/dateTime'; | ||
|
||
const useStyles = makeStyles((theme) => ({ | ||
banner: { | ||
position: 'fixed', | ||
top: 0, | ||
left: 0, | ||
right: 0, | ||
zIndex: 9999, | ||
'& .MuiAlert-message': { | ||
width: '100%', | ||
textAlign: 'center' | ||
} | ||
} | ||
})); | ||
|
||
const MaintenanceBanner = () => { | ||
const classes = useStyles(); | ||
const { maintenance, loading } = useMaintenanceStatus(); | ||
|
||
if (loading || !maintenance || !maintenance.active) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Alert severity="warning" className={classes.banner}> | ||
{maintenance.message || 'System maintenance in progress. Some features may be unavailable.'} | ||
Estimated downtime: {formatDateString(maintenance.startDate)} -{' '} | ||
{formatDateString(maintenance.endDate)} | ||
</Alert> | ||
); | ||
}; | ||
|
||
export default MaintenanceBanner; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,8 +28,8 @@ const UserList = (props) => { | |
const [loading, setLoading] = useState(false); | ||
const [users, setUsers] = useState([]); | ||
const [totalCount, setTotalCount] = useState(0); | ||
const [pageSize, setPageSize] = useState(10); | ||
const [currentPage, setCurrentPage] = useState(0); | ||
const [limit, setLimit] = useState(10); | ||
const [skip, setSkip] = useState(0); | ||
Comment on lines
+31
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider extracting shared pagination logic. The pagination implementation is duplicated between Consider creating a custom hook to share this logic: // usePagination.js
const usePagination = (fetchFn, initialLimit = 10) => {
const [limit, setLimit] = useState(initialLimit);
const [skip, setSkip] = useState(0);
const handlePageChange = (page, pageSize) => {
if (page < 0 || pageSize <= 0) return;
const newSkip = page * pageSize;
if (newSkip >= Number.MAX_SAFE_INTEGER) return;
setSkip(newSkip);
setLimit(pageSize);
fetchFn(newSkip, pageSize);
};
return {
limit,
skip,
currentPage: skip / limit,
handlePageChange
};
}; This would reduce code duplication and centralize the edge case handling. Also applies to: 41-47, 77-81, 94-95 |
||
const roles = useSelector((state) => state.accessControl.rolesSummary); | ||
const activeNetwork = useSelector((state) => state.accessControl.activeNetwork); | ||
|
||
|
@@ -38,13 +38,13 @@ const UserList = (props) => { | |
dispatch(loadRolesSummary(activeNetwork._id)); | ||
}, []); | ||
|
||
const fetchUsers = async (page, limit) => { | ||
const fetchUsers = async (skipCount, limitCount) => { | ||
if (!activeNetwork) return; | ||
setLoading(true); | ||
try { | ||
const res = await getNetworkUsersListApi(activeNetwork._id, { | ||
page: page + 1, | ||
limit | ||
skip: skipCount, | ||
limit: limitCount | ||
}); | ||
setUsers(res.assigned_users); | ||
setTotalCount(res.total || 0); | ||
|
@@ -71,13 +71,14 @@ const UserList = (props) => { | |
|
||
// Initial load | ||
useEffect(() => { | ||
fetchUsers(currentPage, pageSize); | ||
fetchUsers(skip, limit); | ||
}, [activeNetwork]); | ||
|
||
const handlePageChange = (newPage, newPageSize) => { | ||
setCurrentPage(newPage); | ||
setPageSize(newPageSize); | ||
fetchUsers(newPage, newPageSize); | ||
const handlePageChange = (page, pageSize) => { | ||
const newSkip = page * pageSize; | ||
setSkip(newSkip); | ||
setLimit(pageSize); | ||
fetchUsers(newSkip, pageSize); | ||
}; | ||
|
||
return ( | ||
|
@@ -90,8 +91,8 @@ const UserList = (props) => { | |
users={users} | ||
loadData={loading} | ||
totalCount={totalCount} | ||
pageSize={pageSize} | ||
currentPage={currentPage} | ||
pageSize={limit} | ||
currentPage={skip / limit} | ||
onPageChange={handlePageChange} | ||
/> | ||
</div> | ||
|
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
Remove unused import
The
formatDateString
import is not used in the component. Consider removing it.-import { formatDateString } from '../../../utils/dateTime';