From 596a83407e5e6d431c86281d650cab31f016646a Mon Sep 17 00:00:00 2001 From: Peter Holmberg Date: Wed, 24 Oct 2018 16:17:25 +0200 Subject: [PATCH] fixed routes and page --- .../datasources/DataSourceSettings.tsx | 146 +++++++++++------- .../features/plugins/__mocks__/pluginMocks.ts | 2 + public/app/routes/routes.ts | 7 + public/app/types/plugins.ts | 1 + 4 files changed, 96 insertions(+), 60 deletions(-) diff --git a/public/app/features/datasources/DataSourceSettings.tsx b/public/app/features/datasources/DataSourceSettings.tsx index b28394dc4f4..d66ba07990c 100644 --- a/public/app/features/datasources/DataSourceSettings.tsx +++ b/public/app/features/datasources/DataSourceSettings.tsx @@ -1,10 +1,18 @@ import React, { createRef, PureComponent } from 'react'; import { connect } from 'react-redux'; -import { DataSource, Plugin } from 'app/types'; +import { DataSource, NavModel, Plugin } from 'app/types'; +import PageHeader from '../../core/components/PageHeader/PageHeader'; +import { importPluginModule } from '../plugins/plugin_loader'; +import { loadDataSource } from './state/actions'; +import { getNavModel } from '../../core/selectors/navModel'; +import { getRouteParamsId } from '../../core/selectors/location'; export interface Props { + navModel: NavModel; dataSource: DataSource; dataSourceMeta: Plugin; + pageId: number; + loadDataSource: typeof loadDataSource; } interface State { name: string; @@ -24,10 +32,13 @@ export class DataSourceSettings extends PureComponent { showNamePopover: false, }; - componentDidMount() { - // importPluginModule(this.props.dataSourceMeta.module).then(pluginExports => { - // console.log(pluginExports); - // }); + async componentDidMount() { + const { loadDataSource, pageId } = this.props; + + await loadDataSource(pageId); + importPluginModule(this.props.dataSourceMeta.module).then(pluginExports => { + console.log(pluginExports); + }); } onNameChange = event => { @@ -84,75 +95,90 @@ export class DataSourceSettings extends PureComponent { render() { const { name, showNamePopover } = this.state; + console.log(this.props); + return (
-
-
-
-
- Name - -
- -
- {showNamePopover && ( -
- The name is used when you select the data source in panels. The Default data source is - preselected in new panels. + +
+
+ +
+
+
+ Name + +
+ +
+ {showNamePopover && ( +
+ The name is used when you select the data source in panels. The Default data source is + preselected in new panels. +
+ )}
- )} +
-
+ {this.shouldRenderInfoBox() &&
{this.getInfoText()}
} + {this.isReadyOnly() && ( +
+ This datasource was added by config and cannot be modified using the UI. Please contact your server + admin to update this datasource. +
+ )} +
+
+ + + + Back + +
+
- {this.shouldRenderInfoBox() &&
{this.getInfoText()}
} - {this.isReadyOnly() && ( -
- This datasource was added by config and cannot be modified using the UI. Please contact your server admin - to update this datasource. -
- )} -
-
- - - - Back - -
- +
); } } function mapStateToProps(state) { + const pageId = getRouteParamsId(state.location); + return { + navModel: getNavModel(state.navIndex, `datasource-settings-${pageId}`), dataSource: state.dataSources.dataSource, dataSourceMeta: state.dataSources.dataSourceMeta, + pageId: pageId, }; } -export default connect(mapStateToProps)(DataSourceSettings); +const mapDispatchToProps = { + loadDataSource, +}; + +export default connect(mapStateToProps, mapDispatchToProps)(DataSourceSettings); diff --git a/public/app/features/plugins/__mocks__/pluginMocks.ts b/public/app/features/plugins/__mocks__/pluginMocks.ts index d8dd67d5b61..4804cbbc594 100644 --- a/public/app/features/plugins/__mocks__/pluginMocks.ts +++ b/public/app/features/plugins/__mocks__/pluginMocks.ts @@ -26,6 +26,7 @@ export const getMockPlugins = (amount: number): Plugin[] => { pinned: false, state: '', type: '', + module: {}, }); } @@ -55,5 +56,6 @@ export const getMockPlugin = () => { pinned: false, state: '', type: '', + module: {}, }; }; diff --git a/public/app/routes/routes.ts b/public/app/routes/routes.ts index 24cabb63a9d..862aa413884 100644 --- a/public/app/routes/routes.ts +++ b/public/app/routes/routes.ts @@ -14,6 +14,7 @@ import DataSourcesListPage from 'app/features/datasources/DataSourcesListPage'; import NewDataSourcePage from '../features/datasources/NewDataSourcePage'; import UsersListPage from 'app/features/users/UsersListPage'; import DataSourceDashboards from 'app/features/datasources/DataSourceDashboards'; +import DataSourceSettings from '../features/datasources/DataSourceSettings'; /** @ngInject */ export function setupAngularRoutes($routeProvider, $locationProvider) { @@ -73,6 +74,12 @@ export function setupAngularRoutes($routeProvider, $locationProvider) { component: () => DataSourcesListPage, }, }) + .when('/datasources/edit/:id/', { + template: '', + resolve: { + component: () => DataSourceSettings, + }, + }) .when('/datasources/edit/:id/dashboards', { template: '', resolve: { diff --git a/public/app/types/plugins.ts b/public/app/types/plugins.ts index 826ce2d48ec..de640906407 100644 --- a/public/app/types/plugins.ts +++ b/public/app/types/plugins.ts @@ -60,6 +60,7 @@ export interface Plugin { pinned: boolean; state: string; type: string; + module: any; } export interface PluginDashboard {