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
885274bd
Unverified
Commit
885274bd
authored
Dec 28, 2020
by
Hugo Häggmark
Committed by
GitHub
Dec 28, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Graph: Fixes so users can not add annotations in readonly dash (#29990)
parent
7c3f6937
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
12 deletions
+57
-12
public/app/plugins/panel/graph/graph.ts
+14
-11
public/app/plugins/panel/graph/specs/graph.test.ts
+43
-1
No files found.
public/app/plugins/panel/graph/graph.ts
View file @
885274bd
...
...
@@ -24,7 +24,7 @@ import ReactDOM from 'react-dom';
import
{
GraphLegendProps
,
Legend
}
from
'./Legend/Legend'
;
import
{
GraphCtrl
}
from
'./module'
;
import
{
MenuItem
,
MenuItemsGroup
,
graphTimeFormat
,
graphTickFormatter
,
IconName
}
from
'@grafana/ui'
;
import
{
graphTickFormatter
,
graphTimeFormat
,
IconName
,
MenuItem
,
MenuItemsGroup
}
from
'@grafana/ui'
;
import
{
getCurrentTheme
,
provideTheme
}
from
'app/core/utils/ConfigProvider'
;
import
{
DataFrame
,
...
...
@@ -47,6 +47,7 @@ import { GraphContextMenuCtrl } from './GraphContextMenuCtrl';
import
{
TimeSrv
}
from
'app/features/dashboard/services/TimeSrv'
;
import
{
ContextSrv
}
from
'app/core/services/context_srv'
;
import
{
getFieldLinksSupplier
}
from
'app/features/panel/panellinks/linkSuppliers'
;
import
{
DashboardModel
}
from
'../../../features/dashboard/state'
;
const
LegendWithThemeProvider
=
provideTheme
(
Legend
);
...
...
@@ -54,7 +55,7 @@ class GraphElement {
ctrl
:
GraphCtrl
;
contextMenu
:
GraphContextMenuCtrl
;
tooltip
:
any
;
dashboard
:
any
;
dashboard
:
DashboardModel
;
annotations
:
object
[];
panel
:
any
;
plot
:
any
;
...
...
@@ -200,17 +201,19 @@ class GraphElement {
):
(()
=>
MenuItemsGroup
[])
=>
{
return
()
=>
{
// Fixed context menu items
const
items
:
MenuItemsGroup
[]
=
[
{
items
:
[
const
items
:
MenuItemsGroup
[]
=
this
.
dashboard
?.
editable
?
[
{
label
:
'Add annotation'
,
icon
:
'comment-alt'
,
onClick
:
()
=>
this
.
eventManager
.
updateTime
({
from
:
flotPosition
.
x
,
to
:
null
}),
items
:
[
{
label
:
'Add annotation'
,
icon
:
'comment-alt'
,
onClick
:
()
=>
this
.
eventManager
.
updateTime
({
from
:
flotPosition
.
x
,
to
:
null
}),
},
],
},
],
},
];
]
:
[];
if
(
!
linksSupplier
)
{
return
items
;
...
...
public/app/plugins/panel/graph/specs/graph.test.ts
View file @
885274bd
...
...
@@ -24,7 +24,7 @@ import config from 'app/core/config';
import
TimeSeries
from
'app/core/time_series2'
;
import
$
from
'jquery'
;
import
{
graphDirective
}
from
'../graph'
;
import
{
graphDirective
,
GraphElement
}
from
'../graph'
;
import
{
dateTime
,
EventBusSrv
}
from
'@grafana/data'
;
const
ctx
=
{}
as
any
;
...
...
@@ -1286,4 +1286,46 @@ describe('grafanaGraph', () => {
).
toBe
(
300
);
});
});
describe
(
'getContextMenuItemsSupplier'
,
()
=>
{
function
getGraphElement
({
editable
}:
{
editable
?:
boolean
}
=
{})
{
const
element
=
new
GraphElement
(
{
ctrl
:
{
contextMenuCtrl
:
{},
dashboard
:
{
editable
,
events
:
{
on
:
jest
.
fn
()
}
},
events
:
{
on
:
jest
.
fn
()
},
},
},
{
mouseleave
:
jest
.
fn
(),
bind
:
jest
.
fn
()
}
as
any
,
{}
as
any
);
return
element
;
}
describe
(
'when called and dashboard is editable'
,
()
=>
{
it
(
'then the correct menu items should be returned'
,
()
=>
{
const
element
=
getGraphElement
({
editable
:
true
});
const
result
=
element
.
getContextMenuItemsSupplier
({
x
:
1
,
y
:
1
})();
expect
(
result
.
length
).
toEqual
(
1
);
expect
(
result
[
0
].
items
.
length
).
toEqual
(
1
);
expect
(
result
[
0
].
items
[
0
].
label
).
toEqual
(
'Add annotation'
);
expect
(
result
[
0
].
items
[
0
].
icon
).
toEqual
(
'comment-alt'
);
expect
(
result
[
0
].
items
[
0
].
onClick
).
toBeDefined
();
});
});
describe
(
'when called and dashboard is not editable'
,
()
=>
{
it
(
'then the correct menu items should be returned'
,
()
=>
{
const
element
=
getGraphElement
({
editable
:
false
});
const
result
=
element
.
getContextMenuItemsSupplier
({
x
:
1
,
y
:
1
})();
expect
(
result
.
length
).
toEqual
(
0
);
});
});
});
});
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