import React, { PureComponent } from 'react'; import { connect, ConnectedProps } from 'react-redux'; import { dateTimeFormat } from '@grafana/data'; import { locationService, reportInteraction } from '@grafana/runtime'; import { Form, Legend } from '@grafana/ui'; import { StoreState } from 'app/types'; import { clearLoadedDashboard, importDashboard } from '../state/actions'; import { DashboardSource, ImportDashboardDTO } from '../state/reducers'; import { ImportDashboardForm } from './ImportDashboardForm'; const IMPORT_FINISHED_EVENT_NAME = 'dashboard_import_imported'; const mapStateToProps = (state: StoreState) => { const searchObj = locationService.getSearchObject(); return { dashboard: state.importDashboard.dashboard, meta: state.importDashboard.meta, source: state.importDashboard.source, inputs: state.importDashboard.inputs, folder: searchObj.folderId ? { id: Number(searchObj.folderId) } : { id: 0 }, }; }; const mapDispatchToProps = { clearLoadedDashboard, importDashboard, }; const connector = connect(mapStateToProps, mapDispatchToProps); type Props = ConnectedProps; interface State { uidReset: boolean; } class ImportDashboardOverviewUnConnected extends PureComponent { state: State = { uidReset: false, }; onSubmit = (form: ImportDashboardDTO) => { reportInteraction(IMPORT_FINISHED_EVENT_NAME); this.props.importDashboard(form); }; onCancel = () => { this.props.clearLoadedDashboard(); }; onUidReset = () => { this.setState({ uidReset: true }); }; render() { const { dashboard, inputs, meta, source, folder } = this.props; const { uidReset } = this.state; return ( <> {source === DashboardSource.Gcom && (
Importing dashboard from{' '} Grafana.com
Published by {meta.orgName}
Updated on {dateTimeFormat(meta.updatedAt)}
)}
{({ register, errors, control, watch, getValues }) => ( )} ); } } export const ImportDashboardOverview = connector(ImportDashboardOverviewUnConnected); ImportDashboardOverview.displayName = 'ImportDashboardOverview';