diff --git a/packages/grafana-ui/src/components/Table/Table.tsx b/packages/grafana-ui/src/components/Table/Table.tsx index 3beb04bda7c..bf7559f498c 100644 --- a/packages/grafana-ui/src/components/Table/Table.tsx +++ b/packages/grafana-ui/src/components/Table/Table.tsx @@ -44,6 +44,7 @@ export const Table = memo((props: Props) => { data, height, onCellFilterAdded, + onColumnResize, width, columnMinWidth = COLUMN_MIN_WIDTH, noHeader, @@ -128,7 +129,7 @@ export const Table = memo((props: Props) => { // Internal react table state reducer const stateReducer = useTableStateReducer({ - ...props, + onColumnResize, onSortByChange: (state) => { // Collapse all rows. This prevents a known bug that causes the size of the rows to be incorrect due to // using `VariableSizeList` and `useExpanded` together. @@ -138,6 +139,7 @@ export const Table = memo((props: Props) => { props.onSortByChange(state); } }, + data, }); const hasUniqueId = !!data.meta?.uniqueRowIdFields?.length; diff --git a/packages/grafana-ui/src/components/Table/reducer.ts b/packages/grafana-ui/src/components/Table/reducer.ts index 10e52e351e5..97ebf8869dd 100644 --- a/packages/grafana-ui/src/components/Table/reducer.ts +++ b/packages/grafana-ui/src/components/Table/reducer.ts @@ -2,14 +2,14 @@ import { useCallback } from 'react'; import { getFieldDisplayName } from '@grafana/data'; -import { TableSortByFieldState, GrafanaTableColumn, GrafanaTableState, Props } from './types'; +import { TableSortByFieldState, GrafanaTableColumn, GrafanaTableState, TableStateReducerProps, Props } from './types'; export interface ActionType { type: string; id: string | undefined; } -export function useTableStateReducer({ onColumnResize, onSortByChange, data }: Props) { +export function useTableStateReducer({ onColumnResize, onSortByChange, data }: TableStateReducerProps) { return useCallback( (newState: GrafanaTableState, action: ActionType) => { switch (action.type) { diff --git a/packages/grafana-ui/src/components/Table/types.ts b/packages/grafana-ui/src/components/Table/types.ts index 47801e3acdd..dda99074bd3 100644 --- a/packages/grafana-ui/src/components/Table/types.ts +++ b/packages/grafana-ui/src/components/Table/types.ts @@ -75,6 +75,12 @@ export interface GrafanaTableState extends TableState { export interface GrafanaTableRow extends Row, UseExpandedRowProps<{}> {} +export interface TableStateReducerProps { + onColumnResize?: TableColumnResizeActionCallback; + onSortByChange?: TableSortByActionCallback; + data: DataFrame; +} + export interface Props { ariaLabel?: string; data: DataFrame;