Skip to content

Commit

Permalink
fix: fallback to full screen loader if onLoadMore is undefined (#158)
Browse files Browse the repository at this point in the history
fix: fallback to full screen loader if onLoadMore is not passed
  • Loading branch information
paanSinghCoder authored Oct 11, 2024
1 parent 36b5de4 commit cd0169e
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions packages/raystack/table/datatable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function DataTableRoot<TData, TValue>({
observerRef.current = observer;

return () => observer.disconnect();
}, [onLoadMore]);
}, [onLoadMore, isLoading]);

useEffect(() => {
const observer = observerRef.current;
Expand Down Expand Up @@ -140,7 +140,11 @@ function DataTableRoot<TData, TValue>({
))}
</Table.Row>
))
)
);

const tableData = onLoadMore ? data : (isLoading
? [...new Array(loaderRow)].map((_, i) => ({ id: i } as TData))
: data);

const { filteredColumns, addFilterColumn, removeFilterColumn, resetColumns } =
useTableColumn();
Expand All @@ -154,15 +158,25 @@ function DataTableRoot<TData, TValue>({
? tableCustomFilter[colId]
: undefined;

const { cell } = col;
const cell = onLoadMore
? col.cell
: (isLoading
? () => (
<Skeleton
containerClassName={styles.flex1}
highlightColor="var(--background-base)"
baseColor="var(--background-base-hover)"
/>
)
: col.cell);

return {
...col,
cell,
filterFn,
};
}),
[isLoading, columns, tableCustomFilter]
[isLoading, columns, tableCustomFilter, onLoadMore]
);

useEffect(() => {
Expand All @@ -176,7 +190,7 @@ function DataTableRoot<TData, TValue>({
};

const table = useReactTable({
data,
data: tableData,
columns: columnWithCustomFilter as unknown as ColumnDef<TData, TValue>[],
globalFilterFn: "auto",
enableRowSelection: true,
Expand Down Expand Up @@ -277,7 +291,7 @@ function DataTableRoot<TData, TValue>({
}`
}
ref={
rowIndex === table.getRowModel().rows.length - 1
onLoadMore && rowIndex === table.getRowModel().rows.length - 1
? lastRowRef
: null
}
Expand Down Expand Up @@ -305,7 +319,7 @@ function DataTableRoot<TData, TValue>({
</Table.Cell>
</Table.Row> : <></>
)}
{isLoading && getLoader(loaderRow, columns)}
{isLoading && onLoadMore && getLoader(loaderRow, columns)}
</Table.Body>
</Table>
{detail}
Expand Down

0 comments on commit cd0169e

Please sign in to comment.