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
a0da303f
Commit
a0da303f
authored
Dec 11, 2018
by
Johannes Schill
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change KeyboardNavigation from hoc to render prop component
parent
07ce88f6
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
43 deletions
+48
-43
public/app/features/dashboard/dashgrid/DataSourcePicker.tsx
+17
-21
public/app/features/dashboard/dashgrid/KeyboardNavigation.tsx
+15
-9
public/app/features/dashboard/dashgrid/VizTypePicker.tsx
+16
-13
No files found.
public/app/features/dashboard/dashgrid/DataSourcePicker.tsx
View file @
a0da303f
import
React
,
{
PureComponent
}
from
'react'
;
import
classNames
from
'classnames'
;
import
_
from
'lodash'
;
import
withKeyboardNavigation
,
{
KeyboardNavigationProps
}
from
'./with
KeyboardNavigation'
;
import
KeyboardNavigation
,
{
KeyboardNavigationProps
}
from
'./
KeyboardNavigation'
;
import
{
DataSourceSelectItem
}
from
'app/types'
;
export
interface
Props
{
...
...
@@ -13,8 +13,7 @@ interface State {
searchQuery
:
string
;
}
export
const
DataSourcePicker
=
withKeyboardNavigation
(
class
DataSourcePicker
extends
PureComponent
<
Props
&
KeyboardNavigationProps
,
State
>
{
export
class
DataSourcePicker
extends
PureComponent
<
Props
,
State
>
{
searchInput
:
HTMLElement
;
constructor
(
props
)
{
...
...
@@ -41,8 +40,9 @@ export const DataSourcePicker = withKeyboardNavigation(
return
filtered
.
length
-
1
;
}
renderDataSource
=
(
ds
:
DataSourceSelectItem
,
index
:
number
)
=>
{
const
{
onChangeDataSource
,
selected
,
onMouseEnter
}
=
this
.
props
;
renderDataSource
=
(
ds
:
DataSourceSelectItem
,
index
:
number
,
keyNavProps
:
KeyboardNavigationProps
)
=>
{
const
{
onChangeDataSource
}
=
this
.
props
;
const
{
selected
,
onMouseEnter
}
=
keyNavProps
;
const
onClick
=
()
=>
onChangeDataSource
(
ds
);
const
isSelected
=
selected
===
index
;
const
cssClass
=
classNames
({
...
...
@@ -50,13 +50,7 @@ export const DataSourcePicker = withKeyboardNavigation(
'ds-picker-list__item--selected'
:
isSelected
,
});
return
(
<
div
key=
{
index
}
className=
{
cssClass
}
title=
{
ds
.
name
}
onClick=
{
onClick
}
onMouseEnter=
{
()
=>
onMouseEnter
(
index
)
}
>
<
div
key=
{
index
}
className=
{
cssClass
}
title=
{
ds
.
name
}
onClick=
{
onClick
}
onMouseEnter=
{
()
=>
onMouseEnter
(
index
)
}
>
<
img
className=
"ds-picker-list__img"
src=
{
ds
.
meta
.
info
.
logos
.
small
}
/>
<
div
className=
"ds-picker-list__name"
>
{
ds
.
name
}
</
div
>
</
div
>
...
...
@@ -77,11 +71,9 @@ export const DataSourcePicker = withKeyboardNavigation(
}));
};
renderFilters
(
)
{
renderFilters
({
onKeyDown
,
selected
}:
KeyboardNavigationProps
)
{
const
{
searchQuery
}
=
this
.
state
;
const
{
onKeyDown
}
=
this
.
props
;
return
(
<>
<
label
className=
"gf-form--has-input-icon"
>
<
input
type=
"text"
...
...
@@ -92,7 +84,7 @@ export const DataSourcePicker = withKeyboardNavigation(
value=
{
searchQuery
}
onKeyDown=
{
evt
=>
{
onKeyDown
(
evt
,
this
.
maxSelectedIndex
,
()
=>
{
const
{
onChangeDataSource
,
selected
}
=
this
.
props
;
const
{
onChangeDataSource
}
=
this
.
props
;
const
ds
=
this
.
getDataSources
()[
selected
];
onChangeDataSource
(
ds
);
});
...
...
@@ -100,22 +92,26 @@ export const DataSourcePicker = withKeyboardNavigation(
/>
<
i
className=
"gf-form-input-icon fa fa-search"
/>
</
label
>
</>
);
}
render
()
{
return
(
<
KeyboardNavigation
render=
{
(
keyNavProps
:
KeyboardNavigationProps
)
=>
(
<>
<
div
className=
"cta-form__bar"
>
{
this
.
renderFilters
(
)
}
{
this
.
renderFilters
(
keyNavProps
)
}
<
div
className=
"gf-form--grow"
/>
</
div
>
<
div
className=
"ds-picker-list"
>
{
this
.
getDataSources
().
map
(
this
.
renderDataSource
)
}
</
div
>
<
div
className=
"ds-picker-list"
>
{
this
.
getDataSources
().
map
((
ds
,
index
)
=>
this
.
renderDataSource
(
ds
,
index
,
keyNavProps
))
}
</
div
>
</>
)
}
/>
);
}
}
);
}
export
default
DataSourcePicker
;
public/app/features/dashboard/dashgrid/
with
KeyboardNavigation.tsx
→
public/app/features/dashboard/dashgrid/KeyboardNavigation.tsx
View file @
a0da303f
import
React
,
{
KeyboardEvent
,
Component
Type
,
Component
}
from
'react'
;
import
React
,
{
KeyboardEvent
,
Component
}
from
'react'
;
interface
State
{
selected
:
number
;
...
...
@@ -10,8 +10,11 @@ export interface KeyboardNavigationProps {
selected
:
number
;
}
const
withKeyboardNavigation
=
<
P
extends
object
>
(WrappedComponent: ComponentType
<
P
&
KeyboardNavigationProps
>
) =
>
{
return
class
WithKeyboardNavigation
extends
Component
<
P
,
State
>
{
interface
Props
{
render
:
(
injectProps
:
any
)
=>
void
;
}
class
KeyboardNavigation
extends
Component
<
Props
,
State
>
{
constructor
(
props
)
{
super
(
props
);
...
...
@@ -55,11 +58,14 @@ const withKeyboardNavigation = <P extends object>(WrappedComponent: ComponentTyp
};
render
()
{
return
(
<
WrappedComponent
{
...
this
.
state
}
{
...
this
.
props
}
onKeyDown=
{
this
.
onKeyDown
}
onMouseEnter=
{
this
.
onMouseEnter
}
/>
);
}
const
injectProps
=
{
onKeyDown
:
this
.
onKeyDown
,
onMouseEnter
:
this
.
onMouseEnter
,
selected
:
this
.
state
.
selected
,
};
}
;
export default withKeyboardNavigation;
return
<>
{
this
.
props
.
render
({
...
injectProps
})
}
</>;
}
}
export
default
KeyboardNavigation
;
public/app/features/dashboard/dashgrid/VizTypePicker.tsx
View file @
a0da303f
...
...
@@ -4,7 +4,7 @@ import _ from 'lodash';
import
config
from
'app/core/config'
;
import
{
PanelPlugin
}
from
'app/types/plugins'
;
import
VizTypePickerPlugin
from
'./VizTypePickerPlugin'
;
import
withKeyboardNavigation
,
{
KeyboardNavigationProps
}
from
'./with
KeyboardNavigation'
;
import
KeyboardNavigation
,
{
KeyboardNavigationProps
}
from
'./
KeyboardNavigation'
;
export
interface
Props
{
current
:
PanelPlugin
;
...
...
@@ -15,8 +15,7 @@ interface State {
searchQuery
:
string
;
}
export
const
VizTypePicker
=
withKeyboardNavigation
(
class
VizTypePicker
extends
PureComponent
<
Props
&
KeyboardNavigationProps
,
State
>
{
export
class
VizTypePicker
extends
PureComponent
<
Props
,
State
>
{
searchInput
:
HTMLElement
;
pluginList
=
this
.
getPanelPlugins
(
''
);
...
...
@@ -49,8 +48,9 @@ export const VizTypePicker = withKeyboardNavigation(
return
_
.
sortBy
(
panels
,
'sort'
);
}
renderVizPlugin
=
(
plugin
:
PanelPlugin
,
index
:
number
)
=>
{
const
{
onTypeChanged
,
selected
,
onMouseEnter
}
=
this
.
props
;
renderVizPlugin
=
(
plugin
:
PanelPlugin
,
index
:
number
,
keyNavProps
:
KeyboardNavigationProps
)
=>
{
const
{
onTypeChanged
}
=
this
.
props
;
const
{
selected
,
onMouseEnter
}
=
keyNavProps
;
const
isSelected
=
selected
===
index
;
const
isCurrent
=
plugin
.
id
===
this
.
props
.
current
.
id
;
return
(
...
...
@@ -87,9 +87,8 @@ export const VizTypePicker = withKeyboardNavigation(
}));
};
renderFilters
=
(
)
=>
{
renderFilters
=
({
onKeyDown
,
selected
}:
KeyboardNavigationProps
)
=>
{
const
{
searchQuery
}
=
this
.
state
;
const
{
onKeyDown
}
=
this
.
props
;
return
(
<>
<
label
className=
"gf-form--has-input-icon"
>
...
...
@@ -100,10 +99,9 @@ export const VizTypePicker = withKeyboardNavigation(
ref=
{
elem
=>
(
this
.
searchInput
=
elem
)
}
onChange=
{
this
.
onSearchQueryChange
}
value=
{
searchQuery
}
// onKeyDown={this.props.onKeyDown}
onKeyDown=
{
evt
=>
{
onKeyDown
(
evt
,
this
.
maxSelectedIndex
,
()
=>
{
const
{
onTypeChanged
,
select
ed
}
=
this
.
props
;
const
{
onTypeChang
ed
}
=
this
.
props
;
const
vizType
=
this
.
getFilteredPluginList
()[
selected
];
onTypeChanged
(
vizType
);
});
...
...
@@ -119,14 +117,19 @@ export const VizTypePicker = withKeyboardNavigation(
const
filteredPluginList
=
this
.
getFilteredPluginList
();
return
(
<
KeyboardNavigation
render=
{
(
keyNavProps
:
KeyboardNavigationProps
)
=>
(
<>
<
div
className=
"cta-form__bar"
>
{
this
.
renderFilters
(
)
}
{
this
.
renderFilters
(
keyNavProps
)
}
<
div
className=
"gf-form--grow"
/>
</
div
>
<
div
className=
"viz-picker"
>
{
filteredPluginList
.
map
(
this
.
renderVizPlugin
)
}
</
div
>
<
div
className=
"viz-picker"
>
{
filteredPluginList
.
map
((
plugin
,
index
)
=>
this
.
renderVizPlugin
(
plugin
,
index
,
keyNavProps
))
}
</
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