From 857f9b3d261760959571a2e3e0e742e664ac331f Mon Sep 17 00:00:00 2001 From: Galen Date: Tue, 13 Jan 2026 16:01:37 -0600 Subject: [PATCH] chore: stubbing ad-hoc-filter changes --- .../app/plugins/panel/logstable/LogsTable.tsx | 37 ++++++++++++++++++- public/app/plugins/panel/logstable/module.tsx | 1 + public/app/plugins/panel/table/TablePanel.tsx | 13 ++++++- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/public/app/plugins/panel/logstable/LogsTable.tsx b/public/app/plugins/panel/logstable/LogsTable.tsx index 2d533b844a8..501e2e92a52 100644 --- a/public/app/plugins/panel/logstable/LogsTable.tsx +++ b/public/app/plugins/panel/logstable/LogsTable.tsx @@ -25,7 +25,13 @@ import { parseLogsFrame, } from '../../../features/logs/logsFrame'; import { isSetDisplayedFields } from '../logs/types'; -import { TablePanel } from '../table/TablePanel'; +import { + AdHocFilterItem, + FILTER_FOR_OPERATOR, + FILTER_OUT_OPERATOR, + TableFilterActionCallback, + TablePanel, +} from '../table/TablePanel'; import type { Options as TableOptions } from '../table/panelcfg.gen'; import type { Options as LogsTableOptions } from './panelcfg.gen'; @@ -93,6 +99,7 @@ export const LogsTable = ({ ? options.setDisplayedFields : setDisplayedFields; + // Callbacks const onTableOptionsChange = useCallback( (options: TableOptions) => { console.log('onTableOptionsChange', options); @@ -124,6 +131,33 @@ export const LogsTable = ({ [onFieldConfigChange] ); + const handleOnCellFilterAdded: TableFilterActionCallback = (filter: AdHocFilterItem) => { + const { value, key, operator } = filter; + if (operator === FILTER_FOR_OPERATOR) { + onClickFilterLabel(key, value); + } + + if (operator === FILTER_OUT_OPERATOR) { + onClickFilterOutLabel(key, value); + } + }; + + /** + * @todo + * Used by Logs details. + */ + const onClickFilterLabel = (key: string, value: string | number, frame?: DataFrame) => { + console.log('onClickFilterLabel', key, value, frame); + }; + + /** + * @todo + * Used by Logs details. + */ + const onClickFilterOutLabel = (key: string, value: string | number, frame?: DataFrame) => { + console.log('onClickFilterOutLabel', key, value, frame); + }; + /** * Extract fields transform */ @@ -233,6 +267,7 @@ export const LogsTable = ({ onFieldConfigChange={handleTableOnFieldConfigChange} replaceVariables={replaceVariables} onChangeTimeRange={onChangeTimeRange} + onCellFilterAdded={handleOnCellFilterAdded} /> diff --git a/public/app/plugins/panel/logstable/module.tsx b/public/app/plugins/panel/logstable/module.tsx index c1538a48a32..183853dfcd7 100644 --- a/public/app/plugins/panel/logstable/module.tsx +++ b/public/app/plugins/panel/logstable/module.tsx @@ -17,6 +17,7 @@ import { tableSuggestionsSupplier } from '../table/suggestions'; import { LogsTable } from './LogsTable'; import { Options } from './panelcfg.gen'; +// @todo can we pull stuff from table module instead of manually adding? export const plugin = new PanelPlugin(LogsTable) .setPanelChangeHandler(tablePanelChangedHandler) .useFieldConfig({ diff --git a/public/app/plugins/panel/table/TablePanel.tsx b/public/app/plugins/panel/table/TablePanel.tsx index 2ac469eddb8..77a8a7e6ed5 100644 --- a/public/app/plugins/panel/table/TablePanel.tsx +++ b/public/app/plugins/panel/table/TablePanel.tsx @@ -24,7 +24,16 @@ import { getActions } from '../../../features/actions/utils'; import { hasDeprecatedParentRowIndex, migrateFromParentRowIndexToNestedFrames } from './migrations'; import { Options } from './panelcfg.gen'; -interface Props extends PanelProps {} +/** @todo get yelled at by dataviz */ +export const FILTER_FOR_OPERATOR = '='; +export const FILTER_OUT_OPERATOR = '!='; +export type AdHocFilterOperator = typeof FILTER_FOR_OPERATOR | typeof FILTER_OUT_OPERATOR; +export type AdHocFilterItem = { key: string; value: string; operator: AdHocFilterOperator }; +export type TableFilterActionCallback = (item: AdHocFilterItem) => void; + +interface Props extends PanelProps { + onCellFilterAdded?: TableFilterActionCallback; +} export function TablePanel(props: Props) { const { data, height, width, options, fieldConfig, id, timeRange, replaceVariables, transparent } = props; @@ -77,7 +86,7 @@ export function TablePanel(props: Props) { initialSortBy={options.sortBy} onSortByChange={(sortBy) => onSortByChange(sortBy, props)} onColumnResize={(displayName, resizedWidth) => onColumnResize(displayName, resizedWidth, props)} - onCellFilterAdded={panelContext.onAddAdHocFilter} + onCellFilterAdded={props.onCellFilterAdded ?? panelContext.onAddAdHocFilter} frozenColumns={options.frozenColumns?.left} enablePagination={options.enablePagination} cellHeight={options.cellHeight}