import React from 'react'
import { connect } from 'dva'
import DashboardDesigner from '../dashboardDesigner/layout'

class DashboardView extends React.Component {
    afterLoad = (data) => {
        const { dispatch, code } = this.props;
        if(data) {
            dispatch({ type: 'dashboardDesigner/setEditMode', checked: false });
            dispatch({ type: 'home/saveCurrentTabDashboardConfig', code });
        }
    }

    afterRefresh = () => {
        const { dispatch, code } = this.props;
        dispatch({ type: 'home/saveCurrentTabDashboardConfig', code });
    }

    render() {
        return <DashboardDesigner
            dashboardDesigner={this.props.dashboardDesigner}
            code={this.props.code}
            isViewMode
            afterLoad={this.afterLoad}
            afterRefresh={this.afterRefresh}
            config={this.props.config}/>
    }
}
export default connect(({ dashboardDesigner }) => ({ dashboardDesigner }))(DashboardView)