Skip to content

fix: use server-side search for machine identity dropdown in project templates#5543

Merged
x032205 merged 5 commits intomainfrom
devin/1771950979-fix-template-identity-search
Feb 25, 2026
Merged

fix: use server-side search for machine identity dropdown in project templates#5543
x032205 merged 5 commits intomainfrom
devin/1771950979-fix-template-identity-search

Conversation

@devin-ai-integration
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot commented Feb 24, 2026

Context

When adding a machine identity to a project template via the "Assign Existing" flow, the identity dropdown only showed a subset of the organization's identities. The root cause: the component called useSearchOrgIdentityMemberships({ search: {} }) without specifying a limit, so the backend applied its default limit of 50. The FilterableSelect then performed client-side filtering on just those 50 results — meaning any identities outside the first 50 (sorted alphabetically) were invisible regardless of what the user typed.

This was reported by a customer whose taf_* identities were not appearing in the dropdown despite existing in the organization.

Before: Dropdown fetches first 50 identities, filters client-side only. Orgs with >50 identities can't find some of them.

After: Dropdown sends the user's search text to the server as a name: { $contains: ... } filter (debounced at 300ms), matching how the Organization Machine Identities page already works.

Steps to verify the change

  1. Set up an organization with more than 50 machine identities
  2. Go to Organization Settings → Project Templates → edit a template → Machine Identities section
  3. Click "Add Machine Identity" → "Assign Existing"
  4. Type a name that matches an identity outside the first 50 alphabetically
  5. Verify the identity now appears in the dropdown
  6. Select an identity and confirm the modal closes cleanly
  7. Reopen the modal and verify the dropdown shows the full unfiltered list (no stale search term)

Important things for reviewers

  • knownIdentityNamesRef cache (lines ~130–136): A useRef<Map> is populated via useEffect (triggered when searchedIdentities or orgIdentities change) to cache identity names. This avoids stale names in the table when an identity was found via search but falls outside the name-resolution query's limit. Note: since searchedIdentities and orgIdentities are arrays recreated from .map() on each render, the effect will fire on every render — this is functionally correct but could be optimized with useMemo on those arrays if performance becomes a concern.
  • limit: 100 on the name-resolution query: This is an improvement over the implicit 50 default but still won't fully resolve names for orgs with >100 identities in the table view. The ref cache mitigates this. A dedicated batch-lookup-by-ID endpoint would be the ideal long-term solution.
  • filterOption={() => true}: Client-side filtering is fully disabled since the server handles search. During the 300ms debounce window after typing, the dropdown briefly shows results from the previous server response.
  • Not tested in a live environment — lint and type checks pass. Manual QA with a large identity set is recommended.

Updates since initial revision

  • Moved knownIdentityNamesRef population from render-time mutation to a useEffect (per React best practices, raised by Greptile review)
  • Added setIdentitySearchInput("") reset in handleAddOrgIdentity and handleCloseAddIdentityModal to prevent stale dropdown results when reopening the modal (raised by Devin Review)

Link to Devin run: https://app.devin.ai/sessions/d1a8cb051f3d43bd943088cbc553e2c2
Requested by: @0xArshdeep

Type

  • Fix
  • Feature
  • Improvement
  • Breaking
  • Docs
  • Chore

Checklist

…templates

The 'Add Machine Identity to Template' modal was only fetching the first
50 identities (backend default limit) and filtering client-side. Orgs with
more than 50 machine identities would not see all identities in the dropdown.

Changes:
- Add debounced search input that sends name filter to the server via
  the existing search API ( operator)
- Disable client-side filtering on the dropdown (filterOption={() => true)
  since the server handles filtering
- Keep a separate query for name resolution in the table
- Cache identity names in a ref to handle identities outside the fetched page

Co-Authored-By: unknown <>
@devin-ai-integration
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@maidul98
Copy link
Collaborator

maidul98 commented Feb 24, 2026

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 24, 2026

Greptile Summary

Implements server-side search for machine identity dropdown in project templates to fix issue where organizations with >50 identities couldn't find identities outside the first 50 results. The change replaces client-side filtering with debounced server-side search using name: { $contains: ... } filter, matching the pattern used in the Organization Machine Identities page.

Key changes:

  • Frontend now sends search text to server with 300ms debounce
  • Added identityName field to backend types and API responses to avoid name-resolution queries
  • Search input properly resets when modal closes or identity is added
  • Client-side filtering disabled via filterOption={() => true}

Implementation notes:

  • The PR description mentions a knownIdentityNamesRef cache that was moved to useEffect per React best practices, but this cache and ref are not present in the current code - it appears the implementation was simplified to just use identityName from the API
  • The approach matches the existing implementation in IdentityTable.tsx

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The implementation follows existing patterns in the codebase (matches IdentityTable.tsx), properly handles server-side search with debouncing, includes proper cleanup of search state, and adds necessary type safety. The backend changes are minimal and straightforward - just adding a field that's already being fetched via JOIN in the DAL. No security concerns, breaking changes, or logic errors detected.
  • No files require special attention

Important Files Changed

Filename Overview
frontend/src/pages/organization/SettingsPage/components/ProjectTemplatesTab/components/EditProjectTemplateSection/components/ProjectTemplateIdentitiesSection.tsx Adds server-side search with debounced input, properly resets search state on modal close, and includes identityName in form data
backend/src/ee/services/project-template/project-template-service.ts Adds identityName field to identity mapping helper function

Last reviewed commit: ae70ebc

greptile-apps[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

@x032205
Copy link
Member

x032205 commented Feb 25, 2026

@greptile re-review the latest commit

@x032205 x032205 requested a review from victorvhs017 February 25, 2026 14:53
Copy link
Contributor Author

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 new potential issue.

View 8 additional findings in Devin Review.

Open in Devin Review

Copy link
Contributor

@victorvhs017 victorvhs017 left a comment

Choose a reason for hiding this comment

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

Tested and looks good

@x032205 x032205 merged commit c81cc13 into main Feb 25, 2026
12 checks passed
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.

4 participants