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
11fa7c69
Unverified
Commit
11fa7c69
authored
Feb 04, 2021
by
Ryan McKinley
Committed by
GitHub
Feb 04, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Transformers: add search to transform selection (#30854)
parent
48334ab8
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
100 additions
and
35 deletions
+100
-35
packages/grafana-e2e-selectors/src/selectors/components.ts
+1
-0
public/app/features/dashboard/components/TransformationsEditor/TransformationsEditor.test.tsx
+2
-2
public/app/features/dashboard/components/TransformationsEditor/TransformationsEditor.tsx
+97
-33
No files found.
packages/grafana-e2e-selectors/src/selectors/components.ts
View file @
11fa7c69
...
...
@@ -122,6 +122,7 @@ export const Components = {
modeLabel
:
'Transform mode label'
,
calculationsLabel
:
'Transform calculations label'
,
},
searchInput
:
'search transformations'
,
},
PageToolbar
:
{
container
:
()
=>
'.page-toolbar'
,
...
...
public/app/features/dashboard/components/TransformationsEditor/TransformationsEditor.test.tsx
View file @
11fa7c69
...
...
@@ -51,8 +51,8 @@ describe('TransformationsEditor', () => {
const
addTransformationButton
=
screen
.
getByText
(
buttonLabel
);
userEvent
.
click
(
addTransformationButton
);
const
picker
=
screen
.
getByLabelText
(
selectors
.
components
.
ValuePicker
.
select
(
buttonLabel
)
);
expect
(
picker
).
toBeDefined
();
const
search
=
screen
.
getByLabelText
(
selectors
.
components
.
Transforms
.
searchInput
);
expect
(
search
).
toBeDefined
();
});
});
...
...
public/app/features/dashboard/components/TransformationsEditor/TransformationsEditor.tsx
View file @
11fa7c69
import
React
from
'react'
;
import
React
,
{
ChangeEvent
}
from
'react'
;
import
{
Alert
,
Button
,
...
...
@@ -8,9 +8,10 @@ import {
Themeable
,
DismissableFeatureInfoBox
,
useTheme
,
ValuePicker
,
VerticalGroup
,
withTheme
,
Input
,
IconButton
,
}
from
'@grafana/ui'
;
import
{
DataFrame
,
...
...
@@ -40,6 +41,8 @@ interface TransformationsEditorProps extends Themeable {
interface
State
{
data
:
DataFrame
[];
transformations
:
TransformationsEditorTransformation
[];
search
:
string
;
showPicker
?:
boolean
;
}
class
UnThemedTransformationsEditor
extends
React
.
PureComponent
<
TransformationsEditorProps
,
State
>
{
...
...
@@ -56,9 +59,34 @@ class UnThemedTransformationsEditor extends React.PureComponent<TransformationsE
id
:
ids
[
i
],
})),
data
:
[],
search
:
''
,
};
}
onSearchChange
=
(
event
:
ChangeEvent
<
HTMLInputElement
>
)
=>
{
this
.
setState
({
search
:
event
.
target
.
value
});
};
onSearchKeyDown
=
(
event
:
React
.
KeyboardEvent
<
HTMLInputElement
>
)
=>
{
if
(
event
.
key
===
'Enter'
)
{
const
{
search
}
=
this
.
state
;
if
(
search
)
{
const
lower
=
search
.
toLowerCase
();
const
filtered
=
standardTransformersRegistry
.
list
().
filter
((
t
)
=>
{
const
txt
=
(
t
.
name
+
t
.
description
).
toLowerCase
();
return
txt
.
indexOf
(
lower
)
>=
0
;
});
if
(
filtered
.
length
>
0
)
{
this
.
onTransformationAdd
({
value
:
filtered
[
0
].
id
});
}
}
}
else
if
(
event
.
keyCode
===
27
)
{
// Escape key
this
.
setState
({
search
:
''
,
showPicker
:
false
});
event
.
stopPropagation
();
// don't exit the editor
}
};
buildTransformationIds
(
transformations
:
DataTransformerConfig
[])
{
const
transformationCounters
:
Record
<
string
,
number
>
=
{};
const
transformationIds
:
string
[]
=
[];
...
...
@@ -113,6 +141,7 @@ class UnThemedTransformationsEditor extends React.PureComponent<TransformationsE
const
{
transformations
}
=
this
.
state
;
const
nextId
=
this
.
getTransformationNextId
(
selectable
.
value
!
);
this
.
setState
({
search
:
''
,
showPicker
:
false
});
this
.
onChange
([
...
transformations
,
{
...
...
@@ -139,33 +168,6 @@ class UnThemedTransformationsEditor extends React.PureComponent<TransformationsE
this
.
onChange
(
next
);
};
renderTransformationSelector
=
()
=>
{
const
availableTransformers
=
standardTransformersRegistry
.
list
().
map
((
t
)
=>
{
return
{
value
:
t
.
transformation
.
id
,
label
:
t
.
name
,
description
:
t
.
description
,
};
});
return
(
<
div
className=
{
css
`
max-width: 66%;
`
}
>
<
ValuePicker
size=
"md"
variant=
"secondary"
label=
"Add transformation"
options=
{
availableTransformers
}
onChange=
{
this
.
onTransformationAdd
}
isFullWidth=
{
false
}
/>
</
div
>
);
};
onDragEnd
=
(
result
:
DropResult
)
=>
{
const
{
transformations
}
=
this
.
state
;
...
...
@@ -208,9 +210,49 @@ class UnThemedTransformationsEditor extends React.PureComponent<TransformationsE
);
};
renderNoAddedTransformsState
()
{
renderTransformsPicker
()
{
const
{
transformations
,
search
}
=
this
.
state
;
let
suffix
:
React
.
ReactNode
=
null
;
let
xforms
=
standardTransformersRegistry
.
list
();
if
(
search
)
{
const
lower
=
search
.
toLowerCase
();
const
filtered
=
xforms
.
filter
((
t
)
=>
{
const
txt
=
(
t
.
name
+
t
.
description
).
toLowerCase
();
return
txt
.
indexOf
(
lower
)
>=
0
;
});
suffix
=
(
<>
{
filtered
.
length
}
/
{
xforms
.
length
}
<
IconButton
name=
"times"
surface=
"header"
onClick=
{
()
=>
{
this
.
setState
({
search
:
''
});
}
}
/>
</>
);
xforms
=
filtered
;
}
const
noTransforms
=
!
transformations
?.
length
;
const
showPicker
=
noTransforms
||
this
.
state
.
showPicker
;
if
(
!
suffix
&&
showPicker
&&
!
noTransforms
)
{
suffix
=
(
<
IconButton
name=
"times"
surface=
"header"
onClick=
{
()
=>
{
this
.
setState
({
showPicker
:
false
});
}
}
/>
);
}
return
(
<>
{
noTransforms
&&
(
<
Container
grow=
{
1
}
>
<
DismissableFeatureInfoBox
title=
"Transformations"
...
...
@@ -229,8 +271,20 @@ class UnThemedTransformationsEditor extends React.PureComponent<TransformationsE
</
p
>
</
DismissableFeatureInfoBox
>
</
Container
>
)
}
{
showPicker
?
(
<
VerticalGroup
>
{
standardTransformersRegistry
.
list
().
map
((
t
)
=>
{
<
Input
aria
-
label=
{
selectors
.
components
.
Transforms
.
searchInput
}
value=
{
search
??
''
}
autoFocus=
{
!
noTransforms
}
placeholder=
"Add transformation"
onChange=
{
this
.
onSearchChange
}
onKeyDown=
{
this
.
onSearchKeyDown
}
suffix=
{
suffix
}
/>
{
xforms
.
map
((
t
)
=>
{
return
(
<
TransformationCard
key=
{
t
.
name
}
...
...
@@ -245,6 +299,17 @@ class UnThemedTransformationsEditor extends React.PureComponent<TransformationsE
);
})
}
</
VerticalGroup
>
)
:
(
<
Button
icon=
"plus"
variant=
"secondary"
onClick=
{
()
=>
{
this
.
setState
({
showPicker
:
true
});
}
}
>
Add transformation
</
Button
>
)
}
</>
);
}
...
...
@@ -271,9 +336,8 @@ class UnThemedTransformationsEditor extends React.PureComponent<TransformationsE
title=
"Transformations can't be used on a panel with alerts"
/>
)
:
null
}
{
!
hasTransforms
&&
this
.
renderNoAddedTransformsState
()
}
{
hasTransforms
&&
this
.
renderTransformationEditors
()
}
{
hasTransforms
&&
this
.
renderTransformationSelecto
r
()
}
{
this
.
renderTransformsPicke
r
()
}
</
div
>
</
Container
>
</
CustomScrollbar
>
...
...
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