Skip to content

feat: implement AG Grid for user management with header and filters - #1

Open
saumya-cw wants to merge 3 commits into
mainfrom
feature/users-grid-ag
Open

saumya-cw wants to merge 3 commits into
mainfrom
feature/users-grid-ag

Conversation

@saumya-cw

Copy link
Copy Markdown
Collaborator

What this PR does

Introduces a comprehensive AG Grid component for user management. Adds the following reusable grid-specific features:

  • UsersGrid – displays user data in a table with all fields from UserProps
  • Column definitions – renders all user attributes with appropriate filter types (text, number, set)
  • Filter toggling – provides Show/Hide Filters buttons with visual feedback
  • Custom cell rendering – styles eyeColor and isActive columns with contextual colors and text
  • Pagination – integrates pagination with configurable page sizes
  • Responsive layout – ensures horizontal scrolling for large column sets on mobile
  • Ensures the grid is:
    • purely presentational for data display
    • composed of AG Grid library and custom hooks
    • free of complex business logic, with data fetching handled by hooks

Manual steps for reviewer

  • Install dependencies bash npm install
  • Start the development server npm run dev
  • Verify the following:
    - Application starts successfully
    - No TypeScript errors in the terminal
    - No console errors in the browser
    - AG Grid renders correctly with user data
    - Filter buttons toggle filters on/off with visual feedback
    - Columns are sortable, resizable, and filterable
    - Pagination works with page size selector
    - EyeColor column shows background colors, Active column shows green/red text

Why this change is needed

  • Provide a powerful, interactive table for displaying and managing user data
  • Reduce manual table implementation with AG Grid's built-in features (sorting, filtering, pagination)
  • Improve user experience with advanced data manipulation capabilities
  • Establish a clear data display layer for user management features
  • Prepare the codebase for scalable data visualization and management
  • Enforce separation of concerns (UI rendering vs data fetching)

✅ Definition of Done (DoD)

  • AG Grid implemented with all user fields as columns
  • Filter toggling with conditional enable/disable based on state
  • Custom cell rendering for eyeColor and isActive fields
  • Responsive layout with horizontal scrolling and fixed height
  • Pagination integrated using constants for maintainability
  • Accessibility and safety handled by AG Grid and Tailwind CSS
  • Components are reusable and easy to reason about
  • Code follows established folder and naming conventions
  • Build and development server run without errors

🧪 Testing

  • Application loads successfully
  • No console errors on initial render
  • No TypeScript errors during development or build
  • AG Grid renders user data correctly
  • Filters toggle on/off without errors
  • Sorting, resizing, and pagination work as expected
  • Custom cell styles apply correctly
  • No regressions in existing functionality
  • Horizontal scrolling works on mobile viewports

Add header section with title and Show/Hide Filters buttons
Configure all user fields as columns with conditional filters
Style eyeColor and isActive columns with custom rendering
Set responsive layout with violet background and pagination
@saumya-cw

Copy link
Copy Markdown
Collaborator Author

@cw-pr-agent review

@mergemitra

mergemitra Bot commented Feb 2, 2026

Copy link
Copy Markdown

Change Summary

Adds an AG Grid-based user management interface with filter toggles, styled cells, pagination, and responsive layout.
Introduces constants, hook, and types to fetch and type user data while deriving active status for display.
Replaces the placeholder App UI, adds Tests for the grid, and updates Vitest setup plus styling to support the new component.

File Changes
File Summary
package.json Adds ag-grid-enterprise dependency alongside AG Grid packages for enhanced filtering features
src/App.tsx Replaces placeholder UI with UsersGrid container presenting the AG Grid user table
src/features/users-grid/components/UsersGrid.test.tsx Adds UsersGrid tests mocking AG Grid to assert row data and column definitions
src/features/users-grid/components/UsersGrid.tsx Implements UsersGrid with column definitions, filter toggles, styled cells, pagination, responsive layout
src/features/users-grid/constants/users.constants.ts Introduces user grid constants for API base, pagination defaults, and gender definitions
src/features/users-grid/hooks/useUsersGrid.ts Creates useUsersApi hook fetching users, mapping isActive, and handling aborts
src/features/users-grid/types/users.types.ts Defines UserProps interface covering all grid attributes plus API response shape
src/index.css Adds global height and overflow resets to support full-screen AG Grid layout
vite.config.ts Enables globals and updates Vitest setup path, removing stray comments

Based on 90e6707...54cf1cc

@mergemitra

mergemitra Bot commented Feb 2, 2026

Copy link
Copy Markdown

PR Scorecard

Score

Communication Quality Code Correctness & Design Quality Test Quality & Coverage Code Readability & Maintainability
Scoring Methodology

Communication Scoring Framework

The overall communication score is a weighted average:

Dimension Weight Evaluates
PR Description Quality 60% Title format (conventional commits) + Description clarity (what changed & why)
PR Size & Scope 25% Appropriate sizing, scope cohesion, and justification for size
Commit Messages 15% Conventional commits format, atomic & descriptive changes

Formula: (Description x 0.6) + (PR Size x 0.25) + (Commits x 0.15)

Code Scoring Framework

The scorecard evaluates code using 3 key reviewer questions:

Reviewer Question Category
Is this the right solution, implemented the right way? Code Correctness
Would this catch bugs if the code broke tomorrow? Test Quality
Can someone new understand and safely modify this in 6 months? Maintainability
PR Communication Notes

Description Quality

  • ✅ Description clearly covers what/why, manual verification steps, and DoD/testing checklists
  • ✅ Description matches key changes: UsersGrid, filter toggles, custom cells, pagination, responsive wrapper
  • ❌ Claim of "purely presentational" conflicts with useUsersApi deriving isActive from age; call out this behavior
  • ❌ Description omits notable setup changes: added ag-grid-enterprise and updated Vitest globals/setupFiles path

PR Size & Scope

  • ✅ Size is in the ideal range (427 added/21 deleted across 10 files) and stays focused on the users grid feature
  • ✅ Includes a targeted UsersGrid test file, keeping added lines aligned with the feature scope

Commit Messages

  • ✅ Single commit uses conventional format (feat: ...) and the body summarizes key changes well
  • ❌ Commit lacks scope; prefer 'feat(users-grid): ...' going forward for easier history scanning

Issue Notes

Code Correctness & Design Quality

  • 🟠 Adding ag-grid-enterprise at package.json:16 without license key wiring can show trial watermark/console warnings and create licensing/compliance risk
  • 🔴 vi.mock factory references mockUsers before it’s initialized at src/features/users-grid/components/UsersGrid.test.tsx:7 which can throw at module-eval time and prevent the test suite from running
  • 🟠 Missing base grid CSS import at src/features/users-grid/components/UsersGrid.tsx:11 can render AG Grid unstyled/broken (theme CSS alone is often insufficient)
  • 🟠 Using Enterprise Set Filter at src/features/users-grid/components/UsersGrid.tsx:4 without setting an AG Grid license key can show a watermark/console warnings in the UI
  • 🟠 Network errors are swallowed at src/features/users-grid/hooks/useUsersGrid.ts:16 (no catch), leaving the UI silently empty and making failures hard to diagnose
  • 🟠 Global overflow: hidden at src/index.css:6 disables page scrolling and can break accessibility/UX for screens taller than the viewport
  • 🔴 setupFiles path change at vite.config.ts:12 likely points to a non-existent file (src/test/setup.ts vs src/tests/setup.ts), which can break Vitest setup (e.g., jest-dom matchers) and fail CI

Test Quality & Coverage

  • 🟠 Tests at src/features/users-grid/components/UsersGrid.test.tsx:48 only assert props are passed and don’t cover filter toggling/pagination/custom renderers, so regressions in the new behavior will slip through

Code Readability & Maintainability

  • 🟠 Using any in grid typings at src/features/users-grid/components/UsersGrid.tsx:19, src/features/users-grid/components/UsersGrid.tsx:127 bypasses type checking and can hide runtime renderer/style bugs
  • 🟠 Exported functions missing explicit return types at src/features/users-grid/components/UsersGrid.tsx:15, src/features/users-grid/hooks/useUsersGrid.ts:6 makes public API contracts less clear and weakens TS guarantees
💬 Minor Issues (Nitpicks)

Code Readability & Maintainability

  • 💬 Inline event handlers at src/features/users-grid/components/UsersGrid.tsx:158 reduce readability and make it harder to reuse/trace click behavior
  • 💬 Magic layout values at src/features/users-grid/components/UsersGrid.tsx:184, src/features/users-grid/components/UsersGrid.tsx:185 (min width 1200 / height 600) make future layout changes harder; prefer named constants or responsive sizing
  • 💬 Mixed tabs/spaces in src/features/users-grid/constants/users.constants.ts:10 makes formatting inconsistent and increases diff noise
  • 💬 Gender constant naming at src/features/users-grid/constants/users.constants.ts:9 is easy to confuse with the Gender type; consider GENDER/GENDER_VALUES to reduce ambiguity

Based on 90e6707...1d0aad6

Comment thread vite.config.ts
Comment on lines +10 to +12
globals: true,
environment: 'jsdom',
setupFiles: './src/tests/setup.ts',
setupFiles: './src/test/setup.ts',

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Severity: 🔴 Critical

setupFiles should point to an existing setup file (for jest-dom matchers, test globals, etc.); this path change likely breaks the test environment.

test: {
  ...
  setupFiles: './src/tests/setup.ts',
}

import { UsersGrid } from './UsersGrid';
import type { UserProps } from '../types/users.types';

vi.mock('../hooks/useUsersGrid', () => ({

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Severity: 🔴 Critical

vi.mock is hoisted, so referencing mockUsers (declared later) can throw during module evaluation; move the data above the mock or inline it inside the factory.

const mockUsers = [ ... ];
vi.mock('../hooks/useUsersGrid', () => ({
  useUsersApi: () => ({ users: mockUsers, isLoading: false }),
}));

Comment on lines +13 to +16
async function fetchUsersOnMount() {
setIsLoading(true);

try {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Severity: 🟠 Major

Errors from the request are currently swallowed; add a catch (and ideally request cancellation) so failures are observable and don’t silently render an empty grid.

try {
  ...
} catch (error) {
  if (isMounted) console.error('Failed to load users', error);
}

@mergemitra

mergemitra Bot commented Feb 2, 2026

Copy link
Copy Markdown

PR Overview

PR Type: Feature

Focus Areas for Architect Review

  • Adding ag-grid-enterprise implies licensing/key management and bundle-size impact; confirm Enterprise features are required and where the license key will be configured.
  • Global CSS overflow: hidden on html, body may have app-wide UX/a11y implications beyond this grid; consider scoping layout/scroll constraints to the grid page/container.
  • The grid is becoming a large “configuration blob” (many col defs + styles); consider extracting column definitions / renderers into separate modules for easier reuse and testing.
PR Insights

Potential PR Improvements

  • Correctness: Avoid enterprise modules without license wiring or compliance plan.
  • Testing: Fix mockUsers initialization order to prevent module-eval failures.
  • Robustness: Catch and expose fetch errors instead of silent empty UI.
  • Code Maintainability: Replace any types and add explicit function return types.
  • Best Practices: Avoid global overflow hidden; preserve page scrolling accessibility.

PR Strengths

  • Description Quality: PR description lists steps, behaviors, and definition of done.
  • Code Maintainability: Grid uses constants and shared types for column fields.
  • Best Practices: useMemo creates stable column definitions and default column settings.
  • Testing: Unit tests mock AgGridReact to validate integration boundaries.
  • Correctness: Data fetching is isolated in a dedicated React hook.

- Add try-catch block to handle fetch errors and log them to console
- Implement AbortController for request cancellation on component unmount
- Prevent silent failures by making errors observable
- Ensure loading state is properly reset in finally block
@mergemitra

mergemitra Bot commented Feb 2, 2026

Copy link
Copy Markdown

Tip

Need another review?

Tag me and say rereview for re-analysis after you have fixed all the issues.

@cw-pr-agent rereview

@saumya-cw

Copy link
Copy Markdown
Collaborator Author

@cw-pr-agent rereview

@mergemitra

mergemitra Bot commented Feb 2, 2026

Copy link
Copy Markdown

PR Scorecard

Score

Communication Quality Code Correctness & Design Quality Test Quality & Coverage Code Readability & Maintainability
Scoring Methodology

Communication Scoring Framework

The overall communication score is a weighted average:

Dimension Weight Evaluates
PR Description Quality 60% Title format (conventional commits) + Description clarity (what changed & why)
PR Size & Scope 25% Appropriate sizing, scope cohesion, and justification for size
Commit Messages 15% Conventional commits format, atomic & descriptive changes

Formula: (Description x 0.6) + (PR Size x 0.25) + (Commits x 0.15)

Code Scoring Framework

The scorecard evaluates code using 3 key reviewer questions:

Reviewer Question Category
Is this the right solution, implemented the right way? Code Correctness
Would this catch bugs if the code broke tomorrow? Test Quality
Can someone new understand and safely modify this in 6 months? Maintainability
PR Communication Notes

Description Quality

  • ❌ Description still doesn’t mention the new AbortController/catch behavior added to useUsersApi.
  • ❌ Description still claims “purely presentational” though the hook derives fields like isActive.

PR Size & Scope

  • ✅ This update adds ~16 lines across 3 files, staying focused on hook/test/config fixes.
  • ✅ The added robustness and test fixes don’t expand the PR’s scope beyond users-grid.

Commit Messages

  • ✅ New commit 'fix: add error handling and request cancellation...' follows conventional format and explains the why.
  • ❌ New commit lacks scope; prefer 'fix(users-grid): ...' going forward for easier history scanning.

Issue Notes

Code Correctness & Design Quality

  • 🟠 Fetch failures only console.error at src/features/users-grid/hooks/useUsersGrid.ts:32 so the UI likely shows an empty grid with no user-facing error state

Test Quality & Coverage

  • 🟠 No tests cover the error path (network failure) at src/features/users-grid/hooks/useUsersGrid.ts:32 so regressions can silently reintroduce empty/incorrect UI states

Code Readability & Maintainability

  • 🟠 Exported useUsersApi has no explicit return type at src/features/users-grid/hooks/useUsersGrid.ts:9 which weakens the hook’s public contract and makes accidental API changes easier
💬 Minor Issues (Nitpicks)

Code Readability & Maintainability

  • 💬 AgGridReact mock uses (props: any) at src/features/users-grid/components/UsersGrid.test.tsx:35 which bypasses type checking and can hide incorrect prop usage in tests
  • 💬 catch (error) uses an implicitly-any error at src/features/users-grid/hooks/useUsersGrid.ts:32 which bypasses type checking when inspecting/logging errors

Based on 1d0aad6...54cf1cc


setUsers(mappedUsers);
}
} catch (error) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Severity: 🟠 Major

Expose an error state (and type the hook return) so fetch failures don’t silently render an empty grid.

} catch (error: unknown) {
  if (isMounted) {
    setError(error);
  }
}

}));

vi.mock('ag-grid-react', () => ({
AgGridReact: (props: any) => (

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Severity: 💬 Minor [nitpick]

Avoid any in the AG Grid mock; give the props a minimal shape (or unknown) so tests still catch incorrect prop usage.

AgGridReact: (props: { rowData?: unknown }) => (
  <div data-testid="ag-grid" />
)

export function useUsersApi() {
const [users, setUsers] = useState<UserProps[]>([]);
const [isLoading, setIsLoading] = useState(false);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Severity: 🟠 Major

Add a small unit test for the error path (e.g., axios rejects) to ensure isLoading resets and the new error state is set, preventing regressions to “empty grid with no signal.”

@mergemitra

mergemitra Bot commented Feb 2, 2026

Copy link
Copy Markdown

PR Overview

PR Type: Feature

Focus Areas for Architect Review

  • Confirm the project has a plan for AG Grid Enterprise licensing/key management (and whether Enterprise is required) to avoid watermark/compliance surprises.
  • Double-check Vitest config still references a real setupFiles path after earlier edits (not visible in this rereview diff).
  • Consider whether global layout/CSS changes made earlier (e.g., scroll/overflow constraints) are appropriately scoped to the grid page.
Rereview Impressions

Progress Since Last Review

  • The vi.mock hoisting issue is addressed by moving the mock below mockUsers.
  • useUsersApi now cancels in-flight requests via AbortController and logs failures instead of fully swallowing them.

New Issues Introduced (if any)

  • None significant; remaining gaps are mostly around exposing/test-driving error handling rather than new regressions.
PR Insights

Potential PR Improvements

  • Correctness: Add user-facing error state, not just console logging.
  • Testing: Add tests for network failure and loading states.
  • Code Maintainability: Avoid any in AgGridReact mock to keep type safety.
  • Code Maintainability: Add explicit return type for useUsersApi hook.
  • Best Practices: Type caught errors instead of implicit any.

PR Strengths

  • Robustness: Request cancellation prevents state updates after unmount.
  • Robustness: Catch and finally ensure loading state resets on failures.
  • Testing: Reordered test mocks to avoid hoisted vi.mock crashes.
  • Description Quality: Description includes clear steps, behaviors, and testing checklist.
  • PR Size: Changes are small and targeted to specific issues.

});

it('passes column definitions to AG Grid', () => {
render(<UsersGrid />);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

create the render component function check with @vidya

it('passes row data to AG Grid', () => {
render(<UsersGrid />);

const rowData = screen.getByTestId('row-data');

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

it shouldn't be tested in this way. because getByTestId should be our last option. that any other methods are not possible.

Comment on lines +19 to +26
const columnDefs = useMemo<ColDef<UserProps, any>[]>(
() => [
{
field: 'id',
headerName: 'ID',
width: 90,
filter: showFilters ? 'agNumberColumnFilter' : false,
},

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

move this function to the utils file.

Comment on lines +138 to +146
const defaultColDef = useMemo(
() => ({
sortable: true,
resizable: true,
filter: showFilters,
floatingFilter: showFilters,
}),
[showFilters]
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

this also to the utils

Comment on lines +183 to +196
<div
className="ag-theme-alpine min-w-[1200px] rounded-lg border shadow-sm bg-violet-500"
style={{ height: 600 }}
>
<AgGridReact<UserProps>
rowData={users}
columnDefs={columnDefs}
defaultColDef={defaultColDef}
loading={isLoading}
pagination
paginationPageSize={DEFAULT_PAGINATION_PAGE_SIZE}
paginationPageSizeSelector={PAGINATION_PAGE_SIZE_OPTIONS}
/>
</div>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

if you have only one child move the parent div style also here itself.

Comment on lines +157 to +175
<button
onClick={() => setShowFilters(true)}
className={`px-4 py-2 text-sm rounded transition
${showFilters
? 'bg-green-600 text-white'
: 'bg-gray-200 text-gray-700 hover:bg-gray-300'
}`}
>
Show Filters
</button>

<button
onClick={() => setShowFilters(false)}
className={`px-4 py-2 text-sm rounded transition
${!showFilters
? 'bg-green-600 text-white'
: 'bg-gray-200 text-gray-700 hover:bg-gray-300'
}`}
>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

create the common button component with variants. and use here using the map function.

style={{ height: 600 }}
>
<AgGridReact<UserProps>
rowData={users}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

users doesn't convey that it has the data it. it could be rowData or userData

@@ -0,0 +1,16 @@
// User-related constants for the users grid feature

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

remove this type of comments.

Comment thread src/App.tsx Outdated
Comment on lines 7 to 10
<div className="my-8">
<UsersGrid />
</div>
</>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

use flex or any layout to manage the space between components.

…actoring, layout optimization, and improved tests
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