// Libraries import React, { PureComponent } from 'react'; import { PanelProps } from '@grafana/data'; import { getDatasourceSrv } from 'app/features/plugins/datasource_srv'; import { getBackendSrv } from 'app/core/services/backend_srv'; import { contextSrv } from 'app/core/core'; import { getDashboardSrv } from 'app/features/dashboard/services/DashboardSrv'; interface Step { title: string; cta?: string; icon: string; href: string; target?: string; note?: string; check: () => Promise; done?: boolean; } interface State { checksDone: boolean; } export class GettingStarted extends PureComponent { stepIndex = 0; readonly steps: Step[]; constructor(props: PanelProps) { super(props); this.state = { checksDone: false, }; this.steps = [ { title: 'Install Grafana', icon: 'icon-gf icon-gf-check', href: 'http://docs.grafana.org/', target: '_blank', note: 'Review the installation docs', check: () => Promise.resolve(true), }, { title: 'Create your first data source', cta: 'Add data source', icon: 'gicon gicon-datasources', href: 'datasources/new?gettingstarted', check: () => { return new Promise(resolve => { resolve( getDatasourceSrv() .getMetricSources() .filter(item => { return item.meta.builtIn !== true; }).length > 0 ); }); }, }, { title: 'Create your first dashboard', cta: 'New dashboard', icon: 'gicon gicon-dashboard', href: 'dashboard/new?gettingstarted', check: () => { return getBackendSrv() .search({ limit: 1 }) .then(result => { return result.length > 0; }); }, }, { title: 'Invite your team', cta: 'Add Users', icon: 'gicon gicon-team', href: 'org/users?gettingstarted', check: () => { return getBackendSrv() .get('/api/org/users/lookup') .then((res: any) => { return res.length > 1; }); }, }, { title: 'Install apps & plugins', cta: 'Explore plugin repository', icon: 'gicon gicon-plugins', href: 'https://grafana.com/plugins?utm_source=grafana_getting_started', check: () => { return getBackendSrv() .get('/api/plugins', { embedded: 0, core: 0 }) .then((plugins: any[]) => { return plugins.length > 0; }); }, }, ]; } componentDidMount() { this.stepIndex = -1; return this.nextStep().then((res: any) => { this.setState({ checksDone: true }); }); } nextStep(): any { if (this.stepIndex === this.steps.length - 1) { return Promise.resolve(); } this.stepIndex += 1; const currentStep = this.steps[this.stepIndex]; return currentStep.check().then(passed => { if (passed) { currentStep.done = true; return this.nextStep(); } return Promise.resolve(); }); } dismiss = () => { const { id } = this.props; const dashboard = getDashboardSrv().getCurrent(); const panel = dashboard.getPanelById(id); dashboard.removePanel(panel); getBackendSrv() .request({ method: 'PUT', url: '/api/user/helpflags/1', showSuccessAlert: false, }) .then((res: any) => { contextSrv.user.helpFlags1 = res.helpFlags1; }); }; render() { const { checksDone } = this.state; if (!checksDone) { return
checking...
; } return (
{this.steps.map((step, index) => { return ( ); })}
); } }