Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

1.3 KB
Raw Blame
import {
  createContext,
  useContext,
  useState,
  useMemo,
  type ReactNode,
  type Dispatch,
  type SetStateAction,
} from "react";
import type { FilterState, OrderByState } from "@langfuse/shared";

export interface PeekTableState {
  filters: FilterState;
  sorting: OrderByState | undefined;
  pagination: { pageIndex: number; pageSize: number };
  search: { query: string | null; type: string[] };
}

export interface PeekTableStateContextValue {
  tableState: PeekTableState;
  setTableState: Dispatch<SetStateAction<PeekTableState>>;
  getPanelWidthPx?: () => number;
}

const PeekTableStateContext = createContext<
  PeekTableStateContextValue | undefined
>(undefined);

export function PeekTableStateProvider({
  children,
  getPanelWidthPx,
}: {
  children: ReactNode;
  getPanelWidthPx?: () => number;
}) {
  const [tableState, setTableState] = useState<PeekTableState>({
    filters: [],
    sorting: undefined,
    pagination: { pageIndex: 0, pageSize: 50 },
    search: { query: null, type: ["id"] },
  });

  const value = useMemo(
    () => ({ tableState, setTableState, getPanelWidthPx }),
    [tableState, getPanelWidthPx],
  );

  return (
    <PeekTableStateContext.Provider value={value}>
      {children}
    </PeekTableStateContext.Provider>
  );
}

export function usePeekTableState() {
  return useContext(PeekTableStateContext);
}