Skip to content

feat: move taxonomy loading to server route - #185

Merged
johlju merged 6 commits into
viscalyx:mainfrom
johlju:f/b2-april
May 7, 2026
Merged

feat: move taxonomy loading to server route#185
johlju merged 6 commits into
viscalyx:mainfrom
johlju:f/b2-april

Conversation

@johlju

@johlju johlju commented May 7, 2026

Copy link
Copy Markdown
Member

Description

Also:

chore: update dependencies to latest versions

  • upgraded lucide-react from ^1.11.0 to ^1.14.0
  • upgraded mssql from ^12.5.0 to ^12.5.2
  • upgraded next from ^16.2.4 to ^16.2.5
  • upgraded next-intl from ^4.9.1 to ^4.11.0
  • upgraded react and react-dom from ^19.2.5 to ^19.2.6
  • upgraded zod from ^4.3.6 to ^4.4.3
  • upgraded @biomejs/biome from ^2.4.13 to ^2.4.14
  • upgraded jsdom from ^29.1.0 to ^29.1.1
  • upgraded hono from 4.12.15 to 4.12.16
  • added ip-address at version 10.2.0
  • added icu-minify at version 4.11.0

Screenshots (if applicable)

Related Issues

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 not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement (improves performance without changing functionality)
  • Dependency update (updating libraries or tools)

Testing

  • npm run check passes locally
  • All existing tests still pass
  • Manual testing completed
  • UI tested on desktop and mobile (if applicable)

Checklist

  • Documentation updated as needed

Checklist

  • Code follows the project style guidelines (Biome)
  • Tests added/updated as needed
  • Self-review of code completed
  • Comments added for complex logic
  • No hardcoded strings (use translations if i18n is added)

This change is Reviewable

@coderabbitai

coderabbitai Bot commented May 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

This PR centralizes taxonomy option fetching into a new client hook useTaxonomyOptions and refactors form components to consume its result. Parent forms call the hook with a typeId and pass taxonomyOptions into RequirementFormFields; quality characteristics are fetched conditionally by typeId.

Changes

Taxonomy Data Consolidation

Layer / File(s) Summary
Hook Contract and Implementation
hooks/useTaxonomyOptions.ts
New useTaxonomyOptions hook fetches taxonomy arrays (areas, categories, types, quality characteristics, risk levels, requirement packages, norm references) from fixed API endpoints using Promise.allSettled. Exports TypeScript interfaces defining option shapes and hook return value. Quality characteristics are conditionally fetched when typeId is non-empty and cleared when falsy.
Parent Form Components
components/RequirementForm.tsx, components/SpecificationLocalRequirementForm.tsx
Both components now import and invoke useTaxonomyOptions, passing typeId from their respective form state and wiring the returned taxonomyOptions object into RequirementFormFields.
Form Fields Refactoring
components/RequirementFormFields.tsx
Component refactored to receive taxonomyOptions via props rather than managing local state and internal fetches. Local option type interfaces removed in favor of shared exports from the hook. Norm reference merging logic preserved.
Hook Unit Tests
tests/unit/use-taxonomy-options.test.tsx
Comprehensive test suite validates initial parallel fetches, option array population, conditional quality characteristics fetching, loading state transitions, typeId change handling, stale-response protection, thrown-error handling, and partial failure resilience.
Requirement Form Test Update
tests/unit/requirement-form.test.tsx
Existing test updated to assert an AbortSignal is passed to the quality-characteristics fetch call.
Dependency Pins
package.json
Bumps several dependencies and devDependencies and updates an overrides pin for hono plus its explanatory comment text.

Sequence Diagram(s)

sequenceDiagram
  participant Parent as RequirementForm / SpecificationLocalRequirementForm
  participant Hook as useTaxonomyOptions
  participant API as /api/* endpoints
  participant Fields as RequirementFormFields

  Parent->>Hook: call useTaxonomyOptions(typeId)
  Hook->>API: parallel fetch static taxonomy endpoints
  API-->>Hook: respond arrays
  Hook->>Parent: return taxonomyOptions
  Parent->>Fields: pass taxonomyOptions prop
  Fields->>Fields: populate selects/checkboxes with arrays
  Parent->>Hook: (on typeId change) request quality-characteristics
  Hook->>API: fetch /api/quality-characteristics?typeId=...
  API-->>Hook: return qc (or abort/error)
  Hook-->>Parent: updated qualityCharacteristics
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • viscalyx/Kravhantering#177: Modifies the same form components (RequirementForm and RequirementFormFields); changes may intersect with this taxonomy-hook refactor.
🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (3 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning The PR title 'feat: move taxonomy loading to server route' is vague and contradicts the actual changes, which implement client-side taxonomy loading via a custom hook, not server route migration. Revise the title to accurately reflect the actual implementation, such as 'feat: extract taxonomy loading into useTaxonomyOptions hook' or similar.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The PR description lacks concrete details about the main feature work (taxonomy loading refactor) and leaves all checkboxes unchecked despite significant code changes. Add a clear description of the taxonomy loading refactor, specify which type of change applies (New feature/Refactoring), and mark completed testing and checklist items to match the actual changes in the PR.
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/unit/use-taxonomy-options.test.tsx (1)

53-200: ⚡ Quick win

Add regression tests for stale-response and rejected QC fetch paths.

Current tests don’t cover the two failure modes in typeId updates: out-of-order responses and thrown fetch errors for /api/quality-characteristics. Adding those would lock in the hook’s expected behavior.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/unit/use-taxonomy-options.test.tsx` around lines 53 - 200, Add two
tests to tests/unit/use-taxonomy-options.test.tsx covering stale-response and
rejected QC fetch for useTaxonomyOptions: (1) "ignores stale
quality-characteristics responses when typeId changes" — mock fetch so the first
QC request returns a promise you resolve after the second QC request completes
(use controlled Promises), rerender from typeId '1' to '2', resolve promises
out-of-order and assert only the latest QC (for typeId '2') is applied to
result.current.qualityCharacteristics; (2) "handles thrown fetch error for
quality-characteristics" — mock fetch to throw/reject when URL includes
'/api/quality-characteristics' during a typeId change and assert
qualityCharacteristics becomes [] and no unhandled promise errors occur.
Reference useTaxonomyOptions, the '/api/quality-characteristics' URL,
renderHook/rerender/act helpers and fetchMock.mockImplementation to locate where
to implement the mocks.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@hooks/useTaxonomyOptions.ts`:
- Around line 133-155: fetchQualityCharacteristics can produce stale state and
uncaught rejections; update it to use an AbortController (or a requestId ref)
and wrap the fetch/parse in try/catch, abort previous requests in the effect
cleanup, and only call setQualityCharacteristics when the response matches the
latest request and the controller is not aborted. Concretely: in the useCallback
fetchQualityCharacteristics(tid) create an AbortController, pass signal to
fetch, use try { if (!res.ok) handle error; const body = await res.json(); if
(!signal.aborted and tid matches current typeId or requestId ===
latestRef.current) setQualityCharacteristics(body.qualityCharacteristics ?? [])
} catch (err) { if (err.name !== 'AbortError') handle/log error and optionally
setQualityCharacteristics([]) } and in the useEffect that calls
fetchQualityCharacteristics(typeId) abort the previous controller (or increment
latestRef) in its cleanup to prevent out-of-order updates; keep
setQualityCharacteristics as the state setter to update only for the latest
successful response.

---

Nitpick comments:
In `@tests/unit/use-taxonomy-options.test.tsx`:
- Around line 53-200: Add two tests to tests/unit/use-taxonomy-options.test.tsx
covering stale-response and rejected QC fetch for useTaxonomyOptions: (1)
"ignores stale quality-characteristics responses when typeId changes" — mock
fetch so the first QC request returns a promise you resolve after the second QC
request completes (use controlled Promises), rerender from typeId '1' to '2',
resolve promises out-of-order and assert only the latest QC (for typeId '2') is
applied to result.current.qualityCharacteristics; (2) "handles thrown fetch
error for quality-characteristics" — mock fetch to throw/reject when URL
includes '/api/quality-characteristics' during a typeId change and assert
qualityCharacteristics becomes [] and no unhandled promise errors occur.
Reference useTaxonomyOptions, the '/api/quality-characteristics' URL,
renderHook/rerender/act helpers and fetchMock.mockImplementation to locate where
to implement the mocks.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a7d672e3-6a1c-4fdc-af9e-640288f09346

📥 Commits

Reviewing files that changed from the base of the PR and between 0a8860a and d537c7d.

📒 Files selected for processing (5)
  • components/RequirementForm.tsx
  • components/RequirementFormFields.tsx
  • components/SpecificationLocalRequirementForm.tsx
  • hooks/useTaxonomyOptions.ts
  • tests/unit/use-taxonomy-options.test.tsx

Comment thread hooks/useTaxonomyOptions.ts Outdated
@codecov

codecov Bot commented May 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 60.38%. Comparing base (0a8860a) to head (af69a1a).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #185      +/-   ##
==========================================
- Coverage   60.45%   60.38%   -0.07%     
==========================================
  Files         293      293              
  Lines       17333    17294      -39     
  Branches     6665     6538     -127     
==========================================
- Hits        10478    10443      -35     
+ Misses       6714     6710       -4     
  Partials      141      141              
Files with missing lines Coverage Δ
components/RequirementForm.tsx 53.12% <100.00%> (+0.21%) ⬆️
components/RequirementFormFields.tsx 50.89% <100.00%> (-10.55%) ⬇️
components/SpecificationLocalRequirementForm.tsx 29.62% <100.00%> (+0.87%) ⬆️
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

johlju and others added 3 commits May 7, 2026 17:20
- upgraded lucide-react from ^1.11.0 to ^1.14.0
- upgraded mssql from ^12.5.0 to ^12.5.2
- upgraded next from ^16.2.4 to ^16.2.5
- upgraded next-intl from ^4.9.1 to ^4.11.0
- upgraded react and react-dom from ^19.2.5 to ^19.2.6
- upgraded zod from ^4.3.6 to ^4.4.3
- upgraded @biomejs/biome from ^2.4.13 to ^2.4.14
- upgraded jsdom from ^29.1.0 to ^29.1.1
- upgraded hono from 4.12.15 to 4.12.16
- added ip-address at version 10.2.0
- added icu-minify at version 4.11.0
@johlju

johlju commented May 7, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 7, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@johlju
johlju merged commit 87b04ca into viscalyx:main May 7, 2026
9 checks passed
@johlju
johlju deleted the f/b2-april branch May 7, 2026 18:57
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