import React from 'react' import { Button, Popconfirm } from 'antd' import { connect } from 'dva' import './header.less' class DataSourceDetailHeader extends React.Component { constructor(props) { super(props); this.state = { visibleConfirm: false, visibleSaveConfirm: false, } } handleVisibleChange = (visible) => { this.setState({ visibleConfirm: visible }); } handleVisibleSaveConfirmChange = (visible) => { if(this.isValid()) { this.setState({ visibleSaveConfirm: visible }); } } isValid = () => { const { dataSourceDetail } = this.props; const { type, name, columns, targetDirty, description } = dataSourceDetail; return type === 'database' ? ( !!name && name.length < 50 && !targetDirty && !!columns && columns.length > 0 && (description === undefined || description === null || description.length <= 150) ) : ( type === 'file' ? ( +1 === 2 ) : false ) } render() { const { dataSourceDetail, dispatch } = this.props; const { name } = dataSourceDetail; return (
{name || '未命名'}
{ if(this.isValid()) { dispatch({ type: 'dataSource/remoteModify' }); dispatch({ type: 'main/redirect', path: '/workshop/datasource' }); } this.setState({ visibleConfirm: false }); }} onCancel={() => { this.setState({ visibleConfirm: false }, () => { dispatch({ type: 'main/redirect', path: '/workshop/datasource' }); }); }} okText="保存" cancelText="不保存" > 修改数据源可能会对已创建的图表/报表产生影响,是否确认修改?} visible={this.state.visibleSaveConfirm} onVisibleChange={this.handleVisibleSaveConfirmChange} onConfirm={() => { this.setState({ visibleSaveConfirm: false }, () => { dispatch({ type: 'dataSource/remoteModify' }); }); }} onCancel={() => { this.setState({ visibleSaveConfirm: false }); }} okText="确定" cancelText="取消" >
); } } export default connect(({ present: { dataSourceDetail } }) => ({ dataSourceDetail }))(DataSourceDetailHeader);