Skip to content

Conversation

@faisalsiddique4400
Copy link
Contributor

@faisalsiddique4400 faisalsiddique4400 commented Dec 18, 2025

fix(admin-ui): scopes not displayed for clients in client search results (#2529)

Summary

On the Clients search page, scope records were not being displayed for clients that already had scopes assigned. This caused confusion and made it appear as if clients had no associated scopes.

Fix Summary

  • Corrected client scope mapping in the search results view.
  • Ensured scope data is properly read and rendered for each client entry.
  • Fixed UI state handling so scope records are consistently visible.
  • Verified behavior across clients with single and multiple scopes.

Result

Clients with assigned scopes now correctly display their scope records in the Clients search page.

Closes

Closes: #2529

Summary by CodeRabbit

  • Improvements
    • Client scopes are fetched dynamically when the modal opens or input changes.
    • Added a loading indicator while scopes are retrieved.
    • Scopes are displayed as themed badges for clearer visual presentation.
    • Empty results show a localized "no scopes" message.
  • Refactor
    • Replaced the previous scopes modal with a new implementation that centralizes fetching, loading state, theming, and presentation.

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 18, 2025

📝 Walkthrough

Walkthrough

Removed the legacy Redux-connected ClientShowScopes JS component and added a new TypeScript ClientShowScopes TSX component that maps scope DNs to inums, queries OAuth scopes when opened, shows a loading state, renders themed scope badges or a localized "no scopes" message, and exposes a close handler via props.

Changes

Cohort / File(s) Summary
Removed legacy component
admin-ui/plugins/auth-server/components/Clients/ClientShowScopes.js
Deleted the old Redux-connected React component that read state.scopeReducer.items, computed scopes from DNs, and rendered a reactstrap Modal with badges and a close button.
New TypeScript component
admin-ui/plugins/auth-server/components/Clients/ClientShowScopes.tsx
Added a TSX default-exported ClientShowScopes component that converts scope DNs to inums, queries scopes via useGetOauthScopes (joined inums + limit) with an enabled rule tied to isOpen and non-empty input, shows a spinner while loading, displays themed Badge items or a localized "no scopes" message, and invokes the provided handler on close.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–30 minutes

  • Attention points:
    • Correct DN → inum mapping and query pattern construction
    • Hook dependency rules and reactivity when isOpen or data change
    • ThemeContext usage for badge coloring
    • i18n keys and empty-result fallback

Possibly related PRs

Suggested reviewers

  • moabu
  • duttarnab

Poem

🐰 I hopped through DNs to fetch each inum bright,
I twirled a tiny spinner until the scopes took flight,
Badges like carrots lined up just so,
I tapped the close and watched the modal go,
Hooray — the client's scopes are now in sight! 🎉

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the bug being fixed (scopes not displayed for clients in search results) and references the specific component affected (admin-ui).
Linked Issues check ✅ Passed The changes directly address the linked issue #2529 by fixing scope display in the Clients search page through a corrected React component implementation.
Out of Scope Changes check ✅ Passed All changes are focused on fixing the scope display issue in the ClientShowScopes component as defined in the linked issue; no unrelated modifications detected.
✨ 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 admin-ui-issue-2529

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.

@mo-auto mo-auto added comp-admin-ui Component affected by issue or PR kind-bug Issue or PR is a bug in existing functionality labels Dec 18, 2025
@faisalsiddique4400 faisalsiddique4400 requested review from moabu and removed request for syntrydy December 18, 2025 16:32
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: 4

📜 Review details

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c7b4323 and f3705eb.

📒 Files selected for processing (1)
  • admin-ui/plugins/auth-server/components/Clients/ClientShowScopes.js (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
admin-ui/plugins/auth-server/components/Clients/ClientShowScopes.js (3)
admin-ui/plugins/auth-server/components/Clients/ClientScopeUtils.js (1)
  • scopeDn (15-15)
admin-ui/app/utils/Util.ts (1)
  • getClientScopeByInum (34-38)
admin-ui/api-client.ts (1)
  • AXIOS_INSTANCE (9-9)
🔇 Additional comments (2)
admin-ui/plugins/auth-server/components/Clients/ClientShowScopes.js (2)

42-43: Verify the API response structure and scope object properties are correct.

The code assumes the API response at /api/v1/scopes returns either data.entries or data directly as an array, and that each scope object has id, displayName, and inum properties. Confirm these assumptions match the actual API specification to prevent runtime errors if the response structure differs.


36-41: The /api/v1/scopes endpoint parameters are correctly implemented. The pattern parameter accepts comma-separated scope inums and limit specifies the result set size—this matches the API contract used consistently across ClientBasicPanel.js, OAuthScopeSaga.js, and the underlying ScopeApi wrapper. The response structure (entries or data field) is properly handled.

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

♻️ Duplicate comments (1)
admin-ui/plugins/auth-server/components/Clients/ClientShowScopes.js (1)

16-54: Add cleanup to prevent race conditions and memory leaks.

The useEffect does not cancel in-flight API requests when the component unmounts or when isOpen/data changes. This can cause:

  • React warnings about setting state on unmounted components
  • Race conditions where an older request resolves after a newer one, showing stale data
  • Memory leaks
🔎 Apply this diff to add request cancellation:
  useEffect(() => {
    if (!isOpen || !data || data.length === 0) {
      setFetchedScopes([])
      setLoading(false)
      return
    }

    const fetchScopesForClient = async () => {
+     const controller = new AbortController()
      setLoading(true)

      const scopeInums = data
        .map((scopeDn) => getClientScopeByInum(scopeDn))
        .filter((inum) => inum !== null && inum !== undefined && inum !== '')

      if (scopeInums.length === 0) {
        setFetchedScopes([])
        setLoading(false)
        return
      }

      try {
        const response = await AXIOS_INSTANCE.get('/api/v1/scopes', {
          params: {
            pattern: scopeInums.join(','),
            limit: scopeInums.length,
          },
+         signal: controller.signal,
        })
        const scopeResults = response.data?.entries || response.data || []
        setFetchedScopes(Array.isArray(scopeResults) ? scopeResults : [])
      } catch (error) {
+       if (error.name === 'CanceledError' || error.name === 'AbortError') {
+         return
+       }
        console.error('Error fetching scopes:', error)
        setFetchedScopes([])
      }

      setLoading(false)
+     return controller
    }

-   fetchScopesForClient()
+   const controllerPromise = fetchScopesForClient()
+   return () => {
+     controllerPromise.then((controller) => controller?.abort())
+   }
  }, [isOpen, data])
📜 Review details

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 97e7cff and 9a41a2a.

📒 Files selected for processing (1)
  • admin-ui/plugins/auth-server/components/Clients/ClientShowScopes.js (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
admin-ui/plugins/auth-server/components/Clients/ClientShowScopes.js (4)
admin-ui/plugins/auth-server/components/Clients/ClientScopeUtils.js (1)
  • scopeDn (15-15)
admin-ui/app/utils/Util.ts (1)
  • getClientScopeByInum (34-38)
admin-ui/api-client.ts (1)
  • AXIOS_INSTANCE (9-9)
admin-ui/app/components/index.tsx (3)
  • Modal (81-81)
  • ModalHeader (84-84)
  • ModalBody (82-82)
⏰ 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). (1)
  • GitHub Check: sonar scan (flex-linux-setup)
🔇 Additional comments (2)
admin-ui/plugins/auth-server/components/Clients/ClientShowScopes.js (2)

1-14: LGTM: Imports and state setup are appropriate.

The addition of useEffect, useState, Spinner, AXIOS_INSTANCE, and getClientScopeByInum correctly supports the new async data-fetching approach. Local state for fetchedScopes and loading is well-structured for managing the fetch lifecycle.


37-42: The API parameter usage follows established patterns in the codebase. The comma-separated inum format for the pattern parameter is consistent across ClientShowScopes.js and ClientBasicPanel.js, and the response handling already includes defensive fallback logic (response.data?.entries || response.data || []) to accommodate both expected and alternative response formats. No issues identified.

Copy link
Contributor

@duttarnab duttarnab left a comment

Choose a reason for hiding this comment

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

We should use orval to call API.

}

try {
const response = await AXIOS_INSTANCE.get('/api/v1/scopes', {
Copy link
Contributor

Choose a reason for hiding this comment

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

we should use orval to call API

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

📜 Review details

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9a41a2a and 6969735.

📒 Files selected for processing (2)
  • admin-ui/plugins/auth-server/components/Clients/ClientShowScopes.js (0 hunks)
  • admin-ui/plugins/auth-server/components/Clients/ClientShowScopes.tsx (1 hunks)
💤 Files with no reviewable changes (1)
  • admin-ui/plugins/auth-server/components/Clients/ClientShowScopes.js
🔇 Additional comments (5)
admin-ui/plugins/auth-server/components/Clients/ClientShowScopes.tsx (5)

1-8: LGTM!

The imports are well-organized and include all necessary dependencies for the component functionality.


10-14: LGTM!

The interface clearly defines the component props with appropriate TypeScript types.


21-28: LGTM!

The memoized conversion from scope DNs to inums is well-implemented with appropriate filtering to remove invalid values.


76-76: LGTM!

Standard default export following React component conventions.


30-44: Verify the pattern parameter format in the OAuth scopes API.

The pattern parameter is being set to comma-separated scope inums (line 36), but the API may expect a search pattern or filter rather than multiple identifiers. Consider verifying:

  1. Whether the API's pattern parameter actually supports comma-separated identifier lists
  2. Whether using useGetOauthScopesByInum in a loop or an alternative batch-fetch method would be more appropriate

duttarnab
duttarnab previously approved these changes Dec 19, 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: 3

📜 Review details

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6969735 and e2a6639.

📒 Files selected for processing (1)
  • admin-ui/plugins/auth-server/components/Clients/ClientShowScopes.tsx (1 hunks)
🔇 Additional comments (4)
admin-ui/plugins/auth-server/components/Clients/ClientShowScopes.tsx (4)

1-8: LGTM! Well-structured imports.

The imports are appropriate and well-organized, covering React hooks, UI components, theming, translations, and API integration.


10-14: LGTM! Clear prop interface.

The props interface is well-defined with appropriate types for the modal handler, scope data, and visibility state.


16-19: LGTM! Proper hook initialization.

The component correctly initializes translation and theme hooks with a sensible fallback for the theme.


49-73: No issues found. All translation keys used in the component (fields.scopes, messages.no_scope_in_client, actions.close) are properly defined in the locale files. The modal rendering logic is correct with appropriate loading states and fallback messages.

@sonarqubecloud
Copy link

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

📜 Review details

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e2a6639 and 7d8b9cd.

📒 Files selected for processing (1)
  • admin-ui/plugins/auth-server/components/Clients/ClientShowScopes.tsx (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-11-10T14:18:58.310Z
Learnt from: kdhttps
Repo: GluuFederation/flex PR: 2378
File: admin-ui/plugins/admin/components/Cedarling/CedarlingConfigPage.tsx:107-109
Timestamp: 2025-11-10T14:18:58.310Z
Learning: In the Cedarling configuration page (admin-ui/plugins/admin/components/Cedarling/CedarlingConfigPage.tsx), console.error calls should be kept in catch blocks when there are multiple operations in the try block, as they help print the whole error object with details for debugging unexpected errors.

Applied to files:

  • admin-ui/plugins/auth-server/components/Clients/ClientShowScopes.tsx
🧬 Code graph analysis (1)
admin-ui/plugins/auth-server/components/Clients/ClientShowScopes.tsx (4)
admin-ui/plugins/auth-server/components/Clients/ClientScopeUtils.js (1)
  • scopeDn (15-15)
admin-ui/app/utils/Util.ts (1)
  • getClientScopeByInum (34-38)
admin-ui/app/components/index.tsx (6)
  • Modal (81-81)
  • ModalHeader (84-84)
  • ModalBody (82-82)
  • Badge (37-37)
  • ModalFooter (83-83)
  • Button (40-40)
admin-ui/plugins/auth-server/components/Clients/ClientAdvancedPanel.js (1)
  • handler (34-36)
🔇 Additional comments (3)
admin-ui/plugins/auth-server/components/Clients/ClientShowScopes.tsx (3)

1-14: LGTM! Clean TypeScript setup.

The imports are well-organized, and the props interface is properly typed with clear, descriptive names.


21-26: LGTM! Memoization is properly implemented.

The conversion from scope DNs to inums is correctly memoized with appropriate edge case handling. The .filter(Boolean) simplification from the previous review has been successfully applied.


43-70: LGTM! Rendering logic is well-structured.

The modal correctly handles loading and empty states, and all user-facing strings are properly translated. The fixes from the previous review have been successfully applied:

  • Modal header now uses t('fields.scopes') instead of hardcoded text
  • Badge displays scope.displayName || scope.id, prioritizing the user-friendly name

@moabu moabu merged commit c9fa553 into main Dec 19, 2025
8 checks passed
@moabu moabu deleted the admin-ui-issue-2529 branch December 19, 2025 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-admin-ui Component affected by issue or PR kind-bug Issue or PR is a bug in existing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

flex(admin-ui): no scopes records are showing for clients with scopes on Clients search page

5 participants