Skip to content

Enhance fetchEntities with search term permutations and deduplication#9101

Open
vedantlavale wants to merge 1 commit into
backstage:mainfrom
vedantlavale:fix/user-search-error
Open

Enhance fetchEntities with search term permutations and deduplication#9101
vedantlavale wants to merge 1 commit into
backstage:mainfrom
vedantlavale:fix/user-search-error

Conversation

@vedantlavale
Copy link
Copy Markdown
Contributor

Fix user search failing for reversed display name order

Issue Summary

The wheel-of-names participant search failed when user names were entered in a different order than the stored displayName.

For example:

  • displayName: "Jane Smith"
  • Searching "Jane Smith" → worked
  • Searching "Smith Jane" → no results

This happened because the catalog API's fullTextFilter uses substring matching, so reversed word order would not match the stored display name.


Solution

Updated EntityService.fetchEntities() to support name permutations for 2-word search queries.

Changes made:

  • Detect 2-word search inputs
  • Perform catalog queries for both:
    • "first last"
    • "last first"
  • Merge and deduplicate results before returning them
  • Preserve existing behavior for:
    • single-word searches
    • multi-word searches beyond 2 words

This keeps the implementation backward compatible while improving search flexibility for users.


Testing

Added comprehensive unit tests in Service.test.ts covering:

  • Original name order matching
  • Reversed name order matching
  • Result deduplication
  • Existing search behavior regression coverage

Verified with mock user data including:

  • displayName: "Jane Smith"

Files Changed

  • src/components/Participants/Service.ts
    • Enhanced participant search logic
  • src/components/Participants/Service.test.ts
    • Added regression and permutation search tests

Screenshots

Screenshots

Search using original name order

Search for Jane Smith

Search using reversed name order

Search for Smith Jane

Additional Notes

  • Added tests for the new functionality and regression coverage
  • Screenshots attached for both search cases
  • Commits include a Signed-off-by line
  • A changeset describing the change and affected packages
  • Added or updated documentation
  • Tests for new functionality and regression tests for bug fixes
  • Screenshots attached (for UI changes)
  • All commits include a Signed-off-by line

Fixes #8472

…mutations and deduplication

Signed-off-by: vedantlavale <vedantlavale@gmail.com>
Copilot AI review requested due to automatic review settings May 10, 2026 19:37
@vedantlavale vedantlavale requested a review from a team as a code owner May 10, 2026 19:37
@vedantlavale vedantlavale requested a review from vinzscam May 10, 2026 19:37
@backstage-goalie
Copy link
Copy Markdown
Contributor

Missing Changesets

The following package(s) are changed by this PR but do not have a changeset:

  • @backstage-community/plugin-wheel-of-names

See CONTRIBUTING.md for more information about how to add changesets.

Changed Packages

Package Name Package Path Changeset Bump Current Version
@backstage-community/plugin-wheel-of-names workspaces/wheel-of-names/plugins/wheel-of-names none v0.8.0

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Improves the wheel-of-names participant lookup by enhancing EntityService.fetchEntities() to support 2-word search term permutations (e.g., “Jane Smith” vs “Smith Jane”) and deduplicate merged results, with accompanying unit tests.

Changes:

  • Added permutation search for 2-word queries by issuing catalog queries for both word orders and merging results.
  • Added client-side deduplication and sorting of merged entity results.
  • Introduced unit tests covering permutation search, deduplication, and pagination behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
workspaces/wheel-of-names/plugins/wheel-of-names/src/components/Participants/Service.ts Adds 2-word permutation querying, merges/dedupes/sorts results, and applies client-side paging.
workspaces/wheel-of-names/plugins/wheel-of-names/src/components/Participants/Service.test.ts Adds unit tests for the updated fetchEntities behavior and related regressions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 32 to 36
const queryOptions: QueryEntitiesRequest = {
filter: [{ kind: 'group' }, { kind: 'user' }],
limit: limit,
offset: offset,
limit: limit * 2,
offset: 0,
orderFields: { field: 'metadata.name', order: 'asc' },
Comment on lines +81 to +85
const items = uniqueItems.slice(start, end);

const totalItems = uniqueItems.length;

return { items, totalItems };
Comment on lines +69 to +73
const uniqueItems = allItems.filter(
(item, index, self) =>
item.metadata.uid &&
self.findIndex(i => i.metadata.uid === item.metadata.uid) === index,
);
Comment on lines +48 to 68
const allItems: Entity[] = [];

for (const term of terms) {
const options: QueryEntitiesRequest = {
...queryOptions,
};
if (term) {
options.fullTextFilter = {
term,
fields: [
'metadata.name',
'kind',
'spec.profile.displayName',
'metadata.title',
],
};
}
const response = await this.catalogApi.queryEntities(options);
allItems.push(...response.items);
}

Comment on lines +46 to +51
expect(mockCatalogApi.queryEntities).toHaveBeenCalledWith({
filter: [{ kind: 'group' }, { kind: 'user' }],
limit: 20,
offset: 0,
orderFields: { field: 'metadata.name', order: 'asc' },
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 wheel-of-names: user search error

3 participants