Skip to content

Conversation

@ab-smith
Copy link
Contributor

@ab-smith ab-smith commented Jan 20, 2026

adding:
optionsExtraFields={[['folder', 'str']]}
where relevant but adjusting the component to skip it for User

Summary by CodeRabbit

  • Bug Fixes

    • Autocomplete labels now omit empty extra parts for non-user items, producing cleaner, more readable selections.
  • New Features

    • Autocomplete lookups across many forms now include folder information in option payloads so folder details appear when selecting owners, authors, reviewers, assets, processes, etc.
    • Actor data returned by lookups now includes folder information to support the UI display.

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 20, 2026

📝 Walkthrough

Walkthrough

AutocompleteSelect now omits assembling extra label parts for objects with type "user"; for other types it builds and filters extraParts from optionsExtraFields. Many ModelForm AutocompleteSelect instances request a folder string via optionsExtraFields. Backend exposes folder on Actor and in ActorReadSerializer.

Changes

Cohort / File(s) Summary
AutocompleteSelect logic
frontend/src/lib/components/Forms/AutocompleteSelect.svelte
Skip computing optionsExtraFields label parts when obj.type === 'user'; otherwise build extraParts from optionsExtraFields, filter falsy values, and include them in the joined option label.
ModelForm usages — add folder extra field
frontend/src/lib/components/Forms/ModelForm/*, frontend/src/routes/(app)/(internal)/risk-scenarios/[id=uuid]/edit/+page.svelte
Multiple AutocompleteSelect usages (authors, reviewers, owner, processings, assets, etc.) now pass optionsExtraFields={[['folder','str']]} so option payloads include a folder string field; no other control-flow changes.
Backend — Actor folder exposure
backend/core/models.py, backend/core/serializers.py
Added _folder/folder exposure on Actor (delegating to specific.folder) and ActorReadSerializer now includes folder = SerializerMethodField() with get_folder returning {"id": id, "str": str(folder)} or None; folder added to serializer fields.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant Autocomplete as AutocompleteSelect
  participant API as Backend API (ActorRead)
  participant DB as Database/Model

  Client->>Autocomplete: open dropdown / type query
  Autocomplete->>API: GET /actors?fields=...&extra_fields=folder
  API->>DB: fetch Actor(s) including specific and folder
  DB-->>API: Actor record(s) with specific.folder
  API-->>Autocomplete: serialized Actor objects (id,str,type,specific,folder)
  Autocomplete->>Autocomplete: for each obj: if obj.type == "user" skip extraParts else build extraParts from optionsExtraFields and filter falsy
  Autocomplete-->>Client: render option labels (joined parts)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇
I nibble fields both near and far,
I skip the users — leave their star,
I sweep out falsy crumbs with care,
Folder petals float in air,
Hooray — the options bloom anew! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding domain/folder information to actors by restoring serialized folder data and adding optionsExtraFields to relevant form components.

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

✨ Finishing touches
  • 📝 Generate docstrings

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.

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: 1

🤖 Fix all issues with AI agents
In `@frontend/src/lib/components/Forms/AutocompleteSelect.svelte`:
- Around line 226-234: The extraParts construction can throw if getNestedValue
returns null because it checks only !== undefined and then calls toString();
update the conditional to guard against nullish values (use a nullish check such
as value != null or value !== null && value !== undefined) before calling
toString(), or coerce with the nullish coalescing operator so the map in
AutocompleteSelect.svelte (referencing extraParts, getNestedValue,
optionsExtraFields, and object.type) only calls toString() on non-null values
and filters out empty results.

Comment on lines +226 to +234
const extraParts =
object.type === 'user'
? []
: optionsExtraFields
.map((fieldPath) => {
const value = getNestedValue(object, fieldPath[0], fieldPath[1]);
return value !== undefined ? value.toString() : '';
})
.filter(Boolean);
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Potential runtime error when nested value is null.

The condition value !== undefined passes when value is null, causing null.toString() to throw a TypeError. Consider using a nullish check instead.

🐛 Proposed fix
 const extraParts =
   object.type === 'user'
     ? []
     : optionsExtraFields
         .map((fieldPath) => {
           const value = getNestedValue(object, fieldPath[0], fieldPath[1]);
-          return value !== undefined ? value.toString() : '';
+          return value != null ? value.toString() : '';
         })
         .filter(Boolean);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const extraParts =
object.type === 'user'
? []
: optionsExtraFields
.map((fieldPath) => {
const value = getNestedValue(object, fieldPath[0], fieldPath[1]);
return value !== undefined ? value.toString() : '';
})
.filter(Boolean);
const extraParts =
object.type === 'user'
? []
: optionsExtraFields
.map((fieldPath) => {
const value = getNestedValue(object, fieldPath[0], fieldPath[1]);
return value != null ? value.toString() : '';
})
.filter(Boolean);
🤖 Prompt for AI Agents
In `@frontend/src/lib/components/Forms/AutocompleteSelect.svelte` around lines 226
- 234, The extraParts construction can throw if getNestedValue returns null
because it checks only !== undefined and then calls toString(); update the
conditional to guard against nullish values (use a nullish check such as value
!= null or value !== null && value !== undefined) before calling toString(), or
coerce with the nullish coalescing operator so the map in
AutocompleteSelect.svelte (referencing extraParts, getNestedValue,
optionsExtraFields, and object.type) only calls toString() on non-null values
and filters out empty results.

@ab-smith ab-smith changed the title domains on actors autocomplete fix: add domain to teams or entities on actors Jan 20, 2026
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: 0

Caution

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

⚠️ Outside diff range comments (5)
frontend/src/lib/components/Forms/ModelForm/FindingForm.svelte (1)

114-123: Remove invalid folder extra field from actors endpoint

The Actor model and endpoint do not expose a folder field. The ActorReadSerializer only returns id, str, type, and specific. Remove optionsExtraFields={[['folder', 'str']]} or replace it with a valid field if context is needed for the label.

frontend/src/lib/components/Forms/ModelForm/ComplianceAssessmentForm.svelte (1)

269-278: Update actor optionsExtraFields to match actual domain model

The actor endpoint does not expose a folder field directly. The Actor model relates to User, Team, or Entity via OneToOneFields, and those related objects have the folder field through FolderMixin. However, the folder field is not available on the serialized actor response (which includes id, str, type, specific), so optionsExtraFields={[['folder', 'str']]} will not work and the field will not display.

Unlike the evidences endpoint above, which uses Evidence model with direct FolderMixin inheritance, the actor model requires a different approach. Remove this extra field configuration or restructure if folder information from the related object is necessary.

frontend/src/lib/components/Forms/ModelForm/MetricInstanceForm.svelte (1)

84-93: Fix optionsExtraFields for actors endpoint—folder field not exposed

The folder field is not exposed in the ActorReadSerializer (which only includes ["id", "str", "type", "specific"]). The component attempts to access object['folder']['str'] but this will fail since the actors endpoint response does not include the folder field. Either add folder to ActorReadSerializer fields, or use an alternative field that is exposed in the serializer response (such as accessing folder through the specific object if it's a Team or Entity).

frontend/src/lib/components/Forms/ModelForm/ContractForm.svelte (1)

128-139: Remove invalid folder field from actor options configuration

The optionsExtraFields={[['folder', 'str']]} configuration references a field that doesn't exist on the Actor model. Actor has no direct folder property—only its underlying types (Team, User, Entity) may have folder relationships that aren't exposed through the Actor API serialization. This configuration will fail silently or return undefined values.

This pattern is used consistently across 23+ form files with the actors endpoint. Remove the optionsExtraFields prop or identify the correct field to expose (if additional context is needed).

frontend/src/lib/components/Forms/ModelForm/FindingsAssessmentForm.svelte (1)

77-91: Remove optionsExtraFields={[['folder', 'str']]} from the actors autocomplete—the field doesn't exist.

The Actor model has no folder field (only User, Team, and Entity are linked to Actor), and ActorReadSerializer exposes only ["id", "str", "type", "specific"]. Requesting folder as an extra field will result in undefined values that get filtered out, leaving no metadata to display.

@ab-smith
Copy link
Contributor Author

we lost the serialized folder that we need to bring back

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.

3 participants