The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
grafana/public/app/features/datasources/DataSourceDashboards.tsx

103 lines
2.9 KiB

// Libraries
7 years ago
import React, { PureComponent } from 'react';
import { hot } from 'react-hot-loader';
import { connect } from 'react-redux';
// Components
import Page from 'app/core/components/Page/Page';
7 years ago
import DashboardTable from './DashboardsTable';
// Actions & Selectors
7 years ago
import { getNavModel } from 'app/core/selectors/navModel';
import { getRouteParamsId } from 'app/core/selectors/location';
import { loadDataSource } from './state/actions';
import { loadPluginDashboards } from '../plugins/state/actions';
import { importDashboard, removeDashboard } from '../dashboard/state/actions';
import { getDataSource } from './state/selectors';
7 years ago
// Types
import { PluginDashboard, StoreState } from 'app/types';
import { DataSourceSettings } from '@grafana/data';
import { NavModel } from '@grafana/data';
7 years ago
export interface Props {
navModel: NavModel;
dashboards: PluginDashboard[];
dataSource: DataSourceSettings;
7 years ago
pageId: number;
importDashboard: typeof importDashboard;
7 years ago
loadDataSource: typeof loadDataSource;
loadPluginDashboards: typeof loadPluginDashboards;
removeDashboard: typeof removeDashboard;
isLoading: boolean;
7 years ago
}
export class DataSourceDashboards extends PureComponent<Props> {
async componentDidMount() {
const { loadDataSource, pageId } = this.props;
await loadDataSource(pageId);
this.props.loadPluginDashboards();
}
onImport = (dashboard: PluginDashboard, overwrite: boolean) => {
const { dataSource, importDashboard } = this.props;
const data: any = {
pluginId: dashboard.pluginId,
path: dashboard.path,
overwrite,
inputs: [],
};
7 years ago
if (dataSource) {
data.inputs.push({
name: '*',
type: 'datasource',
pluginId: dataSource.type,
value: dataSource.name,
});
}
importDashboard(data, dashboard.title);
};
onRemove = (dashboard: PluginDashboard) => {
this.props.removeDashboard(dashboard.importedUri);
};
7 years ago
render() {
const { dashboards, navModel, isLoading } = this.props;
7 years ago
return (
<Page navModel={navModel}>
<Page.Contents isLoading={isLoading}>
7 years ago
<DashboardTable
dashboards={dashboards}
onImport={(dashboard, overwrite) => this.onImport(dashboard, overwrite)}
onRemove={dashboard => this.onRemove(dashboard)}
/>
</Page.Contents>
</Page>
7 years ago
);
}
}
function mapStateToProps(state: StoreState) {
7 years ago
const pageId = getRouteParamsId(state.location);
return {
navModel: getNavModel(state.navIndex, `datasource-dashboards-${pageId}`),
pageId: pageId,
dashboards: state.plugins.dashboards,
dataSource: getDataSource(state.dataSources, pageId),
isLoading: state.plugins.isLoadingPluginDashboards,
7 years ago
};
}
const mapDispatchToProps = {
importDashboard,
7 years ago
loadDataSource,
loadPluginDashboards,
removeDashboard,
7 years ago
};
export default hot(module)(connect(mapStateToProps, mapDispatchToProps)(DataSourceDashboards));