Skip to content

Update TypeScript configuration to exclude test files and enhance cos… - #44

Open
louistrue wants to merge 1 commit into
mainfrom
ts-fixes
Open

Update TypeScript configuration to exclude test files and enhance cos…#44
louistrue wants to merge 1 commit into
mainfrom
ts-fixes

Conversation

@louistrue

@louistrue louistrue commented Dec 19, 2025

Copy link
Copy Markdown
Collaborator

…t calculation logic in MainPage and CostUploader components. Refactor PreviewModal props for optionality and streamline state management in CostTableRow. Improve Excel dialog configuration handling for better data integrity.

Summary by CodeRabbit

  • Refactor
    • Optimized cost calculation logic to dynamically determine quantities based on item-specific configuration.
    • Improved component flexibility by making optional parameters with sensible defaults.
    • Streamlined data transformation in the cost confirmation workflow.
    • Refined Excel export configuration handling.
    • Updated TypeScript configuration to exclude test files from compilation.

✏️ Tip: You can customize this high-level summary in your review settings.

…t calculation logic in MainPage and CostUploader components. Refactor PreviewModal props for optionality and streamline state management in CostTableRow. Improve Excel dialog configuration handling for better data integrity.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Dec 19, 2025

Copy link
Copy Markdown

Walkthrough

This PR contains refactoring and configuration updates across the cost calculation and component system. Changes include making PreviewModal props optional, refactoring cost data handling in CostUploader, updating totalCost aggregation logic in MainPage to use quantity-aware calculations, adjusting useEffect dependencies in CostTableRow, simplifying config serialization in useExcelDialog, and excluding test files from TypeScript compilation.

Changes

Cohort / File(s) Change Summary
Cost data flow refactoring
src/components/CostUploader/PreviewModal.tsx, src/components/CostUploader/index.tsx
Made metaFile, ebkpStats, and kennwerte props optional in PreviewModal with defaults ([] and {}); refactored handleConfirmPreview to derive cost data from bimElements instead of accepting EnhancedCostItem[] parameter, transforming payload structure for API.
Quantity-aware aggregation
src/components/MainPage.tsx
Updated totalCost calculation to dynamically select per-item quantity type from selectedQuantityType and retrieve corresponding value from availableQuantities instead of using uniform quantity.
Component state & rendering
src/components/CostUploader/CostTableRow.tsx
Removed qtoInTree from useEffect dependency array; now depends only on [item, hasQtoState, hasQtoInTreeState] for derived state updates.
Configuration & utilities
src/hooks/useExcelDialog.ts, tsconfig.app.json
Replaced Array.reduce with forEach loop in useExcelDialog for configToSave construction; added exclude patterns in TypeScript config to omit test/spec files.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • src/components/CostUploader/index.tsx: Verify the data transformation from enhancedData to costData and confirm the filtered payload structure aligns with backend expectations.
  • src/components/MainPage.tsx: Review the quantity-aware aggregation logic to ensure selectedQuantityType fallback and availableQuantities lookups handle edge cases correctly.
  • src/components/CostUploader/PreviewModal.tsx: Confirm that optional props and their defaults do not introduce unexpected behavior in dependent calculations.

Possibly related PRs

Suggested labels

codex

Poem

🐰 A cost calculation hop,
With quantities that never stop,
Props made light, data flows true,
Dependencies pruned, old tests through!
The spreadsheet sings, logic is sound. ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is partially related to the changeset—it mentions updating TypeScript configuration and enhancing cost calculation, which are real aspects of the change, but the title is incomplete (truncated with 'enhance cos…') and doesn't fully convey the scope of additional refactoring in PreviewModal, CostTableRow, and useExcelDialog.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ts-fixes

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/components/CostUploader/CostTableRow.tsx (1)

102-115: Good fix removing qtoInTree from dependencies.

The removal is correct since qtoInTree is a locally computed value derived from item within the effect itself, not an external dependency.

However, consider simplifying the dependency array further by removing hasQtoState and hasQtoInTreeState. These state variables are updated by this effect, creating a feedback loop (though safely guarded by your conditionals). The standard React pattern would be:

🔎 Optional refactor to simplify dependencies
  useEffect(() => {
-   // Check QTO data status
-   const qtoData = hasQtoData(item);
-   const qtoInTree = hasQtoDataInTree(item);
-
-   // Update state if changed
-   if (qtoData !== hasQtoState) {
-     setHasQtoState(qtoData);
-   }
-
-   if (qtoInTree !== hasQtoInTreeState) {
-     setHasQtoInTreeState(qtoInTree);
-   }
- }, [item, hasQtoState, hasQtoInTreeState]);
+   setHasQtoState(hasQtoData(item));
+   setHasQtoInTreeState(hasQtoDataInTree(item));
+ }, [item]);

React automatically skips re-renders when state values haven't changed, making the explicit conditionals unnecessary. This simplifies the code and eliminates the feedback loop pattern.

src/components/CostUploader/index.tsx (1)

148-152: Consider defensive filtering for malformed data.

The filtering on line 152 (filter(item => item.id && item.ebkp_code)) correctly excludes items without required fields. However, consider also validating that item.global_id || item._id produces a truthy value before including the item, as both could theoretically be empty strings.

🔎 Proposed enhancement for more robust filtering
-      })).filter(item => item.id && item.ebkp_code);
+      }))
+        .filter(item => item.id && item.ebkp_code)
+        .filter(item => item.id.trim().length > 0 && item.ebkp_code.trim().length > 0);
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3b6035d and 67fbb55.

📒 Files selected for processing (6)
  • src/components/CostUploader/CostTableRow.tsx (1 hunks)
  • src/components/CostUploader/PreviewModal.tsx (2 hunks)
  • src/components/CostUploader/index.tsx (3 hunks)
  • src/components/MainPage.tsx (1 hunks)
  • src/hooks/useExcelDialog.ts (1 hunks)
  • tsconfig.app.json (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
src/components/CostUploader/PreviewModal.tsx (3)
src/components/CostUploader/types.ts (1)
  • MetaFile (93-104)
src/components/CostUploader/types.tsx (1)
  • MetaFile (3-6)
src/components/EbkpCostForm.tsx (1)
  • EbkpStat (42-54)
src/hooks/useExcelDialog.ts (1)
src/utils/excelService.ts (1)
  • ExcelExportConfig (6-8)
src/components/CostUploader/index.tsx (1)
src/services/costApi.ts (1)
  • costApi (109-117)
🔇 Additional comments (5)
tsconfig.app.json (1)

25-26: LGTM! Standard test file exclusion.

The added exclude patterns properly exclude test and spec files from the TypeScript compilation for the application build, which is a standard best practice.

src/components/CostUploader/PreviewModal.tsx (1)

63-67: Props refactored to be optional with safe defaults.

Making metaFile, ebkpStats, and kennwerte optional with default values ([] and {}) increases component flexibility and prevents undefined errors. The component handles both cases—when all data is provided (MainPage.tsx) and when relying on defaults (CostUploader/index.tsx)—without breaking functionality.

src/components/CostUploader/index.tsx (1)

112-156: Remove concern about cost calculation inconsistency—design is intentional and correct.

The refactored code correctly handles two distinct cost workflows:

  • Excel flow (lines 234-238): Sends pre-calculated totalCost from the imported data, since Excel imports already contain cost information
  • BIM flow (line 150): Sends cost: 0 with ebkp_code, relying on the backend's cost calculation engine to derive costs from kennwerte lookup tables using reapplyCosts()

The backend architecture supports this separation: costs for BIM elements are recalculated server-side based on ebkp code → kennwerte mapping, not assumed to be zero. The comment "Cost is calculated elsewhere based on kennwerte" is accurate and reflects the system design where BIM elements are matched to eBKP codes for dynamic cost calculation.

src/hooks/useExcelDialog.ts (1)

60-65: The code intentionally saves an empty object since ExcelExportConfig only contains the fileName property, which is explicitly excluded with the comment "Don't save the filename as it should be date-based." When the config is loaded from localStorage, the fileName is regenerated with the current date each time. This pattern appears designed for future extensibility—if additional config properties are added to ExcelExportConfig, they will be automatically persisted. Consider whether this forward-looking pattern aligns with your design intent.

src/components/MainPage.tsx (1)

683-692: The updated totalCost calculation safely handles edge cases through defensive programming.

The code correctly uses optional chaining (?.) and fallback operators (|| 0) to prevent runtime errors when availableQuantities is missing or a quantity match fails. Since getAvailableQuantities() guarantees at least one item (defaulting to "count" with value 1), and availableQuantities is populated during EbkpStat initialization, the calculation will produce a valid result even in edge cases—worst case, it safely defaults to 0 quantity and thus 0 cost for that item.

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.

1 participant