TablePanel: support hiding columns, but use them in DataLinks (#41443)

This commit is contained in:
Ryan McKinley 2021-11-09 08:10:21 -08:00 committed by GitHub
parent 0e419e9af1
commit e5d7be3e1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 20 additions and 22 deletions

View File

@ -274,6 +274,7 @@ export interface TableFieldOptions {
hidden?: boolean;
minWidth?: number;
width?: number;
filterable?: boolean;
}
export const defaultTableFieldOptions: TableFieldOptions = {

View File

@ -11,4 +11,5 @@ TableFieldOptions: {
align: FieldTextAlignment | *"auto"
displayMode: TableCellDisplayMode | *"auto"
hidden?: bool // ?? default is missing or false ??
filterable?: bool
} @cuetsy(kind="interface")

View File

@ -49,7 +49,7 @@ export function getColumns(
footerValues?: FooterItem[]
): Column[] {
const columns: any[] = [];
let fieldCountWithoutWidth = data.fields.length;
let fieldCountWithoutWidth = 0;
for (const [fieldIndex, field] of data.fields.entries()) {
const fieldTableOptions = (field.config.custom || {}) as TableFieldOptions;
@ -60,7 +60,8 @@ export function getColumns(
if (fieldTableOptions.width) {
availableWidth -= fieldTableOptions.width;
fieldCountWithoutWidth -= 1;
} else {
fieldCountWithoutWidth++;
}
const selectSortType = (type: FieldType): string => {

View File

@ -28,13 +28,7 @@ Panel: {
showTypeIcons: bool | *false
sortBy?: [...ui.TableSortByFieldState]
}
PanelFieldConfig: {
width?: int
minWidth?: int
align?: string | *"auto"
displayMode?: string | *"auto" // TODO? TableCellDisplayMode
filterable?: bool
}
PanelFieldConfig: ui.TableFieldOptions
},
]
]

View File

@ -4,6 +4,7 @@
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
import { TableCellDisplayMode, TableSortByFieldState } from '@grafana/ui';
import { TableFieldOptions } from '@grafana/schema';
// Only the latest schema version is translated to TypeScript, on the premise
// that either the dashboard loading process, or (eventually) CUE-defined
@ -35,15 +36,7 @@ export const defaultPanelOptions: PanelOptions = {
},
};
export interface PanelFieldConfig {
width?: number;
minWidth?: number;
align?: string;
displayMode?: TableCellDisplayMode;
filterable?: boolean;
}
export const defaultPanelFieldConfig: PanelFieldConfig = {
export const defaultPanelFieldConfig: TableFieldOptions = {
displayMode: TableCellDisplayMode.Auto,
align: 'auto',
};

View File

@ -7,12 +7,13 @@ import {
standardEditorsRegistry,
} from '@grafana/data';
import { TablePanel } from './TablePanel';
import { PanelOptions, PanelFieldConfig, defaultPanelOptions, defaultPanelFieldConfig } from './models.gen';
import { PanelOptions, defaultPanelOptions, defaultPanelFieldConfig } from './models.gen';
import { TableFieldOptions } from '@grafana/schema';
import { tableMigrationHandler, tablePanelChangedHandler } from './migrations';
import { TableCellDisplayMode } from '@grafana/ui';
import { TableSuggestionsSupplier } from './suggestions';
export const plugin = new PanelPlugin<PanelOptions, PanelFieldConfig>(TablePanel)
export const plugin = new PanelPlugin<PanelOptions, TableFieldOptions>(TablePanel)
.setPanelChangeHandler(tablePanelChangedHandler)
.setMigrationHandler(tableMigrationHandler)
.setNoPadding()
@ -79,6 +80,12 @@ export const plugin = new PanelPlugin<PanelOptions, PanelFieldConfig>(TablePanel
name: 'Column filter',
description: 'Enables/disables field filters in table',
defaultValue: defaultPanelFieldConfig.filterable,
})
.addBooleanSwitch({
path: 'hidden',
name: 'Hide in table',
defaultValue: undefined,
hideFromDefaults: true,
});
},
})

View File

@ -1,10 +1,11 @@
import { VisualizationSuggestionsBuilder } from '@grafana/data';
import { TableFieldOptions } from '@grafana/schema';
import { SuggestionName } from 'app/types/suggestions';
import { PanelOptions, PanelFieldConfig } from './models.gen';
import { PanelOptions } from './models.gen';
export class TableSuggestionsSupplier {
getSuggestionsForData(builder: VisualizationSuggestionsBuilder) {
const list = builder.getListAppender<PanelOptions, PanelFieldConfig>({
const list = builder.getListAppender<PanelOptions, TableFieldOptions>({
name: '',
pluginId: 'table',
options: {},