refactor: migrate options and datalist query hooks#18734
Conversation
|
Caution Review failedAn error occurred during the review process. Please try again later. 📝 WalkthroughWalkthroughCentralises options fetching into a new OptionsApi client, exposes it via ApiProvider/useOptionsApi, adds React Query factories and core hooks, removes legacy fetchOptions/fetchDataList, refactors feature hooks to use core hooks, and updates tests and test utilities to mock the new API. ChangesOptions API Refactoring
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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 `@src/App/frontend/src/features/options/useGetOptionsQuery.ts`:
- Around line 20-29: Remove the `as UseQueryResult<...>` cast in
useGetOptionsQuery and instead make the function and upstream call(s) return the
correct typed result: update useOptionsQuery's generic/return type (or add a
properly typed intermediate variable) so that when you build the transformed
result (using castOptionsToStrings on result.data.data and preserving
result.data.headers) the TypeScript compiler infers the exact type { data:
IOptionInternal[]; headers: AxiosResponse['headers'] } | null; ensure
useGetOptionsQuery's signature reflects that return type and return the
transformed object without any `as` cast, referencing the functions
useGetOptionsQuery, useOptionsQuery, and castOptionsToStrings to locate the
change.
In `@src/App/frontend/src/queries/queries.ts`:
- Line 167: fetchProcessState references a missing helper and type:
getProcessStateUrl is not defined/exported from appUrlHelper and IProcess is not
imported here; either add a getProcessStateUrl(instanceId: string) export to
appUrlHelper (mirroring getProcessNextUrl semantics) and import IProcess from
src/types/shared into this file, or remove/replace fetchProcessState with the
correct existing call (e.g., use getProcessNextUrl if that was intended) and
remove the IProcess usage; update the import list and ensure fetchProcessState
uses the newly added getProcessStateUrl or the correct helper.
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 4beb9134-610b-4293-953c-68eb1c6d7ed2
📒 Files selected for processing (16)
src/App/frontend/src/core/api-client/options.api.tssrc/App/frontend/src/core/contexts/ApiProvider.tsxsrc/App/frontend/src/core/queries/options/index.tssrc/App/frontend/src/core/queries/options/options.queries.tssrc/App/frontend/src/features/dataLists/useDataListQuery.tsxsrc/App/frontend/src/features/options/useGetOptions.test.tsxsrc/App/frontend/src/features/options/useGetOptionsQuery.tssrc/App/frontend/src/layout/Checkboxes/CheckboxesContainerComponent.test.tsxsrc/App/frontend/src/layout/Dropdown/DropdownComponent.test.tsxsrc/App/frontend/src/layout/FileUpload/FileUploadComponent.test.tsxsrc/App/frontend/src/layout/FileUpload/Summary/AttachmentWithTagSummaryComponent.test.tsxsrc/App/frontend/src/layout/Likert/LikertTestUtils.tsxsrc/App/frontend/src/layout/List/ListComponent.test.tsxsrc/App/frontend/src/layout/RadioButtons/ControlledRadioGroup.test.tsxsrc/App/frontend/src/queries/queries.tssrc/App/frontend/src/test/renderWithProviders.tsx
…ithub.com/jonny5203/altinn-studio into 18175-options-and-datalists-upstream-main
|
Hi @adamhaeger can you take a look at this, it is a fix for issue #18175 |
Summary
optionsApiclient and core query hooks for options and data lists.useAppQueries().fetchOptions/fetchDataListto the new query hook path while preserving URL construction, option normalization, headers, pagination, sorting, mappings, and query parameters.ApiProvider/optionsApiinstead of legacy query functions.Validation
rg -n "fetchOptions|fetchDataList" src/App/frontend/srcreturns no matches.rg -n "useAppQueries" src/App/frontend/src/features/options src/App/frontend/src/features/dataListsreturns no matches.yarn tscyarn test src/features/options/useGetOptions.test.tsx src/layout/Dropdown/DropdownComponent.test.tsx src/layout/List/ListComponent.test.tsx src/layout/Checkboxes/CheckboxesContainerComponent.test.tsx src/layout/RadioButtons/ControlledRadioGroup.test.tsx src/layout/FileUpload/FileUploadComponent.test.tsx src/layout/FileUpload/Summary/AttachmentWithTagSummaryComponent.test.tsx src/layout/Likert/LikertComponent.test.tsx --runInBandNote: the focused Jest run still prints existing jsdom
window.getComputedStyle(elt, pseudoElt)console errors from design system popover code, but all listed suites pass.Summary by CodeRabbit
New Features
Refactor
Tests
Chores