Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
104292df
Commit
104292df
authored
Dec 14, 2018
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip: unifying select components
parent
e40d2145
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
107 additions
and
91 deletions
+107
-91
public/app/core/components/Picker/Select.tsx
+82
-60
public/app/core/components/SharedPreferences/SharedPreferences.tsx
+11
-15
public/app/plugins/panel/gauge/ValueOptions.tsx
+14
-16
No files found.
public/app/core/components/Picker/Select.tsx
View file @
104292df
// 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<T> extends PureComponent<Props<T>> {
// 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 (
// <ReactSelect
// classNamePrefix="gf-form-select-box"
// className={`gf-form-input gf-form-input--form-dropdown ${widthClass} ${className}`}
// components={{
// Option: DescriptionOption,
// IndicatorsContainer,
// }}
// defaultValue={defaultValue}
// value={value}
// getOptionLabel={getOptionLabel}
// getOptionValue={getOptionValue}
// menuShouldScrollIntoView={false}
// isSearchable={false}
// onChange={onSelected}
// options={options}
// placeholder={placeholder || 'Choose'}
// styles={ResetStyles}
// />
// );
// }
// }
//
// 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
<
Props
>
{
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
(
<
ReactSelect
classNamePrefix=
"gf-form-select-box"
className=
{
selectClassNames
}
components=
{
{
Option
:
DescriptionOption
,
IndicatorsContainer
,
}
}
defaultValue=
{
defaultValue
}
value=
{
value
}
getOptionLabel=
{
getOptionLabel
}
getOptionValue=
{
getOptionValue
}
menuShouldScrollIntoView=
{
false
}
isSearchable=
{
false
}
onChange=
{
onChange
}
options=
{
options
}
placeholder=
{
placeholder
||
'Choose'
}
styles=
{
ResetStyles
}
/>
);
}
}
export
default
Select
;
public/app/core/components/SharedPreferences/SharedPreferences.tsx
View file @
104292df
import
React
,
{
PureComponent
}
from
'react'
;
import
{
Label
}
from
'app/core/components/Label/Label'
;
import
S
implePicker
from
'app/core/components/Picker/SimplePicker
'
;
import
S
elect
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
<
Props
,
State
>
{
...
...
@@ -91,12 +91,10 @@ export class SharedPreferences extends PureComponent<Props, State> {
<
h3
className=
"page-heading"
>
Preferences
</
h3
>
<
div
className=
"gf-form"
>
<
span
className=
"gf-form-label width-11"
>
UI Theme
</
span
>
<
S
implePicker
<
S
elect
value=
{
themes
.
find
(
item
=>
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
}
/>
</
div
>
...
...
@@ -107,11 +105,11 @@ export class SharedPreferences extends PureComponent<Props, State> {
>
Home Dashboard
</
Label
>
<
S
implePicker
<
S
elect
value=
{
dashboards
.
find
(
dashboard
=>
dashboard
.
id
===
homeDashboardId
)
}
getOptionValue=
{
i
=>
i
.
id
}
getOptionLabel=
{
i
=>
i
.
title
}
on
Selected
=
{
(
dashboard
:
DashboardSearchHit
)
=>
this
.
onHomeDashboardChanged
(
dashboard
.
id
)
}
on
Change
=
{
(
dashboard
:
DashboardSearchHit
)
=>
this
.
onHomeDashboardChanged
(
dashboard
.
id
)
}
options=
{
dashboards
}
placeholder=
"Chose default dashboard"
width=
{
20
}
...
...
@@ -119,11 +117,9 @@ export class SharedPreferences extends PureComponent<Props, State> {
</
div
>
<
div
className=
"gf-form"
>
<
label
className=
"gf-form-label width-11"
>
Timezone
</
label
>
<
S
implePicker
<
S
elect
value=
{
timezones
.
find
(
item
=>
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
}
/>
...
...
public/app/plugins/panel/gauge/ValueOptions.tsx
View file @
104292df
import
React
,
{
PureComponent
}
from
'react'
;
import
{
Label
}
from
'app/core/components/Label/Label'
;
import
S
implePicker
from
'app/core/components/Picker/SimplePicker
'
;
import
S
elect
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<OptionModuleProps> {
<
h5
className=
"page-heading"
>
Value
</
h5
>
<
div
className=
"gf-form-inline"
>
<
Label
width=
{
labelWidth
}
>
Stat
</
Label
>
<
S
implePicker
<
S
elect
width=
{
12
}
options=
{
statOptions
}
getOptionLabel=
{
i
=>
i
.
text
}
getOptionValue=
{
i
=>
i
.
value
}
onSelected=
{
this
.
onStatChange
}
onChange=
{
this
.
onStatChange
}
value=
{
statOptions
.
find
(
option
=>
option
.
value
===
stat
)
}
/>
</
div
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment