mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
TablePanel: Refactor to functional component and move add ad hoc filter action to PanelContext (#61360)
* FieldOptions: Add filterable as registry added field item * Refactor to functional component, move ad hoc filter to PanelStateWrapper * review tweaks
This commit is contained in:
@@ -10,6 +10,7 @@ import {
|
||||
DashboardCursorSync,
|
||||
EventFilterOptions,
|
||||
FieldConfigSource,
|
||||
getDataSourceRef,
|
||||
getDefaultTimeRange,
|
||||
LinkModel,
|
||||
LoadingState,
|
||||
@@ -32,13 +33,17 @@ import {
|
||||
PanelContextProvider,
|
||||
PanelPadding,
|
||||
SeriesVisibilityChangeMode,
|
||||
AdHocFilterItem,
|
||||
} from '@grafana/ui';
|
||||
import { PANEL_BORDER } from 'app/core/constants';
|
||||
import { profiler } from 'app/core/profiler';
|
||||
import { applyPanelTimeOverrides } from 'app/features/dashboard/utils/panel';
|
||||
import { InspectTab } from 'app/features/inspector/types';
|
||||
import { getPanelLinksSupplier } from 'app/features/panel/panellinks/linkSuppliers';
|
||||
import { getDatasourceSrv } from 'app/features/plugins/datasource_srv';
|
||||
import { applyFilterFromTable } from 'app/features/variables/adhoc/actions';
|
||||
import { changeSeriesColorConfigFactory } from 'app/plugins/panel/timeseries/overrides/colorSeriesConfigFactory';
|
||||
import { dispatch } from 'app/store/store';
|
||||
import { RenderEvent } from 'app/types/events';
|
||||
|
||||
import { isSoloRoute } from '../../../routes/utils';
|
||||
@@ -108,6 +113,7 @@ export class PanelStateWrapper extends PureComponent<Props, State> {
|
||||
canAddAnnotations: props.dashboard.canAddAnnotations.bind(props.dashboard),
|
||||
canEditAnnotations: props.dashboard.canEditAnnotations.bind(props.dashboard),
|
||||
canDeleteAnnotations: props.dashboard.canDeleteAnnotations.bind(props.dashboard),
|
||||
onAddAdHocFilter: this.onAddAdHocFilter,
|
||||
},
|
||||
data: this.getInitialPanelDataState(),
|
||||
};
|
||||
@@ -444,6 +450,20 @@ export class PanelStateWrapper extends PureComponent<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
onAddAdHocFilter = (filter: AdHocFilterItem) => {
|
||||
const { key, value, operator } = filter;
|
||||
|
||||
// When the datasource is null/undefined (for a default datasource), we use getInstanceSettings
|
||||
// to find the real datasource ref for the default datasource.
|
||||
const datasourceInstance = getDatasourceSrv().getInstanceSettings(this.props.panel.datasource);
|
||||
const datasourceRef = datasourceInstance && getDataSourceRef(datasourceInstance);
|
||||
if (!datasourceRef) {
|
||||
return;
|
||||
}
|
||||
|
||||
dispatch(applyFilterFromTable({ datasource: datasourceRef, key, operator, value }));
|
||||
};
|
||||
|
||||
renderPanelContent(innerWidth: number, innerHeight: number) {
|
||||
const { panel, plugin, dashboard } = this.props;
|
||||
const { renderCounter, data } = this.state;
|
||||
|
||||
@@ -18,8 +18,16 @@ import {
|
||||
} from '@grafana/data';
|
||||
import { selectors } from '@grafana/e2e-selectors';
|
||||
import { config, getDataSourceSrv, reportInteraction } from '@grafana/runtime';
|
||||
import { CustomScrollbar, ErrorBoundaryAlert, Themeable2, withTheme2, PanelContainer, Alert } from '@grafana/ui';
|
||||
import { FILTER_FOR_OPERATOR, FILTER_OUT_OPERATOR, FilterItem } from '@grafana/ui/src/components/Table/types';
|
||||
import {
|
||||
CustomScrollbar,
|
||||
ErrorBoundaryAlert,
|
||||
Themeable2,
|
||||
withTheme2,
|
||||
PanelContainer,
|
||||
Alert,
|
||||
AdHocFilterItem,
|
||||
} from '@grafana/ui';
|
||||
import { FILTER_FOR_OPERATOR, FILTER_OUT_OPERATOR } from '@grafana/ui/src/components/Table/types';
|
||||
import appEvents from 'app/core/app_events';
|
||||
import { FadeIn } from 'app/core/components/Animations/FadeIn';
|
||||
import { supportedFeatures } from 'app/core/history/richHistoryStorageProvider';
|
||||
@@ -157,7 +165,7 @@ export class Explore extends React.PureComponent<Props, ExploreState> {
|
||||
this.props.setQueries(this.props.exploreId, [query]);
|
||||
};
|
||||
|
||||
onCellFilterAdded = (filter: FilterItem) => {
|
||||
onCellFilterAdded = (filter: AdHocFilterItem) => {
|
||||
const { value, key, operator } = filter;
|
||||
if (operator === FILTER_FOR_OPERATOR) {
|
||||
this.onClickFilterLabel(key, value);
|
||||
|
||||
@@ -4,8 +4,7 @@ import { connect, ConnectedProps } from 'react-redux';
|
||||
|
||||
import { applyFieldOverrides, DataFrame, SelectableValue, SplitOpen, TimeZone, ValueLinkConfig } from '@grafana/data';
|
||||
import { reportInteraction } from '@grafana/runtime/src';
|
||||
import { Collapse, RadioButtonGroup, Table } from '@grafana/ui';
|
||||
import { FilterItem } from '@grafana/ui/src/components/Table/types';
|
||||
import { Collapse, RadioButtonGroup, Table, AdHocFilterItem } from '@grafana/ui';
|
||||
import { config } from 'app/core/config';
|
||||
import { PANEL_BORDER } from 'app/core/constants';
|
||||
import { StoreState, TABLE_RESULTS_STYLE } from 'app/types';
|
||||
@@ -20,7 +19,7 @@ interface RawPrometheusContainerProps {
|
||||
exploreId: ExploreId;
|
||||
width: number;
|
||||
timeZone: TimeZone;
|
||||
onCellFilterAdded?: (filter: FilterItem) => void;
|
||||
onCellFilterAdded?: (filter: AdHocFilterItem) => void;
|
||||
showRawPrometheus?: boolean;
|
||||
splitOpenFn: SplitOpen;
|
||||
}
|
||||
|
||||
@@ -2,8 +2,7 @@ import React, { PureComponent } from 'react';
|
||||
import { connect, ConnectedProps } from 'react-redux';
|
||||
|
||||
import { ValueLinkConfig, applyFieldOverrides, TimeZone, SplitOpen, DataFrame } from '@grafana/data';
|
||||
import { Collapse, Table } from '@grafana/ui';
|
||||
import { FilterItem } from '@grafana/ui/src/components/Table/types';
|
||||
import { Collapse, Table, AdHocFilterItem } from '@grafana/ui';
|
||||
import { config } from 'app/core/config';
|
||||
import { PANEL_BORDER } from 'app/core/constants';
|
||||
import { StoreState } from 'app/types';
|
||||
@@ -17,7 +16,7 @@ interface TableContainerProps {
|
||||
exploreId: ExploreId;
|
||||
width: number;
|
||||
timeZone: TimeZone;
|
||||
onCellFilterAdded?: (filter: FilterItem) => void;
|
||||
onCellFilterAdded?: (filter: AdHocFilterItem) => void;
|
||||
splitOpenFn: SplitOpen;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user