All files / src/pages/inventory/handlers useTableHandlers.ts

100% Statements 58/58
100% Branches 4/4
100% Functions 1/1
100% Lines 58/58

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 591x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 4x 4x 1x 1x 4x 4x 4x 4x 4x 1x 1x 4x 4x 4x 4x 4x 1x 1x 4x 4x 4x 4x 4x 4x 4x 4x 4x  
/**
 * @file useTableHandlers.ts
 * @module pages/inventory/handlers/useTableHandlers
 *
 * @summary
 * Custom hook that provides table event handlers for InventoryBoard.
 * Manages: Row click selection, pagination changes, sort changes.
 *
 * @enterprise
 * - Separation of concerns: handler logic isolated from component
 * - Clean orchestrator interface
 */
 
import { useCallback } from 'react';
import type { GridPaginationModel, GridSortModel } from '@mui/x-data-grid';
import type { InventoryState, InventoryStateSetters } from '../hooks/useInventoryState';
 
type InventoryStateReturn = InventoryState & InventoryStateSetters;
 
/**
 * Hook providing table handlers.
 *
 * @param state - Inventory board state object
 * @returns Object with handler functions for table actions
 *
 * @example
 * ```tsx
 * const { handleRowClick, handlePaginationChange, handleSortChange } = useTableHandlers(state);
 * ```
 */
export function useTableHandlers(state: InventoryStateReturn) {
  const handleRowClick = useCallback(
    (id: string) => {
      state.setSelectedId(id);
    },
    [state]
  );
 
  const handlePaginationChange = useCallback(
    (newModel: GridPaginationModel) => {
      state.setPaginationModel(newModel);
    },
    [state]
  );
 
  const handleSortChange = useCallback(
    (newModel: GridSortModel) => {
      state.setSortModel(newModel);
    },
    [state]
  );
 
  return {
    handleRowClick,
    handlePaginationChange,
    handleSortChange,
  };
}