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
08eee871
Unverified
Commit
08eee871
authored
Feb 01, 2021
by
Hugo Häggmark
Committed by
GitHub
Feb 01, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Panels: Fixes so panels are refreshed when scrolling past them fast (#30784)
parent
820866e4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
81 additions
and
0 deletions
+81
-0
public/app/features/dashboard/dashgrid/PanelChrome.test.tsx
+80
-0
public/app/features/dashboard/dashgrid/PanelChrome.tsx
+1
-0
No files found.
public/app/features/dashboard/dashgrid/PanelChrome.test.tsx
0 → 100644
View file @
08eee871
import
React
,
{
FC
}
from
'react'
;
import
{
ReplaySubject
}
from
'rxjs'
;
import
{
act
,
render
,
screen
}
from
'@testing-library/react'
;
import
{
getDefaultTimeRange
,
LoadingState
,
PanelData
,
PanelPlugin
,
PanelProps
}
from
'@grafana/data'
;
import
{
PanelChrome
,
Props
}
from
'./PanelChrome'
;
import
{
DashboardModel
,
PanelModel
}
from
'../state'
;
import
{
updateLocation
}
from
'../../../core/actions'
;
import
{
PanelQueryRunner
}
from
'../../query/state/PanelQueryRunner'
;
import
{
setTimeSrv
,
TimeSrv
}
from
'../services/TimeSrv'
;
jest
.
mock
(
'app/core/profiler'
,
()
=>
({
profiler
:
{
renderingCompleted
:
jest
.
fn
(),
},
}));
function
setupTestContext
(
options
:
Partial
<
Props
>
)
{
const
subject
:
ReplaySubject
<
PanelData
>
=
new
ReplaySubject
<
PanelData
>
();
const
panelQueryRunner
=
({
getData
:
()
=>
subject
,
run
:
()
=>
{
subject
.
next
({
state
:
LoadingState
.
Done
,
series
:
[],
timeRange
:
getDefaultTimeRange
()
});
},
}
as
unknown
)
as
PanelQueryRunner
;
const
timeSrv
=
({
timeRange
:
jest
.
fn
(),
}
as
unknown
)
as
TimeSrv
;
setTimeSrv
(
timeSrv
);
const
defaults
:
Props
=
{
panel
:
({
hasTitle
:
jest
.
fn
(),
replaceVariables
:
jest
.
fn
(),
events
:
{
subscribe
:
jest
.
fn
()
},
getQueryRunner
:
()
=>
panelQueryRunner
,
getOptions
:
jest
.
fn
(),
}
as
unknown
)
as
PanelModel
,
dashboard
:
({
panelInitialized
:
jest
.
fn
(),
getTimezone
:
()
=>
'browser'
,
}
as
unknown
)
as
DashboardModel
,
plugin
:
({
meta
:
{
skipDataQuery
:
false
},
panel
:
TestPanelComponent
,
}
as
unknown
)
as
PanelPlugin
,
isViewing
:
true
,
isEditing
:
false
,
isInView
:
false
,
width
:
100
,
height
:
100
,
updateLocation
:
(
jest
.
fn
()
as
unknown
)
as
typeof
updateLocation
,
};
const
props
=
{
...
defaults
,
...
options
};
const
{
rerender
}
=
render
(<
PanelChrome
{
...
props
}
/>);
return
{
rerender
,
props
,
subject
};
}
describe
(
'PanelChrome'
,
()
=>
{
describe
(
'when the user scrolls by a panel so fast that it starts loading data but scrolls out of view'
,
()
=>
{
it
(
'then it should load the panel successfully when scrolled into view again'
,
()
=>
{
const
{
rerender
,
props
,
subject
}
=
setupTestContext
({});
expect
(
screen
.
queryByText
(
/plugin panel to render/i
)).
not
.
toBeInTheDocument
();
act
(()
=>
{
subject
.
next
({
state
:
LoadingState
.
Loading
,
series
:
[],
timeRange
:
getDefaultTimeRange
()
});
subject
.
next
({
state
:
LoadingState
.
Done
,
series
:
[],
timeRange
:
getDefaultTimeRange
()
});
});
const
newProps
=
{
...
props
,
isInView
:
true
};
rerender
(<
PanelChrome
{
...
newProps
}
/>);
expect
(
screen
.
getByText
(
/plugin panel to render/i
)).
toBeInTheDocument
();
});
});
});
const
TestPanelComponent
:
FC
<
PanelProps
>
=
()
=>
<
div
>
Plugin Panel to Render
</
div
>;
public/app/features/dashboard/dashgrid/PanelChrome.tsx
View file @
08eee871
...
...
@@ -140,6 +140,7 @@ export class PanelChrome extends Component<Props, State> {
if
(
!
this
.
props
.
isInView
)
{
// Ignore events when not visible.
// The call will be repeated when the panel comes into view
this
.
setState
({
refreshWhenInView
:
true
});
return
;
}
...
...
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