Skip to content

Conversation

@talissoncosta
Copy link
Contributor

@talissoncosta talissoncosta commented Dec 2, 2025

Thanks for submitting a PR! Please check the boxes below:

  • I have added information to docs/ if required so people know about the feature!
  • I have filled in the "Changes" section below?
  • I have filled in the "How did you test this code" section below?
  • I have used a Conventional Commit title for this Pull Request

Summary

This PR completes the migration of FeaturesPage from legacy Flux stores to RTK Query with comprehensive refactoring, improved TypeScript type safety, better error handling, and cleaner documentation.

Changes

1. Core RTK Query Migration

  • Migrated FeaturesPage from Flux (ProjectStore, AccountStore) to RTK Query
  • Created useFeatureListWithFilters hook for filtered feature fetching with automatic API key to ID conversion
  • Created useProjectEnvironments hook to replace ProjectStore functionality
  • Removed FeaturesList wrapper component (functionality merged into FeaturesPage)
  • Uses RouteContext exclusively for organization/project data

2. Custom Hooks & Code Organization

  • useFeatureFilters: Manages filters with bidirectional URL synchronization
    • Optimized by removing unnecessary useCallback wrappers with empty dependencies
  • useToggleFeatureWithToast: Toggles features with toast notifications
  • useRemoveFeatureWithToast: Removes features with toast notifications
  • useProjectEnvironments: Provides project/environment data with accessor functions
  • Extracted filter utilities to featureFilterParams.ts for global reuse
  • Created comprehensive type definitions in featureFilters.ts

3. UI/UX Improvements

  • Error Handling: Replaced custom error UI with reusable ErrorMessage component
    • Added user-friendly error context and actionable messages
    • Proper error state handling for failed data fetching
  • Loading States: Added professional skeleton loader for features list
    • Supports reduced motion preferences
    • SCSS-based styling (removed styled-jsx)
  • Mutation State Tracking: Added opacity feedback during toggle/remove operations
    • Tracks isToggling and isRemoving states from mutation hooks
    • Replicates legacy isSaving behavior

4. Component Refactoring

  • FeaturesPage.tsx:
    • Simplified display logic by removing useFeaturePageDisplay hook
    • Extracted nested ternary to renderFeaturesList() helper function
    • Removed inline render functions to named constants for better readability
  • FeaturesPageHeader: Removed unused showCreateButton prop (was always true)
  • FeaturesTableFilters:
    • Fixed TypeScript issues (Row import, isLoading prop naming)
    • Removed readonly type constraint on VIEW_MODE_OPTIONS

5. Type Safety Improvements

  • Standardized projectId type to number across all components
  • Added explicit update body types following team patterns
  • Fixed TypeScript errors in useFeatureList service
  • Aligned pagination field naming with component expectations
  • Added Environment tag type for cross-service cache invalidation
  • Proper typing for filter states and URL parameters

6. Documentation Cleanup

  • Removed ~150 lines of excessive JSDoc documentation across 7 files:
    • useFeatureListWithFilters.ts: 81→34 lines
    • featureFilterParams.ts: Simplified 4 JSDoc blocks
    • useFeatureFilters.ts: 26→3 lines
    • useRemoveFeatureWithToast.ts: 18→1 line
    • useToggleFeatureWithToast.ts: 18→1 line
    • useProjectEnvironments.ts: 25→1 line
    • featureFilters.ts: Simplified type comments
  • Removed obvious inline comments that restated code
  • Kept TypeScript types as primary documentation (self-documenting code)

7. Performance Optimizations

  • Added memoization to prevent unnecessary re-renders
  • Removed complex optimistic update logic (RTK Query handles this)
  • Proper dependency arrays in hooks

8. Code Quality

  • All commits follow conventional commit format (37 commits)
  • Removed unused legacy types and props
  • Standardized parameter naming across hooks
  • Extracted pagination handlers
  • Removed legacy Flux store ignore filter

Files Changed

Created:

  • common/hooks/useFeatureListWithFilters.ts
  • common/hooks/useProjectEnvironments.ts
  • common/types/featureFilters.ts
  • common/utils/featureFilterParams.ts
  • web/components/pages/features/hooks/useFeatureFilters.ts
  • web/components/pages/features/hooks/useToggleFeatureWithToast.ts
  • web/components/pages/features/hooks/useRemoveFeatureWithToast.ts
  • web/components/feature-summary/FeatureRowSkeleton.tsx
  • web/styles/components/_feature-row-skeleton.scss

Modified:

  • web/components/pages/features/FeaturesPage.tsx (major refactor)
  • web/components/pages/features/components/FeaturesPageHeader.tsx
  • web/components/pages/features/components/FeaturesTableFilters.tsx
  • RTK Query service types and hooks

Removed:

  • web/components/pages/features/components/FeaturesList.tsx
  • web/components/pages/features/hooks/useFeaturePageDisplay.ts
  • Legacy Flux store dependencies

Benefits

  • Zero legacy store dependencies - Full RTK Query migration complete
  • Improved type safety - Comprehensive TypeScript types throughout
  • Better UX - Professional loading states, error handling, and user feedback
  • Cleaner codebase - Removed excessive documentation, simplified logic
  • Better performance - Automatic caching, deduplication, and optimized hooks
  • Maintainability - Self-documenting code with clear types and patterns
  • Consistent patterns - Follows modern React best practices
  • Accessibility - Respects prefers-reduced-motion for animations

Breaking Changes

None - all functionality preserved, this is a pure refactor.

How did you test this code?

Manual Testing:

  1. Features Page Load

    • ✅ Navigate to Features page
    • ✅ Verify features list loads with skeleton loaders
    • ✅ Check pagination works correctly
    • ✅ Verify proper error messages display on failure
  2. Filter Functionality

    • ✅ Search filter
    • ✅ Tag filters (including empty tag mutual exclusivity)
    • ✅ Owner and group filters
    • ✅ Archived filter toggle
    • ✅ Enabled/disabled filter
    • ✅ URL parameter synchronization
    • ✅ Clear filters button
  3. Feature Actions

    • ✅ Toggle feature on/off with visual feedback (opacity)
    • ✅ Delete feature with confirmation
    • ✅ Create new feature
    • ✅ Toast notifications appear correctly
    • ✅ Loading states during mutations
  4. Error Handling

    • ✅ Network errors display user-friendly messages
    • ✅ Failed mutations show actionable error context
    • ✅ Error boundary catches component errors
  5. Type Safety

    • ✅ No TypeScript errors in IDE
    • ✅ Full IntelliSense support
    • ✅ Proper type inference throughout
  6. Accessibility

    • ✅ Skeleton animations respect prefers-reduced-motion
    • ✅ Proper ARIA labels maintained
    • ✅ Keyboard navigation works

Validation:

  • ✅ All 37 commits follow conventional commit format
  • ✅ Code formatted and linted (passes lint-staged)
  • ✅ No console errors or warnings
  • ✅ Feature parity maintained with previous implementation

talissoncosta and others added 30 commits November 24, 2025 12:14
Create reusable hook that wraps useUpdateProjectMutation with automatic toast notifications, supporting customizable messages and error callbacks.
Replace duplicated try/catch/toast patterns across 5 components with useUpdateProjectWithToast hook, eliminating ~70 lines of duplicated code.
Replace complex Omit/Partial approach with explicit Pick for better clarity and type safety. This makes it immediately clear which Project fields are updateable via the API.
Add RTK Query optimistic updates to updateProject mutation using
onQueryStarted lifecycle hook. This immediately updates the cache
when mutations are called and automatically rolls back on errors,
providing instant UI feedback without manual rollback logic.

Benefits:
- Instant UI updates before server responds
- Automatic error rollback via patchResult.undo()
- Reduces component complexity by eliminating manual error handling

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Remove useEffect and manual rollback logic from 3 components that now
benefit from mutation-level optimistic updates:

- ProjectInformation: Remove useEffect syncing and onError rollback
- AdditionalSettings: Remove useEffect syncing
- FeatureNameValidation: Remove useEffect syncing and manual optimistic update

Components now use local state only for form editing, with RTK Query
handling all cache updates and automatic rollbacks on errors.

Benefits:
- Simpler components (~22 lines removed across 3 files)
- No cursor jumps during typing when other settings update
- No manual error handling needed

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Create ChangeRequestsApprovalsSetting component following the same
pattern as other settings (PreventFlagDefaultsSetting,
CaseSensitivitySetting, FeatureNameValidation).

Changes:
- New ChangeRequestsApprovalsSetting.tsx component
- AdditionalSettings simplified from 76 to 25 lines
- All settings now follow consistent pattern (receive project prop)

Benefits:
- Better consistency across all setting components
- Improved encapsulation (component owns its state)
- Easier to test in isolation
- Cleaner AdditionalSettings parent component

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Remove 9 unnecessary useCallback wrappers from project settings
components. These callbacks had dependencies that change frequently
(project properties, local state), causing recreation on every render
and providing no memoization benefit.

Changes across 7 files:
- CaseSensitivitySetting: Remove useCallback from handleToggle
- PreventFlagDefaultsSetting: Remove useCallback from handleToggle
- FeatureNameValidation: Remove useCallback from handleToggle + handleSave
- ProjectInformation: Remove useCallback from handleSubmit
- ChangeRequestsApprovalsSetting: Remove useCallback from both functions
- SDKSettingsTab: Remove useCallback from 2 toggle handlers
- DeleteProject: Remove useCallback from handleDelete

Benefits:
- Simpler, more honest code (~36 lines removed)
- Same performance (callbacks already recreated every render)
- Removed unused useCallback imports

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Call AppActions.refreshOrganisation() after project updates to ensure
the legacy OrganisationStore stays in sync with RTK Query cache.

This fixes the navbar not updating when project name changes, which was causing the E2E test (project-test.ts) to fail.
Fixed critical bug where the case sensitivity toggle had inverted behavior.

The backend field 'only_allow_lower_case_feature_names' has a negative
semantic (true = force lowercase), but the UI shows "Case sensitive features"
with a positive semantic (ON = allow uppercase).

Therefore we must invert the checked state to match the UI's meaning:
- checked={!project.only_allow_lower_case_feature_names}

Now when users enable "Case sensitive features", it correctly sets
only_allow_lower_case_feature_names=false, allowing uppercase characters.

This matches the original implementation and fixes the critical issue
documented in PROJECT_ORG_FIXES.md #1.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
…etting

- Add ?? null to handle undefined initial values from backend
- Fix stale closure bug in auto-save by passing value explicitly to saveChangeRequests
- Fix manual save by using arrow function closure for onSave prop
- Ensure both toggle (auto-save) and manual save work correctly

This fixes issues where:
- Initial value could be undefined instead of null
- Auto-save on toggle used stale state value
- Manual save button passed event object instead of current state

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
- Add optional data-test prop to component type definition
- Pass data-test to underlying Setting component
- Follow kebab-case naming convention (js-change-request-approvals)

This enables E2E testing by providing stable selectors that won't
break with styling changes, following the pattern used by other
settings in the codebase.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Add E2E tests covering four critical scenarios:
1. Auto-save on toggle ON - verifies toggle saves immediately
2. Manual save after value change - verifies save button works
3. Auto-save on toggle OFF - verifies disable persists
4. Manual save with new value - verifies full workflow

Each test includes navigation away and back to ensure values
persist to backend, catching stale closure bugs that would
otherwise pass with in-memory state.

Test uses kebab-case data-test selector following codebase conventions.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
…lability

Changed from early return pattern to wrapped conditional block following
the pattern from initialise-tests.ts. This allows future tests added after
the Change Requests tests to run regardless of the segment_change_requests
feature flag status.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
- Add UpdateOrganisationBody type with optional fields
- Add getOrganisation, updateOrganisation, deleteOrganisation request types
- Support for organisation name, force_2fa, and project creation restrictions

Part of OrganisationSettingsPage TypeScript migration
- Add getOrganisation query with cache tags
- Add updateOrganisation mutation with optimistic updates
- Add deleteOrganisation mutation with cache invalidation
- Implement automatic rollback on error for optimistic updates

Part of OrganisationSettingsPage TypeScript migration
- Add useUpdateOrganisationWithToast hook for consistent update handling
- Add useDeleteOrganisationWithToast hook with success callbacks
- Include toast notifications and error handling
- Support legacy store sync via AppActions.refreshOrganisation()

Part of OrganisationSettingsPage TypeScript migration
Use TypeScript's typeof operator for automatic type inference instead
of manually maintaining the Utils type definition. This eliminates
maintenance overhead when Utils methods are added or modified.

Changes:
- Replace manual type definition with `const Utils: typeof Utils`
- Removes need to manually update type signatures

Addresses kyle-ssg's review feedback.
Separates feature mutations from feature state mutations for better
code organization and separation of concerns.

Changes:
- Move `updateFeatureState` mutation from useProjectFlag to useFeatureState
- Add FeatureList and Environment to useFeatureState tag types
- Export useUpdateFeatureStateMutation hook from useFeatureState
- Add updateFeatureState helper function for legacy store usage
- Update useToggleFeatureWithToast import to use useFeatureState

This aligns with the principle of keeping features (project-level)
separate from feature states (environment-level), making the codebase
more maintainable.

Addresses kyle-ssg's review feedback.
Merges PermissionGate functionality into the existing Permission
component to reduce duplication and provide a single, unified API
for permission-based rendering.

Changes:
- Add optional props to Permission: fallback, permissionName, showTooltip
- Support both ReactNode and render function children patterns
- Add tooltip rendering when permission is denied
- Add fallback content support for denied permissions
- Import Utils and Constants for tooltip rendering
- Remove PermissionGate component (now redundant)
- Update FeaturesPage and FeaturesPageHeader to use enhanced Permission

The Permission component now handles all use cases previously split
between Permission (render functions) and PermissionGate (UI wrapping).
This maintains full backward compatibility with existing code.

Addresses kyle-ssg's review feedback.
Remove auto-generated marker comments, outdated usage examples, and
redundant inline comments that don't add value to the code.

Changes:
- Remove "END OF ENDPOINTS/EXPORTS/FUNCTION_EXPORTS" markers (6 total)
- Remove outdated usage examples from service files (2 blocks)
- Remove redundant inline comments in Permission component (2 comments)
- Remove incomplete comment in useFeatureState

The code is now cleaner and more maintainable without losing any
meaningful documentation or context.
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

This PR is being reviewed by Cursor Bugbot

Details

Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

Add detailed JSDoc documentation to improve developer experience:

- Document PermissionType interface with descriptions for all props
- Add JSDoc to useHasPermission hook explaining parameters and return values
- Add comprehensive JSDoc to Permission component with 5 usage examples:
  * Basic usage with simple children
  * Render function pattern with permission state
  * Tooltip on permission denial
  * Fallback content when permission is denied
  * Tag-based permission checking

BREAKING CHANGE: Change id type from any to number | string for better type safety.
This improves type checking without breaking existing usage since all current
usages pass either number (projectId, organisationId) or string (environmentId).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
talissoncosta and others added 4 commits December 11, 2025 10:42
Fix usePageTracking dependency array to use individual context properties
instead of the entire context object reference, preventing unnecessary
effect re-runs on every render.

**Changes:**
- Update useEffect dependency array from `[saveToStorage, context]` to
  `[saveToStorage, context?.environmentId, context?.organisationId, context?.projectId]`
- Uses optional chaining to safely access nested properties
- Add explanatory comment and eslint-disable for intentional deviation

**Impact:**
- Eliminates excessive re-renders when context object reference changes
  but actual values remain the same
- Improves performance on pages using page tracking (e.g., FeaturesPage)

**Addresses:** Cursor Bugbot feedback - Bug #1

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Add environment metrics cache invalidation to removeProjectFlag mutation
to ensure metrics (e.g., enabled_features count) refresh immediately when
features are deleted.

**Changes:**
- Add `{ id: 'METRICS', type: 'Environment' }` to removeProjectFlag's
  invalidatesTags array in useProjectFlag.ts

**Impact:**
- Environment metrics now update immediately after feature deletion
- No more stale metrics requiring manual page refresh
- Fixes metrics display in environment selectors and dashboards

**Addresses:** Cursor Bugbot feedback - Bug #3

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
…functions

Fix Permission component to show tooltips when using render prop pattern.
Previously, render functions would return early before tooltip logic was reached.

**Changes:**
- Restructure render function logic to check showTooltip before returning
- Render children first, then conditionally wrap with tooltip based on
  permission and showTooltip flag
- Remove debug console.log statements

**Impact:**
- Tooltips now display correctly when Permission uses render props
- Fixes tooltip display in FeaturesPageHeader and other components using
  render prop pattern with showTooltip

**Example:**
```tsx
<Permission showTooltip permissionName="Create Features">
  {({ permission }) => <Button disabled={!permission}>Create</Button>}
</Permission>
```
Now correctly shows tooltip when hovering over disabled button.

**Addresses:** Cursor Bugbot feedback - Bug #2

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
…ompatibility

Add adapter functions in CompareEnvironments and CompareFeatures to bridge
the signature mismatch between FeatureListProvider callbacks (4 params) and
FeatureRow expectations (2 params). This fixes Cursor Bugbot issue #4 where
callbacks were being passed with incorrect signatures.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Destructure the error property from useProjectEnvironments and include it
in the error condition check. Previously, if the project or environments
queries failed, the page would show loading skeletons indefinitely because
only the feature list error was being checked. Now users will see a proper
error message instead of infinite loading when project/environment queries fail.

Fixes Cursor Bugbot issue where getEnvironmentIdFromKey returns undefined
due to failed queries, causing the feature list query to be skipped via
skipToken, leaving users staring at loading skeletons forever.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

front-end Issue related to the React Front End Dashboard refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants