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
33acf4c0
Unverified
Commit
33acf4c0
authored
Jul 10, 2020
by
Ryan McKinley
Committed by
GitHub
Jul 10, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Flux: use monaco query editor (#26179)
parent
c1ede4fc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
113 additions
and
36 deletions
+113
-36
public/app/plugins/datasource/influxdb/components/FluxQueryEditor.tsx
+106
-32
public/app/plugins/datasource/influxdb/datasource.ts
+7
-0
public/app/plugins/datasource/influxdb/query_ctrl.ts
+0
-4
No files found.
public/app/plugins/datasource/influxdb/components/FluxQueryEditor.tsx
View file @
33acf4c0
import
React
,
{
Component
}
from
'react'
;
import
React
,
{
Pure
Component
}
from
'react'
;
import
coreModule
from
'app/core/core_module'
;
import
{
InfluxQuery
}
from
'../types'
;
import
{
SelectableValue
}
from
'@grafana/data'
;
import
{
InlineFormLabel
,
LinkButton
,
Segment
,
TextArea
}
from
'@grafana/ui'
;
import
{
cx
,
css
}
from
'emotion'
;
import
{
InlineFormLabel
,
LinkButton
,
Segment
,
CodeEditor
,
CodeEditorSuggestionItem
,
CodeEditorSuggestionItemKind
,
}
from
'@grafana/ui'
;
import
{
getTemplateSrv
}
from
'@grafana/runtime'
;
interface
Props
{
target
:
InfluxQuery
;
...
...
@@ -76,13 +85,10 @@ v1.tagValues(
},
];
export
class
FluxQueryEditor
extends
Component
<
Props
>
{
onFluxQueryChange
=
(
e
:
any
)
=>
{
export
class
FluxQueryEditor
extends
Pure
Component
<
Props
>
{
onFluxQueryChange
=
(
query
:
string
)
=>
{
const
{
target
,
change
}
=
this
.
props
;
change
({
...
target
,
query
:
e
.
currentTarget
.
value
});
};
onFluxBlur
=
(
e
:
any
)
=>
{
change
({
...
target
,
query
});
this
.
props
.
refresh
();
};
...
...
@@ -97,37 +103,105 @@ export class FluxQueryEditor extends Component<Props> {
this
.
props
.
refresh
();
};
getSuggestions
=
():
CodeEditorSuggestionItem
[]
=>
{
const
sugs
:
CodeEditorSuggestionItem
[]
=
[
{
label
:
'v.timeRangeStart'
,
kind
:
CodeEditorSuggestionItemKind
.
Property
,
detail
:
'The start time'
,
},
{
label
:
'v.timeRangeStop'
,
kind
:
CodeEditorSuggestionItemKind
.
Property
,
detail
:
'The stop time'
,
},
{
label
:
'v.windowPeriod'
,
kind
:
CodeEditorSuggestionItemKind
.
Property
,
detail
:
'based on max data points'
,
},
{
label
:
'v.defaultBucket'
,
kind
:
CodeEditorSuggestionItemKind
.
Property
,
detail
:
'bucket configured in the datsource'
,
},
{
label
:
'v.organization'
,
kind
:
CodeEditorSuggestionItemKind
.
Property
,
detail
:
'org configured for the datsource'
,
},
];
const
templateSrv
=
getTemplateSrv
();
templateSrv
.
getVariables
().
forEach
(
variable
=>
{
const
label
=
'${'
+
variable
.
name
+
'}'
;
let
val
=
templateSrv
.
replace
(
label
);
if
(
val
===
label
)
{
val
=
''
;
}
sugs
.
push
({
label
,
kind
:
CodeEditorSuggestionItemKind
.
Text
,
detail
:
`(Template Variable)
${
val
}
`
,
});
});
return
sugs
;
};
// For some reason in angular, when this component gets re-mounted, the width
// is not set properly. This forces the layout shorly after mount so that it
// displays OK. Note: this is not an issue when used directly in react
editorDidMountCallbackHack
=
(
editor
:
any
)
=>
{
setTimeout
(()
=>
editor
.
layout
(),
100
);
};
render
()
{
const
{
target
}
=
this
.
props
;
const
helpTooltip
=
(
<
div
>
Type:
<
i
>
ctrl+space
</
i
>
to show template variable suggestions
<
br
/>
Many queries can be copied from chronograph
</
div
>
);
return
(
<>
<
div
className=
"gf-form"
>
<
TextArea
value=
{
target
.
query
||
''
}
onChange=
{
this
.
onFluxQueryChange
}
onBlur=
{
this
.
onFluxBlur
}
placeholder=
"Flux query"
rows=
{
10
}
/>
</
div
>
<
div
className=
"gf-form-inline"
>
<
div
className=
"gf-form"
>
<
InlineFormLabel
width=
{
5
}
tooltip=
"Queries can be copied from chronograph"
>
Help
</
InlineFormLabel
>
<
Segment
options=
{
samples
}
value=
"Sample Query"
onChange=
{
this
.
onSampleChange
}
/>
<
LinkButton
icon=
"external-link-alt"
variant=
"secondary"
target=
"blank"
href=
"https://docs.influxdata.com/flux/latest/introduction/getting-started/"
>
Flux docs
</
LinkButton
>
</
div
>
<
CodeEditor
height=
{
'200px'
}
language=
"sql"
value=
{
target
.
query
||
''
}
onBlur=
{
this
.
onFluxQueryChange
}
onSave=
{
this
.
onFluxQueryChange
}
showMiniMap=
{
false
}
showLineNumbers=
{
true
}
getSuggestions=
{
this
.
getSuggestions
}
onEditorDidMount=
{
this
.
editorDidMountCallbackHack
}
/>
<
div
className=
{
cx
(
'gf-form-inline'
,
css
`
margin-top: 6px;
`
)
}
>
<
LinkButton
icon=
"external-link-alt"
variant=
"secondary"
target=
"blank"
href=
"https://docs.influxdata.com/flux/latest/introduction/getting-started/"
>
Flux language syntax
</
LinkButton
>
<
Segment
options=
{
samples
}
value=
"Sample Query"
onChange=
{
this
.
onSampleChange
}
/>
<
div
className=
"gf-form gf-form--grow"
>
<
div
className=
"gf-form-label gf-form-label--grow"
></
div
>
</
div
>
<
InlineFormLabel
width=
{
5
}
tooltip=
{
helpTooltip
}
>
Help
</
InlineFormLabel
>
</
div
>
</>
);
...
...
public/app/plugins/datasource/influxdb/datasource.ts
View file @
33acf4c0
...
...
@@ -62,6 +62,13 @@ export default class InfluxDatasource extends DataSourceWithBackend<InfluxQuery,
return
from
(
this
.
classicQuery
(
request
));
}
getQueryDisplayText
(
query
:
InfluxQuery
)
{
if
(
this
.
is2x
)
{
return
query
.
query
;
}
return
new
InfluxQueryModel
(
query
).
render
(
false
);
}
/**
* Only applied on flux queries
*/
...
...
public/app/plugins/datasource/influxdb/query_ctrl.ts
View file @
33acf4c0
...
...
@@ -420,8 +420,4 @@ export class InfluxQueryCtrl extends QueryCtrl {
}
return
null
;
}
getCollapsedText
()
{
return
this
.
queryModel
.
render
(
false
);
}
}
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