From 677eb6d1797c3b434bdb021899a23a8ab0decbea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Fri, 14 Dec 2018 16:27:48 +0100 Subject: [PATCH] fixes to unit picker --- .../components/Select/DataSourcePicker.tsx | 1 + .../{Unit/UnitGroup.tsx => OptionGroup.tsx} | 10 +-- public/app/core/components/Select/Select.tsx | 4 +- .../components/Select/Unit/UnitOption.tsx | 22 ----- .../components/Select/Unit/UnitPicker.tsx | 81 ------------------- .../app/core/components/Select/UnitPicker.tsx | 51 ++++++++++++ .../app/plugins/panel/gauge/ValueOptions.tsx | 4 +- public/sass/_grafana.scss | 1 - public/sass/components/_form_select_box.scss | 16 ++++ public/sass/components/_unit-picker.scss | 24 ------ 10 files changed, 77 insertions(+), 137 deletions(-) rename public/app/core/components/Select/{Unit/UnitGroup.tsx => OptionGroup.tsx} (71%) delete mode 100644 public/app/core/components/Select/Unit/UnitOption.tsx delete mode 100644 public/app/core/components/Select/Unit/UnitPicker.tsx create mode 100644 public/app/core/components/Select/UnitPicker.tsx delete mode 100644 public/sass/components/_unit-picker.scss diff --git a/public/app/core/components/Select/DataSourcePicker.tsx b/public/app/core/components/Select/DataSourcePicker.tsx index c0d6a21e5c1..1a9081038c0 100644 --- a/public/app/core/components/Select/DataSourcePicker.tsx +++ b/public/app/core/components/Select/DataSourcePicker.tsx @@ -50,6 +50,7 @@ export class DataSourcePicker extends PureComponent { return (
- ); - } -} diff --git a/public/app/core/components/Select/UnitPicker.tsx b/public/app/core/components/Select/UnitPicker.tsx new file mode 100644 index 00000000000..da9d4526d2b --- /dev/null +++ b/public/app/core/components/Select/UnitPicker.tsx @@ -0,0 +1,51 @@ +import React, { PureComponent } from 'react'; +import Select from './Select'; +import kbn from 'app/core/utils/kbn'; + +interface Props { + onChange: (item: any) => {} | void; + defaultValue?: string; + width?: number; +} + +export default class UnitPicker extends PureComponent { + static defaultProps = { + width: 12, + }; + + render() { + const { defaultValue, onChange, width } = this.props; + + const unitGroups = kbn.getUnitFormats(); + + // Need to transform the data structure to work well with Select + const groupOptions = unitGroups.map(group => { + const options = group.submenu.map(unit => { + return { + label: unit.text, + value: unit.value, + }; + }); + + return { + label: group.text, + options, + }; + }); + + const value = groupOptions.map(group => { + return group.options.find(option => option.value === defaultValue); + }); + + return ( +