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

Fix Storage Chart #2828

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

Fix Storage Chart #2828

wants to merge 2 commits into from

Commits on Oct 3, 2024

  1. Fix Storage Chart

    # 🛠️ Fix Data Fetching and Conditional Logic in History Charts
    
    ## **Overview**
    
    This PR addresses critical issues in the `AbstractHistoryChart` component related to data fetching and conditional logic, ensuring that historical timeseries data is correctly retrieved and processed for accurate chart rendering.
    
    ## **Issues Addressed**
    
    1. **Incorrect Data Fetching Logic**
       - **Problem:** The `queryHistoricTimeseriesData` method was improperly returning empty data regardless of the API response, leading to charts displaying undefined or empty datasets.
       - **Solution:** Refactored the method to properly handle asynchronous API responses, ensuring that actual data is returned and errors are handled gracefully.
    
    2. **Faulty Conditional Statement**
       - **Problem:** The condition
         ```typescript
         if ("_sum/EssActivePowerL1" && "_sum/EssActivePowerL2" && "_sum/EssActivePowerL3" in result.data && this.showPhases == true) {
         ```
         was always evaluating to `true` due to operator precedence, causing logical errors.
       - **Solution:** Updated the condition to explicitly check each channel using the `in` operator:
         ```typescript
         if ("_sum/EssActivePowerL1" in result.data && "_sum/EssActivePowerL2" in result.data && "_sum/EssActivePowerL3" in result.data && this.showPhases === true) {
         ```
    
    ## **Changes Made**
    
    - **Refactored `queryHistoricTimeseriesData` Method:**
      - Removed the immediate return of empty data.
      - Ensured the method resolves with actual API responses.
      - Implemented proper error handling by rejecting promises on failures.
      - Added a stale response check to prevent race conditions.
    
    - **Fixed Conditional Logic:**
      - Rewrote the `if` statement to individually check each required channel's existence in `result.data`.
      - Used strict equality (`===`) for `this.showPhases` to ensure type-safe comparison.
    
    ## **Why These Changes?**
    
    - **Accurate Data Representation:** Ensures charts display real and complete historical data, improving reliability.
    - **Elimination of Logical Errors:** Correct conditional checks prevent unintended code execution, maintaining data integrity.
    - **Enhanced Error Handling:** Properly managing API errors prevents the application from masking issues and aids in debugging.
    - **Improved Code Quality:** Addressing TypeScript warnings leads to cleaner, more maintainable code.
    
    ## **Testing**
    
    - Verified that charts now display correct data when API responses are received.
    - Confirmed that conditional statements behave as expected without triggering TypeScript warnings.
    - Ensured that error scenarios gracefully initialize empty charts without breaking the application.
    
    ---
    
    **Please review the changes and approve the merge to enhance the reliability and accuracy of our history chart components.**
    Sn0w3y committed Oct 3, 2024
    Configuration menu
    Copy the full SHA
    bb47ae2 View commit details
    Browse the repository at this point in the history

Commits on Oct 6, 2024

  1. Configuration menu
    Copy the full SHA
    94dd8ff View commit details
    Browse the repository at this point in the history