Skip to content

Conversation

rdonigian
Copy link
Contributor

Adds a Projects table prefiltered by userId to the User detail and also creates a new tab list where Profile is separated out from Projects.

@rdonigian rdonigian requested a review from CarsonF as a code owner July 3, 2025 19:45
Copy link
Contributor

coderabbitai bot commented Jul 3, 2025

📝 Walkthrough

Walkthrough

This update introduces a tabbed interface to the user detail view, separating profile and project information into distinct tabs. New React components and a GraphQL query are added to support dynamic user profile and project displays, including live local time and paginated project lists. Type policies are updated for Apollo cache handling.

Changes

Files/Paths Change Summary
src/api/schema/typePolicies/typePolicies.base.ts Added a User type policy with a custom projects field policy to the exported typePolicies.
src/scenes/Users/Detail/Tabs/Profile/UserDetailProfile.tsx Added UserDetailProfile React component with subcomponents for displaying user profile details.
src/scenes/Users/Detail/Tabs/Profile/UserDetailProfile.graphql Added UserProfile GraphQL fragment combining DisplayUser and UserForm fragments.
src/scenes/Users/Detail/Tabs/Projects/UserDetailProjects.tsx Added UserDetailProjects React component for the projects tab content.
src/scenes/Users/Detail/Tabs/Projects/UserProjectPanel/UserProjectList.graphql Added UserProjects GraphQL query and userProjectDataGridRow fragment for user projects.
src/scenes/Users/Detail/Tabs/Projects/UserProjectPanel/UserProjectsPanel.tsx Added UserProjectsPanel React component for displaying a data grid of user projects.
src/scenes/Users/Detail/UserDetail.tsx Refactored UserDetail to use tabbed layout; removed inline profile display and local components.

Possibly related PRs

  • Convert People List to DataGrid #1641: Adds a type policy for the users field under the Query type, related to Apollo cache configuration alongside the User.projects type policy added here.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8ccdc83 and f697c21.

📒 Files selected for processing (7)
  • src/api/schema/typePolicies/typePolicies.base.ts (1 hunks)
  • src/scenes/Users/Detail/Tabs/Profile/UserDetailProfile.graphql (1 hunks)
  • src/scenes/Users/Detail/Tabs/Profile/UserDetailProfile.tsx (1 hunks)
  • src/scenes/Users/Detail/Tabs/Projects/UserDetailProjects.tsx (1 hunks)
  • src/scenes/Users/Detail/Tabs/Projects/UserProjectPanel/UserProjectList.graphql (1 hunks)
  • src/scenes/Users/Detail/Tabs/Projects/UserProjectPanel/UserProjectsPanel.tsx (1 hunks)
  • src/scenes/Users/Detail/UserDetail.tsx (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/scenes/Users/Detail/Tabs/Profile/UserDetailProfile.graphql
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/scenes/Users/Detail/Tabs/Projects/UserDetailProjects.tsx
  • src/api/schema/typePolicies/typePolicies.base.ts
  • src/scenes/Users/Detail/Tabs/Profile/UserDetailProfile.tsx
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: CarsonF
PR: SeedCompany/cord-field#1604
File: src/scenes/Root/Notifications/Notifications.tsx:35-51
Timestamp: 2024-10-21T15:15:09.113Z
Learning: In the `Notifications` component (`src/scenes/Root/Notifications/Notifications.tsx`), Apollo Client automatically updates the notification's unread status in the cache when the mutation returns the updated notification, so manually updating the cache in the `update` function is unnecessary.
src/scenes/Users/Detail/UserDetail.tsx (3)
Learnt from: CarsonF
PR: SeedCompany/cord-field#1604
File: src/components/Feature.tsx:12-19
Timestamp: 2024-10-21T15:17:35.618Z
Learning: In `src/components/Feature.tsx`, the `Feature` component uses `useFeatureFlagPayload` and the `match` prop to determine feature availability, which differs from the `useFeatureEnabled` hook.
Learnt from: CarsonF
PR: SeedCompany/cord-field#1696
File: src/scenes/FieldZones/CreateFieldZone/CreateFieldZone.tsx:0-0
Timestamp: 2025-06-20T17:50:15.534Z
Learning: In this codebase, GraphQL documents (like CreateFieldZoneDocument, CreateFieldRegionDocument, etc.) are already properly typed, and Apollo hooks (useMutation, useQuery, etc.) automatically infer the correct types from these typed documents. Therefore, explicit generic type parameters on Apollo hooks are unnecessary and should not be suggested.
Learnt from: CarsonF
PR: SeedCompany/cord-field#1696
File: src/scenes/FieldZones/Detail/FieldZoneDetail.tsx:79-88
Timestamp: 2025-07-02T15:46:56.008Z
Learning: In this codebase, when using `canEditAny()` with components that have loading states (like FAB), passing `true` as the second argument when the first argument might be null during loading is intentional. This allows the component to render during loading and use its own `loading` prop to show loading state, then evaluate actual permissions once data loads. Example: `canEditAny(fieldZone, true)` with `<Fab loading={!fieldZone}>` allows the FAB to show loading state before permissions are determined.
🪛 Biome (1.9.4)
src/scenes/Users/Detail/UserDetail.tsx

[error] 8-8: Do not shadow the global "Error" property.

Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.

(lint/suspicious/noShadowRestrictedNames)

🔇 Additional comments (4)
src/scenes/Users/Detail/Tabs/Projects/UserProjectPanel/UserProjectList.graphql (1)

1-23: LGTM! Well-structured GraphQL query

The query properly fetches paginated user projects with membership roles, using appropriate fragment composition and variable usage.

src/scenes/Users/Detail/Tabs/Projects/UserProjectPanel/UserProjectsPanel.tsx (2)

69-82: Well-implemented role column addition

The role column is properly configured with appropriate width, multi-enum support, and correct value extraction from the membership data. The column insertion logic safely handles the array manipulation.


32-39: Verify error state in useDataGridSource

I wasn’t able to locate the useDataGridSource implementation in the repo to confirm whether it returns an error field. Please double-check:

  • Does useDataGridSource surface GraphQL errors (e.g. via an error property)?
  • If it doesn’t, update UserProjectsPanel to handle failures (extract error from the hook and render an error message or fallback UI).

File for reference:
• src/scenes/Users/Detail/Tabs/Projects/UserProjectPanel/UserProjectsPanel.tsx (lines 32–39)

src/scenes/Users/Detail/UserDetail.tsx (1)

20-106: Excellent refactoring to tabbed interface

The implementation properly:

  • Manages tab state via URL query params for better UX
  • Provides specific error messages for different error types
  • Cleanly separates profile and projects into dedicated components
  • Uses MUI's TabContext for proper tab management
✨ 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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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

🧹 Nitpick comments (3)
src/scenes/Users/Detail/Tabs/Projects/UserProjectPanel/UserProjectList.graphql (1)

15-17: Remove redundant fragment wrapper

The userProjectDataGridRow fragment only spreads projectDataGridRow without adding any fields. This adds unnecessary indirection.

-        ...userProjectDataGridRow
+        ...projectDataGridRow

Then remove the redundant fragment definition:

-fragment userProjectDataGridRow on Project {
-  ...projectDataGridRow
-}
src/scenes/Users/Detail/Tabs/Profile/UserDetailProfile.tsx (2)

81-89: Consider adding accessibility attributes to the time display.

The LocalTime component correctly handles timezone formatting, but could benefit from accessibility improvements for screen readers.

-  return <>{formatted}</>;
+  return <span title={`Local time in ${timezone}`}>{formatted}</span>;

99-127: Consider simplifying the loading state logic.

The DisplayProperty wrapper has complex loading logic that could be streamlined. The skeleton structure with two Typography components may not perfectly match the actual content structure.

 const DisplayProperty = (props: DisplaySimplePropertyProps) =>
   !props.value && !props.loading ? null : (
     <DisplaySimpleProperty
       variant="body1"
       {...{ component: 'div' }}
       {...props}
       loading={
-        props.loading ? (
-          <>
-            <Typography variant="body2">
-              <Skeleton width="10%" />
-            </Typography>
-            <Typography variant="body1">
-              <Skeleton width="40%" />
-            </Typography>
-          </>
-        ) : null
+        props.loading ? <Skeleton width="60%" /> : null
       }
       LabelProps={{
         color: 'textSecondary',
         variant: 'body2',
         ...props.LabelProps,
       }}
       ValueProps={{
         color: 'textPrimary',
         ...props.ValueProps,
       }}
     />
   );
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 088c72b and 8ccdc83.

📒 Files selected for processing (6)
  • src/api/schema/typePolicies/typePolicies.base.ts (1 hunks)
  • src/scenes/Users/Detail/Tabs/Profile/UserDetailProfile.tsx (1 hunks)
  • src/scenes/Users/Detail/Tabs/Projects/UserDetailProjects.tsx (1 hunks)
  • src/scenes/Users/Detail/Tabs/Projects/UserProjectPanel/UserProjectList.graphql (1 hunks)
  • src/scenes/Users/Detail/Tabs/Projects/UserProjectPanel/UserProjectsPanel.tsx (1 hunks)
  • src/scenes/Users/Detail/UserDetail.tsx (3 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: CarsonF
PR: SeedCompany/cord-field#1604
File: src/scenes/Root/Notifications/Notifications.tsx:35-51
Timestamp: 2024-10-21T15:15:09.113Z
Learning: In the `Notifications` component (`src/scenes/Root/Notifications/Notifications.tsx`), Apollo Client automatically updates the notification's unread status in the cache when the mutation returns the updated notification, so manually updating the cache in the `update` function is unnecessary.
src/scenes/Users/Detail/UserDetail.tsx (2)
Learnt from: CarsonF
PR: SeedCompany/cord-field#1604
File: src/components/Feature.tsx:12-19
Timestamp: 2024-10-21T15:17:35.618Z
Learning: In `src/components/Feature.tsx`, the `Feature` component uses `useFeatureFlagPayload` and the `match` prop to determine feature availability, which differs from the `useFeatureEnabled` hook.
Learnt from: CarsonF
PR: SeedCompany/cord-field#1696
File: src/scenes/FieldZones/CreateFieldZone/CreateFieldZone.tsx:0-0
Timestamp: 2025-06-20T17:50:15.534Z
Learning: In this codebase, GraphQL documents (like CreateFieldZoneDocument, CreateFieldRegionDocument, etc.) are already properly typed, and Apollo hooks (useMutation, useQuery, etc.) automatically infer the correct types from these typed documents. Therefore, explicit generic type parameters on Apollo hooks are unnecessary and should not be suggested.
src/scenes/Users/Detail/Tabs/Profile/UserDetailProfile.tsx (1)
Learnt from: CarsonF
PR: SeedCompany/cord-field#1604
File: src/components/Feature.tsx:12-19
Timestamp: 2024-10-21T15:17:35.618Z
Learning: In `src/components/Feature.tsx`, the `Feature` component uses `useFeatureFlagPayload` and the `match` prop to determine feature availability, which differs from the `useFeatureEnabled` hook.
🧬 Code Graph Analysis (3)
src/scenes/Users/Detail/Tabs/Projects/UserDetailProjects.tsx (2)
src/components/Tabs/TabPanelContent.tsx (1)
  • TabPanelContent (6-22)
src/scenes/Users/Detail/Tabs/Projects/UserProjectPanel/UserProjectsPanel.tsx (1)
  • UserProjectsPanel (23-61)
src/scenes/Users/Detail/UserDetail.tsx (8)
src/hooks/useQueryParams.ts (3)
  • makeQueryHandler (183-247)
  • withDefault (92-104)
  • EnumParam (69-85)
src/components/Comments/CommentsContext.tsx (1)
  • useComments (65-71)
src/components/Dialog/useDialog.tsx (1)
  • useDialog (4-33)
src/components/Error/Error.tsx (1)
  • Error (57-116)
src/components/Tabs/TabsContainer.tsx (1)
  • TabsContainer (4-16)
src/scenes/Users/Detail/Tabs/Profile/UserDetailProfile.tsx (1)
  • UserDetailProfile (18-79)
src/scenes/Users/Detail/Tabs/Projects/UserDetailProjects.tsx (1)
  • UserDetailProjects (4-10)
src/scenes/Users/Edit/EditUser.tsx (1)
  • EditUser (13-57)
src/scenes/Users/Detail/Tabs/Profile/UserDetailProfile.tsx (3)
src/common/displayEnums.ts (1)
  • labelsFrom (16-19)
src/components/PartnerListItemCard/PartnerListItemCard.tsx (1)
  • PartnerListItemCard (37-85)
src/components/DisplaySimpleProperty/DisplaySimpleProperty.tsx (2)
  • DisplaySimplePropertyProps (4-12)
  • DisplaySimpleProperty (14-50)
🪛 Biome (1.9.4)
src/scenes/Users/Detail/UserDetail.tsx

[error] 11-11: Do not shadow the global "Error" property.

Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.

(lint/suspicious/noShadowRestrictedNames)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: run
🔇 Additional comments (6)
src/api/schema/typePolicies/typePolicies.base.ts (1)

88-92: LGTM!

The type policy addition follows the existing pattern used for Partner.projects and correctly configures Apollo cache to avoid page merging for infinite scroll functionality.

src/scenes/Users/Detail/Tabs/Projects/UserDetailProjects.tsx (1)

1-11: LGTM!

Clean wrapper component that properly uses TabPanelContent for consistent tab panel styling.

src/scenes/Users/Detail/UserDetail.tsx (1)

124-124: Verify EditUser rendering logic change

The EditUser component now renders outside the error check, meaning it will render even when there's an error (if user data exists from cache). Is this intentional?

If this change is unintentional, consider moving it back inside the error check:

-      {user ? <EditUser user={user} {...editUserState} /> : null}
+          {user ? <EditUser user={user} {...editUserState} /> : null}
         </>
       )}
src/scenes/Users/Detail/Tabs/Profile/UserDetailProfile.tsx (3)

18-79: Well-structured component with good separation of concerns.

The main component structure is clean and follows React best practices. The use of optional chaining for undefined user data is appropriate, and the conditional rendering for the partners section is correctly implemented.


91-97: Time update interval is reasonable but consider performance implications.

The 1-second update interval is appropriate for a time display. The useInterval hook from ahooks should handle cleanup properly when the component unmounts.


42-42: labelsFrom handles empty/undefined values correctly

The labelsFrom utility in src/common/displayEnums.ts defaults values to an empty array (values ?? []) and returns an empty string when there are no roles, so labelsFrom(RoleLabels)(user?.roles.value) will gracefully display nothing for undefined or empty role lists. No changes are needed.

Comment on lines 24 to 39
const { userId = '' } = useParams();

const [dataGridProps] = useDataGridSource({
query: UserProjectListDocument,
variables: { userId },
listAt: 'user.projects',
initialInput: {
sort: 'name',
},
});
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

Handle missing userId gracefully

Defaulting userId to an empty string could cause the GraphQL query to fail or return unexpected results. Consider adding explicit error handling for this case.

export const UserProjectsPanel = () => {
-  const { userId = '' } = useParams();
+  const { userId } = useParams();
+  
+  if (!userId) {
+    return (
+      <Typography color="error" sx={{ p: 2 }}>
+        User ID is required
+      </Typography>
+    );
+  }

  const [dataGridProps] = useDataGridSource({
    query: UserProjectListDocument,
    variables: { userId },
🤖 Prompt for AI Agents
In src/scenes/Users/Detail/Tabs/Projects/UserProjectPanel/UserProjectsPanel.tsx
around lines 24 to 33, the userId is defaulted to an empty string which may
cause the GraphQL query to fail or behave unexpectedly. Instead of defaulting,
add explicit error handling to check if userId is missing or undefined before
running the query. If userId is not present, handle this case gracefully by
either showing an error message or skipping the query execution to prevent
invalid requests.

@sethmcknight sethmcknight linked an issue Jul 9, 2025 that may be closed by this pull request
@rdonigian rdonigian force-pushed the users-projects-grid branch from 8ccdc83 to f697c21 Compare July 15, 2025 19:53
@rdonigian rdonigian requested a review from CarsonF July 15, 2025 20:50
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.

Add Projects grid to People
2 participants