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

Analytics: Updated client creation and edit #2159

Merged
merged 3 commits into from
Sep 13, 2024
Merged

Conversation

OchiengPaul442
Copy link
Contributor

@OchiengPaul442 OchiengPaul442 commented Sep 11, 2024

Summary of Changes (What does this PR do?)

  • Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Status of maturity (all need to be checked before merging):

  • I've tested this locally
  • I consider this code done
  • This change ready to hit production in its current state

Screenshots (optional)

image
image

Summary by CodeRabbit

  • New Features

    • Introduced DeleteIcon and PlusIcon components for enhanced UI iconography.
    • Enhanced AddClientForm to support multiple IP addresses, allowing users to dynamically add or remove fields.
    • Updated EditClientForm to manage client data more flexibly with a consolidated data prop.
    • Added displayIPAddresses function in UserClientsTable and AdminClientsTable for improved IP address presentation.
    • Improved loading state management for client deactivation actions in AdminClientsTable.
  • Bug Fixes

    • Improved submission logic in forms to filter out empty IP addresses.
  • Style

    • Minor formatting adjustments for improved readability in various components.

Copy link

coderabbitai bot commented Sep 11, 2024

Walkthrough

Walkthrough

The pull request introduces new React components, DeleteIcon and PlusIcon, for visual representation, while enhancing the AddClientForm and EditClientForm to support multiple IP addresses. The UserClientsTable and AdminClientsTable now include a function to format and display IP addresses more effectively. Additionally, modifications to the Redux store configuration improve middleware flexibility. These updates collectively enhance user interactions and data management within the application.

Changes

Files Change Summary
platform/public/icons/Actions/DeleteIcon.js, .../PlusIcon.js Added DeleteIcon and PlusIcon components as functional React components that render SVG icons with customizable properties.
platform/src/common/components/Settings/API/AddClientForm.jsx, .../EditClientForm.jsx Enhanced forms to support multiple IP address entries, including state management for dynamic addition/removal of fields and updated submission logic to filter out empty entries.
platform/src/common/components/Settings/API/UserClientsTable.jsx, .../AdminClientsTable.jsx Introduced displayIPAddresses function to format and display client IP addresses, simplifying the props passed to EditClientForm by using a single data prop.
platform/src/lib/store/index.js Modified middleware configuration in the Redux store setup to use a functional approach for better flexibility in middleware management.

Possibly related PRs

  • netmanager: Edit and register client feature #2157: The changes in the GenerateToken.js component involve managing multiple IP addresses for clients, similar to the enhancements made in the AddClientForm.jsx and EditClientForm.jsx components in the main PR, which also focus on handling multiple IP addresses.

Poem

In the land of code where icons gleam,
A plus and delete, a developer's dream.
Forms now dance with IPs galore,
Adding and removing, who could ask for more?
Redux whispers with middleware's grace,
A smoother journey in this digital space. ✨


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ea900b8 and 5f15f9a.

Files selected for processing (1)
  • platform/src/common/components/Settings/API/AdminClientsTable.jsx (8 hunks)
Additional comments not posted (6)
platform/src/common/components/Settings/API/AdminClientsTable.jsx (6)

22-22: LGTM!

The introduction of the isLoadingDeactivation state variable correctly addresses the previous review comment and improves the loading state management for the deactivation process.


Line range hint 84-99: LGTM!

The update to the handleDeactivate function correctly uses the new isLoadingDeactivation state variable, ensuring accurate representation of the loading state during the deactivation process.


105-109: LGTM!

The introduction of the displayIPAddresses helper function is a great addition. It enhances the component's ability to handle multiple IP addresses per client and improves code readability by extracting the formatting logic into a separate function.


Line range hint 117-161: LGTM!

The formatting adjustments improve code readability, and the usage of the displayIPAddresses function ensures proper display of IP addresses for each client.


Line range hint 169-207:


238-238: LGTM!

The updates to the loading prop of the activation and deactivation DialogWrapper components correctly use the respective loading state variables, ensuring accurate representation of the loading state.

Also applies to: 249-249


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:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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
Contributor

New next-platform changes available for preview here

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: 0

Outside diff range and nitpick comments (1)
platform/public/icons/Actions/DeleteIcon.js (1)

11-11: Consider destructuring the fill prop for cleaner usage.

To improve the readability and conciseness of the code, consider destructuring the fill prop directly from the props object. This way, you can use fill directly instead of props.fill in the stroke attribute.

Here's how you can update the component:

-const DeleteIcon = (props) => {
+const DeleteIcon = ({ fill, ...props }) => {
   return (
     <svg
       xmlns='http://www.w3.org/2000/svg'
       width={24}
       height={24}
       viewBox='0 0 24 24'
       fill='none'
       {...props}>
       <path
         d='M9 3h6M3 6h18m-2 0l-.701 10.52c-.105 1.578-.158 2.367-.499 2.965a3 3 0 01-1.298 1.215c-.62.3-1.41.3-2.993.3h-3.018c-1.582 0-2.373 0-2.993-.3A3 3 0 016.2 19.485c-.34-.598-.394-1.387-.499-2.966L5 6m5 4.5v5m4-5v5'
-        stroke={props.fill || '#1C1D20'}
+        stroke={fill || '#1C1D20'}
         strokeWidth={1.5}
         strokeLinecap='round'
         strokeLinejoin='round'
       />
     </svg>
   );
 };

This way, you can directly use the fill variable in the stroke attribute, making the code cleaner and more readable.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0147246 and b5183fb.

Files selected for processing (6)
  • platform/public/icons/Actions/DeleteIcon.js (1 hunks)
  • platform/public/icons/Actions/PlusIcon.js (1 hunks)
  • platform/src/common/components/Settings/API/AddClientForm.jsx (7 hunks)
  • platform/src/common/components/Settings/API/EditClientForm.jsx (4 hunks)
  • platform/src/common/components/Settings/API/UserClientsTable.jsx (3 hunks)
  • platform/src/lib/store/index.js (2 hunks)
Additional comments not posted (23)
platform/public/icons/Actions/PlusIcon.js (1)

1-23: LGTM!

The PlusIcon component looks good:

  • It's a functional component that renders an SVG icon.
  • It accepts props and spreads them on the SVG element, allowing for customization.
  • The stroke color is determined by the fill prop, defaulting to white if not provided.
  • The component is reusable and properly exported as the default export.

Nice work!

platform/public/icons/Actions/DeleteIcon.js (1)

1-23: LGTM!

The DeleteIcon component looks good overall. It follows a clean and concise structure, properly handles props, and renders the delete icon using an SVG path. The naming and default export are also appropriate.

platform/src/lib/store/index.js (1)

60-65: LGTM!

The changes to the middleware configuration look good. Using a function that returns the default middleware enhances flexibility and allows for potential future modifications without altering the core store setup. The overall structure of the store configuration remains intact.

The code changes are approved.

platform/src/common/components/Settings/API/AddClientForm.jsx (6)

3-7: LGTM!

The code changes are approved.


9-10: LGTM!

The code changes are approved.


21-30: LGTM!

The code changes are approved.


34-45: LGTM!

The code changes are approved.


Line range hint 59-84: LGTM!

The code changes are approved.


Line range hint 98-148: LGTM!

The code changes are approved.

platform/src/common/components/Settings/API/EditClientForm.jsx (12)

1-10: LGTM!

The new imports for PlusIcon and DeleteIcon components are correctly added.


12-15: LGTM!

The changes to the EditClientForm component's props simplify the interface by using a single data prop. The clientID is correctly extracted from the data prop.


22-23: LGTM!

The clientName and ipAddresses state variables are correctly initialized.


26-39: LGTM!

The new handleInitialData function correctly sets the initial state values based on the data prop. The useEffect hook ensures that the state is updated when the data prop changes.


41-51: LGTM!

The handleInputValueChange function correctly updates the ipAddresses state array based on the index of the IP address being edited.


53-59: LGTM!

The handleRemoveInputValue function correctly removes an IP address from the ipAddresses state array based on its index.


61-63: LGTM!

The new handleAddIpAddress function correctly appends an empty string to the ipAddresses state array.


84-86: LGTM!

The changes to the handleSubmit function correctly filter out empty IP addresses before sending the data to the API.


97-104: LGTM!

The updated error handling mechanism using the setIsError function with an object parameter streamlines the error handling and provides more detailed error information.


Line range hint 111-122: LGTM!

The new useEffect hook correctly clears the error state after a timeout of 2 seconds, improving the user experience.


Line range hint 129-177: LGTM!

The updated JSX correctly renders multiple IP address input fields based on the ipAddresses state array. The PlusIcon and DeleteIcon components enhance the user experience for managing IP addresses.


183-183: LGTM!

Wrapping the EditClientForm component with React.memo is a good optimization to prevent unnecessary re-renders and improve performance.

platform/src/common/components/Settings/API/UserClientsTable.jsx (2)

163-167: LGTM!

The displayIPAddresses function looks good. It correctly handles formatting the display of IP addresses, whether client.ip_addresses is an array or not.


217-217: LGTM!

The usage of the displayIPAddresses function to format the display of IP addresses in the table looks good.

Copy link
Contributor

New next-platform changes available for preview here

@OchiengPaul442 OchiengPaul442 changed the title Analytics: Updated client creation and update Analytics: Updated client creation and edit Sep 11, 2024
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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b5183fb and ea900b8.

Files selected for processing (1)
  • platform/src/common/components/Settings/API/AdminClientsTable.jsx (6 hunks)
Additional comments not posted (6)
platform/src/common/components/Settings/API/AdminClientsTable.jsx (6)

104-108: LGTM!

The displayIPAddresses function looks good. It correctly handles both array and non-array values for ip_addresses and provides a clean way to format the display of IP addresses.


116-116: LGTM!

Adding the data-testid attribute to the table element is a good practice for testing purposes. It provides a way to uniquely identify the element in the DOM, making it easier to write tests that interact with the table.


149-160: LGTM!

The code segment correctly renders the client data in the table cells. The usage of the displayIPAddresses function at line 160 ensures that the IP addresses are formatted correctly for display.


168-168: LGTM!

The code segment correctly renders the client activation status in the table cell. The conditional styling based on the isActive property provides a clear visual indication of the activation status.


Line range hint 174-206: LGTM!

The code segment correctly renders the activation and deactivation actions for each client in the table cell. The conditional rendering and click handling based on the isActive property ensures that the actions are only clickable when appropriate. Setting the confirmClientActivation or confirmClientDeactivation state and the selectedClient state on click allows for further handling of the activation or deactivation process.


237-237: LGTM!

The code segment correctly renders the DialogWrapper component for confirming client activation. Setting the loading prop to the isLoadingActivation state ensures that the loading state is properly displayed while the activation request is in progress.

@@ -248,8 +245,7 @@ const AdminClientsTable = () => {
onClose={() => setConfirmClientDeactivation(false)}
handleClick={handleDeactivate}
primaryButtonText={'Deactivate'}
loading={isLoadingActivation}
>
loading={isLoadingActivation}>
Copy link

@coderabbitai coderabbitai bot Sep 11, 2024

Choose a reason for hiding this comment

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

Use a separate state variable for the deactivation loading state.

The code segment correctly renders the DialogWrapper component for confirming client deactivation. However, setting the loading prop to the isLoadingActivation state seems incorrect. It should be set to a separate state variable specific to the deactivation process, such as isLoadingDeactivation.

Consider introducing a new state variable, such as isLoadingDeactivation, to track the loading state of the deactivation process separately from the activation process. Update the loading prop of the deactivation DialogWrapper to use this new state variable.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hi @OchiengPaul442 , please review this AI review comment and share feedback accordingly. Thanks!

Copy link

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Copy link
Collaborator

@Baalmart Baalmart left a comment

Choose a reason for hiding this comment

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

Thanks @OchiengPaul442 , I have just left a couple of code review comments for your attention. Thanks again, this is great! :)

@@ -105,22 +119,22 @@ const EditClientForm = ({ open, closeModal, cIP = '', cName = '', clientID }) =>

return () => clearTimeout(timer);
}
}, [isError]);
}, [isError.isError]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks @OchiengPaul442 :

  • Is this variable "isError" always present?
  • If not always available, we might want to handle this use case to minimise chances of runtime errors. There are couple of options which must be BACKWARD compatible with earlier version of node (JS).

Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @Baalmart ,
The state hook declaration you mentioned is used to manage the error state and display appropriate messages to the user when something goes wrong. This ensures that the error state is always present and updated accordingly whenever an error is detected.

You’re right about the compatibility. This state hook is specifically designed for use in a React frontend and won’t be compatible with a Node.js backend. However, it works perfectly fine for managing error states in a React component.

  const [isError, setIsError] = useState({
    isError: false,
    message: '',
    type: '',
  });

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor

New next-platform changes available for preview here

@Baalmart Baalmart merged commit 6add04b into staging Sep 13, 2024
28 of 29 checks passed
@Baalmart Baalmart deleted the client-refactor branch September 13, 2024 05:04
@Baalmart Baalmart mentioned this pull request Sep 13, 2024
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants