/** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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 PropTypes from 'prop-types'; import { bindActionCreators } from 'redux'; import { connect } from 'react-redux'; import { styled, t } from '@superset-ui/core'; import { EmptyStateMedium } from 'src/components/EmptyState'; import EditableTitle from 'src/components/EditableTitle'; import { setEditMode } from 'src/dashboard/actions/dashboardState'; import DashboardComponent from 'src/dashboard/containers/DashboardComponent'; import AnchorLink from 'src/dashboard/components/AnchorLink'; import DragDroppable from 'src/dashboard/components/dnd/DragDroppable'; import { componentShape } from 'src/dashboard/util/propShapes'; export const RENDER_TAB = 'RENDER_TAB'; export const RENDER_TAB_CONTENT = 'RENDER_TAB_CONTENT'; const propTypes = { dashboardId: PropTypes.number.isRequired, id: PropTypes.string.isRequired, parentId: PropTypes.string.isRequired, component: componentShape.isRequired, parentComponent: componentShape.isRequired, index: PropTypes.number.isRequired, depth: PropTypes.number.isRequired, renderType: PropTypes.oneOf([RENDER_TAB, RENDER_TAB_CONTENT]).isRequired, onDropOnTab: PropTypes.func, onHoverTab: PropTypes.func, editMode: PropTypes.bool.isRequired, canEdit: PropTypes.bool.isRequired, // grid related availableColumnCount: PropTypes.number, columnWidth: PropTypes.number, onResizeStart: PropTypes.func, onResize: PropTypes.func, onResizeStop: PropTypes.func, // redux handleComponentDrop: PropTypes.func.isRequired, updateComponents: PropTypes.func.isRequired, setDirectPathToChild: PropTypes.func.isRequired, setEditMode: PropTypes.func.isRequired, }; const defaultProps = { availableColumnCount: 0, columnWidth: 0, onDropOnTab() {}, onHoverTab() {}, onResizeStart() {}, onResize() {}, onResizeStop() {}, }; const TabTitleContainer = styled.div` ${({ isHighlighted, theme: { gridUnit, colors } }) => ` padding: ${gridUnit}px ${gridUnit * 2}px; margin: ${-gridUnit}px ${gridUnit * -2}px; transition: box-shadow 0.2s ease-in-out; ${ isHighlighted && `box-shadow: 0 0 ${gridUnit}px ${colors.primary.light1};` } `} `; const renderDraggableContentBottom = dropProps => dropProps.dropIndicatorProps && (
); const renderDraggableContentTop = dropProps => dropProps.dropIndicatorProps && ( ); class Tab extends React.PureComponent { constructor(props) { super(props); this.handleChangeText = this.handleChangeText.bind(this); this.handleDrop = this.handleDrop.bind(this); this.handleOnHover = this.handleOnHover.bind(this); this.handleTopDropTargetDrop = this.handleTopDropTargetDrop.bind(this); this.handleChangeTab = this.handleChangeTab.bind(this); } handleChangeTab({ pathToTabIndex }) { this.props.setDirectPathToChild(pathToTabIndex); } handleChangeText(nextTabText) { const { updateComponents, component } = this.props; if (nextTabText && nextTabText !== component.meta.text) { updateComponents({ [component.id]: { ...component, meta: { ...component.meta, text: nextTabText, }, }, }); } } handleDrop(dropResult) { this.props.handleComponentDrop(dropResult); this.props.onDropOnTab(dropResult); } handleOnHover() { this.props.onHoverTab(); } handleTopDropTargetDrop(dropResult) { if (dropResult) { this.props.handleComponentDrop({ ...dropResult, destination: { ...dropResult.destination, // force appending as the first child if top drop target index: 0, }, }); } } renderTabContent() { const { component: tabComponent, parentComponent: tabParentComponent, depth, availableColumnCount, columnWidth, onResizeStart, onResize, onResizeStop, editMode, isComponentVisible, canEdit, setEditMode, dashboardId, } = this.props; const shouldDisplayEmptyState = tabComponent.children.length === 0; return (