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
0de861a3
Commit
0de861a3
authored
Jan 29, 2019
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor progress on react query editor support, solving updating query persisted state
parent
e4244d8b
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
62 additions
and
15 deletions
+62
-15
public/app/core/components/Select/MetricSelect.tsx
+1
-2
public/app/features/dashboard/panel_editor/QueriesTab.tsx
+6
-0
public/app/features/dashboard/panel_editor/QueryEditorRow.tsx
+4
-7
public/app/features/dashboard/panel_model.ts
+13
-0
public/app/plugins/datasource/loki/components/LokiQueryEditor.tsx
+35
-6
public/app/plugins/datasource/loki/types.ts
+3
-0
No files found.
public/app/core/components/Select/MetricSelect.tsx
View file @
0de861a3
import
React
from
'react'
;
import
React
from
'react'
;
import
_
from
'lodash'
;
import
_
from
'lodash'
;
import
{
Select
}
from
'@grafana/ui'
;
import
{
Select
,
SelectOptionItem
}
from
'@grafana/ui'
;
import
{
SelectOptionItem
}
from
'@grafana/ui'
;
import
{
Variable
}
from
'app/types/templates'
;
import
{
Variable
}
from
'app/types/templates'
;
export
interface
Props
{
export
interface
Props
{
...
...
public/app/features/dashboard/panel_editor/QueriesTab.tsx
View file @
0de861a3
...
@@ -165,6 +165,11 @@ export class QueriesTab extends PureComponent<Props, State> {
...
@@ -165,6 +165,11 @@ export class QueriesTab extends PureComponent<Props, State> {
this
.
setState
({
isAddingMixed
:
false
});
this
.
setState
({
isAddingMixed
:
false
});
};
};
onQueryChange
=
(
query
:
DataQuery
,
index
)
=>
{
this
.
props
.
panel
.
changeQuery
(
query
,
index
);
this
.
forceUpdate
();
};
setScrollTop
=
(
event
:
React
.
MouseEvent
<
HTMLElement
>
)
=>
{
setScrollTop
=
(
event
:
React
.
MouseEvent
<
HTMLElement
>
)
=>
{
const
target
=
event
.
target
as
HTMLElement
;
const
target
=
event
.
target
as
HTMLElement
;
this
.
setState
({
scrollTop
:
target
.
scrollTop
});
this
.
setState
({
scrollTop
:
target
.
scrollTop
});
...
@@ -201,6 +206,7 @@ export class QueriesTab extends PureComponent<Props, State> {
...
@@ -201,6 +206,7 @@ export class QueriesTab extends PureComponent<Props, State> {
key=
{
query
.
refId
}
key=
{
query
.
refId
}
panel=
{
panel
}
panel=
{
panel
}
query=
{
query
}
query=
{
query
}
onChange=
{
query
=>
this
.
onQueryChange
(
query
,
index
)
}
onRemoveQuery=
{
this
.
onRemoveQuery
}
onRemoveQuery=
{
this
.
onRemoveQuery
}
onAddQuery=
{
this
.
onAddQuery
}
onAddQuery=
{
this
.
onAddQuery
}
onMoveQuery=
{
this
.
onMoveQuery
}
onMoveQuery=
{
this
.
onMoveQuery
}
...
...
public/app/features/dashboard/panel_editor/QueryEditorRow.tsx
View file @
0de861a3
...
@@ -18,6 +18,7 @@ interface Props {
...
@@ -18,6 +18,7 @@ interface Props {
onAddQuery
:
(
query
?:
DataQuery
)
=>
void
;
onAddQuery
:
(
query
?:
DataQuery
)
=>
void
;
onRemoveQuery
:
(
query
:
DataQuery
)
=>
void
;
onRemoveQuery
:
(
query
:
DataQuery
)
=>
void
;
onMoveQuery
:
(
query
:
DataQuery
,
direction
:
number
)
=>
void
;
onMoveQuery
:
(
query
:
DataQuery
,
direction
:
number
)
=>
void
;
onChange
:
(
query
:
DataQuery
)
=>
void
;
dataSourceValue
:
string
|
null
;
dataSourceValue
:
string
|
null
;
inMixedMode
:
boolean
;
inMixedMode
:
boolean
;
}
}
...
@@ -105,16 +106,12 @@ export class QueryEditorRow extends PureComponent<Props, State> {
...
@@ -105,16 +106,12 @@ export class QueryEditorRow extends PureComponent<Props, State> {
this
.
setState
({
isCollapsed
:
!
this
.
state
.
isCollapsed
});
this
.
setState
({
isCollapsed
:
!
this
.
state
.
isCollapsed
});
};
};
onQueryChange
=
(
query
:
DataQuery
)
=>
{
Object
.
assign
(
this
.
props
.
query
,
query
);
};
onRunQuery
=
()
=>
{
onRunQuery
=
()
=>
{
this
.
props
.
panel
.
refresh
();
this
.
props
.
panel
.
refresh
();
};
};
renderPluginEditor
()
{
renderPluginEditor
()
{
const
{
query
}
=
this
.
props
;
const
{
query
,
onChange
}
=
this
.
props
;
const
{
datasource
}
=
this
.
state
;
const
{
datasource
}
=
this
.
state
;
if
(
datasource
.
pluginExports
.
QueryCtrl
)
{
if
(
datasource
.
pluginExports
.
QueryCtrl
)
{
...
@@ -127,7 +124,7 @@ export class QueryEditorRow extends PureComponent<Props, State> {
...
@@ -127,7 +124,7 @@ export class QueryEditorRow extends PureComponent<Props, State> {
<
QueryEditor
<
QueryEditor
query=
{
query
}
query=
{
query
}
datasource=
{
datasource
}
datasource=
{
datasource
}
onChange=
{
this
.
onQuery
Change
}
onChange=
{
on
Change
}
onRunQuery=
{
this
.
onRunQuery
}
onRunQuery=
{
this
.
onRunQuery
}
/>
/>
);
);
...
@@ -165,7 +162,7 @@ export class QueryEditorRow extends PureComponent<Props, State> {
...
@@ -165,7 +162,7 @@ export class QueryEditorRow extends PureComponent<Props, State> {
onDisableQuery
=
()
=>
{
onDisableQuery
=
()
=>
{
this
.
props
.
query
.
hide
=
!
this
.
props
.
query
.
hide
;
this
.
props
.
query
.
hide
=
!
this
.
props
.
query
.
hide
;
this
.
on
Execute
Query
();
this
.
on
Run
Query
();
this
.
forceUpdate
();
this
.
forceUpdate
();
};
};
...
...
public/app/features/dashboard/panel_model.ts
View file @
0de861a3
...
@@ -268,6 +268,19 @@ export class PanelModel {
...
@@ -268,6 +268,19 @@ export class PanelModel {
});
});
}
}
changeQuery
(
query
:
DataQuery
,
index
:
number
)
{
// ensure refId is maintained
query
.
refId
=
this
.
targets
[
index
].
refId
;
// update query in array
this
.
targets
=
this
.
targets
.
map
((
item
,
itemIndex
)
=>
{
if
(
itemIndex
===
index
)
{
return
query
;
}
return
item
;
});
}
destroy
()
{
destroy
()
{
this
.
events
.
emit
(
'panel-teardown'
);
this
.
events
.
emit
(
'panel-teardown'
);
this
.
events
.
removeAllListeners
();
this
.
events
.
removeAllListeners
();
...
...
public/app/plugins/datasource/loki/components/LokiQueryEditor.tsx
View file @
0de861a3
// Libraries
// Libraries
import
React
,
{
PureComponent
}
from
'react'
;
import
React
,
{
PureComponent
}
from
'react'
;
// Components
import
{
Select
,
SelectOptionItem
}
from
'@grafana/ui'
;
// Types
// Types
import
{
QueryEditorProps
}
from
'@grafana/ui/src/types'
;
import
{
QueryEditorProps
}
from
'@grafana/ui/src/types'
;
import
{
LokiDatasource
}
from
'../datasource'
;
import
{
LokiDatasource
}
from
'../datasource'
;
...
@@ -14,13 +17,12 @@ interface State {
...
@@ -14,13 +17,12 @@ interface State {
}
}
export
class
LokiQueryEditor
extends
PureComponent
<
Props
>
{
export
class
LokiQueryEditor
extends
PureComponent
<
Props
>
{
state
:
State
=
{
state
:
State
=
{
query
:
this
.
props
.
query
query
:
this
.
props
.
query
,
};
};
onRunQuery
=
()
=>
{
onRunQuery
=
()
=>
{
const
{
query
}
=
this
.
state
;
const
{
query
}
=
this
.
state
;
this
.
props
.
onChange
(
query
);
this
.
props
.
onChange
(
query
);
this
.
props
.
onRunQuery
();
this
.
props
.
onRunQuery
();
...
@@ -28,17 +30,44 @@ export class LokiQueryEditor extends PureComponent<Props> {
...
@@ -28,17 +30,44 @@ export class LokiQueryEditor extends PureComponent<Props> {
onFieldChange
=
(
query
:
LokiQuery
,
override
?)
=>
{
onFieldChange
=
(
query
:
LokiQuery
,
override
?)
=>
{
this
.
setState
({
this
.
setState
({
query
:
query
query
:
{
...
this
.
state
.
query
,
expr
:
query
.
expr
,
}
});
};
onFormatChanged
=
(
option
:
SelectOptionItem
)
=>
{
this
.
props
.
onChange
({
...
this
.
state
.
query
,
resultFormat
:
option
.
value
,
});
});
};
};
render
()
{
render
()
{
const
{
query
}
=
this
.
state
;
const
{
query
}
=
this
.
state
;
const
{
datasource
}
=
this
.
props
;
const
{
datasource
}
=
this
.
props
;
const
formatOptions
:
SelectOptionItem
[]
=
[
{
label
:
'Time Series'
,
value
:
'time_series'
},
{
label
:
'Table'
,
value
:
'table'
},
{
label
:
'Logs'
,
value
:
'logs'
},
];
query
.
resultFormat
=
query
.
resultFormat
||
'time_series'
;
const
currentFormat
=
formatOptions
.
find
(
item
=>
item
.
value
===
query
.
resultFormat
);
return
(
return
(
<
div
>
<
div
>
<
LokiQueryField
datasource=
{
datasource
}
initialQuery=
{
query
}
onQueryChange=
{
this
.
onFieldChange
}
onPressEnter=
{
this
.
onRunQuery
}
/>
<
LokiQueryField
datasource=
{
datasource
}
initialQuery=
{
query
}
onQueryChange=
{
this
.
onFieldChange
}
onPressEnter=
{
this
.
onRunQuery
}
/>
<
div
className=
"gf-form"
>
<
div
className=
"gf-form-label"
>
Format as
</
div
>
<
Select
isSearchable=
{
false
}
options=
{
formatOptions
}
onChange=
{
this
.
onFormatChanged
}
value=
{
currentFormat
}
/>
</
div
>
</
div
>
</
div
>
);
);
}
}
...
...
public/app/plugins/datasource/loki/types.ts
View file @
0de861a3
...
@@ -2,5 +2,8 @@ import { DataQuery } from '@grafana/ui/src/types';
...
@@ -2,5 +2,8 @@ import { DataQuery } from '@grafana/ui/src/types';
export
interface
LokiQuery
extends
DataQuery
{
export
interface
LokiQuery
extends
DataQuery
{
expr
:
string
;
expr
:
string
;
resultFormat
?:
LokiQueryResultFormats
;
}
}
export
type
LokiQueryResultFormats
=
'time_series'
|
'logs'
;
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