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
9b4d2a5f
Commit
9b4d2a5f
authored
Mar 18, 2019
by
ryan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove the error collector
parent
ed1b515f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
26 deletions
+45
-26
packages/grafana-ui/src/components/StatsPicker/StatsPicker.story.tsx
+16
-5
packages/grafana-ui/src/components/StatsPicker/StatsPicker.tsx
+7
-7
packages/grafana-ui/src/utils/statsCalculator.test.ts
+10
-8
packages/grafana-ui/src/utils/statsCalculator.ts
+12
-6
No files found.
packages/grafana-ui/src/components/StatsPicker/StatsPicker.story.tsx
View file @
9b4d2a5f
...
...
@@ -6,6 +6,15 @@ import { withCenteredStory } from '../../utils/storybook/withCenteredStory';
import
{
StatsPicker
}
from
'./StatsPicker'
;
import
{
text
,
boolean
}
from
'@storybook/addon-knobs'
;
const
getKnobs
=
()
=>
{
return
{
placeholder
:
text
(
'Placeholder Text'
,
''
),
defaultStat
:
text
(
'Default Stat'
,
''
),
allowMultiple
:
boolean
(
'Allow Multiple'
,
false
),
initialStats
:
text
(
'Initial Stats'
,
''
),
};
};
interface
State
{
stats
:
string
[];
}
...
...
@@ -19,12 +28,16 @@ export class WrapperWithState extends PureComponent<any, State> {
}
toStatsArray
=
(
txt
:
string
):
string
[]
=>
{
if
(
!
txt
)
{
return
[];
}
return
txt
.
split
(
','
).
map
(
v
=>
v
.
trim
());
};
componentDidUpdate
(
prevProps
:
any
)
{
const
{
initialReducers
}
=
this
.
props
;
if
(
initialReducers
!==
prevProps
.
initialReducers
)
{
console
.
log
(
'Changing initial reducers'
);
this
.
setState
({
stats
:
this
.
toStatsArray
(
initialReducers
)
});
}
}
...
...
@@ -48,13 +61,11 @@ export class WrapperWithState extends PureComponent<any, State> {
}
}
const
story
=
storiesOf
(
'UI/
TableReduce
Picker'
,
module
);
const
story
=
storiesOf
(
'UI/
Stats
Picker'
,
module
);
story
.
addDecorator
(
withCenteredStory
);
story
.
add
(
'picker'
,
()
=>
{
const
placeholder
=
text
(
'Placeholder Text'
,
''
);
const
defaultStat
=
text
(
'Default Stat'
,
''
);
const
allowMultiple
=
boolean
(
'Allow Multiple'
,
false
);
const
initialStats
=
text
(
'Initial Stats'
,
''
);
const
{
placeholder
,
defaultStat
,
allowMultiple
,
initialStats
}
=
getKnobs
();
return
(
<
div
>
<
WrapperWithState
...
...
packages/grafana-ui/src/components/StatsPicker/StatsPicker.tsx
View file @
9b4d2a5f
import
React
,
{
PureComponent
}
from
'react'
;
import
isArray
from
'lodash/isArray'
;
import
difference
from
'lodash/difference'
;
import
{
Select
}
from
'../index'
;
...
...
@@ -33,12 +34,12 @@ export class StatsPicker extends PureComponent<Props> {
checkInput
=
()
=>
{
const
{
stats
,
allowMultiple
,
defaultStat
,
onChange
}
=
this
.
props
;
// Check that the selected reducers are all real
const
notFound
:
string
[]
=
[];
const
current
=
getStatsCalculators
(
stats
,
notFound
);
if
(
notFound
.
length
>
0
)
{
console
.
warn
(
'Unknown
reducer
s'
,
notFound
,
stats
);
onChange
(
current
.
map
(
reducer
=>
reducer
.
value
));
const
current
=
getStatsCalculators
(
stats
);
if
(
current
.
length
!==
stats
.
length
)
{
const
found
=
current
.
map
(
v
=>
v
.
value
);
const
notFound
=
difference
(
stats
,
found
);
console
.
warn
(
'Unknown
stat
s'
,
notFound
,
stats
);
onChange
(
current
.
map
(
stat
=>
stat
.
value
));
}
// Make sure there is only one
...
...
@@ -65,7 +66,6 @@ export class StatsPicker extends PureComponent<Props> {
render
()
{
const
{
width
,
stats
,
allowMultiple
,
defaultStat
,
placeholder
}
=
this
.
props
;
const
current
=
getStatsCalculators
(
stats
);
return
(
<
Select
width=
{
width
}
...
...
packages/grafana-ui/src/utils/statsCalculator.test.ts
View file @
9b4d2a5f
import
{
parseCSV
}
from
'./processTableData'
;
import
{
getStatsCalculators
,
StatID
,
calculateStats
}
from
'./statsCalculator'
;
import
_
from
'lodash'
;
describe
(
'Stats Calculators'
,
()
=>
{
const
basicTable
=
parseCSV
(
'a,b,c
\
n10,20,30
\
n20,30,40'
);
...
...
@@ -21,20 +23,20 @@ describe('Stats Calculators', () => {
// StatID.allIsZero,
// StatID.allIsNull,
];
const
notFound
:
string
[]
=
[];
const
stats
=
getStatsCalculators
(
names
,
notFound
);
stats
.
forEach
((
stat
,
index
)
=>
{
expect
(
stat
?
stat
.
value
:
'<missing>'
).
toEqual
(
names
[
index
]);
});
expect
(
notFound
.
length
).
toBe
(
0
);
const
stats
=
getStatsCalculators
(
names
);
expect
(
stats
.
length
).
toBe
(
names
.
length
);
});
it
(
'should fail to load unknown stats'
,
()
=>
{
const
names
=
[
'not a stat'
,
StatID
.
max
,
StatID
.
min
,
'also not a stat'
];
const
notFound
:
string
[]
=
[];
const
stats
=
getStatsCalculators
(
names
,
notFound
);
const
stats
=
getStatsCalculators
(
names
);
expect
(
stats
.
length
).
toBe
(
2
);
const
found
=
stats
.
map
(
v
=>
v
.
value
);
const
notFound
=
_
.
difference
(
names
,
found
);
expect
(
notFound
.
length
).
toBe
(
2
);
expect
(
notFound
[
0
]).
toBe
(
'not a stat'
);
});
it
(
'should calculate stats'
,
()
=>
{
...
...
packages/grafana-ui/src/utils/statsCalculator.ts
View file @
9b4d2a5f
...
...
@@ -42,18 +42,18 @@ export interface StatCalculatorInfo {
/**
* @param ids list of stat names or null to get all of them
* @param notFound optional error object that will be filled with the names on unknown stats
*/
export
function
getStatsCalculators
(
ids
?:
string
[]
,
notFound
?:
string
[]
):
StatCalculatorInfo
[]
{
export
function
getStatsCalculators
(
ids
?:
string
[]):
StatCalculatorInfo
[]
{
if
(
ids
===
null
||
ids
===
undefined
)
{
if
(
!
hasBuiltIndex
)
{
getById
(
StatID
.
mean
);
}
return
listOfStats
;
}
return
ids
.
reduce
((
list
,
id
)
=>
{
const
stat
=
getById
(
id
);
if
(
stat
)
{
list
.
push
(
stat
);
}
else
if
(
notFound
&&
id
)
{
notFound
.
push
(
id
);
}
return
list
;
},
new
Array
<
StatCalculatorInfo
>
());
...
...
@@ -146,7 +146,13 @@ function getById(id: string): StatCalculatorInfo | undefined {
standard
:
true
,
alias
:
'total'
,
},
{
value
:
StatID
.
count
,
label
:
'Count'
,
description
:
'Value Count'
,
emptyInputResult
:
0
,
standard
:
true
},
{
value
:
StatID
.
count
,
label
:
'Count'
,
description
:
'Number of values in response'
,
emptyInputResult
:
0
,
standard
:
true
,
},
{
value
:
StatID
.
range
,
label
:
'Range'
,
...
...
@@ -156,7 +162,7 @@ function getById(id: string): StatCalculatorInfo | undefined {
{
value
:
StatID
.
delta
,
label
:
'Delta'
,
description
:
'Cumulative change in value
'
,
// HELP! not totally sure what this does
description
:
'Cumulative change in value
(??? help not really sure ???)'
,
standard
:
true
,
},
{
...
...
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