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
7e3ac4eb
Unverified
Commit
7e3ac4eb
authored
May 20, 2019
by
Ryan McKinley
Committed by
GitHub
May 20, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
AppPlugin: add an init function (#17150)
parent
458bb3b0
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
77 additions
and
1 deletions
+77
-1
packages/grafana-ui/src/types/app.ts
+7
-0
public/app/features/plugins/plugin_loader.test.ts
+68
-0
public/app/features/plugins/plugin_loader.ts
+2
-1
No files found.
packages/grafana-ui/src/types/app.ts
View file @
7e3ac4eb
...
@@ -27,6 +27,13 @@ export class AppPlugin extends GrafanaPlugin<AppPluginMeta> {
...
@@ -27,6 +27,13 @@ export class AppPlugin extends GrafanaPlugin<AppPluginMeta> {
angularPages
?:
{
[
component
:
string
]:
any
};
angularPages
?:
{
[
component
:
string
]:
any
};
/**
/**
* Called after the module has loaded, and before the app is used.
* This function may be called multiple times on the same instance.
* The first time, `this.meta` will be undefined
*/
init
(
meta
:
AppPluginMeta
)
{}
/**
* Set the component displayed under:
* Set the component displayed under:
* /a/${plugin-id}/*
* /a/${plugin-id}/*
*/
*/
...
...
public/app/features/plugins/plugin_loader.test.ts
0 → 100644
View file @
7e3ac4eb
// Use the real plugin_loader (stubbed by default)
jest
.
unmock
(
'app/features/plugins/plugin_loader'
);
(
global
as
any
).
ace
=
{
define
:
jest
.
fn
(),
};
jest
.
mock
(
'app/core/core'
,
()
=>
{
return
{
coreModule
:
{
directive
:
jest
.
fn
(),
},
};
});
/* tslint:disable:import-blacklist */
import
System
from
'systemjs/dist/system.js'
;
import
{
AppPluginMeta
,
PluginMetaInfo
,
PluginType
,
AppPlugin
}
from
'@grafana/ui'
;
import
{
importAppPlugin
}
from
'./plugin_loader'
;
class
MyCustomApp
extends
AppPlugin
{
initWasCalled
=
false
;
calledTwice
=
false
;
init
(
meta
:
AppPluginMeta
)
{
this
.
initWasCalled
=
true
;
this
.
calledTwice
=
this
.
meta
===
meta
;
}
}
describe
(
'Load App'
,
()
=>
{
const
app
=
new
MyCustomApp
();
const
modulePath
=
'my/custom/plugin/module'
;
beforeAll
(()
=>
{
System
.
set
(
modulePath
,
System
.
newModule
({
plugin
:
app
}));
});
afterAll
(()
=>
{
System
.
delete
(
modulePath
);
});
it
(
'should call init and set meta'
,
async
()
=>
{
const
meta
:
AppPluginMeta
=
{
id
:
'test-app'
,
module
:
modulePath
,
baseUrl
:
'xxx'
,
info
:
{}
as
PluginMetaInfo
,
type
:
PluginType
.
app
,
name
:
'test'
,
};
// Check that we mocked the import OK
const
m
=
await
System
.
import
(
modulePath
);
expect
(
m
.
plugin
).
toBe
(
app
);
const
loaded
=
await
importAppPlugin
(
meta
);
expect
(
loaded
).
toBe
(
app
);
expect
(
app
.
meta
).
toBe
(
meta
);
expect
(
app
.
initWasCalled
).
toBeTruthy
();
expect
(
app
.
calledTwice
).
toBeFalsy
();
const
again
=
await
importAppPlugin
(
meta
);
expect
(
again
).
toBe
(
app
);
expect
(
app
.
calledTwice
).
toBeTruthy
();
});
});
public/app/features/plugins/plugin_loader.ts
View file @
7e3ac4eb
...
@@ -181,8 +181,9 @@ export function importDataSourcePlugin(meta: DataSourcePluginMeta): Promise<Data
...
@@ -181,8 +181,9 @@ export function importDataSourcePlugin(meta: DataSourcePluginMeta): Promise<Data
export
function
importAppPlugin
(
meta
:
PluginMeta
):
Promise
<
AppPlugin
>
{
export
function
importAppPlugin
(
meta
:
PluginMeta
):
Promise
<
AppPlugin
>
{
return
importPluginModule
(
meta
.
module
).
then
(
pluginExports
=>
{
return
importPluginModule
(
meta
.
module
).
then
(
pluginExports
=>
{
const
plugin
=
pluginExports
.
plugin
?
(
pluginExports
.
plugin
as
AppPlugin
)
:
new
AppPlugin
();
const
plugin
=
pluginExports
.
plugin
?
(
pluginExports
.
plugin
as
AppPlugin
)
:
new
AppPlugin
();
plugin
.
meta
=
meta
;
plugin
.
setComponentsFromLegacyExports
(
pluginExports
);
plugin
.
setComponentsFromLegacyExports
(
pluginExports
);
plugin
.
init
(
meta
);
plugin
.
meta
=
meta
;
return
plugin
;
return
plugin
;
});
});
}
}
...
...
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