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
5feef220
Unverified
Commit
5feef220
authored
May 13, 2020
by
Andrej Ocenas
Committed by
GitHub
May 13, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CloudWatch/Logs: Make stats hint show consistently (#24392)
parent
75de6165
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
32 deletions
+39
-32
packages/grafana-ui/src/components/QueryField/QueryField.tsx
+4
-0
public/app/plugins/datasource/cloudwatch/components/LogsQueryField.tsx
+35
-32
No files found.
packages/grafana-ui/src/components/QueryField/QueryField.tsx
View file @
5feef220
...
@@ -29,6 +29,7 @@ export interface QueryFieldProps {
...
@@ -29,6 +29,7 @@ export interface QueryFieldProps {
onRunQuery
?:
()
=>
void
;
onRunQuery
?:
()
=>
void
;
onBlur
?:
()
=>
void
;
onBlur
?:
()
=>
void
;
onChange
?:
(
value
:
string
)
=>
void
;
onChange
?:
(
value
:
string
)
=>
void
;
onRichValueChange
?:
(
value
:
Value
)
=>
void
;
onClick
?:
(
event
:
Event
,
editor
:
CoreEditor
,
next
:
()
=>
any
)
=>
any
;
onClick
?:
(
event
:
Event
,
editor
:
CoreEditor
,
next
:
()
=>
any
)
=>
any
;
onTypeahead
?:
(
typeahead
:
TypeaheadInput
)
=>
Promise
<
TypeaheadOutput
>
;
onTypeahead
?:
(
typeahead
:
TypeaheadInput
)
=>
Promise
<
TypeaheadOutput
>
;
onWillApplySuggestion
?:
(
suggestion
:
string
,
state
:
SuggestionsState
)
=>
string
;
onWillApplySuggestion
?:
(
suggestion
:
string
,
state
:
SuggestionsState
)
=>
string
;
...
@@ -121,6 +122,9 @@ export class QueryField extends React.PureComponent<QueryFieldProps, QueryFieldS
...
@@ -121,6 +122,9 @@ export class QueryField extends React.PureComponent<QueryFieldProps, QueryFieldS
onChange
=
(
value
:
Value
,
runQuery
?:
boolean
)
=>
{
onChange
=
(
value
:
Value
,
runQuery
?:
boolean
)
=>
{
const
documentChanged
=
value
.
document
!==
this
.
state
.
value
.
document
;
const
documentChanged
=
value
.
document
!==
this
.
state
.
value
.
document
;
const
prevValue
=
this
.
state
.
value
;
const
prevValue
=
this
.
state
.
value
;
if
(
this
.
props
.
onRichValueChange
)
{
this
.
props
.
onRichValueChange
(
value
);
}
// Update local state with new value and optionally change value upstream.
// Update local state with new value and optionally change value upstream.
this
.
setState
({
value
},
()
=>
{
this
.
setState
({
value
},
()
=>
{
...
...
public/app/plugins/datasource/cloudwatch/components/LogsQueryField.tsx
View file @
5feef220
// Libraries
// Libraries
import
React
,
{
ReactNode
}
from
'react'
;
import
React
,
{
ReactNode
}
from
'react'
;
import
intersection
from
'lodash/intersection'
;
import
intersection
from
'lodash/intersection'
;
import
debounce
from
'lodash/debounce'
;
import
{
import
{
QueryField
,
QueryField
,
...
@@ -12,10 +13,11 @@ import {
...
@@ -12,10 +13,11 @@ import {
Select
,
Select
,
MultiSelect
,
MultiSelect
,
}
from
'@grafana/ui'
;
}
from
'@grafana/ui'
;
import
Plain
from
'slate-plain-serializer'
;
// Utils & Services
// Utils & Services
// dom also includes Element polyfills
// dom also includes Element polyfills
import
{
Plugin
,
Node
,
Editor
}
from
'slate'
;
import
{
Plugin
,
Node
,
Editor
,
Value
}
from
'slate'
;
import
syntax
from
'../syntax'
;
import
syntax
from
'../syntax'
;
// Types
// Types
...
@@ -140,33 +142,11 @@ export class CloudWatchLogsQueryField extends React.PureComponent<CloudWatchLogs
...
@@ -140,33 +142,11 @@ export class CloudWatchLogsQueryField extends React.PureComponent<CloudWatchLogs
});
});
};
};
onChangeQuery
=
(
value
:
string
,
override
?:
boolean
)
=>
{
onChangeQuery
=
(
value
:
string
)
=>
{
// Send text change to parent
// Send text change to parent
const
{
query
,
onChange
,
onRunQuery
,
datasource
,
exploreMode
}
=
this
.
props
;
const
{
query
,
onChange
}
=
this
.
props
;
const
{
selectedLogGroups
,
selectedRegion
}
=
this
.
state
;
const
{
selectedLogGroups
,
selectedRegion
}
=
this
.
state
;
// TEMP: Remove when logs/metrics unification is complete
if
(
datasource
.
languageProvider
&&
exploreMode
===
ExploreMode
.
Logs
)
{
const
cloudwatchLanguageProvider
=
datasource
.
languageProvider
as
CloudWatchLanguageProvider
;
const
queryUsesStatsCommand
=
cloudwatchLanguageProvider
.
isStatsQuery
(
query
.
expression
);
if
(
queryUsesStatsCommand
)
{
this
.
setState
({
hint
:
{
message
:
'You are trying to run a stats query in Logs mode. '
,
fix
:
{
label
:
'Switch to Metrics mode.'
,
action
:
this
.
switchToMetrics
,
},
},
});
}
else
{
this
.
setState
({
hint
:
undefined
,
});
}
}
if
(
onChange
)
{
if
(
onChange
)
{
const
nextQuery
=
{
const
nextQuery
=
{
...
query
,
...
query
,
...
@@ -175,10 +155,6 @@ export class CloudWatchLogsQueryField extends React.PureComponent<CloudWatchLogs
...
@@ -175,10 +155,6 @@ export class CloudWatchLogsQueryField extends React.PureComponent<CloudWatchLogs
region
:
selectedRegion
.
value
??
'default'
,
region
:
selectedRegion
.
value
??
'default'
,
};
};
onChange
(
nextQuery
);
onChange
(
nextQuery
);
if
(
override
&&
onRunQuery
)
{
onRunQuery
();
}
}
}
};
};
...
@@ -240,12 +216,10 @@ export class CloudWatchLogsQueryField extends React.PureComponent<CloudWatchLogs
...
@@ -240,12 +216,10 @@ export class CloudWatchLogsQueryField extends React.PureComponent<CloudWatchLogs
const
{
history
,
absoluteRange
}
=
this
.
props
;
const
{
history
,
absoluteRange
}
=
this
.
props
;
const
{
prefix
,
text
,
value
,
wrapperClasses
,
labelKey
,
editor
}
=
typeahead
;
const
{
prefix
,
text
,
value
,
wrapperClasses
,
labelKey
,
editor
}
=
typeahead
;
const
result
=
await
cloudwatchLanguageProvider
.
provideCompletionItems
(
return
await
cloudwatchLanguageProvider
.
provideCompletionItems
(
{
text
,
value
,
prefix
,
wrapperClasses
,
labelKey
,
editor
},
{
text
,
value
,
prefix
,
wrapperClasses
,
labelKey
,
editor
},
{
history
,
absoluteRange
,
logGroupNames
:
selectedLogGroups
.
map
(
logGroup
=>
logGroup
.
value
!
)
}
{
history
,
absoluteRange
,
logGroupNames
:
selectedLogGroups
.
map
(
logGroup
=>
logGroup
.
value
!
)
}
);
);
return
result
;
};
};
switchToMetrics
=
()
=>
{
switchToMetrics
=
()
=>
{
...
@@ -282,6 +256,34 @@ export class CloudWatchLogsQueryField extends React.PureComponent<CloudWatchLogs
...
@@ -282,6 +256,34 @@ export class CloudWatchLogsQueryField extends React.PureComponent<CloudWatchLogs
});
});
};
};
/**
* Check if query is stats query in logs mode and shows a hint to switch to metrics mode. Needs to be done
* on update of the rich Value because standard onChange is not called on load for example.
*/
checkForStatsQuery
=
debounce
((
value
:
Value
)
=>
{
const
{
datasource
}
=
this
.
props
;
// TEMP: Remove when logs/metrics unification is complete
if
(
datasource
.
languageProvider
&&
this
.
props
.
exploreMode
===
ExploreMode
.
Logs
)
{
const
cloudwatchLanguageProvider
=
datasource
.
languageProvider
as
CloudWatchLanguageProvider
;
const
queryUsesStatsCommand
=
cloudwatchLanguageProvider
.
isStatsQuery
(
Plain
.
serialize
(
value
));
if
(
queryUsesStatsCommand
)
{
this
.
setState
({
hint
:
{
message
:
'You are trying to run a stats query in Logs mode. '
,
fix
:
{
label
:
'Switch to Metrics mode.'
,
action
:
this
.
switchToMetrics
,
},
},
});
}
else
{
this
.
setState
({
hint
:
undefined
,
});
}
}
},
250
);
render
()
{
render
()
{
const
{
ExtraFieldElement
,
data
,
query
,
syntaxLoaded
,
datasource
}
=
this
.
props
;
const
{
ExtraFieldElement
,
data
,
query
,
syntaxLoaded
,
datasource
}
=
this
.
props
;
const
{
const
{
...
@@ -359,6 +361,7 @@ export class CloudWatchLogsQueryField extends React.PureComponent<CloudWatchLogs
...
@@ -359,6 +361,7 @@ export class CloudWatchLogsQueryField extends React.PureComponent<CloudWatchLogs
portalOrigin=
"cloudwatch"
portalOrigin=
"cloudwatch"
syntaxLoaded=
{
syntaxLoaded
}
syntaxLoaded=
{
syntaxLoaded
}
disabled=
{
loadingLogGroups
||
selectedLogGroups
.
length
===
0
}
disabled=
{
loadingLogGroups
||
selectedLogGroups
.
length
===
0
}
onRichValueChange=
{
this
.
checkForStatsQuery
}
/>
/>
</
div
>
</
div
>
{
ExtraFieldElement
}
{
ExtraFieldElement
}
...
...
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