Skip to content

Commit 7f3ea8c

Browse files
authored
fix: table is broken because of batching (#2356)
1 parent ce13b7f commit 7f3ea8c

File tree

5 files changed

+42
-18
lines changed

5 files changed

+42
-18
lines changed

src/components/PaginatedTable/PaginatedTableContext.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const defaultTableState: PaginatedTableState = {
1414
interface PaginatedTableStateContextType {
1515
// State
1616
tableState: PaginatedTableState;
17+
noBatching?: boolean;
1718

1819
// Granular setters
1920
setSortParams: (params: PaginatedTableState['sortParams']) => void;
@@ -35,12 +36,14 @@ export const PaginatedTableStateContext = React.createContext<PaginatedTableStat
3536
interface PaginatedTableStateProviderProps {
3637
children: React.ReactNode;
3738
initialState?: Partial<PaginatedTableState>;
39+
noBatching?: boolean;
3840
}
3941

4042
// Provider component
4143
export const PaginatedTableProvider = ({
4244
children,
4345
initialState = {},
46+
noBatching,
4447
}: PaginatedTableStateProviderProps) => {
4548
// Use individual state variables for each field
4649
const [sortParams, setSortParams] = React.useState<PaginatedTableState['sortParams']>(
@@ -71,12 +74,13 @@ export const PaginatedTableProvider = ({
7174
const contextValue = React.useMemo(
7275
() => ({
7376
tableState,
77+
noBatching,
7478
setSortParams,
7579
setTotalEntities,
7680
setFoundEntities,
7781
setIsInitialLoad,
7882
}),
79-
[tableState, setSortParams, setTotalEntities, setFoundEntities, setIsInitialLoad],
83+
[tableState, noBatching],
8084
);
8185

8286
return (

src/components/PaginatedTable/PaginatedTableWithLayout.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export interface PaginatedTableWithLayoutProps {
1313
error?: React.ReactNode;
1414
initialState?: Partial<PaginatedTableState>;
1515
fullHeight?: boolean;
16+
noBatching?: boolean;
1617
}
1718

1819
export const PaginatedTableWithLayout = ({
@@ -21,9 +22,10 @@ export const PaginatedTableWithLayout = ({
2122
tableProps,
2223
error,
2324
initialState,
25+
noBatching,
2426
fullHeight = true,
2527
}: PaginatedTableWithLayoutProps) => (
26-
<PaginatedTableProvider initialState={initialState}>
28+
<PaginatedTableProvider initialState={initialState} noBatching={noBatching}>
2729
<TableWithControlsLayout fullHeight={fullHeight}>
2830
<TableWithControlsLayout.Controls>{controls}</TableWithControlsLayout.Controls>
2931
{error}

src/components/PaginatedTable/TableChunk.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {getArray} from '../../utils';
66
import {useAutoRefreshInterval} from '../../utils/hooks';
77
import {ResponseError} from '../Errors/ResponseError';
88

9+
import {usePaginatedTableState} from './PaginatedTableContext';
910
import {EmptyTableRow, LoadingTableRow, TableRow} from './TableRow';
1011
import i18n from './i18n';
1112
import type {
@@ -63,6 +64,7 @@ export const TableChunk = typedMemo(function TableChunk<T, F>({
6364
}: TableChunkProps<T, F>) {
6465
const [isTimeoutActive, setIsTimeoutActive] = React.useState(true);
6566
const [autoRefreshInterval] = useAutoRefreshInterval();
67+
const {noBatching} = usePaginatedTableState();
6668

6769
const columnsIds = columns.map((column) => column.name);
6870

@@ -74,6 +76,7 @@ export const TableChunk = typedMemo(function TableChunk<T, F>({
7476
sortParams,
7577
columnsIds,
7678
tableName,
79+
noBatching,
7780
};
7881

7982
tableDataApi.useFetchTableChunkQuery(queryParams, {

src/containers/Tenant/Diagnostics/TopicData/TopicData.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ export function TopicData({scrollContainerRef, path, database}: TopicDataProps)
348348
scrollDependencies: [baseOffset, baseEndOffset, tableFilters],
349349
}}
350350
fullHeight
351+
noBatching
351352
/>
352353
</DrawerWrapper>
353354
)

src/store/reducers/tableData.ts

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,35 +13,49 @@ interface PaginatedTableParams<T, F> {
1313
sortParams?: SortParams;
1414
columnsIds: string[];
1515
tableName: string;
16+
noBatching?: boolean;
1617
}
1718

1819
function endpoints<T, F>(build: EndpointBuilder<BaseQueryFn, string, string>) {
1920
return {
2021
fetchTableChunk: build.query<PaginatedTableData<T>, PaginatedTableParams<T, F>>({
2122
queryFn: async (
22-
{offset, limit, sortParams, filters, columnsIds, fetchData, tableName},
23+
{offset, limit, sortParams, filters, columnsIds, fetchData, tableName, noBatching},
2324
{signal},
2425
) => {
2526
try {
26-
// Use the request batcher for potential merging
27-
const result = await requestBatcher.queueRequest(
28-
{
29-
offset,
27+
if (noBatching) {
28+
const response = await fetchData({
3029
limit,
31-
sortParams,
30+
offset,
3231
filters,
32+
sortParams,
3333
columnsIds,
34-
fetchData,
35-
tableName,
36-
},
37-
signal,
38-
);
39-
40-
if ('error' in result) {
41-
return {error: result.error};
42-
}
4334

44-
return result;
35+
signal,
36+
});
37+
return {data: response};
38+
} else {
39+
// Use the request batcher for potential merging
40+
const result = await requestBatcher.queueRequest(
41+
{
42+
offset,
43+
limit,
44+
sortParams,
45+
filters,
46+
columnsIds,
47+
fetchData,
48+
tableName,
49+
},
50+
signal,
51+
);
52+
53+
if ('error' in result) {
54+
return {error: result.error};
55+
}
56+
57+
return result;
58+
}
4559
} catch (error) {
4660
return {error: error};
4761
}

0 commit comments

Comments
 (0)