-
Notifications
You must be signed in to change notification settings - Fork 1
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
cluster status issue fix #291
Conversation
Reviewer's Guide by SourceryThis pull request addresses a cluster status issue by implementing a new query for listing cluster statuses and updating the related components. The changes improve the efficiency of fetching cluster status information and add an online event listener to update the status when the network connection is restored. File-Level Changes
Tips
|
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.
Hey @tulsiojha - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider making the pagination limit in listClusterStatus configurable or explain the reasoning behind the fixed value of 5. This could impact scalability if the number of clusters grows beyond this limit.
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟡 Complexity: 1 issue found
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.
(acc, c) => { | ||
acc[c.metadata.name] = c; | ||
return acc; | ||
const cl = await api.listClusterStatus({ |
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.
issue (complexity): Consider refactoring the code to improve readability and reduce complexity.
While the changes introduce necessary functionality, we can improve readability and reduce complexity:
- Refactor
listCluster
using async/await and reduce nesting:
const listCluster = useCallback(async () => {
try {
const { data } = await api.listClusterStatus({
pagination: { first: 5 },
});
const parsed = parseNodes(data).reduce((acc, c) => {
acc[c.metadata.name] = c;
return acc;
}, {} as IClusterMap);
setClusters(parsed);
return parsed;
} catch (err) {
console.error(err);
return false;
}
}, [api]);
- Split the
useEffect
hook for better separation of concerns:
useEffect(() => {
const intervalId = setInterval(listCluster, 30 * 1000);
return () => clearInterval(intervalId);
}, [listCluster]);
useEffect(() => {
const onlineEvent = () => {
setTimeout(listCluster, 3000);
};
window.addEventListener('online', onlineEvent);
return () => window.removeEventListener('online', onlineEvent);
}, [listCluster]);
- Consider removing the pagination limit of 5 in the API call, or add a comment explaining why it's necessary:
const { data } = await api.listClusterStatus({
// pagination: { first: 5 }, // Removed unless there's a specific reason for this limit
});
These changes maintain the added functionality while improving code readability and reducing complexity.
cluster status issue fix
Summary by Sourcery
Fix the cluster status issue by implementing a new GraphQL query to list cluster statuses and updating the cluster status retrieval logic. Enhance the cluster status provider to refresh data when the network connection is restored.
New Features:
Bug Fixes:
Enhancements: