From 104292df636fc44399a811094b92793f96ba8190 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Fri, 14 Dec 2018 11:23:05 +0100 Subject: [PATCH 01/10] wip: unifying select components --- public/app/core/components/Picker/Select.tsx | 142 ++++++++++-------- .../SharedPreferences/SharedPreferences.tsx | 26 ++-- .../app/plugins/panel/gauge/ValueOptions.tsx | 30 ++-- 3 files changed, 107 insertions(+), 91 deletions(-) diff --git a/public/app/core/components/Picker/Select.tsx b/public/app/core/components/Picker/Select.tsx index b8704893cdb..40ee1af2148 100644 --- a/public/app/core/components/Picker/Select.tsx +++ b/public/app/core/components/Picker/Select.tsx @@ -1,60 +1,82 @@ -// import React, { PureComponent } from 'react'; -// import Select as ReactSelect from 'react-select'; -// import DescriptionOption from './DescriptionOption'; -// import IndicatorsContainer from './IndicatorsContainer'; -// import ResetStyles from './ResetStyles'; -// -// export interface OptionType { -// label: string; -// value: string; -// } -// -// interface Props { -// defaultValue?: any; -// getOptionLabel: (item: T) => string; -// getOptionValue: (item: T) => string; -// onChange: (item: T) => {} | void; -// options: T[]; -// placeholder?: string; -// width?: number; -// value: T; -// className?: string; -// } -// -// export class Select extends PureComponent> { -// static defaultProps = { -// width: null, -// className: '', -// } -// -// render() { -// const { defaultValue, getOptionLabel, getOptionValue, onSelected, options, placeholder, width, value, className } = this.props; -// let widthClass = ''; -// if (width) { -// widthClass = 'width-'+width; -// } -// -// return ( -// -// ); -// } -// } -// -// export default Select; +// Libraries +import classNames from 'classnames'; +import React, { PureComponent } from 'react'; +import { default as ReactSelect } from 'react-select'; + +// Components +import DescriptionOption from './DescriptionOption'; +import IndicatorsContainer from './IndicatorsContainer'; +import ResetStyles from './ResetStyles'; + +export interface SelectOptionItem { + label?: string; + value?: string; + imgUrl?: string; + description?: string; + [key: string]: any; +} + +interface Props { + defaultValue?: any; + getOptionLabel?: (item: SelectOptionItem) => string; + getOptionValue?: (item: SelectOptionItem) => string; + onChange: (item: SelectOptionItem) => {} | void; + options: SelectOptionItem[]; + placeholder?: string; + width?: number; + value: SelectOptionItem; + className?: string; + components: object; +} + +export class Select extends PureComponent { + static defaultProps = { + width: null, + className: '', + components: {}, + }; + + render() { + const { + defaultValue, + getOptionLabel, + getOptionValue, + onChange, + options, + placeholder, + width, + value, + className, + } = this.props; + + let widthClass = ''; + if (width) { + widthClass = 'width-' + width; + } + + const selectClassNames = classNames('gf-form-input', 'gf-form-input--form-dropdown', widthClass, className); + + return ( + + ); + } +} + +export default Select; diff --git a/public/app/core/components/SharedPreferences/SharedPreferences.tsx b/public/app/core/components/SharedPreferences/SharedPreferences.tsx index 098cbe16ab8..1ab3f048a9b 100644 --- a/public/app/core/components/SharedPreferences/SharedPreferences.tsx +++ b/public/app/core/components/SharedPreferences/SharedPreferences.tsx @@ -1,7 +1,7 @@ import React, { PureComponent } from 'react'; import { Label } from 'app/core/components/Label/Label'; -import SimplePicker from 'app/core/components/Picker/SimplePicker'; +import Select from 'app/core/components/Picker/Select'; import { getBackendSrv, BackendSrv } from 'app/core/services/backend_srv'; import { DashboardSearchHit } from 'app/types'; @@ -17,12 +17,12 @@ export interface State { dashboards: DashboardSearchHit[]; } -const themes = [{ value: '', text: 'Default' }, { value: 'dark', text: 'Dark' }, { value: 'light', text: 'Light' }]; +const themes = [{ value: '', label: 'Default' }, { value: 'dark', label: 'Dark' }, { value: 'light', label: 'Light' }]; const timezones = [ - { value: '', text: 'Default' }, - { value: 'browser', text: 'Local browser time' }, - { value: 'utc', text: 'UTC' }, + { value: '', label: 'Default' }, + { value: 'browser', label: 'Local browser time' }, + { value: 'utc', label: 'UTC' }, ]; export class SharedPreferences extends PureComponent { @@ -91,12 +91,10 @@ export class SharedPreferences extends PureComponent {

Preferences

UI Theme - item.value === theme)} options={themes} - getOptionValue={i => i.value} - getOptionLabel={i => i.text} - onSelected={theme => this.onThemeChanged(theme.value)} + onChange={theme => this.onThemeChanged(theme.value)} width={20} />
@@ -107,11 +105,11 @@ export class SharedPreferences extends PureComponent { > Home Dashboard - dashboard.id === homeDashboardId)} getOptionValue={i => i.id} getOptionLabel={i => i.title} - onSelected={(dashboard: DashboardSearchHit) => this.onHomeDashboardChanged(dashboard.id)} + onChange={(dashboard: DashboardSearchHit) => this.onHomeDashboardChanged(dashboard.id)} options={dashboards} placeholder="Chose default dashboard" width={20} @@ -119,11 +117,9 @@ export class SharedPreferences extends PureComponent {
- item.value === timezone)} - getOptionValue={i => i.value} - getOptionLabel={i => i.text} - onSelected={timezone => this.onTimeZoneChanged(timezone.value)} + onChange={timezone => this.onTimeZoneChanged(timezone.value)} options={timezones} width={20} /> diff --git a/public/app/plugins/panel/gauge/ValueOptions.tsx b/public/app/plugins/panel/gauge/ValueOptions.tsx index e3052f10861..7cb1c90d347 100644 --- a/public/app/plugins/panel/gauge/ValueOptions.tsx +++ b/public/app/plugins/panel/gauge/ValueOptions.tsx @@ -1,21 +1,21 @@ import React, { PureComponent } from 'react'; import { Label } from 'app/core/components/Label/Label'; -import SimplePicker from 'app/core/components/Picker/SimplePicker'; +import Select from 'app/core/components/Picker/Select'; import UnitPicker from 'app/core/components/Picker/Unit/UnitPicker'; import { OptionModuleProps } from './module'; const statOptions = [ - { value: 'min', text: 'Min' }, - { value: 'max', text: 'Max' }, - { value: 'avg', text: 'Average' }, - { value: 'current', text: 'Current' }, - { value: 'total', text: 'Total' }, - { value: 'name', text: 'Name' }, - { value: 'first', text: 'First' }, - { value: 'delta', text: 'Delta' }, - { value: 'diff', text: 'Difference' }, - { value: 'range', text: 'Range' }, - { value: 'last_time', text: 'Time of last point' }, + { value: 'min', label: 'Min' }, + { value: 'max', label: 'Max' }, + { value: 'avg', label: 'Average' }, + { value: 'current', label: 'Current' }, + { value: 'total', label: 'Total' }, + { value: 'name', label: 'Name' }, + { value: 'first', label: 'First' }, + { value: 'delta', label: 'Delta' }, + { value: 'diff', label: 'Difference' }, + { value: 'range', label: 'Range' }, + { value: 'last_time', label: 'Time of last point' }, ]; const labelWidth = 6; @@ -43,12 +43,10 @@ export default class ValueOptions extends PureComponent {
Value
- i.text} - getOptionValue={i => i.value} - onSelected={this.onStatChange} + onChange={this.onStatChange} value={statOptions.find(option => option.value === stat)} />
From 58cc2e34d68cdf9691e840876a93bb722373c53c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Fri, 14 Dec 2018 12:38:36 +0100 Subject: [PATCH 02/10] User picker using common select componnet --- .../components/Picker/NoOptionsMessage.tsx | 12 +-- public/app/core/components/Picker/Select.tsx | 87 +++++++++++++++++-- .../app/core/components/Picker/UserPicker.tsx | 27 +++--- public/app/features/panel/panel_header.ts | 4 +- 4 files changed, 100 insertions(+), 30 deletions(-) diff --git a/public/app/core/components/Picker/NoOptionsMessage.tsx b/public/app/core/components/Picker/NoOptionsMessage.tsx index 1d2ad4a179e..3626684df22 100644 --- a/public/app/core/components/Picker/NoOptionsMessage.tsx +++ b/public/app/core/components/Picker/NoOptionsMessage.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React from 'react'; import { components } from 'react-select'; import { OptionProps } from 'react-select/lib/components/Option'; @@ -6,13 +6,15 @@ export interface Props { children: Element; } -export const PickerOption = (props: OptionProps) => { - const { children, className } = props; +export const NoOptionsMessage = (props: OptionProps) => { + const { children } = props; return ( -
{children}
+
+
{children}
+
); }; -export default PickerOption; +export default NoOptionsMessage; diff --git a/public/app/core/components/Picker/Select.tsx b/public/app/core/components/Picker/Select.tsx index 40ee1af2148..5b7cad5b921 100644 --- a/public/app/core/components/Picker/Select.tsx +++ b/public/app/core/components/Picker/Select.tsx @@ -2,10 +2,12 @@ import classNames from 'classnames'; import React, { PureComponent } from 'react'; import { default as ReactSelect } from 'react-select'; +import { default as ReactAsyncSelect } from 'react-select/lib/Async'; // Components -import DescriptionOption from './DescriptionOption'; +import { Option, SingleValue } from './PickerOption'; import IndicatorsContainer from './IndicatorsContainer'; +import NoOptionsMessage from './NoOptionsMessage'; import ResetStyles from './ResetStyles'; export interface SelectOptionItem { @@ -16,20 +18,31 @@ export interface SelectOptionItem { [key: string]: any; } -interface Props { +interface CommonProps { defaultValue?: any; getOptionLabel?: (item: SelectOptionItem) => string; getOptionValue?: (item: SelectOptionItem) => string; onChange: (item: SelectOptionItem) => {} | void; - options: SelectOptionItem[]; placeholder?: string; width?: number; - value: SelectOptionItem; + value?: SelectOptionItem; className?: string; components: object; } -export class Select extends PureComponent { +interface SelectProps { + options: SelectOptionItem[]; +} + +interface AsyncProps { + defaultOptions: boolean; + loadOptions: (query: string) => Promise; + isLoading: boolean; + loadingMessage?: () => string; + noOptionsMessage?: () => string; +} + +export class Select extends PureComponent { static defaultProps = { width: null, className: '', @@ -61,7 +74,8 @@ export class Select extends PureComponent { classNamePrefix="gf-form-select-box" className={selectClassNames} components={{ - Option: DescriptionOption, + Option, + SingleValue, IndicatorsContainer, }} defaultValue={defaultValue} @@ -79,4 +93,65 @@ export class Select extends PureComponent { } } +export class AsyncSelect extends PureComponent { + static defaultProps = { + width: null, + className: '', + components: {}, + loadingMessage: () => 'Loading...', + }; + + render() { + const { + defaultValue, + getOptionLabel, + getOptionValue, + onChange, + placeholder, + width, + value, + className, + loadOptions, + defaultOptions, + isLoading, + loadingMessage, + noOptionsMessage, + } = this.props; + + let widthClass = ''; + if (width) { + widthClass = 'width-' + width; + } + + const selectClassNames = classNames('gf-form-input', 'gf-form-input--form-dropdown', widthClass, className); + + return ( + + ); + } +} + export default Select; diff --git a/public/app/core/components/Picker/UserPicker.tsx b/public/app/core/components/Picker/UserPicker.tsx index 01dbb1fd3ea..97bdc230173 100644 --- a/public/app/core/components/Picker/UserPicker.tsx +++ b/public/app/core/components/Picker/UserPicker.tsx @@ -1,12 +1,15 @@ +// Libraries import React, { Component } from 'react'; -import AsyncSelect from 'react-select/lib/Async'; -import PickerOption from './PickerOption'; + +// Components +import { AsyncSelect } from 'app/core/components/Picker/Select'; + +// Utils & Services import { debounce } from 'lodash'; import { getBackendSrv } from 'app/core/services/backend_srv'; + +// Types import { User } from 'app/types'; -import ResetStyles from './ResetStyles'; -import IndicatorsContainer from './IndicatorsContainer'; -import NoOptionsMessage from './NoOptionsMessage'; export interface Props { onSelected: (user: User) => void; @@ -40,6 +43,7 @@ export class UserPicker extends Component { .then(result => { return result.map(user => ({ id: user.userId, + value: user.userId, label: user.login === user.email ? user.login : `${user.login} - ${user.email}`, imgUrl: user.avatarUrl, login: user.login, @@ -57,24 +61,13 @@ export class UserPicker extends Component { return (
'Loading...'} noOptionsMessage={() => 'No users found'} - getOptionValue={i => i.id} - getOptionLabel={i => i.label} />
); diff --git a/public/app/features/panel/panel_header.ts b/public/app/features/panel/panel_header.ts index 1d29d04ad98..6a0f81a4c33 100644 --- a/public/app/features/panel/panel_header.ts +++ b/public/app/features/panel/panel_header.ts @@ -111,11 +111,11 @@ function panelHeader($compile) { */ function togglePanelStackPosition() { const menuOpenClass = 'dropdown-menu-open'; - const panelGridClass = '.react-grid-item.panel'; + const panelGridClass = '.react-grid-item'; let panelElem = elem .find('[data-toggle=dropdown]') - .parentsUntil('.panel') + .parentsUntil(panelGridClass) .parent(); const menuElem = elem.find('[data-toggle=dropdown]').parent(); panelElem = panelElem && panelElem.length ? panelElem[0] : undefined; From 24825dc8994a81df9ab89659b41f9d2873a12676 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Fri, 14 Dec 2018 12:59:45 +0100 Subject: [PATCH 03/10] renamed folder to select --- .../PermissionList/AddPermission.tsx | 17 +++--- .../DisabledPermissionListItem.tsx | 12 ++--- .../PermissionList/PermissionListItem.tsx | 12 ++--- .../components/Picker/DescriptionOption.tsx | 26 ---------- .../components/Picker/DescriptionPicker.tsx | 52 ------------------- .../core/components/Picker/SimplePicker.tsx | 52 ------------------- .../IndicatorsContainer.tsx | 0 .../{Picker => Select}/NoOptionsMessage.tsx | 0 .../{Picker => Select}/PickerOption.test.tsx | 0 .../{Picker => Select}/PickerOption.tsx | 0 .../{Picker => Select}/ResetStyles.tsx | 0 .../components/{Picker => Select}/Select.tsx | 20 +++++-- .../{Picker => Select}/TeamPicker.test.tsx | 0 .../{Picker => Select}/TeamPicker.tsx | 0 .../{Picker => Select}/Unit/UnitGroup.tsx | 0 .../{Picker => Select}/Unit/UnitOption.tsx | 0 .../{Picker => Select}/Unit/UnitPicker.tsx | 0 .../{Picker => Select}/UserPicker.test.tsx | 0 .../{Picker => Select}/UserPicker.tsx | 2 +- .../__snapshots__/PickerOption.test.tsx.snap | 0 .../__snapshots__/TeamPicker.test.tsx.snap | 0 .../__snapshots__/UserPicker.test.tsx.snap | 0 .../SharedPreferences/SharedPreferences.tsx | 4 +- .../core/components/TagFilter/TagFilter.tsx | 6 +-- .../dashboard/dashgrid/DataSourcePicker.tsx | 6 +-- public/app/features/explore/Explore.tsx | 8 +-- public/app/features/teams/TeamMembers.tsx | 2 +- public/app/plugins/panel/gauge/MappingRow.tsx | 9 ++-- .../app/plugins/panel/gauge/ValueOptions.tsx | 4 +- 29 files changed, 57 insertions(+), 175 deletions(-) delete mode 100644 public/app/core/components/Picker/DescriptionOption.tsx delete mode 100644 public/app/core/components/Picker/DescriptionPicker.tsx delete mode 100644 public/app/core/components/Picker/SimplePicker.tsx rename public/app/core/components/{Picker => Select}/IndicatorsContainer.tsx (100%) rename public/app/core/components/{Picker => Select}/NoOptionsMessage.tsx (100%) rename public/app/core/components/{Picker => Select}/PickerOption.test.tsx (100%) rename public/app/core/components/{Picker => Select}/PickerOption.tsx (100%) rename public/app/core/components/{Picker => Select}/ResetStyles.tsx (100%) rename public/app/core/components/{Picker => Select}/Select.tsx (90%) rename public/app/core/components/{Picker => Select}/TeamPicker.test.tsx (100%) rename public/app/core/components/{Picker => Select}/TeamPicker.tsx (100%) rename public/app/core/components/{Picker => Select}/Unit/UnitGroup.tsx (100%) rename public/app/core/components/{Picker => Select}/Unit/UnitOption.tsx (100%) rename public/app/core/components/{Picker => Select}/Unit/UnitPicker.tsx (100%) rename public/app/core/components/{Picker => Select}/UserPicker.test.tsx (100%) rename public/app/core/components/{Picker => Select}/UserPicker.tsx (96%) rename public/app/core/components/{Picker => Select}/__snapshots__/PickerOption.test.tsx.snap (100%) rename public/app/core/components/{Picker => Select}/__snapshots__/TeamPicker.test.tsx.snap (100%) rename public/app/core/components/{Picker => Select}/__snapshots__/UserPicker.test.tsx.snap (100%) diff --git a/public/app/core/components/PermissionList/AddPermission.tsx b/public/app/core/components/PermissionList/AddPermission.tsx index d6da7c68544..19828d7eef5 100644 --- a/public/app/core/components/PermissionList/AddPermission.tsx +++ b/public/app/core/components/PermissionList/AddPermission.tsx @@ -1,7 +1,7 @@ import React, { Component } from 'react'; -import { UserPicker } from 'app/core/components/Picker/UserPicker'; -import { TeamPicker, Team } from 'app/core/components/Picker/TeamPicker'; -import DescriptionPicker, { OptionWithDescription } from 'app/core/components/Picker/DescriptionPicker'; +import { UserPicker } from 'app/core/components/Select/UserPicker'; +import { TeamPicker, Team } from 'app/core/components/Select/TeamPicker'; +import { Select, SelectOptionItem } from 'app/core/components/Select/Select'; import { User } from 'app/types'; import { dashboardPermissionLevels, @@ -61,7 +61,7 @@ class AddPermissions extends Component { this.setState({ teamId: team && !Array.isArray(team) ? team.id : 0 }); }; - onPermissionChanged = (permission: OptionWithDescription) => { + onPermissionChanged = (permission: SelectOptionItem) => { this.setState({ permission: permission.value }); }; @@ -121,11 +121,10 @@ class AddPermissions extends Component { ) : null}
-
diff --git a/public/app/core/components/PermissionList/DisabledPermissionListItem.tsx b/public/app/core/components/PermissionList/DisabledPermissionListItem.tsx index ff679f67ae2..ae25aecce15 100644 --- a/public/app/core/components/PermissionList/DisabledPermissionListItem.tsx +++ b/public/app/core/components/PermissionList/DisabledPermissionListItem.tsx @@ -1,5 +1,5 @@ import React, { Component } from 'react'; -import DescriptionPicker from 'app/core/components/Picker/DescriptionPicker'; +import Select from 'app/core/components/Select/Select'; import { dashboardPermissionLevels } from 'app/types/acl'; export interface Props { @@ -23,11 +23,11 @@ export default class DisabledPermissionListItem extends Component { Can
- {}} - disabled={true} - className={'gf-form-select-box__control--menu-right'} + i.value} - getOptionLabel={i => i.label} - value={selectedOption} - /> -
- ); - } -} - -export default DescriptionPicker; diff --git a/public/app/core/components/Picker/SimplePicker.tsx b/public/app/core/components/Picker/SimplePicker.tsx deleted file mode 100644 index 18b8b4bfc02..00000000000 --- a/public/app/core/components/Picker/SimplePicker.tsx +++ /dev/null @@ -1,52 +0,0 @@ -import React, { SFC } from 'react'; -import Select from 'react-select'; -import DescriptionOption from './DescriptionOption'; -import IndicatorsContainer from './IndicatorsContainer'; -import ResetStyles from './ResetStyles'; - -interface Props { - className?: string; - defaultValue?: any; - getOptionLabel: (item: any) => string; - getOptionValue: (item: any) => string; - onSelected: (item: any) => {} | void; - options: any[]; - placeholder?: string; - width?: number; - value: any; -} - -const SimplePicker: SFC = ({ - className, - defaultValue, - getOptionLabel, - getOptionValue, - onSelected, - options, - placeholder, - width, - value, -}) => { - return ( - item.value === theme)} options={themes} onChange={theme => this.onThemeChanged(theme.value)} @@ -118,6 +119,7 @@ export class SharedPreferences extends PureComponent {
void; + onChange: (ds: DataSourceSelectItem) => void; datasources: DataSourceSelectItem[]; current: DataSourceSelectItem; onBlur?: () => void; @@ -32,7 +29,7 @@ export class DataSourcePicker extends PureComponent { onChange = item => { const ds = this.props.datasources.find(ds => ds.name === item.value); - this.props.onChangeDataSource(ds); + this.props.onChange(ds); }; render() { @@ -53,27 +50,18 @@ export class DataSourcePicker extends PureComponent { return (
'Loading datasources...'} - noOptionsMessage={() => 'No datasources found'} - value={selectedDatasource} - components={{ - Option: PickerOption, - IndicatorsContainer, - NoOptionsMessage, - }} + datasources={exploreDatasources} + current={selectedDatasource} />
) : null} diff --git a/public/app/types/explore.ts b/public/app/types/explore.ts index 5152e26af39..80d55eedb60 100644 --- a/public/app/types/explore.ts +++ b/public/app/types/explore.ts @@ -3,6 +3,7 @@ import { Value } from 'slate'; import { DataQuery, RawTimeRange } from './series'; import TableModel from 'app/core/table_model'; import { LogsModel } from 'app/core/logs_model'; +import { DataSourceSelectItem } from 'app/types/datasources'; export interface CompletionItem { /** @@ -74,11 +75,6 @@ export interface CompletionItemGroup { skipSort?: boolean; } -interface ExploreDatasource { - value: string; - label: string; -} - export interface HistoryItem { ts: number; query: DataQuery; @@ -159,7 +155,7 @@ export interface ExploreState { datasourceLoading: boolean | null; datasourceMissing: boolean; datasourceName?: string; - exploreDatasources: ExploreDatasource[]; + exploreDatasources: DataSourceSelectItem[]; graphInterval: number; // in ms graphResult?: any[]; history: HistoryItem[]; diff --git a/public/sass/components/_form_select_box.scss b/public/sass/components/_form_select_box.scss index aecc21d8176..940bb0143b0 100644 --- a/public/sass/components/_form_select_box.scss +++ b/public/sass/components/_form_select_box.scss @@ -116,7 +116,7 @@ $select-input-bg-disabled: $input-bg-disabled; .gf-form-select-box__select-arrow { border-color: $input-color-select-arrow transparent transparent; border-style: solid; - border-width: 5px 5px 2.5px; + border-width: 4px 4px 2.5px; display: inline-block; height: 0; width: 0; @@ -125,7 +125,7 @@ $select-input-bg-disabled: $input-bg-disabled; &.gf-form-select-box__select-arrow--reversed { border-color: transparent transparent $input-color-select-arrow; top: -2px; - border-width: 0 5px 5px; + border-width: 0 4px 4px; } } From cb7ffb4415ca1baa0bed26cd4905f9a10abcde2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Fri, 14 Dec 2018 14:19:39 +0100 Subject: [PATCH 05/10] select refactor fixes --- .../PermissionList/AddPermission.tsx | 1 + .../DisabledPermissionListItem.tsx | 3 ++- .../PermissionList/PermissionListItem.tsx | 3 ++- .../components/Select/DataSourcePicker.tsx | 2 +- public/app/core/components/Select/Select.tsx | 2 +- .../app/core/components/Select/TeamPicker.tsx | 20 +++---------------- 6 files changed, 10 insertions(+), 21 deletions(-) diff --git a/public/app/core/components/PermissionList/AddPermission.tsx b/public/app/core/components/PermissionList/AddPermission.tsx index 19828d7eef5..749bef680bf 100644 --- a/public/app/core/components/PermissionList/AddPermission.tsx +++ b/public/app/core/components/PermissionList/AddPermission.tsx @@ -122,6 +122,7 @@ class AddPermissions extends Component {
{} | void; placeholder?: string; width?: number; - value?: any; + value?: SelectOptionItem; className?: string; components: object; isDisabled?: boolean; diff --git a/public/app/core/components/Select/TeamPicker.tsx b/public/app/core/components/Select/TeamPicker.tsx index 31b78b19830..6449114cfff 100644 --- a/public/app/core/components/Select/TeamPicker.tsx +++ b/public/app/core/components/Select/TeamPicker.tsx @@ -1,11 +1,7 @@ import React, { Component } from 'react'; -import AsyncSelect from 'react-select/lib/Async'; -import PickerOption from './PickerOption'; +import { AsyncSelect } from './Select'; import { debounce } from 'lodash'; import { getBackendSrv } from 'app/core/services/backend_srv'; -import ResetStyles from './ResetStyles'; -import IndicatorsContainer from './IndicatorsContainer'; -import NoOptionsMessage from './NoOptionsMessage'; export interface Team { id: number; @@ -45,6 +41,7 @@ export class TeamPicker extends Component { const teams = result.teams.map(team => { return { id: team.id, + value: team.id, label: team.name, name: team.name, imgUrl: team.avatarUrl, @@ -62,24 +59,13 @@ export class TeamPicker extends Component { return (
'Loading...'} noOptionsMessage={() => 'No teams found'} - getOptionValue={i => i.id} - getOptionLabel={i => i.label} />
); From 9e4547f7875bde8103af638e84555ec8d903fcdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Fri, 14 Dec 2018 14:25:35 +0100 Subject: [PATCH 06/10] fixed cloudwatch issue --- .../cloudwatch/query_parameter_ctrl.ts | 31 +++++++++---------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/public/app/plugins/datasource/cloudwatch/query_parameter_ctrl.ts b/public/app/plugins/datasource/cloudwatch/query_parameter_ctrl.ts index ba5a39688b3..33948ef2345 100644 --- a/public/app/plugins/datasource/cloudwatch/query_parameter_ctrl.ts +++ b/public/app/plugins/datasource/cloudwatch/query_parameter_ctrl.ts @@ -2,21 +2,6 @@ import angular from 'angular'; import coreModule from 'app/core/core_module'; import _ from 'lodash'; -export class CloudWatchQueryParameter { - constructor() { - return { - templateUrl: 'public/app/plugins/datasource/cloudwatch/partials/query.parameter.html', - controller: 'CloudWatchQueryParameterCtrl', - restrict: 'E', - scope: { - target: '=', - datasource: '=', - onChange: '&', - }, - }; - } -} - export class CloudWatchQueryParameterCtrl { /** @ngInject */ constructor($scope, templateSrv, uiSegmentSrv, datasourceSrv, $q) { @@ -240,5 +225,17 @@ export class CloudWatchQueryParameterCtrl { } } -coreModule.directive('cloudwatchQueryParameter', CloudWatchQueryParameter); -coreModule.controller('CloudWatchQueryParameterCtrl', CloudWatchQueryParameterCtrl); +export function cloudWatchQueryParameter() { + return { + templateUrl: 'public/app/plugins/datasource/cloudwatch/partials/query.parameter.html', + controller: CloudWatchQueryParameterCtrl, + restrict: 'E', + scope: { + target: '=', + datasource: '=', + onChange: '&', + }, + }; +} + +coreModule.directive('cloudwatchQueryParameter', cloudWatchQueryParameter); From 84df0e2dde317bea1f381a0a79f725c0011beeec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Fri, 14 Dec 2018 15:25:49 +0100 Subject: [PATCH 07/10] Added custom scrollbar to select component --- .../components/CustomScrollbar/CustomScrollbar.tsx | 4 ++-- public/app/core/components/Select/Select.tsx | 11 +++++++++++ public/sass/components/_form_select_box.scss | 1 + 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/public/app/core/components/CustomScrollbar/CustomScrollbar.tsx b/public/app/core/components/CustomScrollbar/CustomScrollbar.tsx index 9b9a9c4d02a..590c11c0615 100644 --- a/public/app/core/components/CustomScrollbar/CustomScrollbar.tsx +++ b/public/app/core/components/CustomScrollbar/CustomScrollbar.tsx @@ -28,8 +28,8 @@ class CustomScrollbar extends PureComponent {
} renderTrackVertical={props =>
} renderThumbHorizontal={props =>
} diff --git a/public/app/core/components/Select/Select.tsx b/public/app/core/components/Select/Select.tsx index ebd318842aa..09c8e2ceb8e 100644 --- a/public/app/core/components/Select/Select.tsx +++ b/public/app/core/components/Select/Select.tsx @@ -3,12 +3,14 @@ import classNames from 'classnames'; import React, { PureComponent } from 'react'; import { default as ReactSelect } from 'react-select'; import { default as ReactAsyncSelect } from 'react-select/lib/Async'; +import { components } from 'react-select'; // Components import { Option, SingleValue } from './PickerOption'; import IndicatorsContainer from './IndicatorsContainer'; import NoOptionsMessage from './NoOptionsMessage'; import ResetStyles from './ResetStyles'; +import CustomScrollbar from '../CustomScrollbar/CustomScrollbar'; export interface SelectOptionItem { label?: string; @@ -51,6 +53,14 @@ interface AsyncProps { loadingMessage?: () => string; } +export const MenuList = props => { + return ( + + {props.children} + + ); +}; + export class Select extends PureComponent { static defaultProps = { width: null, @@ -106,6 +116,7 @@ export class Select extends PureComponent { Option, SingleValue, IndicatorsContainer, + MenuList, }} defaultValue={defaultValue} value={value} diff --git a/public/sass/components/_form_select_box.scss b/public/sass/components/_form_select_box.scss index 940bb0143b0..4aa5f54a3d0 100644 --- a/public/sass/components/_form_select_box.scss +++ b/public/sass/components/_form_select_box.scss @@ -79,6 +79,7 @@ $select-input-bg-disabled: $input-bg-disabled; .gf-form-select-box__option { border-left: 2px solid transparent; white-space: nowrap; + background-color: $input-bg; &.gf-form-select-box__option--is-focused { color: $dropdownLinkColorHover; 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 08/10] 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 ( +