/* * << * Davinci * == * Copyright (C) 2016 - 2017 EDP * == * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * >> */ import React from 'react' import { Icon, Tooltip, Popover } from 'antd' const styles = require('../Dashboard.less') import { IProject } from 'containers/Projects/types' import ShareDownloadPermission from 'containers/Account/components/checkShareDownloadPermission' import ModulePermission from 'containers/Account/components/checkModulePermission' import { getTextWidth } from 'utils/util' interface IDashboardActionProps { currentProject: IProject depth: number item: { id: number, type: number, name: string } splitWidth: number onInitOperateMore: (item: any, type: string) => any initChangeDashboard: (id: number) => any } interface IDashboardActionState { popoverVisible: boolean } export class DashboardAction extends React.PureComponent { constructor (props) { super(props) this.state = { popoverVisible: false } } private handleVisibleChange = (visible) => { this.setState({ popoverVisible: visible }) } private operateMore = (item, type) => (e) => { const { popoverVisible } = this.state const { onInitOperateMore } = this.props if (this.state.popoverVisible) { this.setState({ popoverVisible: false }) } onInitOperateMore(item, type) } private computeTitleWidth (text: string, wrapperWidth: number) { const textWidth = getTextWidth(text) const textLength = text.length return text } public render () { const { currentProject, depth, item, initChangeDashboard, splitWidth } = this.props const { popoverVisible } = this.state const EditActionButton = ModulePermission, HTMLLIElement>>(currentProject, 'viz')(Li) const editAction = ( 编辑 ) const DownloadButton = ShareDownloadPermission, HTMLLIElement>>(currentProject, 'download')(Li) const downloadAction = ( 下载 ) const moveAction = ( 移动 ) const DeleteActionButton = ModulePermission, HTMLLIElement>>(currentProject, 'viz', true)(Li) const deleteAction = ( 删除 ) const ulActionAll = (
  • {editAction}
  • {/*
  • {downloadAction}
  • */}
  • {moveAction}
  • {deleteAction}
) const ulActionPart = (
  • {editAction}
  • {/*
  • {downloadAction}
  • */}
  • {moveAction}
) const icon = ( ) let ulPopover if (currentProject && currentProject.permission) { const currentPermission = currentProject.permission.vizPermission if (currentPermission === 0) { ulPopover = null } else { ulPopover = ( {icon} ) } } const computeWidth: number = splitWidth - 60 - 18 * depth - 6 const titleWidth: string = `${computeWidth}px` const computeTitleWidth = this.computeTitleWidth return ( { item.type === 0 ?

{computeTitleWidth(item.name, computeWidth)}

: {computeTitleWidth(item.name, computeWidth)} } {ulPopover}
) } } function Li (props: React.DetailedHTMLProps, HTMLLIElement>) { return ( {props.children} ) } export default DashboardAction