Skip to content

Commit 6ce133f

Browse files
committed
fix: better code
1 parent f9b9200 commit 6ce133f

File tree

1 file changed

+8
-38
lines changed

1 file changed

+8
-38
lines changed

src/components/PaginatedTable/PaginatedTableWithLayout.tsx

Lines changed: 8 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,24 @@ export interface PaginatedTableWithLayoutProps {
1515
fullHeight?: boolean;
1616
}
1717

18-
/**
19-
* Hook to enhance table wrapper props with sort-dependent scroll behavior
20-
*/
21-
const useTableWrapperPropsWithSortDependency = (
22-
tableWrapperProps?: TableWrapperProps,
23-
): TableWrapperProps => {
18+
const TableWrapper = ({
19+
table,
20+
tableWrapperProps,
21+
}: {
22+
table: React.ReactNode;
23+
tableWrapperProps?: TableWrapperProps;
24+
}) => {
2425
const {tableState} = usePaginatedTableState();
2526
const {sortParams} = tableState;
2627

27-
return React.useMemo(() => {
28+
const enhancedTableWrapperProps = React.useMemo(() => {
2829
const existingScrollDependencies = tableWrapperProps?.scrollDependencies || [];
2930

3031
return {
3132
...tableWrapperProps,
3233
scrollDependencies: [...existingScrollDependencies, sortParams],
3334
};
3435
}, [tableWrapperProps, sortParams]);
35-
};
36-
37-
/**
38-
* Internal component that wraps the table with sort-dependent scrolling behavior.
39-
* This component has access to the paginated table context and automatically
40-
* scrolls to top when sort parameters change.
41-
*/
42-
const TableWrapper = ({
43-
table,
44-
tableWrapperProps,
45-
}: {
46-
table: React.ReactNode;
47-
tableWrapperProps?: TableWrapperProps;
48-
}) => {
49-
const enhancedTableWrapperProps = useTableWrapperPropsWithSortDependency(tableWrapperProps);
5036

5137
return (
5238
<TableWithControlsLayout.Table {...enhancedTableWrapperProps}>
@@ -55,9 +41,6 @@ const TableWrapper = ({
5541
);
5642
};
5743

58-
/**
59-
* Renders the controls section if controls are provided
60-
*/
6144
const ControlsSection = ({controls}: {controls?: React.ReactNode}) => {
6245
if (!controls) {
6346
return null;
@@ -66,9 +49,6 @@ const ControlsSection = ({controls}: {controls?: React.ReactNode}) => {
6649
return <TableWithControlsLayout.Controls>{controls}</TableWithControlsLayout.Controls>;
6750
};
6851

69-
/**
70-
* Renders the error section if an error is provided
71-
*/
7252
const ErrorSection = ({error}: {error?: React.ReactNode}) => {
7353
if (!error) {
7454
return null;
@@ -77,16 +57,6 @@ const ErrorSection = ({error}: {error?: React.ReactNode}) => {
7757
return <React.Fragment>{error}</React.Fragment>;
7858
};
7959

80-
/**
81-
* A complete table layout component that provides pagination context and
82-
* integrates with TableWithControlsLayout for consistent styling and behavior.
83-
*
84-
* Features:
85-
* - Provides pagination context to child components
86-
* - Automatic scroll-to-top on sort changes
87-
* - Optional controls and error display
88-
* - Configurable height behavior
89-
*/
9060
export const PaginatedTableWithLayout = ({
9161
controls,
9262
table,

0 commit comments

Comments
 (0)