Skip to content

refactor(platform): clean up route pending states and ability ref#541

Merged
yannickmonney merged 1 commit into
mainfrom
feat/data-table-independent-loading
Feb 23, 2026
Merged

refactor(platform): clean up route pending states and ability ref#541
yannickmonney merged 1 commit into
mainfrom
feat/data-table-independent-loading

Conversation

@yannickmonney
Copy link
Copy Markdown
Contributor

@yannickmonney yannickmonney commented Feb 23, 2026

Remove unnecessary pendingComponent/pendingMs overrides from data table routes now that tables load their parts independently. Simplify the ability ref in dashboard layout to use a single ref object tracking both role and ability, and tighten defineAbilityFor parameter type.

Summary by CodeRabbit

  • Refactor
    • Optimized user role and permission computation in the dashboard.
    • Simplified loading behavior across knowledge and automation routes by removing explicit loading placeholders.
    • Updated permission validation logic for role parameter handling.

Remove unnecessary pendingComponent/pendingMs overrides from data table
routes now that tables load their parts independently. Simplify the
ability ref in dashboard layout to use a single ref object tracking both
role and ability, and tighten defineAbilityFor parameter type.
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Feb 23, 2026

Greptile Summary

Cleaned up route pending states following PR #540's independent data table loading, and refactored the dashboard layout's ability ref to track both role and ability in a single object instead of using two separate refs.

  • Removed pendingComponent and pendingMs from 8 route files (no longer needed with independent table loading)
  • Simplified ability ref logic in dashboard/$id.tsx from two refs to one combined object
  • Tightened defineAbilityFor parameter type from optional to explicit string | null

Confidence Score: 3/5

  • This PR is mostly safe but contains a TypeScript type error that should be fixed before merging
  • The refactoring is sound and simplifies the codebase, but there's a type mismatch in the abilityRef initialization that could cause TypeScript compilation issues
  • Pay attention to services/platform/app/routes/dashboard/$id.tsx - fix the type error before merging

Important Files Changed

Filename Overview
services/platform/app/routes/dashboard/$id.tsx Refactored ability ref to track both role and ability in single object, but has a TypeScript type error in ref initialization
services/platform/lib/permissions/ability.ts Tightened parameter type from `string

Last reviewed commit: e208153

Copy link
Copy Markdown

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

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

10 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile


const abilityRef = useRef<AppAbility>(defineAbilityFor(memberContext?.role));
const lastRoleRef = useRef<string | undefined>(memberContext?.role);
const abilityRef = useRef<{ role: string | null; ability: AppAbility }>(null);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

type mismatch between generic parameter and initial value - ref type doesn't allow null but is initialized with null

Suggested change
const abilityRef = useRef<{ role: string | null; ability: AppAbility }>(null);
const abilityRef = useRef<{ role: string | null; ability: AppAbility } | null>(null);

@yannickmonney yannickmonney merged commit 6b2a696 into main Feb 23, 2026
17 of 18 checks passed
@yannickmonney yannickmonney deleted the feat/data-table-independent-loading branch February 23, 2026 12:45
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 23, 2026

📝 Walkthrough

Walkthrough

This pull request refactors role and permissions management in the dashboard root route by replacing per-context recomputation with a single ref object containing {role, ability}, eliminating separate refs for tracking role changes. Concurrently, it removes pending UI configuration properties (pendingComponent and pendingMs) from eight route definitions across knowledge, automations, custom-agents, and settings sections. Additionally, the defineAbilityFor function signature is updated to require a non-undefined role parameter instead of an optional one.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main changes: removing pending state configurations from routes and simplifying ability ref logic in the dashboard.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/data-table-independent-loading

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

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@services/platform/app/routes/dashboard/`$id.tsx:
- Around line 37-45: TypeScript may not narrow abilityRef.current after the
in-render assignment, so update the destructure to use a non-null assertion and
remove the unused role variable: replace "const { role, ability } =
abilityRef.current" with "const { ability } = abilityRef.current!" (or change
the useRef typing to be non-nullable), and compute hasRole from the available
value (e.g., "const hasRole = abilityRef.current!.role !== null" or "const
hasRole = !!ability") to avoid the potential null typing error and remove the
unused role binding; keep defineAbilityFor and the lazy assignment logic as-is.

ℹ️ Review info

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 423f664 and e208153.

📒 Files selected for processing (10)
  • services/platform/app/routes/dashboard/$id.tsx
  • services/platform/app/routes/dashboard/$id/_knowledge/customers.tsx
  • services/platform/app/routes/dashboard/$id/_knowledge/products.tsx
  • services/platform/app/routes/dashboard/$id/_knowledge/tone-of-voice.tsx
  • services/platform/app/routes/dashboard/$id/_knowledge/vendors.tsx
  • services/platform/app/routes/dashboard/$id/_knowledge/websites.tsx
  • services/platform/app/routes/dashboard/$id/automations/index.tsx
  • services/platform/app/routes/dashboard/$id/custom-agents/index.tsx
  • services/platform/app/routes/dashboard/$id/settings/teams.tsx
  • services/platform/lib/permissions/ability.ts
💤 Files with no reviewable changes (8)
  • services/platform/app/routes/dashboard/$id/_knowledge/vendors.tsx
  • services/platform/app/routes/dashboard/$id/_knowledge/websites.tsx
  • services/platform/app/routes/dashboard/$id/custom-agents/index.tsx
  • services/platform/app/routes/dashboard/$id/settings/teams.tsx
  • services/platform/app/routes/dashboard/$id/_knowledge/tone-of-voice.tsx
  • services/platform/app/routes/dashboard/$id/_knowledge/products.tsx
  • services/platform/app/routes/dashboard/$id/_knowledge/customers.tsx
  • services/platform/app/routes/dashboard/$id/automations/index.tsx

Comment on lines +37 to +45
if (!abilityRef.current || abilityRef.current.role !== currentRole) {
abilityRef.current = {
role: currentRole,
ability: defineAbilityFor(currentRole),
};
}

const hasRole = !!memberContext?.role;
const { role, ability } = abilityRef.current;
const hasRole = role !== null;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

The during-render ref mutation pattern is valid, but confirm TypeScript narrows correctly after the assignment.

The lazy-initialization pattern (writing to a ref during render when the value is stale) is a supported React idiom. However, TypeScript does not narrow abilityRef.current through the ref assignment inside the if-block, so line 44 const { role, ability } = abilityRef.current may require a non-null assertion (abilityRef.current!) depending on whether the ref type includes null (see the useRef typing issue above).

Additionally, role on line 44 is only ever consumed to compute hasRole on line 45 and is never referenced elsewhere in this function. You can simplify:

♻️ Minor cleanup suggestion
-  const { role, ability } = abilityRef.current;
-  const hasRole = role !== null;
+  const { ability } = abilityRef.current!;
+  const hasRole = abilityRef.current!.role !== null;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (!abilityRef.current || abilityRef.current.role !== currentRole) {
abilityRef.current = {
role: currentRole,
ability: defineAbilityFor(currentRole),
};
}
const hasRole = !!memberContext?.role;
const { role, ability } = abilityRef.current;
const hasRole = role !== null;
if (!abilityRef.current || abilityRef.current.role !== currentRole) {
abilityRef.current = {
role: currentRole,
ability: defineAbilityFor(currentRole),
};
}
const { ability } = abilityRef.current!;
const hasRole = abilityRef.current!.role !== null;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@services/platform/app/routes/dashboard/`$id.tsx around lines 37 - 45,
TypeScript may not narrow abilityRef.current after the in-render assignment, so
update the destructure to use a non-null assertion and remove the unused role
variable: replace "const { role, ability } = abilityRef.current" with "const {
ability } = abilityRef.current!" (or change the useRef typing to be
non-nullable), and compute hasRole from the available value (e.g., "const
hasRole = abilityRef.current!.role !== null" or "const hasRole = !!ability") to
avoid the potential null typing error and remove the unused role binding; keep
defineAbilityFor and the lazy assignment logic as-is.

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.

1 participant