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
93649e1f
Unverified
Commit
93649e1f
authored
Dec 14, 2020
by
Giordano Ricci
Committed by
GitHub
Dec 14, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Elasticsearch: ensure query model has timeField configured in datasource settings (#29807)
parent
ac09baae
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
1 deletions
+23
-1
public/app/plugins/datasource/elasticsearch/components/QueryEditor/ElasticsearchQueryContext.test.tsx
+17
-0
public/app/plugins/datasource/elasticsearch/components/QueryEditor/ElasticsearchQueryContext.tsx
+6
-1
No files found.
public/app/plugins/datasource/elasticsearch/components/QueryEditor/ElasticsearchQueryContext.test.tsx
View file @
93649e1f
import
React
,
{
FunctionComponent
}
from
'react'
;
import
{
renderHook
}
from
'@testing-library/react-hooks'
;
import
{
render
}
from
'@testing-library/react'
;
import
{
ElasticsearchProvider
,
useDatasource
,
useQuery
}
from
'./ElasticsearchQueryContext'
;
import
{
ElasticsearchQuery
}
from
'../../types'
;
import
{
ElasticDatasource
}
from
'../../datasource'
;
...
...
@@ -11,6 +12,22 @@ const query: ElasticsearchQuery = {
};
describe
(
'ElasticsearchQueryContext'
,
()
=>
{
it
(
'Should call onChange with the default query when the query is empty'
,
()
=>
{
const
datasource
=
{
timeField
:
'TIMEFIELD'
}
as
ElasticDatasource
;
const
onChange
=
jest
.
fn
();
render
(<
ElasticsearchProvider
query=
{
{
refId
:
'A'
}
}
onChange=
{
onChange
}
datasource=
{
datasource
}
/>);
const
changedQuery
:
ElasticsearchQuery
=
onChange
.
mock
.
calls
[
0
][
0
];
expect
(
changedQuery
.
query
).
toBeDefined
();
expect
(
changedQuery
.
alias
).
toBeDefined
();
expect
(
changedQuery
.
metrics
).
toBeDefined
();
expect
(
changedQuery
.
bucketAggs
).
toBeDefined
();
// Should also set timeField to the configured `timeField` option in datasource configuration
expect
(
changedQuery
.
timeField
).
toBe
(
datasource
.
timeField
);
});
describe
(
'useQuery Hook'
,
()
=>
{
it
(
'Should throw when used outside of ElasticsearchQueryContext'
,
()
=>
{
const
{
result
}
=
renderHook
(()
=>
useQuery
());
...
...
public/app/plugins/datasource/elasticsearch/components/QueryEditor/ElasticsearchQueryContext.tsx
View file @
93649e1f
...
...
@@ -24,7 +24,12 @@ export const ElasticsearchProvider: FunctionComponent<Props> = ({ children, onCh
bucketAggs
:
bucketAggsReducer
,
});
const
dispatch
=
useStatelessReducer
(
newState
=>
onChange
({
...
query
,
...
newState
}),
query
,
reducer
);
const
dispatch
=
useStatelessReducer
(
// timeField is part of the query model, but its value is always set to be the one from datasource settings.
newState
=>
onChange
({
...
query
,
...
newState
,
timeField
:
datasource
.
timeField
}),
query
,
reducer
);
// This initializes the query by dispatching an init action to each reducer.
// useStatelessReducer will then call `onChange` with the newly generated query
...
...
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