Skip to content

Comments

Fix multiple api calls#30

Merged
technologic-technologic merged 1 commit into28-fix-tests-with-vitestfrom
12-keeps-stage-between-refreshes
Oct 14, 2025
Merged

Fix multiple api calls#30
technologic-technologic merged 1 commit into28-fix-tests-with-vitestfrom
12-keeps-stage-between-refreshes

Conversation

@technologic-technologic
Copy link
Owner

Fixed the bug where multiple calls to the backend where made for no reason

Key changes

  • Updated DataProvider
  • Added exposed component to interact with the one and only DataContext context.

Fixed the bug where multiple calls to the backend where made for no reason

## Key changes
- Updated DataProvider
- Added exposed component to interact with the one and only DataContext context.

Signed-off-by: Leonardo Trevizo <leonardo.trevizo@encora.com>
@github-actions
Copy link

PR Summary

WHAT Changed

  • InputSearch Component: Added a debounce mechanism for the search input to reduce the frequency of state updates.
  • ProductForm, InventoryTable, InventoryTablePageSelector, InventoryMetricsTable: Updated to use useDataContext instead of useProductsData, centralizing data fetching logic.
  • DataContext: Refactored to include a default context value and improved error handling. Added a refresh function for fetching products and categories.

WHY It Matters

  • Performance Improvement: The debounce in InputSearch enhances user experience by preventing excessive re-renders during typing.
  • Code Consistency: Using useDataContext across components simplifies data management and reduces redundancy.
  • Error Handling: Improved error handling in DataContext provides clearer feedback in case of data fetching issues.

RISKS

  • Potential Bugs: Changes in data fetching logic may introduce bugs if not thoroughly tested, especially in components relying on the previous useProductsData.
  • Performance: While debounce improves performance, it may introduce a delay in state updates that could affect user experience if not properly tuned.

TESTS to Add

  • Unit tests for the debounce functionality in InputSearch.
  • Integration tests for components using useDataContext to ensure they correctly handle data fetching and state updates.
  • Tests for error handling in the DataContext to verify that errors are reported correctly.

BREAKING CHANGES

  • Context Hook Change: Components previously using useProductsData must now use useDataContext, which may require updates in how data is accessed.
  • Data Fetching Logic: The structure of the data context has changed, which may affect components that rely on the previous implementation.

Changed File Paths

  • inventory-manager/src/components/page-content/segment1-search_product/input-bars/InputSearch.tsx
  • inventory-manager/src/components/page-content/segment2-new_product/ProductForm.tsx
  • inventory-manager/src/components/page-content/segment3-table/InventoryTable.tsx
  • inventory-manager/src/components/page-content/segment3-table/InventoryTablePageSelector.tsx
  • inventory-manager/src/components/page-content/segment4-metrics/InventoryMetricsTable.tsx
  • inventory-manager/src/context/DataContext.tsx

@technologic-technologic technologic-technologic added the bug Something isn't working label Oct 14, 2025
@technologic-technologic technologic-technologic added this to the Major fixes milestone Oct 14, 2025
@technologic-technologic technologic-technologic linked an issue Oct 14, 2025 that may be closed by this pull request
@technologic-technologic technologic-technologic merged commit 2fb27c8 into 28-fix-tests-with-vitest Oct 14, 2025
1 check passed
@technologic-technologic technologic-technologic deleted the 12-keeps-stage-between-refreshes branch October 14, 2025 22:30
@technologic-technologic technologic-technologic linked an issue Oct 15, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

After creating new ProductData, Table shows new product Keeps stage between refreshes

1 participant