Skip to content
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: Edit infrastructure monitor page #1308

Open
wants to merge 18 commits into
base: develop
Choose a base branch
from

Conversation

peterpardo
Copy link
Contributor

@peterpardo peterpardo commented Dec 6, 2024

Summary

This PR adds the "Configure" button at the infrastructure details page to edit the selected infrastructure.

Changes Made

  • Added Infrastructure configure page
  • Added Configure Button at the top right of the Infrastructure details page which redirects to the Infrastructure configure page
  • Auto populate fields when editing infrastructure
  • Added Pause/Resume Infrastructure monitor functionality
  • Added Delete Infrastructure monitor functionality

Related Issue/s

Fixes #1277

Screenshots / Demo Video

checkmate-issue-1277-demo-1.mp4

Additional Context/s

  • Edit functionality not yet working. We can create another PR for it
  • Noticed that the pulse dot which indicates if the infra monitor is active or not doesn't go back to green when resumed
  • Auto populating the Customized Alerts not yet working. We can create another PR for it
  • Copy pasted the code in the Pagespeed configure page and made adjustment from there. We can create a PR to refactor redundant codes and do some cleanup

@peterpardo peterpardo changed the title Feat/edit infrastructure monitor feat: Edit infrastructure monitor page Dec 6, 2024
@peterpardo peterpardo marked this pull request as ready for review December 6, 2024 17:58
Copy link

@llamapreview llamapreview bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto Pull Request Review from LlamaPReview

Large PR Notification

Dear contributor,

Thank you for your substantial contribution to this project. LlamaPReview has detected that this Pull Request contains a large volume of changes, which exceeds our current processing capacity.

Details:

  • PR and related contents total size: Approximately 51,530 characters
  • Current limit: 50,000 characters

Next steps:

  1. Consider breaking this PR into smaller, more focused changes if possible.
  2. For manual review, please reach out to your team members or maintainers.

We appreciate your understanding and commitment to improving this project. Your contributions are valuable, and we want to ensure they receive the attention they deserve.

LlamaPReview is continuously evolving to better serve the community. Share your thoughts on handling large PRs in our GitHub Discussions - your feedback helps us improve and expand our capabilities.

If you have any questions or need assistance, our community and support team are here to help.

Best regards,
LlamaPReview Team

Copy link

coderabbitai bot commented Dec 6, 2024

Walkthrough

The pull request introduces a new route for configuring infrastructure monitors in a React application, enhancing the routing functionality by allowing access to a dedicated configuration page. Modifications to state management are made in the infrastructureMonitorsSlice.js, including the introduction of a FormAction object and a selectedInfraMonitor state. A new ConfigureInfrastructureMonitor component is created for user input and monitor management. Additionally, the InfrastructureDetails component is updated to conditionally render an admin button, and new constants are added for infrastructure-related functionalities.

Changes

File Path Change Summary
Client/src/App.jsx New route added: path="infrastructure/configure/:monitorId" for ConfigureInfrastructureMonitor.
Client/src/Features/InfrastructureMonitors/infrastructureMonitorsSlice.js New FormAction constants, selectedInfraMonitor and formAction in initialState, updated deleteInfrastructureMonitor action, and added resetInfrastructureMonitorFormAction reducer.
Client/src/Pages/Infrastructure/Configure/index.jsx Component ConfigureInfrastructureMonitor added for configuring infrastructure monitors.
Client/src/Pages/Infrastructure/Details/index.jsx Updated InfrastructureDetails component to accept isAdmin prop and conditionally render an admin button.
Client/src/Pages/Infrastructure/constants.js Added constants: THRESHOLD_FIELD_PREFIX and HARDWARE_MONITOR_TYPES.
Client/src/Pages/Infrastructure/index.jsx Integrated useDispatch for resetting form action on mount.

Assessment against linked issues

Objective Addressed Explanation
Infrastructure monitors should be editable (#1277)

Possibly related PRs

Suggested reviewers

  • marcelluscaio
  • ajhollid
  • jennifer-gan

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (10)
Client/src/Pages/Infrastructure/Configure/index.jsx (5)

347-347: Simplify conditional expression in error prop

The expression errors["url"] ? true : false is unnecessary. You can simplify it by directly using !!errors["url"] or Boolean(errors["url"]).

Apply this diff to simplify the expression:

-error={errors["url"] ? true : false}
+error={!!errors["url"]}
🧰 Tools
🪛 Biome (1.9.4)

[error] 347-347: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)


369-369: Simplify conditional expression in error prop

The expression errors["secret"] ? true : false is unnecessary. You can simplify it by directly using !!errors["secret"] or Boolean(errors["secret"]).

Apply this diff to simplify the expression:

-error={errors["secret"] ? true : false}
+error={!!errors["secret"]}
🧰 Tools
🪛 Biome (1.9.4)

[error] 369-369: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)


93-93: Use strict equality operators

In JavaScript, it's best practice to use strict equality (=== and !==) to avoid type coercion issues. In line 93, consider replacing == with ===.

Apply this diff:

-[id]: prev[id] == undefined && value == "on" ? true : !prev[id],
+[id]: prev[id] === undefined && value === "on" ? true : !prev[id],

267-267: Correct typo in status message

The word "Editting..." should be "Editing..." to fix the typo.

Apply this diff to correct the typo:

-Editting...
+Editing...

170-170: Fix typo in TODO comment

There's a typo in the TODO comment. "functionalityf" should be "functionality".

Apply this diff:

-// TODO: add update infrastructure monitor functionalityf
+// TODO: add update infrastructure monitor functionality
Client/src/Pages/Infrastructure/index.jsx (2)

3-3: Clean up import statement

Please remove the commented-out useDispatch import to tidy up the code.

Apply this diff:

-import { /* useDispatch, */ useDispatch, useSelector } from "react-redux";
+import { useDispatch, useSelector } from "react-redux";

134-137: Include dispatch in useEffect dependency array

To ensure consistency and avoid potential issues, include dispatch in the dependency array of the useEffect hook.

Apply this diff:

-useEffect(() => {
+useEffect(() => {
    dispatch(resetInfrastructureMonitorFormAction());
-}, []);
+}, [dispatch]);
Client/src/Features/InfrastructureMonitors/infrastructureMonitorsSlice.js (1)

261-261: Review usage of success flag during pending states

Setting success to false during pending actions may be misleading. Consider leaving success as null until the action is fulfilled or rejected to accurately reflect the loading state.

Also applies to: 281-281, 300-300, 320-320, 340-340, 361-361, 380-380, 399-399, 419-419

Client/src/Pages/Infrastructure/Details/index.jsx (2)

502-521: Mom's spaghetti! Extract tooltip into a reusable component

The tooltip configuration with modifiers could be reused across the application.

Consider extracting into a shared component:

+ const StatusTooltip = ({ children, title }) => (
+   <Tooltip
+     title={title}
+     disableInteractive
+     slotProps={{
+       popper: {
+         modifiers: [
+           {
+             name: "offset",
+             options: {
+               offset: [0, -8],
+             },
+           },
+         ],
+       },
+     }}
+   >
+     {children}
+   </Tooltip>
+ );

Line range hint 607-619: Knees weak! Address the FE team comments and improve layout maintainability

The comments requesting "FE team HELP!" indicate potential layout issues that need attention.

Consider these improvements:

  1. Use CSS Grid instead of flexbox for the chart layout
  2. Create a constant for the layout calculations
  3. Document the layout constraints and requirements
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 958904e and 7a3f278.

📒 Files selected for processing (6)
  • Client/src/App.jsx (2 hunks)
  • Client/src/Features/InfrastructureMonitors/infrastructureMonitorsSlice.js (13 hunks)
  • Client/src/Pages/Infrastructure/Configure/index.jsx (1 hunks)
  • Client/src/Pages/Infrastructure/Details/index.jsx (5 hunks)
  • Client/src/Pages/Infrastructure/constants.js (1 hunks)
  • Client/src/Pages/Infrastructure/index.jsx (4 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
Client/src/Pages/Infrastructure/Configure/index.jsx

[error] 347-347: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)


[error] 369-369: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)

🔇 Additional comments (2)
Client/src/Pages/Infrastructure/constants.js (1)

1-2: Constants are appropriately defined

The constants THRESHOLD_FIELD_PREFIX and HARDWARE_MONITOR_TYPES are correctly defined and exported.

Client/src/App.jsx (1)

143-146: New route for configuring infrastructure monitors added correctly

The route for ConfigureInfrastructureMonitor has been added properly, enabling navigation to the configuration page.

Comment on lines +552 to +569
{isAdmin && (
<Button
variant="contained"
color="secondary"
onClick={() => navigate(`/infrastructure/configure/${monitorId}`)}
sx={{
px: theme.spacing(5),
"& svg": {
mr: theme.spacing(3),
"& path": {
stroke: theme.palette.text.tertiary,
},
},
}}
>
<SettingsIcon /> Configure
</Button>
)}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Arms are heavy! Extract route paths into constants

The hardcoded navigation path could cause maintenance issues if routes change.

Create a routes constant file:

+ // src/constants/routes.js
+ export const ROUTES = {
+   INFRASTRUCTURE_CONFIGURE: (id) => `/infrastructure/configure/${id}`,
+ };

// In your component:
- onClick={() => navigate(`/infrastructure/configure/${monitorId}`)}
+ onClick={() => navigate(ROUTES.INFRASTRUCTURE_CONFIGURE(monitorId))}

Committable suggestion skipped: line range outside the PR's diff.

@@ -182,7 +183,7 @@ GaugeBox.propTypes = {
* Renders the infrastructure details page
* @returns {React.ReactElement} Infrastructure details page component
*/
const InfrastructureDetails = () => {
const InfrastructureDetails = ({ isAdmin }) => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Yo! Add PropTypes validation for isAdmin prop

The isAdmin prop needs PropTypes validation to prevent potential runtime issues.

Add this after the component:

+ InfrastructureDetails.propTypes = {
+   isAdmin: PropTypes.bool.isRequired
+ };

Committable suggestion skipped: line range outside the PR's diff.

@ajhollid
Copy link
Collaborator

ajhollid commented Dec 8, 2024

Hi @peterpardo !

As always we greatly appreciate your contributions to the project!

We haven't decided on an approach for the "Configure" pages yet however, so we won't be able to address this PR at the current time.

The issue at hand is that the "Configure" pages are practically identical to the "Create" pages, so it probably makes sense just to refactor the "Create" pages for dual use.

Appreciate your hard work here, if we decide to go with the approach of having two separate pages we can revisit this PR!

@peterpardo
Copy link
Contributor Author

Hi @peterpardo !

As always we greatly appreciate your contributions to the project!

We haven't decided on an approach for the "Configure" pages yet however, so we won't be able to address this PR at the current time.

The issue at hand is that the "Configure" pages are practically identical to the "Create" pages, so it probably makes sense just to refactor the "Create" pages for dual use.

Appreciate your hard work here, if we decide to go with the approach of having two separate pages we can revisit this PR!

Sure! No worries. Actually, I noticed that as well that there are code duplications in some parts of the pages.

I can try to make a PR to refactor the Create and Configure pages, but I'll implement it on the Infrastructure Monitor only first to avoid a large PR. Let me know if that sounds good.

@ajhollid
Copy link
Collaborator

ajhollid commented Dec 9, 2024

Hi @peterpardo !
As always we greatly appreciate your contributions to the project!
We haven't decided on an approach for the "Configure" pages yet however, so we won't be able to address this PR at the current time.
The issue at hand is that the "Configure" pages are practically identical to the "Create" pages, so it probably makes sense just to refactor the "Create" pages for dual use.
Appreciate your hard work here, if we decide to go with the approach of having two separate pages we can revisit this PR!

Sure! No worries. Actually, I noticed that as well that there are code duplications in some parts of the pages.

I can try to make a PR to refactor the Create and Configure pages, but I'll implement it on the Infrastructure Monitor only first to avoid a large PR. Let me know if that sounds good.

I think it would be best to hold off until we decide what direction we're going with these pages. The maintainers are meeting tomorrow so we'll discuss this topic then, I'll update the issues page after that with the results of our discussion. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Infratructure monitors should be editable
2 participants