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
5c992ba1
Commit
5c992ba1
authored
Nov 23, 2018
by
Peter Holmberg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
created test for some functions
parent
142cd92b
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
248 additions
and
42 deletions
+248
-42
public/app/core/components/Label/Label.tsx
+4
-1
public/app/plugins/panel/gauge/Threshold.test.tsx
+111
-0
public/app/plugins/panel/gauge/Thresholds.tsx
+77
-41
public/sass/components/_thresholds.scss
+56
-0
No files found.
public/app/core/components/Label/Label.tsx
View file @
5c992ba1
...
...
@@ -6,11 +6,14 @@ interface Props {
for
?:
string
;
children
:
ReactNode
;
width
?:
number
;
className
?:
string
;
}
export
const
Label
:
SFC
<
Props
>
=
props
=>
{
return
(
<
span
className=
{
`gf-form-label width-${props.width ? props.width : '10'}`
}
>
<
span
className=
{
`gf-form-label width-${props.width ? props.width : '10'} ${props.className ? props.className : ''}`
}
>
<
span
>
{
props
.
children
}
</
span
>
{
props
.
tooltip
&&
(
<
Tooltip
className=
"gf-form-help-icon--right-normal"
placement=
"auto"
content=
{
props
.
tooltip
}
>
...
...
public/app/plugins/panel/gauge/Threshold.test.tsx
0 → 100644
View file @
5c992ba1
import
React
from
'react'
;
import
{
shallow
}
from
'enzyme'
;
import
Thresholds
from
'./Thresholds'
;
import
{
OptionsProps
}
from
'./module'
;
import
{
PanelOptionsProps
}
from
'../../../types'
;
const
setup
=
(
propOverrides
?:
object
)
=>
{
const
props
:
PanelOptionsProps
<
OptionsProps
>
=
{
onChange
:
jest
.
fn
(),
options
:
{}
as
OptionsProps
,
};
Object
.
assign
(
props
,
propOverrides
);
return
shallow
(<
Thresholds
{
...
props
}
/>).
instance
()
as
Thresholds
;
};
describe
(
'Add threshold'
,
()
=>
{
it
(
'should add treshold between min and max'
,
()
=>
{
const
instance
=
setup
();
instance
.
onAddThreshold
(
1
);
expect
(
instance
.
state
.
thresholds
).
toEqual
([
{
index
:
0
,
label
:
'Min'
,
value
:
0
,
canRemove
:
false
},
{
index
:
1
,
label
:
''
,
value
:
0
,
canRemove
:
true
},
{
index
:
2
,
label
:
'Max'
,
value
:
100
,
canRemove
:
false
},
]);
});
it
(
'should add threshold between min and added threshold'
,
()
=>
{
const
instance
=
setup
();
instance
.
state
=
{
thresholds
:
[
{
index
:
0
,
label
:
'Min'
,
value
:
0
,
canRemove
:
false
},
{
index
:
1
,
label
:
''
,
value
:
50
,
canRemove
:
true
},
{
index
:
2
,
label
:
'Max'
,
value
:
100
,
canRemove
:
false
},
],
userAddedThresholds
:
1
,
};
instance
.
onAddThreshold
(
1
);
expect
(
instance
.
state
.
thresholds
).
toEqual
([
{
index
:
0
,
label
:
'Min'
,
value
:
0
,
canRemove
:
false
},
{
index
:
1
,
label
:
''
,
value
:
0
,
canRemove
:
true
},
{
index
:
2
,
label
:
''
,
value
:
50
,
canRemove
:
true
},
{
index
:
3
,
label
:
'Max'
,
value
:
100
,
canRemove
:
false
},
]);
});
});
describe
(
'Add at index'
,
()
=>
{
it
(
'should return 1, no added thresholds'
,
()
=>
{
const
instance
=
setup
();
const
result
=
instance
.
insertAtIndex
(
1
);
expect
(
result
).
toEqual
(
1
);
});
it
(
'should return 1, one added threshold'
,
()
=>
{
const
instance
=
setup
();
instance
.
state
=
{
thresholds
:
[
{
index
:
0
,
label
:
'Min'
,
value
:
0
,
canRemove
:
false
},
{
index
:
1
,
label
:
''
,
value
:
50
,
canRemove
:
true
},
{
index
:
2
,
label
:
'Max'
,
value
:
100
,
canRemove
:
false
},
],
userAddedThresholds
:
1
,
};
const
result
=
instance
.
insertAtIndex
(
1
);
expect
(
result
).
toEqual
(
1
);
});
it
(
'should return 2, two added thresholds'
,
()
=>
{
const
instance
=
setup
();
instance
.
state
=
{
thresholds
:
[
{
index
:
0
,
label
:
'Min'
,
value
:
0
,
canRemove
:
false
},
{
index
:
1
,
label
:
''
,
value
:
25
,
canRemove
:
true
},
{
index
:
2
,
label
:
''
,
value
:
50
,
canRemove
:
true
},
{
index
:
3
,
label
:
'Max'
,
value
:
100
,
canRemove
:
false
},
],
userAddedThresholds
:
2
,
};
const
result
=
instance
.
insertAtIndex
(
2
);
expect
(
result
).
toEqual
(
2
);
});
it
(
'should return 2, one added threshold'
,
()
=>
{
const
instance
=
setup
();
instance
.
state
=
{
thresholds
:
[
{
index
:
0
,
label
:
'Min'
,
value
:
0
,
canRemove
:
false
},
{
index
:
1
,
label
:
''
,
value
:
50
,
canRemove
:
true
},
{
index
:
2
,
label
:
'Max'
,
value
:
100
,
canRemove
:
false
},
],
userAddedThresholds
:
1
,
};
const
result
=
instance
.
insertAtIndex
(
2
);
expect
(
result
).
toEqual
(
2
);
});
});
public/app/plugins/panel/gauge/Thresholds.tsx
View file @
5c992ba1
...
...
@@ -74,11 +74,11 @@ export default class Thresholds extends PureComponent<PanelOptionsProps<OptionsP
};
getIndicatorColor
(
index
)
{
const
{
userAddedT
hresholds
}
=
this
.
state
;
const
{
t
hresholds
}
=
this
.
state
;
if
(
index
===
0
)
{
return
'green'
;
}
else
if
(
index
<
userAddedThresholds
)
{
}
else
if
(
index
<
thresholds
.
length
)
{
return
'yellow'
;
}
...
...
@@ -89,7 +89,7 @@ export default class Thresholds extends PureComponent<PanelOptionsProps<OptionsP
const
{
thresholds
}
=
this
.
state
;
return
[
<
div
className=
"gf-form"
key=
"min"
>
<
div
className=
"gf-form
threshold-row threshold-row-min
"
key=
"min"
>
<
input
className=
"gf-form-input"
onBlur=
{
this
.
onBlur
}
...
...
@@ -98,23 +98,15 @@ export default class Thresholds extends PureComponent<PanelOptionsProps<OptionsP
/>
<
Label
width=
{
3
}
>
{
thresholds
[
0
].
label
}
</
Label
>
</
div
>,
<
div
className=
"gf-form"
key=
"add"
>
<
div
onClick=
{
()
=>
this
.
onAddThreshold
(
1
)
}
style=
{
{
display
:
'flex'
,
alignItems
:
'center'
,
justifyContent
:
'center'
,
width
:
'36px'
,
height
:
'36px'
,
backgroundColor
:
'green'
,
}
}
>
<
div
className=
"gf-form threshold-row"
key=
"add"
>
<
div
onClick=
{
()
=>
this
.
onAddThreshold
(
1
)
}
className=
"threshold-row-add"
>
<
i
className=
"fa fa-plus"
/>
</
div
>
<
Label
width=
{
18
}
>
Add new threshold by clicking the line
</
Label
>
<
Label
className=
"threshold-row-label"
width=
{
18
}
>
Add new threshold by clicking the line
</
Label
>
</
div
>,
<
div
className=
"gf-form"
key=
"max"
>
<
div
className=
"gf-form
threshold-row threshold-row-max
"
key=
"max"
>
<
input
className=
"gf-form-input"
onBlur=
{
this
.
onBlur
}
...
...
@@ -130,7 +122,12 @@ export default class Thresholds extends PureComponent<PanelOptionsProps<OptionsP
const
{
thresholds
}
=
this
.
state
;
return
thresholds
.
map
((
threshold
,
index
)
=>
{
return
(
<
div
className=
"gf-form"
key=
{
`${threshold}-${index}`
}
>
<
div
className=
{
`gf-form threshold-row ${index === 0 ? 'threshold-row-min' : ''} ${
index === thresholds.length ? 'threshold-row-max' : ''
} `
}
key=
{
`${threshold}-${index}`
}
>
<
input
className=
"gf-form-input"
type=
"text"
...
...
@@ -164,37 +161,84 @@ export default class Thresholds extends PureComponent<PanelOptionsProps<OptionsP
if
(
userAddedThresholds
===
0
)
{
return
1
;
}
else
if
(
index
===
userAddedThresholds
)
{
}
else
if
(
userAddedThresholds
>
1
&&
index
===
this
.
state
.
thresholds
.
length
)
{
return
index
-
1
;
}
else
if
(
index
===
0
)
{
return
1
;
}
else
if
(
index
>
0
)
{
return
index
+
1
;
return
index
;
}
// SAD
return
-
1
;
}
renderIndicator
(
)
{
renderIndicator
Section
(
index
)
{
const
{
userAddedThresholds
}
=
this
.
state
;
const
indicators
=
userAddedThresholds
+
1
;
const
sections
=
[];
if
(
index
===
0
||
index
===
indicators
)
{
return
(
<
div
key=
{
index
}
className=
"indicator-section"
style=
{
{
height
:
`calc(100%/${indicators})`
,
}
}
>
<
div
onClick=
{
()
=>
this
.
onAddThreshold
(
this
.
insertAtIndex
(
index
-
1
))
}
style=
{
{
height
:
'100%'
,
background
:
this
.
getIndicatorColor
(
index
),
}
}
/>
</
div
>
);
}
for
(
let
i
=
0
;
i
<
indicators
;
i
++
)
{
sections
.
push
(
return
(
<
div
key=
{
`${i}`
}
onClick=
{
()
=>
this
.
onAddThreshold
(
this
.
insertAtIndex
(
i
))
}
key=
{
index
}
className=
"indicator-section"
style=
{
{
width
:
'100%'
,
height
:
`calc(100%/${indicators})`
,
}
}
>
<
div
onClick=
{
()
=>
this
.
onAddThreshold
(
this
.
insertAtIndex
(
index
-
1
))
}
style=
{
{
height
:
'50%'
,
background
:
this
.
getIndicatorColor
(
index
),
}
}
>
{
index
}
</
div
>
<
div
onClick=
{
()
=>
this
.
onAddThreshold
(
this
.
insertAtIndex
(
index
))
}
style=
{
{
height
:
`50%`
,
cursor
:
'pointer'
,
background
:
this
.
getIndicatorColor
(
i
),
background
:
this
.
getIndicatorColor
(
i
ndex
),
}
}
/>
>
{
index
}
</
div
>
</
div
>
);
}
renderIndicator
()
{
const
{
userAddedThresholds
}
=
this
.
state
;
const
indicators
=
userAddedThresholds
+
1
;
const
sections
=
[];
for
(
let
i
=
0
;
i
<
indicators
;
i
++
)
{
sections
.
push
(
this
.
renderIndicatorSection
(
i
));
}
return
sections
;
}
...
...
@@ -204,17 +248,9 @@ export default class Thresholds extends PureComponent<PanelOptionsProps<OptionsP
return
(
<
div
className=
"section gf-form-group"
>
<
h5
className=
"page-heading"
>
Thresholds
</
h5
>
<
div
style=
{
{
display
:
'flex'
,
alignItems
:
'flexStart'
}
}
>
<
div
style=
{
{
width
:
'20px'
,
minHeight
:
'40px'
,
flex
:
'0 1 auto'
,
}
}
>
{
this
.
renderIndicator
()
}
</
div
>
<
div
style=
{
{
flex
:
'1 0 auto'
,
marginLeft
:
'10px'
}
}
>
<
div
className=
"thresholds"
>
<
div
className=
"color-indicators"
>
{
this
.
renderIndicator
()
}
</
div
>
<
div
className=
"threshold-rows"
>
{
userAddedThresholds
===
0
?
this
.
renderNoThresholds
()
:
this
.
renderThresholds
()
}
</
div
>
</
div
>
...
...
public/sass/components/_thresholds.scss
View file @
5c992ba1
.thresholds
{
display
:
flex
;
margin-top
:
30px
;
}
.threshold-rows
{
flex
:
1
0
auto
;
margin-left
:
10px
;
}
.threshold-row
{
&
:
:
before
{
font-family
:
'FontAwesome'
;
content
:
'\f0d9'
;
color
:
$input-label-border-color
;
}
}
.threshold-row-min
{
margin-top
:
-17px
;
}
.threshold-row-max
{
margin-bottom
:
-17px
;
}
.threshold-row-add
{
border
:
$border-width
solid
$input-label-border-color
;
border-radius
:
$border-radius
0
0
$border-radius
;
display
:
flex
;
align-items
:
center
;
justify-content
:
center
;
width
:
36px
;
height
:
36px
;
background-color
:
$green
;
}
.threshold-row-label
{
border-top-left-radius
:
0
;
border-bottom-left-radius
:
0
;
}
.indicator-section
{
width
:
100%
;
border-top
:
1px
solid
black
;
cursor
:
pointer
;
:first-of-type
{
border-top
:
none
;
}
}
.color-indicators
{
width
:
20px
;
min-height
:
40px
;
flex
:
0
1
auto
;
}
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