[PR #581] [MERGED] Refactor frontend utility functions to reduce duplication #1073

Closed
opened 2026-05-06 12:34:53 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/maziggy/bambuddy/pull/581
Author: @aneopsy
Created: 3/3/2026
Status: Merged
Merged: 3/4/2026
Merged by: @maziggy

Base: 0.2.2b1Head: refactor-utils


📝 Commits (3)

  • 15521de Refactor date and currency utility functions
  • abe40f1 Consolidate duplicate utility functions into shared modules
  • ba2abe1 Merge branch '0.2.2b1' into refactor-utils

📊 Changes

15 files changed (+8840 additions, -303 deletions)

View changed files

📝 frontend/src/components/FilamentHoverCard.tsx (+1 -11)
📝 frontend/src/components/FileManagerModal.tsx (+0 -1)
📝 frontend/src/components/GitHubBackupSettings.tsx (+6 -6)
📝 frontend/src/components/SpoolUsageHistory.tsx (+4 -5)
📝 frontend/src/components/TimelapseEditorModal.tsx (+5 -10)
📝 frontend/src/components/TimelapseViewer.tsx (+3 -8)
📝 frontend/src/contexts/ToastContext.tsx (+2 -9)
📝 frontend/src/pages/PrintersPage.tsx (+5 -86)
📝 frontend/src/pages/ProjectDetailPage.tsx (+3 -17)
📝 frontend/src/pages/spoolbuddy/SpoolBuddySettingsPage.tsx (+0 -1)
📝 frontend/src/utils/colors.ts (+30 -0)
📝 frontend/src/utils/currency.ts (+4 -28)
📝 frontend/src/utils/date.ts (+78 -120)
📝 frontend/src/utils/file.ts (+1 -1)
static/assets/index-BAl7JF0v.js (+8698 -0)

📄 Description

Description

Consolidate duplicate helper functions scattered across frontend components into shared utility modules, reducing code duplication while preserving exact UI behavior. No visual or functional changes, every local function was verified against its shared replacement through multiple behavioral reviews.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Code refactoring
  • Performance improvement
  • Test addition or update

Changes Made

  • Extract isLightColor, parseFilamentColor, hexToColorName (with brown detection) into utils/colors.ts
  • Add formatMediaTime, formatDurationFromHours to utils/date.ts; refactor detectSystemDateFormat, parseDateInput, parseTimeInput, formatETA
  • Derive SUPPORTED_CURRENCIES from CURRENCY_SYMBOLS map in utils/currency.ts
  • Harden formatFileSize guard for NaN/negative inputs in utils/file.ts
  • Deduplicate formatTime (TimelapseViewer, TimelapseEditorModal) and formatBytes (ToastContext)
  • Functions with subtly different behavior intentionally kept local to preserve exact UI output (e.g., formatFilament, formatStorageSize, formatUptime, formatDateTime, formatTimeAgo)

Screenshots

N/A — pure refactoring with no visual changes.

Testing

  • I have tested this on my local machine

  • I have tested with my printer model:

  • npm run build passes (tsc -b + Vite)

  • All 1029 frontend tests pass

  • All 1783 backend tests pass

  • Multiple behavioral code reviews confirmed zero UI changes

Checklist

  • My code follows the project's coding style
  • I have commented my code where necessary
  • I have updated the documentation (if needed)
  • My changes generate no new warnings
  • I have tested my changes thoroughly

Additional Notes

Net result: -161 lines across 16 files. Only truly identical functions were consolidated; any function with even slightly different formatting (decimal precision, time interpretation, locale handling) was kept local to guarantee no behavior change.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/maziggy/bambuddy/pull/581 **Author:** [@aneopsy](https://github.com/aneopsy) **Created:** 3/3/2026 **Status:** ✅ Merged **Merged:** 3/4/2026 **Merged by:** [@maziggy](https://github.com/maziggy) **Base:** `0.2.2b1` ← **Head:** `refactor-utils` --- ### 📝 Commits (3) - [`15521de`](https://github.com/maziggy/bambuddy/commit/15521deb0a010d2bdb69c72245353fbcda43a306) Refactor date and currency utility functions - [`abe40f1`](https://github.com/maziggy/bambuddy/commit/abe40f1ed06cfb94dd02c8af4daeba6f3791402c) Consolidate duplicate utility functions into shared modules - [`ba2abe1`](https://github.com/maziggy/bambuddy/commit/ba2abe100d0e411cb633d030956c917f310357e9) Merge branch '0.2.2b1' into refactor-utils ### 📊 Changes **15 files changed** (+8840 additions, -303 deletions) <details> <summary>View changed files</summary> 📝 `frontend/src/components/FilamentHoverCard.tsx` (+1 -11) 📝 `frontend/src/components/FileManagerModal.tsx` (+0 -1) 📝 `frontend/src/components/GitHubBackupSettings.tsx` (+6 -6) 📝 `frontend/src/components/SpoolUsageHistory.tsx` (+4 -5) 📝 `frontend/src/components/TimelapseEditorModal.tsx` (+5 -10) 📝 `frontend/src/components/TimelapseViewer.tsx` (+3 -8) 📝 `frontend/src/contexts/ToastContext.tsx` (+2 -9) 📝 `frontend/src/pages/PrintersPage.tsx` (+5 -86) 📝 `frontend/src/pages/ProjectDetailPage.tsx` (+3 -17) 📝 `frontend/src/pages/spoolbuddy/SpoolBuddySettingsPage.tsx` (+0 -1) 📝 `frontend/src/utils/colors.ts` (+30 -0) 📝 `frontend/src/utils/currency.ts` (+4 -28) 📝 `frontend/src/utils/date.ts` (+78 -120) 📝 `frontend/src/utils/file.ts` (+1 -1) ➕ `static/assets/index-BAl7JF0v.js` (+8698 -0) </details> ### 📄 Description ## Description Consolidate duplicate helper functions scattered across frontend components into shared utility modules, reducing code duplication while preserving exact UI behavior. No visual or functional changes, every local function was verified against its shared replacement through multiple behavioral reviews. ## Related Issue <!-- No specific issue — general code quality improvement --> ## Type of Change - [ ] Bug fix (non-breaking change that fixes an issue) - [ ] New feature (non-breaking change that adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation update - [x] Code refactoring - [ ] Performance improvement - [ ] Test addition or update ## Changes Made - Extract `isLightColor`, `parseFilamentColor`, `hexToColorName` (with brown detection) into `utils/colors.ts` - Add `formatMediaTime`, `formatDurationFromHours` to `utils/date.ts`; refactor `detectSystemDateFormat`, `parseDateInput`, `parseTimeInput`, `formatETA` - Derive `SUPPORTED_CURRENCIES` from `CURRENCY_SYMBOLS` map in `utils/currency.ts` - Harden `formatFileSize` guard for NaN/negative inputs in `utils/file.ts` - Deduplicate `formatTime` (TimelapseViewer, TimelapseEditorModal) and `formatBytes` (ToastContext) - Functions with subtly different behavior intentionally kept local to preserve exact UI output (e.g., `formatFilament`, `formatStorageSize`, `formatUptime`, `formatDateTime`, `formatTimeAgo`) ## Screenshots N/A — pure refactoring with no visual changes. ## Testing - [x] I have tested this on my local machine - [ ] I have tested with my printer model: - `npm run build` passes (tsc -b + Vite) - All 1029 frontend tests pass - All 1783 backend tests pass - Multiple behavioral code reviews confirmed zero UI changes ## Checklist - [x] My code follows the project's coding style - [x] I have commented my code where necessary - [ ] I have updated the documentation (if needed) - [x] My changes generate no new warnings - [x] I have tested my changes thoroughly ## Additional Notes Net result: -161 lines across 16 files. Only truly identical functions were consolidated; any function with even slightly different formatting (decimal precision, time interpretation, locale handling) was kept local to guarantee no behavior change. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 12:34:53 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/bambuddy#1073
No description provided.