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

refactor: percent calcuation and typescript deifinition in agent list #2690

Merged
merged 1 commit into from
Sep 5, 2024

Conversation

yomybaby
Copy link
Member

@yomybaby yomybaby commented Sep 4, 2024

TL;DR

Refactored the AgentList component to improve type safety and code readability.

What changed?

  • Improved type safety by explicitly defining types for parsedOccupiedSlots and parsedAvailableSlots.
  • Refactored the rendering logic for resource allocation to use a more consistent approach across different resource types.
  • Simplified calculations for percentage values and improved variable naming.
  • Consolidated duplicate code into reusable logic for CPU, memory, and other resource types.

How to test?

  1. Navigate to the Agent List view in the application.
  2. Verify that the allocation information for CPU, memory, and other resources is displayed correctly.
  3. Check that the progress bars accurately reflect the resource usage percentages.
  4. Ensure that the color coding (red for high usage, green for normal usage) is working as expected.

Why make this change?

This refactoring improves code maintainability and reduces the likelihood of bugs by:

  1. Enhancing type safety, which helps catch potential errors at compile-time.
  2. Reducing code duplication, making it easier to update and maintain the component.
  3. Improving readability, making it easier for developers to understand and work with the code.
  4. Ensuring consistent handling of different resource types, which can simplify future additions or modifications to resource allocation display.

Copy link
Member Author

yomybaby commented Sep 4, 2024

Copy link
Contributor

@ironAiken2 ironAiken2 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@lizable lizable left a comment

Choose a reason for hiding this comment

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

LGTM.

Copy link

graphite-app bot commented Sep 5, 2024

Merge activity

…#2690)

### TL;DR

Refactored the AgentList component to improve type safety and code readability.

### What changed?

- Improved type safety by explicitly defining types for `parsedOccupiedSlots` and `parsedAvailableSlots`.
- Refactored the rendering logic for resource allocation to use a more consistent approach across different resource types.
- Simplified calculations for percentage values and improved variable naming.
- Consolidated duplicate code into reusable logic for CPU, memory, and other resource types.

### How to test?

1. Navigate to the Agent List view in the application.
2. Verify that the allocation information for CPU, memory, and other resources is displayed correctly.
3. Check that the progress bars accurately reflect the resource usage percentages.
4. Ensure that the color coding (red for high usage, green for normal usage) is working as expected.

### Why make this change?

This refactoring improves code maintainability and reduces the likelihood of bugs by:

1. Enhancing type safety, which helps catch potential errors at compile-time.
2. Reducing code duplication, making it easier to update and maintain the component.
3. Improving readability, making it easier for developers to understand and work with the code.
4. Ensuring consistent handling of different resource types, which can simplify future additions or modifications to resource allocation display.
@lizable lizable force-pushed the refactor/remove-hard-coded-resource-name branch from 92df5b7 to d52c682 Compare September 5, 2024 02:53
@lizable lizable force-pushed the refactor/percent-and-types-in-agent-list branch from 9302462 to b49b666 Compare September 5, 2024 02:54
Base automatically changed from refactor/remove-hard-coded-resource-name to main September 5, 2024 02:56
@graphite-app graphite-app bot merged commit b49b666 into main Sep 5, 2024
4 checks passed
@graphite-app graphite-app bot deleted the refactor/percent-and-types-in-agent-list branch September 5, 2024 02:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:L 100~500 LoC
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants