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
e341d4b2
Unverified
Commit
e341d4b2
authored
May 11, 2020
by
Hugo Häggmark
Committed by
GitHub
May 11, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reduce Transform: sort order is preserved as entered by user (#24494)
parent
c3b6ee14
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
4 deletions
+41
-4
packages/grafana-data/src/utils/Registry.test.ts
+31
-0
packages/grafana-data/src/utils/Registry.ts
+10
-4
No files found.
packages/grafana-data/src/utils/Registry.test.ts
0 → 100644
View file @
e341d4b2
import
{
Registry
}
from
'./Registry'
;
import
{
FieldReducerInfo
,
fieldReducers
,
ReducerID
}
from
'../transformations'
;
describe
(
'Registry'
,
()
=>
{
describe
(
'selectOptions'
,
()
=>
{
describe
(
'when called with current'
,
()
=>
{
it
(
'then order in select.current should be same as current'
,
()
=>
{
const
list
=
fieldReducers
.
list
();
const
registry
=
new
Registry
<
FieldReducerInfo
>
(()
=>
list
);
const
current
=
[
ReducerID
.
step
,
ReducerID
.
mean
,
ReducerID
.
allIsZero
,
ReducerID
.
first
,
ReducerID
.
delta
];
const
select
=
registry
.
selectOptions
(
current
);
expect
(
select
.
current
).
toEqual
([
{
description
:
'Minimum interval between values'
,
label
:
'Step'
,
value
:
'step'
},
{
description
:
'Average Value'
,
label
:
'Mean'
,
value
:
'mean'
},
{
description
:
'All values are zero'
,
label
:
'All Zeros'
,
value
:
'allIsZero'
},
{
description
:
'First Value'
,
label
:
'First'
,
value
:
'first'
},
{
description
:
'Cumulative change in value'
,
label
:
'Delta'
,
value
:
'delta'
},
]);
});
describe
(
'when called without current'
,
()
=>
{
it
(
'then it should return an empty array'
,
()
=>
{
const
list
=
fieldReducers
.
list
();
const
registry
=
new
Registry
<
FieldReducerInfo
>
(()
=>
list
);
const
select
=
registry
.
selectOptions
();
expect
(
select
.
current
).
toEqual
([]);
});
});
});
});
});
packages/grafana-data/src/utils/Registry.ts
View file @
e341d4b2
...
...
@@ -84,10 +84,10 @@ export class Registry<T extends RegistryItem> {
current
:
[],
}
as
RegistrySelectInfo
;
const
current
Ids
:
any
=
{};
const
current
Options
:
Record
<
string
,
SelectableValue
<
string
>>
=
{};
if
(
current
)
{
for
(
const
id
of
current
)
{
current
Ids
[
id
]
=
true
;
current
Options
[
id
]
=
{}
;
}
}
...
...
@@ -106,10 +106,16 @@ export class Registry<T extends RegistryItem> {
};
select
.
options
.
push
(
option
);
if
(
current
Id
s
[
ext
.
id
])
{
select
.
current
.
push
(
option
)
;
if
(
current
Option
s
[
ext
.
id
])
{
currentOptions
[
ext
.
id
]
=
option
;
}
}
if
(
current
)
{
// this makes sure we preserve the order of ids
select
.
current
=
Object
.
values
(
currentOptions
);
}
return
select
;
}
...
...
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