refactor: make DataTableProvider framework-agnostic by requiring tableIdentifier (#24513)

* refactor: make DataTableProvider framework-agnostic by requiring tableIdentifier

- Remove Next.js usePathname dependency from DataTableProvider
- Make tableIdentifier a required prop instead of optional
- Update all usages to provide explicit tableIdentifier values
- This makes DataTableProvider usable in non-Next.js contexts

Co-Authored-By: [email protected] <[email protected]>

* refactor: use usePathname at usage sites instead of hardcoding tableIdentifier

- Add validation in DataTableProvider for empty/nullish tableIdentifier
- Use usePathname() in Next.js apps to pass pathname as tableIdentifier
- Use descriptive identifiers for non-Next.js package components
- This keeps DataTableProvider framework-agnostic while allowing Next.js apps to use pathname

Co-Authored-By: [email protected] <[email protected]>

* use pathname instead of hard-coded identifiers

* change type of tableIdentifier

* simplify

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
Eunjae LeeandDevin AI authored and GitHub committed 2025-10-23 15:32:16 +02:00
1 parent 4ac8a51bc2
commit 09ddbe886f
14 files changed
+67 -42

No files matched your search

@@ -1,11 +1,8 @@
"use client";
import type { SortingState, OnChangeFn, VisibilityState, ColumnSizingState } from "@tanstack/react-table";
// eslint-disable-next-line no-restricted-imports
import debounce from "lodash/debounce";
// eslint-disable-next-line no-restricted-imports
import isEqual from "lodash/isEqual";
import { usePathname } from "next/navigation";
import { useQueryState } from "nuqs";
import { useState, createContext, useCallback, useEffect, useRef, useMemo } from "react";
@@ -79,9 +76,9 @@ export type DataTableContextType = {
export const DataTableContext = createContext<DataTableContextType | null>(null);
interface DataTableProviderProps {
useSegments?: UseSegments;
tableIdentifier?: string;
tableIdentifier: string;
children: React.ReactNode;
useSegments?: UseSegments;
ctaContainerClassName?: string;
defaultPageSize?: number;
segments?: FilterSegmentOutput[];
@@ -91,7 +88,7 @@ interface DataTableProviderProps {
}
export function DataTableProvider({
tableIdentifier: _tableIdentifier,
tableIdentifier,
children,
useSegments = useSegmentsNoop,
defaultPageSize = DEFAULT_PAGE_SIZE,
@@ -101,10 +98,8 @@ export function DataTableProvider({
preferredSegmentId,
systemSegments,
}: DataTableProviderProps) {
const pathname = usePathname() as string | null;
const tableIdentifier = _tableIdentifier ?? pathname ?? undefined;
if (!tableIdentifier) {
throw new Error("tableIdentifier is required");
if (!tableIdentifier.trim()) {
throw new Error("tableIdentifier is required and cannot be empty");
}
const filterToOpen = useRef<string | undefined>(undefined);