mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* baldm0mma/addRowNumbers/ add showRowNums to panel cue * baldm0mma/addRowNumbers/ add panel option for sowing row numbers * baldm0mma/addRowNumbers/ update typing for showRowNums * baldm0mma/addRowNumbers/ add buildFieldsForOptionalRowNums * baldm0mma/addRowNumbers/ update addOptionalNumbersRowToTable * baldm0mma/addRowNumbers/ adjust display method to return numeric and text values * baldm0mma/ chaneg prop name to match * baldm0mma/addRowNumbers/ update boolean swicth path * baldm0mma/addRowNumbers/ move function * baldm0mma/addRowNumbers/ add getToggleHiddenProps * baldm0mma/addRowNumbers/ remove addNumbersRowToTable second arg * baldm0mma/addRowNumbers/ add updateInitialState * baldm0mma/addRowNumbers/ update getInitialState reducer with initialShowRowNumbers arg * baldm0mma/addRowNumbers/ add useEffect for RowNumberColumn toggling * baldm0mma/addRowNums/ bootleg fix * baldm0mma/addRowNumbers/ export OPTIONAL_ROW_NUMBER_COLUMN_WIDTH * baldm0mma/addRowNumbers/ add annos for readability * baldm0mma/addRowNumbers/ remove superfluous annos * baldm0mma/addRowNumbers/ add a few logs * baldm0mma/addRowNumbers/ update annos * baldm0mma/addRowNumbers/ update which footer row displays reducer type * baldm0mma/addRowNumbers/ abstract away defaultRowNumberColumnFieldData * baldm0mma/addRowNumbers/ update annos in utils.tsx * baldm0mma/addRowNumbers/ update annos for defaultRowNumberColumnFieldData * baldm0mma/addRowNumbers/ mark unused args with underscore * baldm0mma/addRowNumbers/ add annos to addRowNumbersFieldToData * baldm0mma/addRowNumbers/ update utils file type * baldm0mma/addRowNumbers/ remove console.logs * baldm0mma/addRowNumbers/ update file type * baldm0mma/addRowNumbers/ update annos in utils * baldm0mma/addRowNumbers/ remove superfluous footerGroups object * baldm0mma/addRowNumbers/ add annos for tests * baldm0mma/addRowNumbers/ add annos for self * baldm0mma/addRowNumbers/ add tests to table.test.tsx * baldm0mma/addRowNumbers/ update tests in utils.test * baldm0mma/addRowNumbers/ update annos and tests * baldm0mma/addRowNumbers/ remove console.logs * baldm0mma/addRowNumbers/ update utils file ext * baldm0mma/addRowNumbers/ update anno in table.tsx * baldm0mma/addRowNumbers/ update annos in table.tsx * baldm0mma/addRowNumbers/ rem error annos * baldm0mma/addRowNumbers/ revert footerCell * baldm0mma/addRowNumbers/ revert tests * baldm0mma/addRowNumbers/ skip tests * baldm0mma/addRowNumbers/ revert table isCountRowSet * baldm0mma/addRowNumbers/ remove cloneDeep * baldm0mma/addRowNumbers/ update filterFields * baldm0mma/addRowNumbers/ skip tests * Refactor count rows * baldm0mma/addRowNumbers/ rem test skips * baldm0mma/addRowNumbers/ update with annos * baldm0mma/addRowNumbers/ skip timeing out test * baldm0mma/addRowNumbers/ static row numbering and test updates * baldm0mma/addRowNumbers/ remove dupe --------- Co-authored-by: Victor Marin <victor.marin@grafana.com>
177 lines
6.0 KiB
TypeScript
177 lines
6.0 KiB
TypeScript
import {
|
|
FieldOverrideContext,
|
|
FieldType,
|
|
getFieldDisplayName,
|
|
PanelPlugin,
|
|
ReducerID,
|
|
standardEditorsRegistry,
|
|
identityOverrideProcessor,
|
|
} from '@grafana/data';
|
|
import { TableFieldOptions, TableCellOptions, TableCellDisplayMode } from '@grafana/schema';
|
|
|
|
import { PaginationEditor } from './PaginationEditor';
|
|
import { TableCellOptionEditor } from './TableCellOptionEditor';
|
|
import { TablePanel } from './TablePanel';
|
|
import { tableMigrationHandler, tablePanelChangedHandler } from './migrations';
|
|
import { PanelOptions, defaultPanelOptions, defaultPanelFieldConfig } from './models.gen';
|
|
import { TableSuggestionsSupplier } from './suggestions';
|
|
|
|
const footerCategory = 'Table footer';
|
|
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,
|
|
})
|
|
.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,
|
|
category: cellCategory,
|
|
showIf: (cfg) => {
|
|
return (
|
|
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: 'showRowNums',
|
|
name: 'Show row numbers',
|
|
defaultValue: defaultPanelOptions.showRowNums,
|
|
})
|
|
.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,
|
|
});
|
|
})
|
|
.setSuggestionsSupplier(new TableSuggestionsSupplier());
|