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
645812f6
Commit
645812f6
authored
Dec 11, 2018
by
Johannes Schill
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Let VizTypePicker use the keyboard navigation hoc
parent
5d4034be
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
53 deletions
+33
-53
public/app/features/dashboard/dashgrid/DataSourcePicker.tsx
+3
-6
public/app/features/dashboard/dashgrid/VizTypePicker.tsx
+21
-45
public/app/features/dashboard/dashgrid/withKeyboardNavigation.tsx
+9
-2
No files found.
public/app/features/dashboard/dashgrid/DataSourcePicker.tsx
View file @
645812f6
import
React
,
{
PureComponent
}
from
'react'
;
import
classNames
from
'classnames'
;
import
_
from
'lodash'
;
import
withKeyboardNavigation
from
'./withKeyboardNavigation'
;
import
withKeyboardNavigation
,
{
KeyboardNavigationProps
}
from
'./withKeyboardNavigation'
;
import
{
DataSourceSelectItem
}
from
'app/types'
;
export
interface
Props
{
onChangeDataSource
:
(
ds
:
any
)
=>
void
;
onChangeDataSource
:
(
ds
:
DataSourceSelectItem
)
=>
void
;
datasources
:
DataSourceSelectItem
[];
selected
?:
number
;
onKeyDown
?:
(
evt
:
any
,
maxSelectedIndex
:
number
,
onEnterAction
:
()
=>
void
)
=>
void
;
onMouseEnter
?:
(
select
:
number
)
=>
void
;
}
interface
State
{
...
...
@@ -17,7 +14,7 @@ interface State {
}
export
const
DataSourcePicker
=
withKeyboardNavigation
(
class
DataSourcePicker
extends
PureComponent
<
Props
,
State
>
{
class
DataSourcePicker
extends
PureComponent
<
Props
&
KeyboardNavigationProps
,
State
>
{
searchInput
:
HTMLElement
;
constructor
(
props
)
{
...
...
public/app/features/dashboard/dashgrid/VizTypePicker.tsx
View file @
645812f6
...
...
@@ -4,18 +4,19 @@ import _ from 'lodash';
import
config
from
'app/core/config'
;
import
{
PanelPlugin
}
from
'app/types/plugins'
;
import
VizTypePickerPlugin
from
'./VizTypePickerPlugin'
;
import
withKeyboardNavigation
,
{
KeyboardNavigationProps
}
from
'./withKeyboardNavigation'
;
interface
Props
{
export
interface
Props
{
current
:
PanelPlugin
;
onTypeChanged
:
(
newType
:
PanelPlugin
)
=>
void
;
}
interface
State
{
searchQuery
:
string
;
selected
:
number
;
}
export
class
VizTypePicker
extends
PureComponent
<
Props
,
State
>
{
export
const
VizTypePicker
=
withKeyboardNavigation
(
class
VizTypePicker
extends
PureComponent
<
Props
&
KeyboardNavigationProps
,
State
>
{
searchInput
:
HTMLElement
;
pluginList
=
this
.
getPanelPlugins
(
''
);
...
...
@@ -24,7 +25,6 @@ export class VizTypePicker extends PureComponent<Props, State> {
this
.
state
=
{
searchQuery
:
''
,
selected
:
0
,
};
}
...
...
@@ -33,35 +33,6 @@ export class VizTypePicker extends PureComponent<Props, State> {
return
filteredPluginList
.
length
-
1
;
}
goRight
=
()
=>
{
const
nextIndex
=
this
.
state
.
selected
>=
this
.
maxSelectedIndex
?
0
:
this
.
state
.
selected
+
1
;
this
.
setState
({
selected
:
nextIndex
,
});
};
goLeft
=
()
=>
{
const
nextIndex
=
this
.
state
.
selected
<=
0
?
this
.
maxSelectedIndex
:
this
.
state
.
selected
-
1
;
this
.
setState
({
selected
:
nextIndex
,
});
};
onKeyDown
=
evt
=>
{
if
(
evt
.
key
===
'ArrowDown'
)
{
evt
.
preventDefault
();
this
.
goRight
();
}
if
(
evt
.
key
===
'ArrowUp'
)
{
evt
.
preventDefault
();
this
.
goLeft
();
}
if
(
evt
.
key
===
'Enter'
)
{
const
filteredPluginList
=
this
.
getFilteredPluginList
();
this
.
props
.
onTypeChanged
(
filteredPluginList
[
this
.
state
.
selected
]);
}
};
componentDidMount
()
{
setTimeout
(()
=>
{
this
.
searchInput
.
focus
();
...
...
@@ -78,14 +49,9 @@ export class VizTypePicker extends PureComponent<Props, State> {
return
_
.
sortBy
(
panels
,
'sort'
);
}
onMouseEnter
=
(
mouseEnterIndex
:
number
)
=>
{
this
.
setState
({
selected
:
mouseEnterIndex
,
});
};
renderVizPlugin
=
(
plugin
:
PanelPlugin
,
index
:
number
)
=>
{
const
isSelected
=
this
.
state
.
selected
===
index
;
const
{
onTypeChanged
,
selected
,
onMouseEnter
}
=
this
.
props
;
const
isSelected
=
selected
===
index
;
const
isCurrent
=
plugin
.
id
===
this
.
props
.
current
.
id
;
return
(
<
VizTypePickerPlugin
...
...
@@ -94,9 +60,9 @@ export class VizTypePicker extends PureComponent<Props, State> {
isCurrent=
{
isCurrent
}
plugin=
{
plugin
}
onMouseEnter=
{
()
=>
{
this
.
onMouseEnter
(
index
);
onMouseEnter
(
index
);
}
}
onClick=
{
()
=>
this
.
props
.
onTypeChanged
(
plugin
)
}
onClick=
{
()
=>
onTypeChanged
(
plugin
)
}
/>
);
};
...
...
@@ -118,11 +84,12 @@ export class VizTypePicker extends PureComponent<Props, State> {
this
.
setState
(
prevState
=>
({
...
prevState
,
searchQuery
:
value
,
selected
:
0
,
}));
};
renderFilters
=
()
=>
{
const
{
searchQuery
}
=
this
.
state
;
const
{
onKeyDown
}
=
this
.
props
;
return
(
<>
<
label
className=
"gf-form--has-input-icon"
>
...
...
@@ -132,7 +99,15 @@ export class VizTypePicker extends PureComponent<Props, State> {
placeholder=
""
ref=
{
elem
=>
(
this
.
searchInput
=
elem
)
}
onChange=
{
this
.
onSearchQueryChange
}
onKeyDown=
{
this
.
onKeyDown
}
value=
{
searchQuery
}
// onKeyDown={this.props.onKeyDown}
onKeyDown=
{
evt
=>
{
onKeyDown
(
evt
,
this
.
maxSelectedIndex
,
()
=>
{
const
{
onTypeChanged
,
selected
}
=
this
.
props
;
const
vizType
=
this
.
getFilteredPluginList
()[
selected
];
onTypeChanged
(
vizType
);
});
}
}
/>
<
i
className=
"gf-form-input-icon fa fa-search"
/>
</
label
>
...
...
@@ -153,4 +128,5 @@ export class VizTypePicker extends PureComponent<Props, State> {
</>
);
}
}
}
);
public/app/features/dashboard/dashgrid/withKeyboardNavigation.tsx
View file @
645812f6
import
React
from
'react'
;
import
{
Props
}
from
'./DataSourcePicker'
;
import
{
Props
as
DataSourceProps
}
from
'./DataSourcePicker'
;
import
{
Props
as
VizTypeProps
}
from
'./VizTypePicker'
;
interface
State
{
selected
:
number
;
}
export
interface
KeyboardNavigationProps
{
selected
?:
number
;
onKeyDown
?:
(
evt
:
React
.
KeyboardEvent
<
EventTarget
>
,
maxSelectedIndex
:
number
,
onEnterAction
:
()
=>
void
)
=>
void
;
onMouseEnter
?:
(
select
:
number
)
=>
void
;
}
const
withKeyboardNavigation
=
WrappedComponent
=>
{
return
class
extends
React
.
Component
<
Props
,
State
>
{
return
class
extends
React
.
Component
<
DataSourceProps
|
VizType
Props
,
State
>
{
constructor
(
props
)
{
super
(
props
);
...
...
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