Skip to content

refactor: quality-of-life improvements — reduce duplication and improve type safety#762

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1779681876-qol-improvements
Open

refactor: quality-of-life improvements — reduce duplication and improve type safety#762
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1779681876-qol-improvements

Conversation

@devin-ai-integration
Copy link
Copy Markdown
Contributor

Summary

Four targeted quality-of-life improvements that reduce code duplication and improve type safety without changing any functionality. Net result: -59 lines (243 added, 302 removed) across 7 files.

1. Backend: Extract fetchClientWithEntries helper in reports.js

All three report routes (/client/:clientId, /export/csv/:clientId, /export/pdf/:clientId) duplicated the same pattern — parse clientId, validate, verify client ownership, fetch work entries, handle errors. Extracted into a single reusable helper that accepts the SELECT columns and a callback. Eliminates ~60 lines of triplication.

2. Frontend: Add getApiErrorMessage utility (types/api.ts)

The pattern err as { response?: { data?: { error?: string } } } was repeated 8 times across LoginPage, ClientsPage, and WorkEntriesPage. Replaced with a single getApiErrorMessage(err, fallback) function that centralizes the extraction logic and the ApiErrorBody interface.

3. Frontend: Extract downloadBlob + handleExport in ReportsPage

The CSV and PDF export handlers had near-identical code for creating object URLs, triggering downloads, and cleaning up. Extracted downloadBlob (reusable blob-to-download helper) and a generic handleExport that takes the API function, extension, and error message.

4. Frontend: Migrate DashboardPage Grid to MUI v2 API

Replaced deprecated <Grid item xs={} sm={} md={}> props with <Grid size={{ xs:, sm:, md: }}>, matching the pattern already used in ReportsPage. Eliminates 3 @ts-expect-error suppression comments.

Review & Testing Checklist for Human

  • Verify report endpoints still work correctly: fetch a client report, export as CSV, and export as PDF — the fetchClientWithEntries refactor touches all three routes
  • Verify error messages still display correctly on frontend forms (create/update/delete client, create/update/delete work entry, login) — the getApiErrorMessage change touches all mutation error handlers
  • Verify CSV/PDF download triggers correctly from the Reports page — the export refactor changes how blob downloads are initiated
  • Spot-check the Dashboard page layout at different breakpoints (mobile, tablet, desktop) to confirm Grid sizing behaves identically after the v1→v2 API migration

Notes

  • All 161 backend tests pass
  • Frontend lint (eslint src/) passes with no errors
  • Frontend build (tsc -b && vite build) succeeds
  • No functionality changes — purely structural/quality improvements

Link to Devin session: https://partner-workshops.devinenterprise.com/sessions/bc89425a2d8e4128af32ea28ce6f98e1

- Extract fetchClientWithEntries helper in reports.js to eliminate
  triplication of client verification + work entry fetching
- Add getApiErrorMessage utility to centralize error extraction,
  replacing 8 repeated unsafe type casts across 3 frontend pages
- Extract downloadBlob helper and generic handleExport in ReportsPage
  to remove duplicated CSV/PDF export logic
- Migrate DashboardPage Grid from deprecated v1 item props to v2 size
  API, eliminating 3 @ts-expect-error suppressions
@devin-ai-integration
Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@sonarqubecloud
Copy link
Copy Markdown

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.

0 participants