grafana/public/app/plugins/panel/table/module.tsx

172 lines
5.9 KiB
TypeScript
Raw Normal View History

import {
FieldOverrideContext,
FieldType,
getFieldDisplayName,
PanelPlugin,
ReducerID,
standardEditorsRegistry,
Table Panel: Refactor Cell Options to Allow for Options per Cell Type (#59363) * Update table data structure schema. * Update table panel configuration options for new structure * Fix TS errors from refactor * Separate background and gauge display modes * Remove the now used Bar Gauge display from the mud * Fix types up * Reorganize data structures * Fix type issues. * Start stubbing necessary code. * Continue implementing option refactor * Change category for cell type selection. * Consolidate cell options * Fix various typing issues * Clean up dead code * Stub handling display mode changes * Make subOption editor dynamic * Setup interface for sub-option editor props * Remove unused imports * Remove console.log call * Persist display mode changes, stub sub options change, update comments. * Make sure updates from cells are persisted * Persist sub-option changes * Update BarGaugeCell to take into account new settings. * Add deprecated field back * Remove unecessary options in configuration * Update default cell to accept new settings * Make sure color text display works * Add deprecated property notice * Use constant as opposed to string * Make sure we name globally namespaced things uniquely * Update to use unique name * Use union type with discriminator. * Simplify types and operation * Update type definitons * Update types * Update property names in cells * Remove React.FC usage * Update option editor signature * Update options structure * Change variable name * Fix "Color Text" display * Remove debug statement * Make sure we remain backwards compatible with display mode. * Add migration for configuration. * Export BarGaugeDisplayMode from grafana-ui * Update import * Fix bar gauge and dashboard migrator tests * Fix potential undefined references causing test failures * Fix another potential reference error in DefaultCell * Try to fix breaking change detection. * Cache setting changes * Make sure we return with onChange invocation * Fixed migrating overrides * Fix a number of review comments * Simplify option editors * Fix unused imports * Fill out comments for types * Actually use defaultPanelConfig for editor default * Move TableCellEditorProps alongside TableCellOptionEditor * Update docs for table panel * Also make sure we remove TableCellEditorProps from model file * Stub migration tests * Add tests for default config migration * Add basic overrides test * Flesh out tests a bit more * Add inspect to same category as cell editor Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
2023-01-12 05:42:57 -06:00
identityOverrideProcessor,
} from '@grafana/data';
Table Panel: Refactor Cell Options to Allow for Options per Cell Type (#59363) * Update table data structure schema. * Update table panel configuration options for new structure * Fix TS errors from refactor * Separate background and gauge display modes * Remove the now used Bar Gauge display from the mud * Fix types up * Reorganize data structures * Fix type issues. * Start stubbing necessary code. * Continue implementing option refactor * Change category for cell type selection. * Consolidate cell options * Fix various typing issues * Clean up dead code * Stub handling display mode changes * Make subOption editor dynamic * Setup interface for sub-option editor props * Remove unused imports * Remove console.log call * Persist display mode changes, stub sub options change, update comments. * Make sure updates from cells are persisted * Persist sub-option changes * Update BarGaugeCell to take into account new settings. * Add deprecated field back * Remove unecessary options in configuration * Update default cell to accept new settings * Make sure color text display works * Add deprecated property notice * Use constant as opposed to string * Make sure we name globally namespaced things uniquely * Update to use unique name * Use union type with discriminator. * Simplify types and operation * Update type definitons * Update types * Update property names in cells * Remove React.FC usage * Update option editor signature * Update options structure * Change variable name * Fix "Color Text" display * Remove debug statement * Make sure we remain backwards compatible with display mode. * Add migration for configuration. * Export BarGaugeDisplayMode from grafana-ui * Update import * Fix bar gauge and dashboard migrator tests * Fix potential undefined references causing test failures * Fix another potential reference error in DefaultCell * Try to fix breaking change detection. * Cache setting changes * Make sure we return with onChange invocation * Fixed migrating overrides * Fix a number of review comments * Simplify option editors * Fix unused imports * Fill out comments for types * Actually use defaultPanelConfig for editor default * Move TableCellEditorProps alongside TableCellOptionEditor * Update docs for table panel * Also make sure we remove TableCellEditorProps from model file * Stub migration tests * Add tests for default config migration * Add basic overrides test * Flesh out tests a bit more * Add inspect to same category as cell editor Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
2023-01-12 05:42:57 -06:00
import { TableFieldOptions, TableCellOptions, TableCellDisplayMode } from '@grafana/schema';
import { PaginationEditor } from './PaginationEditor';
Table Panel: Refactor Cell Options to Allow for Options per Cell Type (#59363) * Update table data structure schema. * Update table panel configuration options for new structure * Fix TS errors from refactor * Separate background and gauge display modes * Remove the now used Bar Gauge display from the mud * Fix types up * Reorganize data structures * Fix type issues. * Start stubbing necessary code. * Continue implementing option refactor * Change category for cell type selection. * Consolidate cell options * Fix various typing issues * Clean up dead code * Stub handling display mode changes * Make subOption editor dynamic * Setup interface for sub-option editor props * Remove unused imports * Remove console.log call * Persist display mode changes, stub sub options change, update comments. * Make sure updates from cells are persisted * Persist sub-option changes * Update BarGaugeCell to take into account new settings. * Add deprecated field back * Remove unecessary options in configuration * Update default cell to accept new settings * Make sure color text display works * Add deprecated property notice * Use constant as opposed to string * Make sure we name globally namespaced things uniquely * Update to use unique name * Use union type with discriminator. * Simplify types and operation * Update type definitons * Update types * Update property names in cells * Remove React.FC usage * Update option editor signature * Update options structure * Change variable name * Fix "Color Text" display * Remove debug statement * Make sure we remain backwards compatible with display mode. * Add migration for configuration. * Export BarGaugeDisplayMode from grafana-ui * Update import * Fix bar gauge and dashboard migrator tests * Fix potential undefined references causing test failures * Fix another potential reference error in DefaultCell * Try to fix breaking change detection. * Cache setting changes * Make sure we return with onChange invocation * Fixed migrating overrides * Fix a number of review comments * Simplify option editors * Fix unused imports * Fill out comments for types * Actually use defaultPanelConfig for editor default * Move TableCellEditorProps alongside TableCellOptionEditor * Update docs for table panel * Also make sure we remove TableCellEditorProps from model file * Stub migration tests * Add tests for default config migration * Add basic overrides test * Flesh out tests a bit more * Add inspect to same category as cell editor Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
2023-01-12 05:42:57 -06:00
import { TableCellOptionEditor } from './TableCellOptionEditor';
import { TablePanel } from './TablePanel';
import { tableMigrationHandler, tablePanelChangedHandler } from './migrations';
import { PanelOptions, defaultPanelOptions, defaultPanelFieldConfig } from './models.gen';
import { TableSuggestionsSupplier } from './suggestions';
2019-03-05 18:07:46 -06:00
const footerCategory = 'Table footer';
Table Panel: Refactor Cell Options to Allow for Options per Cell Type (#59363) * Update table data structure schema. * Update table panel configuration options for new structure * Fix TS errors from refactor * Separate background and gauge display modes * Remove the now used Bar Gauge display from the mud * Fix types up * Reorganize data structures * Fix type issues. * Start stubbing necessary code. * Continue implementing option refactor * Change category for cell type selection. * Consolidate cell options * Fix various typing issues * Clean up dead code * Stub handling display mode changes * Make subOption editor dynamic * Setup interface for sub-option editor props * Remove unused imports * Remove console.log call * Persist display mode changes, stub sub options change, update comments. * Make sure updates from cells are persisted * Persist sub-option changes * Update BarGaugeCell to take into account new settings. * Add deprecated field back * Remove unecessary options in configuration * Update default cell to accept new settings * Make sure color text display works * Add deprecated property notice * Use constant as opposed to string * Make sure we name globally namespaced things uniquely * Update to use unique name * Use union type with discriminator. * Simplify types and operation * Update type definitons * Update types * Update property names in cells * Remove React.FC usage * Update option editor signature * Update options structure * Change variable name * Fix "Color Text" display * Remove debug statement * Make sure we remain backwards compatible with display mode. * Add migration for configuration. * Export BarGaugeDisplayMode from grafana-ui * Update import * Fix bar gauge and dashboard migrator tests * Fix potential undefined references causing test failures * Fix another potential reference error in DefaultCell * Try to fix breaking change detection. * Cache setting changes * Make sure we return with onChange invocation * Fixed migrating overrides * Fix a number of review comments * Simplify option editors * Fix unused imports * Fill out comments for types * Actually use defaultPanelConfig for editor default * Move TableCellEditorProps alongside TableCellOptionEditor * Update docs for table panel * Also make sure we remove TableCellEditorProps from model file * Stub migration tests * Add tests for default config migration * Add basic overrides test * Flesh out tests a bit more * Add inspect to same category as cell editor Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
2023-01-12 05:42:57 -06:00
const cellCategory = ['Cell Options'];
export const plugin = new PanelPlugin<PanelOptions, TableFieldOptions>(TablePanel)
.setPanelChangeHandler(tablePanelChangedHandler)
.setMigrationHandler(tableMigrationHandler)
.useFieldConfig({
useCustomConfig: (builder) => {
builder
.addNumberInput({
path: 'minWidth',
name: 'Minimum column width',
description: 'The minimum width for column auto resizing',
settings: {
placeholder: '150',
min: 50,
max: 500,
},
shouldApply: () => true,
defaultValue: defaultPanelFieldConfig.minWidth,
})
.addNumberInput({
path: 'width',
name: 'Column width',
settings: {
placeholder: 'auto',
min: 20,
max: 300,
},
shouldApply: () => true,
defaultValue: defaultPanelFieldConfig.width,
})
.addRadio({
path: 'align',
name: 'Column alignment',
settings: {
options: [
{ label: 'auto', value: 'auto' },
{ label: 'left', value: 'left' },
{ label: 'center', value: 'center' },
{ label: 'right', value: 'right' },
],
},
defaultValue: defaultPanelFieldConfig.align,
})
Table Panel: Refactor Cell Options to Allow for Options per Cell Type (#59363) * Update table data structure schema. * Update table panel configuration options for new structure * Fix TS errors from refactor * Separate background and gauge display modes * Remove the now used Bar Gauge display from the mud * Fix types up * Reorganize data structures * Fix type issues. * Start stubbing necessary code. * Continue implementing option refactor * Change category for cell type selection. * Consolidate cell options * Fix various typing issues * Clean up dead code * Stub handling display mode changes * Make subOption editor dynamic * Setup interface for sub-option editor props * Remove unused imports * Remove console.log call * Persist display mode changes, stub sub options change, update comments. * Make sure updates from cells are persisted * Persist sub-option changes * Update BarGaugeCell to take into account new settings. * Add deprecated field back * Remove unecessary options in configuration * Update default cell to accept new settings * Make sure color text display works * Add deprecated property notice * Use constant as opposed to string * Make sure we name globally namespaced things uniquely * Update to use unique name * Use union type with discriminator. * Simplify types and operation * Update type definitons * Update types * Update property names in cells * Remove React.FC usage * Update option editor signature * Update options structure * Change variable name * Fix "Color Text" display * Remove debug statement * Make sure we remain backwards compatible with display mode. * Add migration for configuration. * Export BarGaugeDisplayMode from grafana-ui * Update import * Fix bar gauge and dashboard migrator tests * Fix potential undefined references causing test failures * Fix another potential reference error in DefaultCell * Try to fix breaking change detection. * Cache setting changes * Make sure we return with onChange invocation * Fixed migrating overrides * Fix a number of review comments * Simplify option editors * Fix unused imports * Fill out comments for types * Actually use defaultPanelConfig for editor default * Move TableCellEditorProps alongside TableCellOptionEditor * Update docs for table panel * Also make sure we remove TableCellEditorProps from model file * Stub migration tests * Add tests for default config migration * Add basic overrides test * Flesh out tests a bit more * Add inspect to same category as cell editor Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
2023-01-12 05:42:57 -06:00
.addCustomEditor<void, TableCellOptions>({
id: 'cellOptions',
path: 'cellOptions',
name: 'Cell Type',
editor: TableCellOptionEditor,
override: TableCellOptionEditor,
defaultValue: defaultPanelFieldConfig.cellOptions,
process: identityOverrideProcessor,
category: cellCategory,
shouldApply: () => true,
})
.addBooleanSwitch({
path: 'inspect',
name: 'Cell value inspect',
description: 'Enable cell value inspection in a modal window',
defaultValue: false,
Table Panel: Refactor Cell Options to Allow for Options per Cell Type (#59363) * Update table data structure schema. * Update table panel configuration options for new structure * Fix TS errors from refactor * Separate background and gauge display modes * Remove the now used Bar Gauge display from the mud * Fix types up * Reorganize data structures * Fix type issues. * Start stubbing necessary code. * Continue implementing option refactor * Change category for cell type selection. * Consolidate cell options * Fix various typing issues * Clean up dead code * Stub handling display mode changes * Make subOption editor dynamic * Setup interface for sub-option editor props * Remove unused imports * Remove console.log call * Persist display mode changes, stub sub options change, update comments. * Make sure updates from cells are persisted * Persist sub-option changes * Update BarGaugeCell to take into account new settings. * Add deprecated field back * Remove unecessary options in configuration * Update default cell to accept new settings * Make sure color text display works * Add deprecated property notice * Use constant as opposed to string * Make sure we name globally namespaced things uniquely * Update to use unique name * Use union type with discriminator. * Simplify types and operation * Update type definitons * Update types * Update property names in cells * Remove React.FC usage * Update option editor signature * Update options structure * Change variable name * Fix "Color Text" display * Remove debug statement * Make sure we remain backwards compatible with display mode. * Add migration for configuration. * Export BarGaugeDisplayMode from grafana-ui * Update import * Fix bar gauge and dashboard migrator tests * Fix potential undefined references causing test failures * Fix another potential reference error in DefaultCell * Try to fix breaking change detection. * Cache setting changes * Make sure we return with onChange invocation * Fixed migrating overrides * Fix a number of review comments * Simplify option editors * Fix unused imports * Fill out comments for types * Actually use defaultPanelConfig for editor default * Move TableCellEditorProps alongside TableCellOptionEditor * Update docs for table panel * Also make sure we remove TableCellEditorProps from model file * Stub migration tests * Add tests for default config migration * Add basic overrides test * Flesh out tests a bit more * Add inspect to same category as cell editor Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
2023-01-12 05:42:57 -06:00
category: cellCategory,
showIf: (cfg) => {
return (
Table Panel: Refactor Cell Options to Allow for Options per Cell Type (#59363) * Update table data structure schema. * Update table panel configuration options for new structure * Fix TS errors from refactor * Separate background and gauge display modes * Remove the now used Bar Gauge display from the mud * Fix types up * Reorganize data structures * Fix type issues. * Start stubbing necessary code. * Continue implementing option refactor * Change category for cell type selection. * Consolidate cell options * Fix various typing issues * Clean up dead code * Stub handling display mode changes * Make subOption editor dynamic * Setup interface for sub-option editor props * Remove unused imports * Remove console.log call * Persist display mode changes, stub sub options change, update comments. * Make sure updates from cells are persisted * Persist sub-option changes * Update BarGaugeCell to take into account new settings. * Add deprecated field back * Remove unecessary options in configuration * Update default cell to accept new settings * Make sure color text display works * Add deprecated property notice * Use constant as opposed to string * Make sure we name globally namespaced things uniquely * Update to use unique name * Use union type with discriminator. * Simplify types and operation * Update type definitons * Update types * Update property names in cells * Remove React.FC usage * Update option editor signature * Update options structure * Change variable name * Fix "Color Text" display * Remove debug statement * Make sure we remain backwards compatible with display mode. * Add migration for configuration. * Export BarGaugeDisplayMode from grafana-ui * Update import * Fix bar gauge and dashboard migrator tests * Fix potential undefined references causing test failures * Fix another potential reference error in DefaultCell * Try to fix breaking change detection. * Cache setting changes * Make sure we return with onChange invocation * Fixed migrating overrides * Fix a number of review comments * Simplify option editors * Fix unused imports * Fill out comments for types * Actually use defaultPanelConfig for editor default * Move TableCellEditorProps alongside TableCellOptionEditor * Update docs for table panel * Also make sure we remove TableCellEditorProps from model file * Stub migration tests * Add tests for default config migration * Add basic overrides test * Flesh out tests a bit more * Add inspect to same category as cell editor Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
2023-01-12 05:42:57 -06:00
cfg.cellOptions.type === TableCellDisplayMode.Auto ||
cfg.cellOptions.type === TableCellDisplayMode.JSONView ||
cfg.cellOptions.type === TableCellDisplayMode.ColorText ||
cfg.cellOptions.type === TableCellDisplayMode.ColorBackground
);
},
})
.addBooleanSwitch({
path: 'filterable',
name: 'Column filter',
description: 'Enables/disables field filters in table',
defaultValue: defaultPanelFieldConfig.filterable,
})
.addBooleanSwitch({
path: 'hidden',
name: 'Hide in table',
defaultValue: undefined,
hideFromDefaults: true,
});
},
})
.setPanelOptions((builder) => {
builder
.addBooleanSwitch({
path: 'showHeader',
name: 'Show table header',
defaultValue: defaultPanelOptions.showHeader,
})
.addBooleanSwitch({
path: 'footer.show',
category: [footerCategory],
name: 'Show table footer',
defaultValue: defaultPanelOptions.footer?.show,
})
.addCustomEditor({
id: 'footer.reducer',
category: [footerCategory],
path: 'footer.reducer',
name: 'Calculation',
description: 'Choose a reducer function / calculation',
editor: standardEditorsRegistry.get('stats-picker').editor as any,
defaultValue: [ReducerID.sum],
showIf: (cfg) => cfg.footer?.show,
})
.addBooleanSwitch({
path: 'footer.countRows',
category: [footerCategory],
name: 'Count rows',
description: 'Display a single count for all data rows',
defaultValue: defaultPanelOptions.footer?.countRows,
showIf: (cfg) => cfg.footer?.reducer?.length === 1 && cfg.footer?.reducer[0] === ReducerID.count,
})
.addMultiSelect({
path: 'footer.fields',
category: [footerCategory],
name: 'Fields',
description: 'Select the fields that should be calculated',
settings: {
allowCustomValue: false,
options: [],
placeholder: 'All Numeric Fields',
getOptions: async (context: FieldOverrideContext) => {
const options = [];
if (context && context.data && context.data.length > 0) {
const frame = context.data[0];
for (const field of frame.fields) {
if (field.type === FieldType.number) {
const name = getFieldDisplayName(field, frame, context.data);
const value = field.name;
options.push({ value, label: name } as any);
}
}
}
return options;
},
},
defaultValue: '',
showIf: (cfg) =>
(cfg.footer?.show && !cfg.footer?.countRows) ||
(cfg.footer?.reducer?.length === 1 && cfg.footer?.reducer[0] !== ReducerID.count),
})
.addCustomEditor({
id: 'footer.enablePagination',
path: 'footer.enablePagination',
name: 'Enable pagination',
editor: PaginationEditor,
});
VisualizationSelection: Real previews of suitable visualisation and options based on current data (#40527) * Initial pass to move panel state to it's own, and make it by key not panel.id * Progress * Not making much progress, having panel.key be mutable is causing a lot of issues * Think this is starting to work * Began fixing tests * Add selector * Bug fixes and changes to cleanup, and fixing all flicking when switching library panels * Removed console.log * fixes after merge * fixing tests * fixing tests * Added new test for changePlugin thunk * Initial struture in place * responding to state changes in another part of the state * bha * going in a different direction * This is getting exciting * minor * More structure * More real * Added builder to reduce boiler plate * Lots of progress * Adding more visualizations * More smarts * tweaks * suggestions * Move to separate view * Refactoring to builder concept * Before hover preview test * Increase line width in preview * More suggestions * Removed old elements of onSuggestVisualizations * Don't call suggestion suppliers if there is no data * Restore card styles to only borders * Changing supplier interface to support data vs option suggestion scenario * Renamed functions * Add dynamic width support * not sure about this * Improve suggestions * Improve suggestions * Single grid/list * Store vis select pane & size * Prep for option suggestions * more suggestions * Name/title option for preview cards * Improve barchart suggestions * Support suggestions when there are no data * Minor change * reverted some changes * Improve suggestions for stacking * Removed size option * starting on unit tests, hit cyclic dependency issue * muuu * First test for getting suggestion seems to work, going to bed * add missing file * A basis for more unit tests * More tests * More unit tests * Fixed unit tests * Update * Some extreme scenarios * Added basic e2e test * Added another unit test for changePanelPlugin action * More cleanup * Minor tweak * add wait to e2e test * Renamed function and cleanup of unused function * Adding search support and adding search test to e2e test
2021-10-25 06:55:06 -05:00
})
.setSuggestionsSupplier(new TableSuggestionsSupplier());