Skip to content

refactor: move data fetching from RoomEdit to RoomEditWithData#38688

Closed
sezallagwal wants to merge 2 commits intoRocketChat:developfrom
sezallagwal:refactor/room-edit-data-fetching
Closed

refactor: move data fetching from RoomEdit to RoomEditWithData#38688
sezallagwal wants to merge 2 commits intoRocketChat:developfrom
sezallagwal:refactor/room-edit-data-fetching

Conversation

@sezallagwal
Copy link
Copy Markdown
Contributor

@sezallagwal sezallagwal commented Feb 14, 2026

Description

Moves data-fetching hooks (useSlaPolicies, useCustomFieldsMetadata, useOmnichannelPriorities) and the canViewCustomFields permission check from RoomEdit (child) to RoomEditWithData (parent), resolving the TODO at RoomEdit.tsx:120-121.

This ensures RoomEdit is a purely presentational component that receives all data as props — matching the established pattern used by all sibling *WithData components (AgentEditWithData, UnitEditWithData, TagEditWithData, EditTriggerWithData, EditCustomFieldsWithData, SlaEditWithData, PriorityEditFormWithData).

Changes

  • RoomEditWithData.tsx — Added 3 data-fetching hooks + permission check. Extended the loading guard to cover all queries.
  • RoomEdit.tsx — Removed hooks, loading block, and TODO comment. Added slaPolicies, customFieldsMetadata, priorities, canViewCustomFields as props.

Summary by CodeRabbit

  • Refactor

    • Centralized data handling for SLA policies, custom fields, and priorities to streamline the room edit experience.
  • Bug Fixes

    • Fixed permission-based access so custom fields only appear to users with view/edit rights and loading behaves correctly.
  • UI

    • Conditional rendering improves loading behavior and prevents unnecessary placeholders for unauthorized users.

@sezallagwal sezallagwal requested a review from a team as a code owner February 14, 2026 18:43
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Feb 14, 2026

⚠️ No Changeset found

Latest commit: 94bf10b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@dionisio-bot
Copy link
Copy Markdown
Contributor

dionisio-bot Bot commented Feb 14, 2026

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Feb 14, 2026

CLA assistant check
All committers have signed the CLA.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 14, 2026

No actionable comments were generated in the recent review. 🎉

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 567d84e and 94bf10b.

📒 Files selected for processing (1)
  • apps/meteor/client/views/omnichannel/directory/chats/ChatInfo/RoomEdit/RoomEditWithData.tsx
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • apps/meteor/client/views/omnichannel/directory/chats/ChatInfo/RoomEdit/RoomEditWithData.tsx
🧠 Learnings (4)
📚 Learning: 2025-10-28T16:53:42.761Z
Learnt from: ricardogarim
Repo: RocketChat/Rocket.Chat PR: 37205
File: ee/packages/federation-matrix/src/FederationMatrix.ts:296-301
Timestamp: 2025-10-28T16:53:42.761Z
Learning: In the Rocket.Chat federation-matrix integration (ee/packages/federation-matrix/), the createRoom method from rocket.chat/federation-sdk will support a 4-argument signature (userId, roomName, visibility, displayName) in newer versions. Code using this 4-argument call is forward-compatible with planned library updates and should not be flagged as an error.

Applied to files:

  • apps/meteor/client/views/omnichannel/directory/chats/ChatInfo/RoomEdit/RoomEditWithData.tsx
📚 Learning: 2025-11-27T17:56:26.050Z
Learnt from: MartinSchoeler
Repo: RocketChat/Rocket.Chat PR: 37557
File: apps/meteor/client/views/admin/ABAC/AdminABACRooms.tsx:115-116
Timestamp: 2025-11-27T17:56:26.050Z
Learning: In Rocket.Chat, the GET /v1/abac/rooms endpoint (implemented in ee/packages/abac/src/index.ts) only returns rooms where abacAttributes exists and is not an empty array (query: { abacAttributes: { $exists: true, $ne: [] } }). Therefore, in components consuming this endpoint (like AdminABACRooms.tsx), room.abacAttributes is guaranteed to be defined for all returned rooms, and optional chaining before calling array methods like .join() is sufficient without additional null coalescing.

Applied to files:

  • apps/meteor/client/views/omnichannel/directory/chats/ChatInfo/RoomEdit/RoomEditWithData.tsx
📚 Learning: 2025-11-04T16:49:19.107Z
Learnt from: ricardogarim
Repo: RocketChat/Rocket.Chat PR: 37377
File: apps/meteor/ee/server/hooks/federation/index.ts:86-88
Timestamp: 2025-11-04T16:49:19.107Z
Learning: In Rocket.Chat's federation system (apps/meteor/ee/server/hooks/federation/), permission checks follow two distinct patterns: (1) User-initiated federation actions (creating rooms, adding users to federated rooms, joining from invites) should throw MeteorError to inform users they lack 'access-federation' permission. (2) Remote server-initiated federation events should silently skip/ignore when users lack permission. The beforeAddUserToRoom hook only executes for local user-initiated actions, so throwing an error there is correct. Remote federation events are handled separately by the federation Matrix package with silent skipping logic.

Applied to files:

  • apps/meteor/client/views/omnichannel/directory/chats/ChatInfo/RoomEdit/RoomEditWithData.tsx
📚 Learning: 2025-09-25T09:59:26.461Z
Learnt from: Dnouv
Repo: RocketChat/Rocket.Chat PR: 37057
File: packages/apps-engine/src/definition/accessors/IUserRead.ts:23-27
Timestamp: 2025-09-25T09:59:26.461Z
Learning: UserBridge.doGetUserRoomIds in packages/apps-engine/src/server/bridges/UserBridge.ts has a bug where it implicitly returns undefined when the app lacks read permission (missing return statement in the else case of the permission check).

Applied to files:

  • apps/meteor/client/views/omnichannel/directory/chats/ChatInfo/RoomEdit/RoomEditWithData.tsx
🧬 Code graph analysis (1)
apps/meteor/client/views/omnichannel/directory/chats/ChatInfo/RoomEdit/RoomEditWithData.tsx (3)
packages/ui-contexts/src/index.ts (1)
  • useAtLeastOnePermission (26-26)
apps/meteor/client/views/omnichannel/directory/hooks/useSlaPolicies.tsx (1)
  • useSlaPolicies (7-21)
apps/meteor/client/views/omnichannel/directory/hooks/useCustomFieldsMetadata.tsx (1)
  • useCustomFieldsMetadata (12-19)
⏰ 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: cubic · AI code reviewer
🔇 Additional comments (3)
apps/meteor/client/views/omnichannel/directory/chats/ChatInfo/RoomEdit/RoomEditWithData.tsx (3)

23-23: Good: reactive permission hook adopted.

The switch from hasAtLeastOnePermission to useAtLeastOnePermission correctly ensures the component re-renders when user permissions change at runtime.


48-60: Clean prop pass-through aligning with the presentational pattern.

The new props (slaPolicies, customFieldsMetadata, priorities, canViewCustomFields) are passed cleanly to RoomEdit, completing the separation of concerns.


29-36: RoomEdit properly handles undefined for all three new data sources.

RoomEdit guards against undefined values for slaPolicies, customFieldsMetadata, and priorities through conditional rendering (e.g., {canViewCustomFields && customFieldsMetadata && <CustomFieldsForm ... />}). If these queries fail, undefined values will simply be skipped during render, which is acceptable since these are optional enrichments. No error handling UI is needed for these features.


Walkthrough

RoomEdit was converted into a presentational component: it no longer fetches SLA policies, priorities, or custom-fields metadata. RoomEditWithData now performs permission checks and data fetching, then passes slaPolicies, priorities, customFieldsMetadata, and canViewCustomFields down as props.

Changes

Cohort / File(s) Summary
RoomEdit Presentational Component
apps/meteor/client/views/omnichannel/directory/chats/ChatInfo/RoomEdit/RoomEdit.tsx
Removed internal data-fetching hooks and loading guards; added public props: slaPolicies, customFieldsMetadata, priorities, canViewCustomFields (typed via ComponentProps). Conditional rendering now depends on canViewCustomFields. Removed import of ContextualbarContent.
RoomEditWithData Container
apps/meteor/client/views/omnichannel/directory/chats/ChatInfo/RoomEdit/RoomEditWithData.tsx
Added permission calculation for canViewCustomFields; fetches slaPolicies, priorities, and customFieldsMetadata when permitted; aggregates loading flags (isSlaPoliciesLoading, isCustomFieldsLoading, isPrioritiesLoading) and passes fetched data plus canViewCustomFields to RoomEdit.

Sequence Diagram(s)

sequenceDiagram
    rect rgba(200,200,255,0.5)
    actor User
    end
    rect rgba(200,255,200,0.5)
    participant UI as RoomEditWithData
    participant Comp as RoomEdit
    end
    rect rgba(255,200,200,0.5)
    participant API as DataSources
    participant Perm as Permissions
    end

    User->>UI: open Room Edit
    UI->>Perm: check permissions (view/edit custom fields)
    Perm-->>UI: canViewCustomFields (true/false)
    alt canViewCustomFields == true
        UI->>API: fetch customFieldsMetadata
        API-->>UI: customFieldsMetadata
    end
    UI->>API: fetch slaPolicies, priorities
    API-->>UI: slaPolicies, priorities
    UI->>Comp: render with props (slaPolicies, priorities, customFieldsMetadata?, canViewCustomFields)
    Comp-->>User: rendered RoomEdit UI
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I nudged the fetches up a hill so small,

now parent hums and children only call.
Permissions guard the hidden fields with care,
data passed along the sunny air.
A tiny hop — cleaner code everywhere. 🥕

🚥 Pre-merge checks | ✅ 3 | ❌ 1
❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main refactoring work: moving data fetching logic from the RoomEdit presentational component to its parent RoomEditWithData container component.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into develop

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


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
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 2 files

Copy link
Copy Markdown
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
`@apps/meteor/client/views/omnichannel/directory/chats/ChatInfo/RoomEdit/RoomEditWithData.tsx`:
- Line 5: Replace the non-reactive hasAtLeastOnePermission usage with the
reactive hook useAtLeastOnePermission from `@rocket.chat/ui-contexts` in the
RoomEditWithData component: update the import (remove hasAtLeastOnePermission
and import useAtLeastOnePermission) and change the place where
canViewCustomFields is computed to call useAtLeastOnePermission(...) instead of
hasAtLeastOnePermission(...), ensuring the component re-renders when permissions
change.
🧹 Nitpick comments (2)
apps/meteor/client/views/omnichannel/directory/chats/ChatInfo/RoomEdit/RoomEdit.tsx (2)

53-53: Long function signature — consider destructuring on multiple lines for readability.

The parameter list is getting wide. This is a minor nit; consider breaking it across lines.


130-136: Truthiness checks on imported components are always true.

SlaPoliciesSelect && (Line 130) and PrioritiesSelect && (Line 134) are always truthy since these are statically imported components. These guards are redundant. That said, this appears to be pre-existing code not introduced in this PR, so it can be addressed separately.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 11e1c51 and 567d84e.

📒 Files selected for processing (2)
  • apps/meteor/client/views/omnichannel/directory/chats/ChatInfo/RoomEdit/RoomEdit.tsx
  • apps/meteor/client/views/omnichannel/directory/chats/ChatInfo/RoomEdit/RoomEditWithData.tsx
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • apps/meteor/client/views/omnichannel/directory/chats/ChatInfo/RoomEdit/RoomEdit.tsx
  • apps/meteor/client/views/omnichannel/directory/chats/ChatInfo/RoomEdit/RoomEditWithData.tsx
🧠 Learnings (3)
📚 Learning: 2025-10-28T16:53:42.761Z
Learnt from: ricardogarim
Repo: RocketChat/Rocket.Chat PR: 37205
File: ee/packages/federation-matrix/src/FederationMatrix.ts:296-301
Timestamp: 2025-10-28T16:53:42.761Z
Learning: In the Rocket.Chat federation-matrix integration (ee/packages/federation-matrix/), the createRoom method from rocket.chat/federation-sdk will support a 4-argument signature (userId, roomName, visibility, displayName) in newer versions. Code using this 4-argument call is forward-compatible with planned library updates and should not be flagged as an error.

Applied to files:

  • apps/meteor/client/views/omnichannel/directory/chats/ChatInfo/RoomEdit/RoomEdit.tsx
  • apps/meteor/client/views/omnichannel/directory/chats/ChatInfo/RoomEdit/RoomEditWithData.tsx
📚 Learning: 2025-11-27T17:56:26.050Z
Learnt from: MartinSchoeler
Repo: RocketChat/Rocket.Chat PR: 37557
File: apps/meteor/client/views/admin/ABAC/AdminABACRooms.tsx:115-116
Timestamp: 2025-11-27T17:56:26.050Z
Learning: In Rocket.Chat, the GET /v1/abac/rooms endpoint (implemented in ee/packages/abac/src/index.ts) only returns rooms where abacAttributes exists and is not an empty array (query: { abacAttributes: { $exists: true, $ne: [] } }). Therefore, in components consuming this endpoint (like AdminABACRooms.tsx), room.abacAttributes is guaranteed to be defined for all returned rooms, and optional chaining before calling array methods like .join() is sufficient without additional null coalescing.

Applied to files:

  • apps/meteor/client/views/omnichannel/directory/chats/ChatInfo/RoomEdit/RoomEdit.tsx
  • apps/meteor/client/views/omnichannel/directory/chats/ChatInfo/RoomEdit/RoomEditWithData.tsx
📚 Learning: 2025-11-04T16:49:19.107Z
Learnt from: ricardogarim
Repo: RocketChat/Rocket.Chat PR: 37377
File: apps/meteor/ee/server/hooks/federation/index.ts:86-88
Timestamp: 2025-11-04T16:49:19.107Z
Learning: In Rocket.Chat's federation system (apps/meteor/ee/server/hooks/federation/), permission checks follow two distinct patterns: (1) User-initiated federation actions (creating rooms, adding users to federated rooms, joining from invites) should throw MeteorError to inform users they lack 'access-federation' permission. (2) Remote server-initiated federation events should silently skip/ignore when users lack permission. The beforeAddUserToRoom hook only executes for local user-initiated actions, so throwing an error there is correct. Remote federation events are handled separately by the federation Matrix package with silent skipping logic.

Applied to files:

  • apps/meteor/client/views/omnichannel/directory/chats/ChatInfo/RoomEdit/RoomEditWithData.tsx
🧬 Code graph analysis (2)
apps/meteor/client/views/omnichannel/directory/chats/ChatInfo/RoomEdit/RoomEdit.tsx (2)
apps/meteor/client/views/omnichannel/additionalForms/SlaPoliciesSelect.tsx (1)
  • SlaPoliciesSelect (15-32)
apps/meteor/client/views/omnichannel/additionalForms/PrioritiesSelect.tsx (1)
  • PrioritiesSelect (20-69)
apps/meteor/client/views/omnichannel/directory/chats/ChatInfo/RoomEdit/RoomEditWithData.tsx (4)
apps/meteor/server/services/authorization/service.ts (1)
  • hasAtLeastOnePermission (73-78)
packages/ddp-client/src/livechat/LivechatClientImpl.ts (1)
  • visitor (151-159)
apps/meteor/client/views/omnichannel/directory/hooks/useSlaPolicies.tsx (1)
  • useSlaPolicies (7-21)
apps/meteor/client/views/omnichannel/directory/hooks/useCustomFieldsMetadata.tsx (1)
  • useCustomFieldsMetadata (12-19)
⏰ 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: cubic · AI code reviewer
🔇 Additional comments (3)
apps/meteor/client/views/omnichannel/directory/chats/ChatInfo/RoomEdit/RoomEdit.tsx (1)

22-32: Clean prop typing using ComponentProps.

The derived types keep RoomEdit's prop contract in sync with the child components automatically. This is a good pattern.

apps/meteor/client/views/omnichannel/directory/chats/ChatInfo/RoomEdit/RoomEditWithData.tsx (2)

29-34: Data-fetching hooks look correctly lifted.

The hooks are properly invoked at the top level and their results are passed down as props. The conditional enabled: canViewCustomFields on useCustomFieldsMetadata correctly avoids unnecessary fetching.


36-38: Loading guard correctly aggregates all query states.

When a query is disabled (e.g., useCustomFieldsMetadata with enabled: false), TanStack Query v5 reports isLoading as false (since isLoading = isPending && isFetching), so this won't block rendering unnecessarily.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

@sezallagwal sezallagwal closed this Apr 3, 2026
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.

2 participants