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
d5a31fa5
Unverified
Commit
d5a31fa5
authored
Jan 06, 2021
by
Domas
Committed by
GitHub
Jan 06, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Plugins: prevent app plugin from rendering with wrong location (#30017)
parent
437cb121
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
1 deletions
+62
-1
public/app/features/plugins/AppRootPage.test.tsx
+58
-1
public/app/features/plugins/AppRootPage.tsx
+4
-0
No files found.
public/app/features/plugins/AppRootPage.test.tsx
View file @
d5a31fa5
import
{
render
,
screen
}
from
'@testing-library/react'
;
import
{
act
,
render
,
screen
}
from
'@testing-library/react'
;
import
React
,
{
Component
}
from
'react'
;
import
{
StoreState
}
from
'app/types'
;
import
{
Provider
}
from
'react-redux'
;
...
...
@@ -8,6 +8,9 @@ import { getPluginSettings } from './PluginSettingsCache';
import
{
importAppPlugin
}
from
'./plugin_loader'
;
import
{
getMockPlugin
}
from
'./__mocks__/pluginMocks'
;
import
{
AppPlugin
,
PluginType
,
AppRootProps
,
NavModelItem
}
from
'@grafana/data'
;
import
{
updateLocation
}
from
'app/core/actions'
;
import
{
createRootReducer
}
from
'app/core/reducers/root'
;
import
{
createStore
}
from
'redux'
;
jest
.
mock
(
'./PluginSettingsCache'
,
()
=>
({
getPluginSettings
:
jest
.
fn
(),
...
...
@@ -110,4 +113,58 @@ describe('AppRootPage', () => {
await
screen
.
findAllByRole
(
'link'
,
{
name
:
/Another page/
});
expect
(
timesMounted
).
toEqual
(
1
);
});
it
(
'should not render component if not at plugin path'
,
async
()
=>
{
getPluginSettingsMock
.
mockResolvedValue
(
getMockPlugin
({
type
:
PluginType
.
app
,
enabled
:
true
,
})
);
let
timesRendered
=
0
;
class
RootComponent
extends
Component
<
AppRootProps
>
{
render
()
{
timesRendered
+=
1
;
return
<
p
>
my great component
</
p
>;
}
}
const
plugin
=
new
AppPlugin
();
plugin
.
root
=
RootComponent
;
importAppPluginMock
.
mockResolvedValue
(
plugin
);
const
store
=
createStore
(
createRootReducer
());
store
.
dispatch
(
updateLocation
({
path
:
'/a/foo'
}));
render
(
<
Provider
store=
{
store
}
>
<
AppRootPage
/>
</
Provider
>
);
await
screen
.
findByText
(
'my great component'
);
// renders the first time
expect
(
timesRendered
).
toEqual
(
1
);
await
act
(
async
()
=>
{
await
store
.
dispatch
(
updateLocation
({
path
:
'/foo'
,
})
);
});
expect
(
timesRendered
).
toEqual
(
1
);
await
act
(
async
()
=>
{
await
store
.
dispatch
(
updateLocation
({
path
:
'/a/foo'
,
})
);
});
expect
(
timesRendered
).
toEqual
(
2
);
});
});
public/app/features/plugins/AppRootPage.tsx
View file @
d5a31fa5
...
...
@@ -50,6 +50,10 @@ class AppRootPage extends Component<Props, State> {
};
}
shouldComponentUpdate
(
nextProps
:
Props
)
{
return
nextProps
.
path
.
startsWith
(
'/a/'
);
}
async
componentDidMount
()
{
const
{
pluginId
}
=
this
.
props
;
...
...
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