Skip to content

Forbedre visning av arv på enkelt action - #1971

Open
mgunnerud wants to merge 5 commits into
mainfrom
fix/2320-forbedre-visning-av-arv-pa-enkelt-action
Open

Forbedre visning av arv på enkelt action#1971
mgunnerud wants to merge 5 commits into
mainfrom
fix/2320-forbedre-visning-av-arv-pa-enkelt-action

Conversation

@mgunnerud

@mgunnerud mgunnerud commented Feb 24, 2026

Copy link
Copy Markdown
Contributor

Description

image

Related Issue(s)

Verification

  • Your code builds clean without any errors or warnings
  • Manual testing done (required)
  • Relevant automated test added (if you find this hard, leave it and we'll help out)
  • All tests run green

Documentation

  • User documentation is updated with a separate linked PR in altinn-studio-docs. (if applicable)

Summary by CodeRabbit

  • New Features

    • Chips now display contextual inherited-status messages (role, connection, keyrole) with formatted names and open a popover when inheritance exists.
  • Bug Fixes

    • Chip toggle behavior refined to prevent changing inherited actions and reflect checked state reliably.
  • Localization

    • Replaced generic inheritance text with three source-specific messages in English, Norwegian Bokmål, and Norwegian Nynorsk.

@coderabbitai

coderabbitai Bot commented Feb 24, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Consolidates inheritance metadata into a new internal chip-right shape, updates mapping and chip construction to carry isChecked, toParty, and inheritedStatus directly, and replaces a generic inheritance localization key with three context-specific translation keys used by the UI popover.

Changes

Cohort / File(s) Summary
Rights Mapping & Types
src/features/amUI/common/DelegationModal/SingleRights/hooks/rightsUtils.tsx
mapRightsToChipRights now accepts ChipDelegationCheckedRight[]; ChipRight gains inheritedStatus?: InheritedStatusMessageType[] and toParty?: Party; mapping sources checked, inheritedStatus, and toParty from input objects rather than external predicates.
Chip UI & Inheritance Rendering
src/features/amUI/common/DelegationModal/SingleRights/hooks/useRightChips.tsx
Adds STATUS_TRANSLATION_KEYS and getInheritedStatusMessage (uses formatDisplayName and Trans); popover target/aria and click handling now depend on right.inheritedStatus?.length; popover displays contextual inherited messages.
Chip Construction / Rights Section
src/features/amUI/common/DelegationModal/SingleRights/hooks/useRightsSection.tsx
Transforms delegationCheckedActions into the new chip shape including toParty, isChecked, and inheritedStatus (computed via getInheritedStatus where applicable); updates mapRightsToChipRights usage and adds toParty to effect deps.
Localizations
src/localizations/en.json, src/localizations/no_nb.json, src/localizations/no_nn.json
Removes generic right_inherited and adds three specific keys: right_inherited_via_role, right_inherited_via_connection, and right_inherited_via_keyrole with templated messages for popover rendering.
Manifest
package.json
Minor metadata/formatting edits (small lines changed).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

A chip now tells the story neat and clear,
From whom it came and how the path was paved,
Three phrases whisper why the toggle won't steer,
Names placed with care, inheritance engraved,
Small types, bright messages — the UI saved. ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Forbedre visning av arv på enkelt action' (Improve display of inheritance on single action) clearly describes the main change: enhancing how inherited rights/permissions are displayed in the UI.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/2320-forbedre-visning-av-arv-pa-enkelt-action

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.

@github-actions github-actions Bot added bugfix kind/bug Used when something isn't working labels Feb 24, 2026

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/features/amUI/common/DelegationModal/SingleRights/hooks/useRightsSection.tsx (1)

120-147: ⚠️ Potential issue | 🟡 Minor

Include toParty in the dependency list to avoid stale inheritance context.

toParty is used to compute inheritedStatus and to populate the chip payload, but the effect won’t rerun if only toParty changes without other dependencies. This can leave stale user/via context in the UI.

🔧 Suggested fix
-  }, [delegationCheckedActions, resource.identifier, hasAccess, currentRights, resourceRights]);
+  }, [
+    delegationCheckedActions,
+    resource.identifier,
+    hasAccess,
+    currentRights,
+    resourceRights,
+    toParty,
+  ]);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/features/amUI/common/DelegationModal/SingleRights/hooks/useRightsSection.tsx`
around lines 120 - 147, The effect inside useRightsSection is missing toParty
from its dependency array, causing stale inheritedStatus and chip payloads when
toParty changes; update the dependency list for the useEffect that
setsMissingAccess and setRights (the block that maps delegationCheckedActions ->
mapRightsToChipRights and computes inheritedStatus via findInheritedRight) to
include toParty so the effect re-runs whenever toParty changes.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In
`@src/features/amUI/common/DelegationModal/SingleRights/hooks/useRightsSection.tsx`:
- Around line 120-147: The effect inside useRightsSection is missing toParty
from its dependency array, causing stale inheritedStatus and chip payloads when
toParty changes; update the dependency list for the useEffect that
setsMissingAccess and setRights (the block that maps delegationCheckedActions ->
mapRightsToChipRights and computes inheritedStatus via findInheritedRight) to
include toParty so the effect re-runs whenever toParty changes.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3983bec and 3c0e03c.

📒 Files selected for processing (6)
  • src/features/amUI/common/DelegationModal/SingleRights/hooks/rightsUtils.tsx
  • src/features/amUI/common/DelegationModal/SingleRights/hooks/useRightChips.tsx
  • src/features/amUI/common/DelegationModal/SingleRights/hooks/useRightsSection.tsx
  • src/localizations/en.json
  • src/localizations/no_nb.json
  • src/localizations/no_nn.json

@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.

🧹 Nitpick comments (2)
src/features/amUI/common/DelegationModal/SingleRights/hooks/useRightsSection.tsx (2)

107-118: findInheritedRight closes over toParty but is missing from the useEffect dependency array.

findInheritedRight is a plain (unstable) function defined in the component body that captures toParty via closure. It's called inside the useEffect at line 131, but it isn't listed as a dependency. React's exhaustive-deps rule will flag this.

Functionally it's correct today — because toParty is already in the deps array — but it's fragile: any future change to the closure that adds a new captured variable won't be caught automatically.

Cleanest fix is to move the helper inside the effect (it's only used there):

♻️ Move helper inside the useEffect
-  const findInheritedRight = (right: ResourceRight, ruleKey: string) => {
-    const rule = right.indirectRules.find((r) => r.rule.key === ruleKey);
-    // if rule is found, this is inherited.
-    if (rule) {
-      return getInheritedStatus({
-        permissions: rule?.permissions,
-        toParty: toParty,
-      });
-    }
-    return [];
-  };

   useEffect(() => {
     if (delegationCheckedActions) {
       setMissingAccess(getMissingAccessMessage(delegationCheckedActions));
+
+      const findInheritedRight = (right: ResourceRight, ruleKey: string) => {
+        const rule = right.indirectRules.find((r) => r.rule.key === ruleKey);
+        if (rule) {
+          return getInheritedStatus({ permissions: rule.permissions, toParty });
+        }
+        return [];
+      };

       if (hasAccess && resourceRights) {

Also note line 113: rule?.permissions — the optional chain is redundant inside the if (rule) guard; rule.permissions is sufficient.

Also applies to: 147-154

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/features/amUI/common/DelegationModal/SingleRights/hooks/useRightsSection.tsx`
around lines 107 - 118, findInheritedRight currently closes over toParty and is
used only inside the useEffect, but it isn’t included in the deps array which is
fragile; move the findInheritedRight helper into the same useEffect where it’s
used (the effect that reads rights and calls getInheritedStatus) so it no longer
closes over toParty, and update its body to use rule.permissions (drop the
redundant optional chaining rule?.permissions inside the if (rule) guard); apply
the same change for the similar helper usage around lines 147-154 to avoid
unstable closures and dependency issues.

130-130: Minor: prefer Array.includes over Array.some for simple equality checks.

♻️ Readability nit
-            isChecked: currentRights.some((key) => key === right.rule.key),
+            isChecked: currentRights.includes(right.rule.key),
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/features/amUI/common/DelegationModal/SingleRights/hooks/useRightsSection.tsx`
at line 130, Replace the equality check using Array.some with Array.includes for
readability: in useRightsSection.tsx update the isChecked assignment that
currently uses currentRights.some((key) => key === right.rule.key) to use
currentRights.includes(right.rule.key) instead (references: currentRights,
right.rule.key, isChecked).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@src/features/amUI/common/DelegationModal/SingleRights/hooks/useRightsSection.tsx`:
- Around line 107-118: findInheritedRight currently closes over toParty and is
used only inside the useEffect, but it isn’t included in the deps array which is
fragile; move the findInheritedRight helper into the same useEffect where it’s
used (the effect that reads rights and calls getInheritedStatus) so it no longer
closes over toParty, and update its body to use rule.permissions (drop the
redundant optional chaining rule?.permissions inside the if (rule) guard); apply
the same change for the similar helper usage around lines 147-154 to avoid
unstable closures and dependency issues.
- Line 130: Replace the equality check using Array.some with Array.includes for
readability: in useRightsSection.tsx update the isChecked assignment that
currently uses currentRights.some((key) => key === right.rule.key) to use
currentRights.includes(right.rule.key) instead (references: currentRights,
right.rule.key, isChecked).

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3c0e03c and ca6660e.

📒 Files selected for processing (1)
  • src/features/amUI/common/DelegationModal/SingleRights/hooks/useRightsSection.tsx

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/features/amUI/common/DelegationModal/SingleRights/hooks/useRightsSection.tsx (1)

108-150: ⚠️ Potential issue | 🟡 Minor

Add getMissingAccessMessage to the effect dependencies.

When t, reportee?.name, or resource?.resourceOwnerName change, the callback is recreated but the effect won't re-run, causing stale messages to display. Include the callback in the dependency array to ensure the effect executes whenever the callback updates.

🔧 Suggested fix
   }, [
     delegationCheckedActions,
     resource.identifier,
     hasAccess,
     currentRights,
     resourceRights,
     toParty,
+    getMissingAccessMessage,
   ]);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/features/amUI/common/DelegationModal/SingleRights/hooks/useRightsSection.tsx`
around lines 108 - 150, The effect updating missing access and rights should
include the getMissingAccessMessage callback in its dependency array so it
re-runs when the callback (which depends on t, reportee?.name, or
resource?.resourceOwnerName) changes; update the useEffect dependencies to
include getMissingAccessMessage alongside delegationCheckedActions,
resource.identifier, hasAccess, currentRights, resourceRights, and toParty so
that setMissingAccess(getMissingAccessMessage(...)) always uses the current
callback.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In
`@src/features/amUI/common/DelegationModal/SingleRights/hooks/useRightsSection.tsx`:
- Around line 108-150: The effect updating missing access and rights should
include the getMissingAccessMessage callback in its dependency array so it
re-runs when the callback (which depends on t, reportee?.name, or
resource?.resourceOwnerName) changes; update the useEffect dependencies to
include getMissingAccessMessage alongside delegationCheckedActions,
resource.identifier, hasAccess, currentRights, resourceRights, and toParty so
that setMissingAccess(getMissingAccessMessage(...)) always uses the current
callback.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ca6660e and 8e019c9.

📒 Files selected for processing (1)
  • src/features/amUI/common/DelegationModal/SingleRights/hooks/useRightsSection.tsx

@allinox

allinox commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

@mgunnerud
Den blokkerende tasken skal ha blitt fikset nå (🎉)
Kunne du tatt en ny titt på denne PRen? 😊

@allinox allinox removed the Blocked label Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix kind/bug Used when something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Forbedre visning av arv på enkelt action

2 participants