mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
TablePanel: support hiding columns, but use them in DataLinks (#41443)
This commit is contained in:
parent
0e419e9af1
commit
e5d7be3e1c
@ -274,6 +274,7 @@ export interface TableFieldOptions {
|
|||||||
hidden?: boolean;
|
hidden?: boolean;
|
||||||
minWidth?: number;
|
minWidth?: number;
|
||||||
width?: number;
|
width?: number;
|
||||||
|
filterable?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const defaultTableFieldOptions: TableFieldOptions = {
|
export const defaultTableFieldOptions: TableFieldOptions = {
|
||||||
|
@ -11,4 +11,5 @@ TableFieldOptions: {
|
|||||||
align: FieldTextAlignment | *"auto"
|
align: FieldTextAlignment | *"auto"
|
||||||
displayMode: TableCellDisplayMode | *"auto"
|
displayMode: TableCellDisplayMode | *"auto"
|
||||||
hidden?: bool // ?? default is missing or false ??
|
hidden?: bool // ?? default is missing or false ??
|
||||||
|
filterable?: bool
|
||||||
} @cuetsy(kind="interface")
|
} @cuetsy(kind="interface")
|
||||||
|
@ -49,7 +49,7 @@ export function getColumns(
|
|||||||
footerValues?: FooterItem[]
|
footerValues?: FooterItem[]
|
||||||
): Column[] {
|
): Column[] {
|
||||||
const columns: any[] = [];
|
const columns: any[] = [];
|
||||||
let fieldCountWithoutWidth = data.fields.length;
|
let fieldCountWithoutWidth = 0;
|
||||||
|
|
||||||
for (const [fieldIndex, field] of data.fields.entries()) {
|
for (const [fieldIndex, field] of data.fields.entries()) {
|
||||||
const fieldTableOptions = (field.config.custom || {}) as TableFieldOptions;
|
const fieldTableOptions = (field.config.custom || {}) as TableFieldOptions;
|
||||||
@ -60,7 +60,8 @@ export function getColumns(
|
|||||||
|
|
||||||
if (fieldTableOptions.width) {
|
if (fieldTableOptions.width) {
|
||||||
availableWidth -= fieldTableOptions.width;
|
availableWidth -= fieldTableOptions.width;
|
||||||
fieldCountWithoutWidth -= 1;
|
} else {
|
||||||
|
fieldCountWithoutWidth++;
|
||||||
}
|
}
|
||||||
|
|
||||||
const selectSortType = (type: FieldType): string => {
|
const selectSortType = (type: FieldType): string => {
|
||||||
|
@ -28,13 +28,7 @@ Panel: {
|
|||||||
showTypeIcons: bool | *false
|
showTypeIcons: bool | *false
|
||||||
sortBy?: [...ui.TableSortByFieldState]
|
sortBy?: [...ui.TableSortByFieldState]
|
||||||
}
|
}
|
||||||
PanelFieldConfig: {
|
PanelFieldConfig: ui.TableFieldOptions
|
||||||
width?: int
|
|
||||||
minWidth?: int
|
|
||||||
align?: string | *"auto"
|
|
||||||
displayMode?: string | *"auto" // TODO? TableCellDisplayMode
|
|
||||||
filterable?: bool
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
import { TableCellDisplayMode, TableSortByFieldState } from '@grafana/ui';
|
import { TableCellDisplayMode, TableSortByFieldState } from '@grafana/ui';
|
||||||
|
import { TableFieldOptions } from '@grafana/schema';
|
||||||
|
|
||||||
// Only the latest schema version is translated to TypeScript, on the premise
|
// Only the latest schema version is translated to TypeScript, on the premise
|
||||||
// that either the dashboard loading process, or (eventually) CUE-defined
|
// that either the dashboard loading process, or (eventually) CUE-defined
|
||||||
@ -35,15 +36,7 @@ export const defaultPanelOptions: PanelOptions = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface PanelFieldConfig {
|
export const defaultPanelFieldConfig: TableFieldOptions = {
|
||||||
width?: number;
|
|
||||||
minWidth?: number;
|
|
||||||
align?: string;
|
|
||||||
displayMode?: TableCellDisplayMode;
|
|
||||||
filterable?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const defaultPanelFieldConfig: PanelFieldConfig = {
|
|
||||||
displayMode: TableCellDisplayMode.Auto,
|
displayMode: TableCellDisplayMode.Auto,
|
||||||
align: 'auto',
|
align: 'auto',
|
||||||
};
|
};
|
||||||
|
@ -7,12 +7,13 @@ import {
|
|||||||
standardEditorsRegistry,
|
standardEditorsRegistry,
|
||||||
} from '@grafana/data';
|
} from '@grafana/data';
|
||||||
import { TablePanel } from './TablePanel';
|
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 { tableMigrationHandler, tablePanelChangedHandler } from './migrations';
|
||||||
import { TableCellDisplayMode } from '@grafana/ui';
|
import { TableCellDisplayMode } from '@grafana/ui';
|
||||||
import { TableSuggestionsSupplier } from './suggestions';
|
import { TableSuggestionsSupplier } from './suggestions';
|
||||||
|
|
||||||
export const plugin = new PanelPlugin<PanelOptions, PanelFieldConfig>(TablePanel)
|
export const plugin = new PanelPlugin<PanelOptions, TableFieldOptions>(TablePanel)
|
||||||
.setPanelChangeHandler(tablePanelChangedHandler)
|
.setPanelChangeHandler(tablePanelChangedHandler)
|
||||||
.setMigrationHandler(tableMigrationHandler)
|
.setMigrationHandler(tableMigrationHandler)
|
||||||
.setNoPadding()
|
.setNoPadding()
|
||||||
@ -79,6 +80,12 @@ export const plugin = new PanelPlugin<PanelOptions, PanelFieldConfig>(TablePanel
|
|||||||
name: 'Column filter',
|
name: 'Column filter',
|
||||||
description: 'Enables/disables field filters in table',
|
description: 'Enables/disables field filters in table',
|
||||||
defaultValue: defaultPanelFieldConfig.filterable,
|
defaultValue: defaultPanelFieldConfig.filterable,
|
||||||
|
})
|
||||||
|
.addBooleanSwitch({
|
||||||
|
path: 'hidden',
|
||||||
|
name: 'Hide in table',
|
||||||
|
defaultValue: undefined,
|
||||||
|
hideFromDefaults: true,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
import { VisualizationSuggestionsBuilder } from '@grafana/data';
|
import { VisualizationSuggestionsBuilder } from '@grafana/data';
|
||||||
|
import { TableFieldOptions } from '@grafana/schema';
|
||||||
import { SuggestionName } from 'app/types/suggestions';
|
import { SuggestionName } from 'app/types/suggestions';
|
||||||
import { PanelOptions, PanelFieldConfig } from './models.gen';
|
import { PanelOptions } from './models.gen';
|
||||||
|
|
||||||
export class TableSuggestionsSupplier {
|
export class TableSuggestionsSupplier {
|
||||||
getSuggestionsForData(builder: VisualizationSuggestionsBuilder) {
|
getSuggestionsForData(builder: VisualizationSuggestionsBuilder) {
|
||||||
const list = builder.getListAppender<PanelOptions, PanelFieldConfig>({
|
const list = builder.getListAppender<PanelOptions, TableFieldOptions>({
|
||||||
name: '',
|
name: '',
|
||||||
pluginId: 'table',
|
pluginId: 'table',
|
||||||
options: {},
|
options: {},
|
||||||
|
Loading…
Reference in New Issue
Block a user