Skip to content

Conversation

@Jondyr
Copy link
Member

@Jondyr Jondyr commented Dec 16, 2025

Description

Related Issue(s)

  • closes #{issue number}

Verification/QA

  • Manual functionality testing
    • I have tested these changes manually
    • Creator of the original issue (or service owner) has been contacted for manual testing (or will be contacted when released in alpha)
    • No testing done/necessary
  • Automated tests
    • Unit test(s) have been added/updated
    • Cypress E2E test(s) have been added/updated
    • No automatic tests are needed here (no functional changes/additions)
    • I want someone to help me make some tests
  • UU/WCAG (follow these guidelines until we have our own)
    • I have tested with a screen reader/keyboard navigation/automated wcag validator
    • No testing done/necessary (no DOM/visual changes)
    • I want someone to help me perform accessibility testing
  • User documentation @ altinn-studio-docs
    • Has been added/updated
    • No functionality has been changed/added, so no documentation is needed
    • I will do that later/have created an issue
  • Support in Altinn Studio
    • Issue(s) created for support in Studio
    • This change/feature does not require any changes to Altinn Studio
  • Sprint board
    • The original issue (or this PR itself) has been added to the Team Apps project and to the current sprint board
    • I don't have permissions to do that, please help me out
  • Labels
    • I have added a kind/* and backport* label to this PR for proper release notes grouping
    • I don't have permissions to add labels, please help me out

Summary by CodeRabbit

  • New Features

    • Added optional instance-aware layout and layout-settings retrieval controlled by a feature flag and instance identifier.
    • Added new URL endpoints for instance-scoped layouts, rule handling, active-instance queries and instance UI paths.
  • Tests

    • Extended test query mocks to include instance-specific layout settings.

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

@Jondyr Jondyr self-assigned this Dec 16, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 16, 2025

📝 Walkthrough

Walkthrough

Adds instance-aware fetching for layouts and layout settings, new URL helpers for instance-scoped endpoints, and test mocks; fetching switches to instance-specific endpoints when the feature flag and an instance ID are present, otherwise falls back to existing behavior.

Changes

Cohort / File(s) Summary
Layout settings context
src/features/form/layoutSettings/LayoutSettingsContext.tsx
Conditional instance-aware fetch: uses feature flag features.addInstanceIdentifierToLayoutRequests and instanceId to choose between fetchLayoutSettingsForInstance(layoutSetId, instanceId) and fetchLayoutSettings(layoutSetId). Adds useApplicationMetadata, useLaxInstanceId, fetchLayoutSettingsForInstance, and uses skipToken when layoutSetId is absent.
Layouts context
src/features/form/layout/LayoutsContext.tsx
Mirrors instance-aware change: destructures fetchLayoutsForInstance from app queries and conditionally calls it when feature flag + instanceId present; falls back to existing fetchLayouts.
Query API
src/queries/queries.ts
Adds exported fetchLayoutSettingsForInstance(layoutSetId: string, instanceId: string): Promise<ILayoutSettings> that uses getInstanceLayoutSettingsUrl(layoutSetId, instanceId). Existing fetchLayoutSettings left unchanged.
URL helpers
src/utils/urls/appUrlHelper.ts
Adds instance and layout-related helpers: getInstanceLayoutSettingsUrl, getLayoutsUrl, getInstanceLayoutsUrl, getRulehandlerUrl, getActiveInstancesUrl, getInstanceUiUrl.
Test providers / mocks
src/test/renderWithProviders.tsx
Adds fetchLayoutSettingsForInstance to default AppQueries mocks (returns { pages: { order: [] } }) and updates test query surface accordingly.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Areas needing extra attention:
    • LayoutSettingsContext.tsx and LayoutsContext.tsx — verify conditional branches, skipToken usage, and correct retrieval of instanceId and feature flags.
    • appUrlHelper.ts — ensure URL formats match existing conventions and encoding where applicable.
    • queries.ts and test mocks — confirm the new query is wired consistently and tests cover both instance and non-instance paths.

Possibly related PRs

Suggested labels

squad/utforming

Suggested reviewers

  • Magnusrm

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is incomplete; it contains only the template structure with unchecked placeholders and no actual implementation details, testing results, or related issue references. Provide a detailed description of what the feature does, specify which issue is being closed, and document which verification/QA items have been completed or why they aren't applicable.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: instance contextual layout settings' is specific, clear, and accurately summarizes the main change—introducing instance-aware layout settings fetching.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ 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 feat/instance-contextual-layout-settings

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f04d99e and 1d7aebf.

📒 Files selected for processing (2)
  • src/features/form/layout/LayoutsContext.tsx (1 hunks)
  • src/features/form/layoutSettings/LayoutSettingsContext.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/features/form/layoutSettings/LayoutSettingsContext.tsx
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx}: Avoid using any type or type casting (as type) in TypeScript code; improve typing by avoiding casts and anys when refactoring
Use objects for managing query keys and functions, and queryOptions for sharing TanStack Query patterns across the system for central management

Files:

  • src/features/form/layout/LayoutsContext.tsx
{**/*.module.css,**/*.{ts,tsx}}

📄 CodeRabbit inference engine (CLAUDE.md)

Use CSS Modules for component styling and leverage Digdir Design System components when possible

Files:

  • src/features/form/layout/LayoutsContext.tsx
🧠 Learnings (4)
📚 Learning: 2025-08-28T12:00:32.967Z
Learnt from: olemartinorg
Repo: Altinn/app-frontend-react PR: 3645
File: src/features/datamodel/DataModelsProvider.tsx:172-175
Timestamp: 2025-08-28T12:00:32.967Z
Learning: In DataModelsProvider.tsx, the effect that processes referenced data types must run for both stateless and non-stateless apps. The `isFetching` guard is appropriate because stateless apps don't fetch instance data (useInstanceDataQuery is disabled with `enabled: !isStateless`) but still need the data type processing to occur.

Applied to files:

  • src/features/form/layout/LayoutsContext.tsx
📚 Learning: 2025-11-25T12:53:54.399Z
Learnt from: CR
Repo: Altinn/app-frontend-react PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T12:53:54.399Z
Learning: Applies to **/*.test.{ts,tsx} : Use `renderWithProviders` from `src/test/renderWithProviders.tsx` when testing components that require form layout context

Applied to files:

  • src/features/form/layout/LayoutsContext.tsx
📚 Learning: 2025-11-25T12:53:54.399Z
Learnt from: CR
Repo: Altinn/app-frontend-react PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T12:53:54.399Z
Learning: Applies to src/layout/*/{config,Component,index,config.generated}.{ts,tsx} : Layout components must follow standardized structure with `config.ts`, `Component.tsx`, `index.tsx`, and `config.generated.ts` files

Applied to files:

  • src/features/form/layout/LayoutsContext.tsx
📚 Learning: 2025-11-25T12:53:54.399Z
Learnt from: CR
Repo: Altinn/app-frontend-react PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T12:53:54.399Z
Learning: Reduce dependency on React Context and migrate state management towards React Query patterns instead of Zustand wrappers

Applied to files:

  • src/features/form/layout/LayoutsContext.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Install
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Type-checks, eslint, unit tests and SonarCloud
🔇 Additional comments (2)
src/features/form/layout/LayoutsContext.tsx (2)

35-35: LGTM! Consistent with existing patterns.

Retrieving fetchLayoutsForInstance from useAppQueries() aligns with how fetchLayouts is obtained and maintains consistency in query function management.


43-46: Function signatures and return types are correctly implemented.

Both fetchLayoutsForInstance and fetchLayouts return Promise<ILayoutCollection>, ensuring type compatibility. The signature for fetchLayoutsForInstance(layoutSetId: string, instanceId: string) is correct, and the conditional logic properly checks both the feature flag and instanceId presence before using the instance-specific endpoint. The pattern is consistently applied to layout settings functions as well.


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.

@Jondyr Jondyr added kind/product-feature Pull requests containing new features backport-ignore This PR is a new feature and should not be cherry-picked onto release branches labels Dec 16, 2025
@Jondyr Jondyr moved this to 👷 In progress in Team Altinn Studio Dec 16, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/features/form/layoutSettings/LayoutSettingsContext.tsx (1)

20-38: Consider using queryOptions pattern for better maintainability.

The coding guidelines recommend using objects for managing query keys and queryOptions for sharing TanStack Query patterns across the system. This would improve consistency and make it easier to reuse query definitions.

Based on learnings, the codebase is moving towards centralized query management with queryOptions. Consider refactoring to follow this pattern in a future update:

export const layoutSettingsQueryOptions = (
  layoutSetId: string | undefined,
  instanceId: string | undefined,
  features: Record<string, unknown>,
  fetchLayoutSettings: (layoutSetId: string) => Promise<ILayoutSettings>,
  fetchLayoutSettingsForInstance: (layoutSetId: string, instanceId: string) => Promise<ILayoutSettings>,
) => ({
  queryKey: ['layoutSettings', layoutSetId, instanceId],
  queryFn: layoutSetId
    ? async () => {
        const shouldUseInstanceEndpoint = features.addInstanceIdentifierToLayoutRequests && instanceId;
        const layoutSettings = shouldUseInstanceEndpoint
          ? await fetchLayoutSettingsForInstance(layoutSetId, instanceId)
          : await fetchLayoutSettings(layoutSetId);
        return processData(layoutSettings);
      }
    : skipToken,
});

As per coding guidelines, this approach enables better central management of query patterns.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4d68844 and f04d99e.

📒 Files selected for processing (4)
  • src/features/form/layoutSettings/LayoutSettingsContext.tsx (1 hunks)
  • src/queries/queries.ts (2 hunks)
  • src/test/renderWithProviders.tsx (1 hunks)
  • src/utils/urls/appUrlHelper.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx}: Avoid using any type or type casting (as type) in TypeScript code; improve typing by avoiding casts and anys when refactoring
Use objects for managing query keys and functions, and queryOptions for sharing TanStack Query patterns across the system for central management

Files:

  • src/test/renderWithProviders.tsx
  • src/features/form/layoutSettings/LayoutSettingsContext.tsx
  • src/queries/queries.ts
  • src/utils/urls/appUrlHelper.ts
{**/*.module.css,**/*.{ts,tsx}}

📄 CodeRabbit inference engine (CLAUDE.md)

Use CSS Modules for component styling and leverage Digdir Design System components when possible

Files:

  • src/test/renderWithProviders.tsx
  • src/features/form/layoutSettings/LayoutSettingsContext.tsx
  • src/queries/queries.ts
  • src/utils/urls/appUrlHelper.ts
🧠 Learnings (4)
📚 Learning: 2025-11-25T12:53:54.399Z
Learnt from: CR
Repo: Altinn/app-frontend-react PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T12:53:54.399Z
Learning: Applies to **/*.test.{ts,tsx} : Use `renderWithProviders` from `src/test/renderWithProviders.tsx` when testing components that require form layout context

Applied to files:

  • src/test/renderWithProviders.tsx
📚 Learning: 2025-11-25T12:53:54.399Z
Learnt from: CR
Repo: Altinn/app-frontend-react PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T12:53:54.399Z
Learning: Reduce dependency on React Context and migrate state management towards React Query patterns instead of Zustand wrappers

Applied to files:

  • src/features/form/layoutSettings/LayoutSettingsContext.tsx
📚 Learning: 2025-11-25T12:53:54.399Z
Learnt from: CR
Repo: Altinn/app-frontend-react PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T12:53:54.399Z
Learning: Applies to **/*.{ts,tsx} : Use objects for managing query keys and functions, and `queryOptions` for sharing TanStack Query patterns across the system for central management

Applied to files:

  • src/features/form/layoutSettings/LayoutSettingsContext.tsx
📚 Learning: 2025-08-28T12:00:32.967Z
Learnt from: olemartinorg
Repo: Altinn/app-frontend-react PR: 3645
File: src/features/datamodel/DataModelsProvider.tsx:172-175
Timestamp: 2025-08-28T12:00:32.967Z
Learning: In DataModelsProvider.tsx, the effect that processes referenced data types must run for both stateless and non-stateless apps. The `isFetching` guard is appropriate because stateless apps don't fetch instance data (useInstanceDataQuery is disabled with `enabled: !isStateless`) but still need the data type processing to occur.

Applied to files:

  • src/features/form/layoutSettings/LayoutSettingsContext.tsx
🧬 Code graph analysis (2)
src/features/form/layoutSettings/LayoutSettingsContext.tsx (5)
src/core/queries/usePrefetchQuery.ts (1)
  • QueryDefinition (4-4)
src/core/contexts/AppQueriesProvider.tsx (1)
  • useAppQueries (58-58)
src/features/instance/InstanceContext.tsx (1)
  • useLaxInstanceId (58-62)
src/features/applicationMetadata/ApplicationMetadataProvider.tsx (1)
  • useApplicationMetadata (67-67)
src/queries/queries.ts (2)
  • fetchLayoutSettingsForInstance (303-304)
  • fetchLayoutSettings (300-301)
src/queries/queries.ts (3)
src/utils/network/networking.ts (1)
  • httpGet (10-17)
src/utils/network/sharedNetworking.ts (1)
  • httpGet (7-13)
src/utils/urls/appUrlHelper.ts (1)
  • getInstanceLayoutSettingsUrl (185-186)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Install
  • GitHub Check: Type-checks, eslint, unit tests and SonarCloud
🔇 Additional comments (3)
src/utils/urls/appUrlHelper.ts (1)

185-186: LGTM! Clean URL helper implementation.

The new getInstanceLayoutSettingsUrl function follows the established pattern of other instance-scoped URL helpers in the file and has a clear, descriptive name.

src/test/renderWithProviders.tsx (1)

154-154: LGTM! Test mock properly added.

The mock for fetchLayoutSettingsForInstance correctly mirrors the structure of the existing fetchLayoutSettings mock, ensuring consistent test behavior.

src/queries/queries.ts (1)

303-304: LGTM! Fetch function follows established patterns.

The new fetchLayoutSettingsForInstance function is implemented consistently with other query functions in the file, using the same httpGet pattern and returning the correct type.

@Jondyr
Copy link
Member Author

Jondyr commented Dec 16, 2025

/publish

@github-actions
Copy link
Contributor

github-actions bot commented Dec 16, 2025

PR release:

  • <link rel="stylesheet" type="text/css" href="https://altinncdn.no/toolkits/altinn-app-frontend/4.24.1-pr.3311.instance-contextual-layout-settings.1d7aebf9/altinn-app-frontend.css">
  • <script src="https://altinncdn.no/toolkits/altinn-app-frontend/4.24.1-pr.3311.instance-contextual-layout-settings.1d7aebf9/altinn-app-frontend.js"></script>

⚙️ Building...
✅ Done!

@sonarqubecloud
Copy link

@olemartinorg olemartinorg added the squad/utforming Issues that belongs to the named squad. label Dec 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-ignore This PR is a new feature and should not be cherry-picked onto release branches kind/product-feature Pull requests containing new features squad/utforming Issues that belongs to the named squad.

Projects

Status: 👷 In progress

Development

Successfully merging this pull request may close these issues.

2 participants