|
@@ -29,6 +29,7 @@ import { AppConfigCtrlWrapper } from './wrappers/AppConfigWrapper';
|
|
|
import { PluginDashboards } from './PluginDashboards';
|
|
import { PluginDashboards } from './PluginDashboards';
|
|
|
import { appEvents } from 'app/core/core';
|
|
import { appEvents } from 'app/core/core';
|
|
|
import { config } from 'app/core/config';
|
|
import { config } from 'app/core/config';
|
|
|
|
|
+import { ContextSrv } from '../../core/services/context_srv';
|
|
|
|
|
|
|
|
export function getLoadingNav(): NavModel {
|
|
export function getLoadingNav(): NavModel {
|
|
|
const node = {
|
|
const node = {
|
|
@@ -69,6 +70,7 @@ interface Props {
|
|
|
pluginId: string;
|
|
pluginId: string;
|
|
|
query: UrlQueryMap;
|
|
query: UrlQueryMap;
|
|
|
path: string; // the URL path
|
|
path: string; // the URL path
|
|
|
|
|
+ $contextSrv: ContextSrv;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
interface State {
|
|
interface State {
|
|
@@ -93,7 +95,7 @@ class PluginPage extends PureComponent<Props, State> {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async componentDidMount() {
|
|
async componentDidMount() {
|
|
|
- const { pluginId, path, query } = this.props;
|
|
|
|
|
|
|
+ const { pluginId, path, query, $contextSrv } = this.props;
|
|
|
const { appSubUrl } = config;
|
|
const { appSubUrl } = config;
|
|
|
|
|
|
|
|
const plugin = await loadPlugin(pluginId);
|
|
const plugin = await loadPlugin(pluginId);
|
|
@@ -105,97 +107,16 @@ class PluginPage extends PureComponent<Props, State> {
|
|
|
return; // 404
|
|
return; // 404
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const { meta } = plugin;
|
|
|
|
|
- let defaultPage: string;
|
|
|
|
|
- const pages: NavModelItem[] = [];
|
|
|
|
|
-
|
|
|
|
|
- if (true) {
|
|
|
|
|
- pages.push({
|
|
|
|
|
- text: 'Readme',
|
|
|
|
|
- icon: 'fa fa-fw fa-file-text-o',
|
|
|
|
|
- url: `${appSubUrl}${path}?page=${PAGE_ID_README}`,
|
|
|
|
|
- id: PAGE_ID_README,
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Only show Config/Pages for app
|
|
|
|
|
- if (meta.type === PluginType.app) {
|
|
|
|
|
- // Legacy App Config
|
|
|
|
|
- if (plugin.angularConfigCtrl) {
|
|
|
|
|
- pages.push({
|
|
|
|
|
- text: 'Config',
|
|
|
|
|
- icon: 'gicon gicon-cog',
|
|
|
|
|
- url: `${appSubUrl}${path}?page=${PAGE_ID_CONFIG_CTRL}`,
|
|
|
|
|
- id: PAGE_ID_CONFIG_CTRL,
|
|
|
|
|
- });
|
|
|
|
|
- defaultPage = PAGE_ID_CONFIG_CTRL;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (plugin.configPages) {
|
|
|
|
|
- for (const page of plugin.configPages) {
|
|
|
|
|
- pages.push({
|
|
|
|
|
- text: page.title,
|
|
|
|
|
- icon: page.icon,
|
|
|
|
|
- url: path + '?page=' + page.id,
|
|
|
|
|
- id: page.id,
|
|
|
|
|
- });
|
|
|
|
|
- if (!defaultPage) {
|
|
|
|
|
- defaultPage = page.id;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Check for the dashboard pages
|
|
|
|
|
- if (find(meta.includes, { type: 'dashboard' })) {
|
|
|
|
|
- pages.push({
|
|
|
|
|
- text: 'Dashboards',
|
|
|
|
|
- icon: 'gicon gicon-dashboard',
|
|
|
|
|
- url: `${appSubUrl}${path}?page=${PAGE_ID_DASHBOARDS}`,
|
|
|
|
|
- id: PAGE_ID_DASHBOARDS,
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (!defaultPage) {
|
|
|
|
|
- defaultPage = pages[0].id; // the first tab
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- const node = {
|
|
|
|
|
- text: meta.name,
|
|
|
|
|
- img: meta.info.logos.large,
|
|
|
|
|
- subTitle: meta.info.author.name,
|
|
|
|
|
- breadcrumbs: [{ title: 'Plugins', url: '/plugins' }],
|
|
|
|
|
- url: `${appSubUrl}${path}`,
|
|
|
|
|
- children: this.setActivePage(query.page as string, pages, defaultPage),
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ const { defaultPage, nav } = getPluginTabsNav(plugin, appSubUrl, path, query, $contextSrv.hasRole('Admin'));
|
|
|
|
|
|
|
|
this.setState({
|
|
this.setState({
|
|
|
loading: false,
|
|
loading: false,
|
|
|
plugin,
|
|
plugin,
|
|
|
defaultPage,
|
|
defaultPage,
|
|
|
- nav: {
|
|
|
|
|
- node: node,
|
|
|
|
|
- main: node,
|
|
|
|
|
- },
|
|
|
|
|
|
|
+ nav,
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- setActivePage(pageId: string, pages: NavModelItem[], defaultPageId: string): NavModelItem[] {
|
|
|
|
|
- let found = false;
|
|
|
|
|
- const selected = pageId || defaultPageId;
|
|
|
|
|
- const changed = pages.map(p => {
|
|
|
|
|
- const active = !found && selected === p.id;
|
|
|
|
|
- if (active) {
|
|
|
|
|
- found = true;
|
|
|
|
|
- }
|
|
|
|
|
- return { ...p, active };
|
|
|
|
|
- });
|
|
|
|
|
- if (!found) {
|
|
|
|
|
- changed[0].active = true;
|
|
|
|
|
- }
|
|
|
|
|
- return changed;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
componentDidUpdate(prevProps: Props) {
|
|
componentDidUpdate(prevProps: Props) {
|
|
|
const prevPage = prevProps.query.page as string;
|
|
const prevPage = prevProps.query.page as string;
|
|
|
const page = this.props.query.page as string;
|
|
const page = this.props.query.page as string;
|
|
@@ -203,7 +124,7 @@ class PluginPage extends PureComponent<Props, State> {
|
|
|
const { nav, defaultPage } = this.state;
|
|
const { nav, defaultPage } = this.state;
|
|
|
const node = {
|
|
const node = {
|
|
|
...nav.node,
|
|
...nav.node,
|
|
|
- children: this.setActivePage(page, nav.node.children, defaultPage),
|
|
|
|
|
|
|
+ children: setActivePage(page, nav.node.children, defaultPage),
|
|
|
};
|
|
};
|
|
|
this.setState({
|
|
this.setState({
|
|
|
nav: {
|
|
nav: {
|
|
@@ -369,6 +290,8 @@ class PluginPage extends PureComponent<Props, State> {
|
|
|
|
|
|
|
|
render() {
|
|
render() {
|
|
|
const { loading, nav, plugin } = this.state;
|
|
const { loading, nav, plugin } = this.state;
|
|
|
|
|
+ const { $contextSrv } = this.props;
|
|
|
|
|
+ const isAdmin = $contextSrv.hasRole('Admin');
|
|
|
return (
|
|
return (
|
|
|
<Page navModel={nav}>
|
|
<Page navModel={nav}>
|
|
|
<Page.Contents isLoading={loading}>
|
|
<Page.Contents isLoading={loading}>
|
|
@@ -379,7 +302,7 @@ class PluginPage extends PureComponent<Props, State> {
|
|
|
{plugin && (
|
|
{plugin && (
|
|
|
<section className="page-sidebar-section">
|
|
<section className="page-sidebar-section">
|
|
|
{this.renderVersionInfo(plugin.meta)}
|
|
{this.renderVersionInfo(plugin.meta)}
|
|
|
- {this.renderSidebarIncludes(plugin.meta.includes)}
|
|
|
|
|
|
|
+ {isAdmin && this.renderSidebarIncludes(plugin.meta.includes)}
|
|
|
{this.renderSidebarDependencies(plugin.meta.dependencies)}
|
|
{this.renderSidebarDependencies(plugin.meta.dependencies)}
|
|
|
{this.renderSidebarLinks(plugin.meta.info)}
|
|
{this.renderSidebarLinks(plugin.meta.info)}
|
|
|
</section>
|
|
</section>
|
|
@@ -393,6 +316,106 @@ class PluginPage extends PureComponent<Props, State> {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+function getPluginTabsNav(
|
|
|
|
|
+ plugin: GrafanaPlugin,
|
|
|
|
|
+ appSubUrl: string,
|
|
|
|
|
+ path: string,
|
|
|
|
|
+ query: UrlQueryMap,
|
|
|
|
|
+ isAdmin: boolean
|
|
|
|
|
+): { defaultPage: string; nav: NavModel } {
|
|
|
|
|
+ const { meta } = plugin;
|
|
|
|
|
+ let defaultPage: string;
|
|
|
|
|
+ const pages: NavModelItem[] = [];
|
|
|
|
|
+
|
|
|
|
|
+ if (true) {
|
|
|
|
|
+ pages.push({
|
|
|
|
|
+ text: 'Readme',
|
|
|
|
|
+ icon: 'fa fa-fw fa-file-text-o',
|
|
|
|
|
+ url: `${appSubUrl}${path}?page=${PAGE_ID_README}`,
|
|
|
|
|
+ id: PAGE_ID_README,
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // We allow non admins to see plugins but only their readme. Config is hidden even though the API needs to be
|
|
|
|
|
+ // public for plugins to work properly.
|
|
|
|
|
+ if (isAdmin) {
|
|
|
|
|
+ // Only show Config/Pages for app
|
|
|
|
|
+ if (meta.type === PluginType.app) {
|
|
|
|
|
+ // Legacy App Config
|
|
|
|
|
+ if (plugin.angularConfigCtrl) {
|
|
|
|
|
+ pages.push({
|
|
|
|
|
+ text: 'Config',
|
|
|
|
|
+ icon: 'gicon gicon-cog',
|
|
|
|
|
+ url: `${appSubUrl}${path}?page=${PAGE_ID_CONFIG_CTRL}`,
|
|
|
|
|
+ id: PAGE_ID_CONFIG_CTRL,
|
|
|
|
|
+ });
|
|
|
|
|
+ defaultPage = PAGE_ID_CONFIG_CTRL;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (plugin.configPages) {
|
|
|
|
|
+ for (const page of plugin.configPages) {
|
|
|
|
|
+ pages.push({
|
|
|
|
|
+ text: page.title,
|
|
|
|
|
+ icon: page.icon,
|
|
|
|
|
+ url: path + '?page=' + page.id,
|
|
|
|
|
+ id: page.id,
|
|
|
|
|
+ });
|
|
|
|
|
+ if (!defaultPage) {
|
|
|
|
|
+ defaultPage = page.id;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Check for the dashboard pages
|
|
|
|
|
+ if (find(meta.includes, { type: 'dashboard' })) {
|
|
|
|
|
+ pages.push({
|
|
|
|
|
+ text: 'Dashboards',
|
|
|
|
|
+ icon: 'gicon gicon-dashboard',
|
|
|
|
|
+ url: `${appSubUrl}${path}?page=${PAGE_ID_DASHBOARDS}`,
|
|
|
|
|
+ id: PAGE_ID_DASHBOARDS,
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (!defaultPage) {
|
|
|
|
|
+ defaultPage = pages[0].id; // the first tab
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const node = {
|
|
|
|
|
+ text: meta.name,
|
|
|
|
|
+ img: meta.info.logos.large,
|
|
|
|
|
+ subTitle: meta.info.author.name,
|
|
|
|
|
+ breadcrumbs: [{ title: 'Plugins', url: '/plugins' }],
|
|
|
|
|
+ url: `${appSubUrl}${path}`,
|
|
|
|
|
+ children: setActivePage(query.page as string, pages, defaultPage),
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ return {
|
|
|
|
|
+ defaultPage,
|
|
|
|
|
+ nav: {
|
|
|
|
|
+ node: node,
|
|
|
|
|
+ main: node,
|
|
|
|
|
+ },
|
|
|
|
|
+ };
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function setActivePage(pageId: string, pages: NavModelItem[], defaultPageId: string): NavModelItem[] {
|
|
|
|
|
+ let found = false;
|
|
|
|
|
+ const selected = pageId || defaultPageId;
|
|
|
|
|
+ const changed = pages.map(p => {
|
|
|
|
|
+ const active = !found && selected === p.id;
|
|
|
|
|
+ if (active) {
|
|
|
|
|
+ found = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ return { ...p, active };
|
|
|
|
|
+ });
|
|
|
|
|
+ if (!found) {
|
|
|
|
|
+ changed[0].active = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ return changed;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
function getPluginIcon(type: string) {
|
|
function getPluginIcon(type: string) {
|
|
|
switch (type) {
|
|
switch (type) {
|
|
|
case 'datasource':
|
|
case 'datasource':
|