From 073c84179fa0142732e10e21e87a0e5c74ddfd6b Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Sat, 4 May 2019 01:08:48 -0700 Subject: [PATCH] FieldDisplay: shared options model for singlestat panels (#16703) * update single stat data model * update single stat data model * update single stat data model * show limit default * merge master * change stat selector to single until #15954 * add tooltip * begin children * move options under display * align gauge options * add migration tests * Docs: Updated changelog * SingleStatPanels: show title if manual specified * FieldPropEditor: Max should change max * change stats to calcs in config * remove prefix/suffix * add test * abort field cycle when passed the limit * stub a better test * move title to Field * remove title --- CHANGELOG.md | 4 + .../SingleStatShared/FieldDisplayEditor.tsx | 98 ++++++ .../FieldPropertiesEditor.tsx | 112 +++++++ .../SingleStatShared/SingleStatBaseOptions.ts | 62 ++++ .../SingleStatValueEditor.tsx | 91 ------ .../src/components/SingleStatShared/index.ts | 8 + .../src/components/SingleStatShared/shared.ts | 131 --------- packages/grafana-ui/src/components/index.ts | 2 +- packages/grafana-ui/src/types/data.ts | 5 + .../grafana-ui/src/utils/displayValue.test.ts | 27 +- packages/grafana-ui/src/utils/displayValue.ts | 29 +- .../grafana-ui/src/utils/fieldDisplay.test.ts | 132 +++++++++ packages/grafana-ui/src/utils/fieldDisplay.ts | 278 ++++++++++++++++++ packages/grafana-ui/src/utils/index.ts | 1 + packages/grafana-ui/src/utils/string.ts | 15 + .../plugins/panel/bargauge/BarGaugePanel.tsx | 18 +- .../panel/bargauge/BarGaugePanelEditor.tsx | 59 ++-- public/app/plugins/panel/bargauge/types.ts | 17 +- .../panel/gauge/GaugeMigrations.test.ts | 82 ++++++ .../plugins/panel/gauge/GaugeMigrations.ts | 43 +++ .../plugins/panel/gauge/GaugeOptionsBox.tsx | 50 ---- public/app/plugins/panel/gauge/GaugePanel.tsx | 22 +- .../plugins/panel/gauge/GaugePanelEditor.tsx | 75 ++++- .../GaugeMigrations.test.ts.snap | 53 ++++ public/app/plugins/panel/gauge/types.ts | 26 +- .../panel/graph2/getGraphSeriesModel.ts | 4 +- .../plugins/panel/piechart/PieChartPanel.tsx | 10 +- .../panel/piechart/PieChartPanelEditor.tsx | 38 ++- public/app/plugins/panel/piechart/types.ts | 16 +- .../panel/singlestat2/SingleStatEditor.tsx | 44 ++- .../panel/singlestat2/SingleStatPanel.tsx | 142 ++------- public/app/plugins/panel/singlestat2/types.ts | 22 +- 32 files changed, 1154 insertions(+), 562 deletions(-) create mode 100644 packages/grafana-ui/src/components/SingleStatShared/FieldDisplayEditor.tsx create mode 100644 packages/grafana-ui/src/components/SingleStatShared/FieldPropertiesEditor.tsx create mode 100644 packages/grafana-ui/src/components/SingleStatShared/SingleStatBaseOptions.ts delete mode 100644 packages/grafana-ui/src/components/SingleStatShared/SingleStatValueEditor.tsx create mode 100644 packages/grafana-ui/src/components/SingleStatShared/index.ts delete mode 100644 packages/grafana-ui/src/components/SingleStatShared/shared.ts create mode 100644 packages/grafana-ui/src/utils/fieldDisplay.test.ts create mode 100644 packages/grafana-ui/src/utils/fieldDisplay.ts create mode 100644 public/app/plugins/panel/gauge/GaugeMigrations.test.ts create mode 100644 public/app/plugins/panel/gauge/GaugeMigrations.ts delete mode 100644 public/app/plugins/panel/gauge/GaugeOptionsBox.tsx create mode 100644 public/app/plugins/panel/gauge/__snapshots__/GaugeMigrations.test.ts.snap diff --git a/CHANGELOG.md b/CHANGELOG.md index 752c8f8caf9..b920883ffff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # 6.2.0 (unreleased) +### Breaking changes + +* **Gauge Panel**: The suffix / prefix options have been removed from the new Guage Panel (introduced in v6.0). [#16870](https://github.com/grafana/grafana/issues/16870). + # 6.1.6 (2019-04-29) ### Features / Enhancements * **Security**: Bump jQuery to 3.4.0 . [#16761](https://github.com/grafana/grafana/pull/16761), [@dprokop](https://github.com/dprokop) diff --git a/packages/grafana-ui/src/components/SingleStatShared/FieldDisplayEditor.tsx b/packages/grafana-ui/src/components/SingleStatShared/FieldDisplayEditor.tsx new file mode 100644 index 00000000000..fccf211004d --- /dev/null +++ b/packages/grafana-ui/src/components/SingleStatShared/FieldDisplayEditor.tsx @@ -0,0 +1,98 @@ +// Libraries +import React, { PureComponent, ChangeEvent } from 'react'; + +// Components +import { FormField, FormLabel, PanelOptionsGroup, StatsPicker, ReducerID } from '@grafana/ui'; + +// Types +import { FieldDisplayOptions, DEFAULT_FIELD_DISPLAY_VALUES_LIMIT } from '../../utils/fieldDisplay'; +import { Field } from '../../types/data'; +import Select, { SelectOptionItem } from '../Select/Select'; +import { toNumberString, toIntegerOrUndefined } from '../../utils'; + +const showOptions: Array> = [ + { + value: true, + label: 'All Values', + description: 'Each row in the response data', + }, + { + value: false, + label: 'Calculation', + description: 'Calculate a value based on the response', + }, +]; + +export interface Props { + options: FieldDisplayOptions; + onChange: (valueOptions: FieldDisplayOptions) => void; + labelWidth?: number; + children?: JSX.Element[]; +} + +export class FieldDisplayEditor extends PureComponent { + onShowValuesChange = (item: SelectOptionItem) => { + const val = item.value === true; + this.props.onChange({ ...this.props.options, values: val }); + }; + + onCalcsChange = (calcs: string[]) => { + this.props.onChange({ ...this.props.options, calcs }); + }; + + onDefaultsChange = (value: Partial) => { + this.props.onChange({ ...this.props.options, defaults: value }); + }; + + onLimitChange = (event: ChangeEvent) => { + this.props.onChange({ + ...this.props.options, + limit: toIntegerOrUndefined(event.target.value), + }); + }; + + render() { + const { options, children } = this.props; + const { calcs, values, limit } = options; + + const labelWidth = this.props.labelWidth || 5; + + return ( + + <> +
+ Show +
- Display Mode + Mode