import React from 'react'; import PropTypes from 'prop-types'; import moment from 'moment'; import { t } from '../../locales'; import EditableTitle from '../../components/EditableTitle'; import TooltipWrapper from '../../components/TooltipWrapper'; const propTypes = { slice: PropTypes.object.isRequired, exploreChartUrl: PropTypes.string, exportCSVUrl: PropTypes.string, isExpanded: PropTypes.bool, isCached: PropTypes.bool, cachedDttm: PropTypes.string, formDataExtra: PropTypes.object, removeSlice: PropTypes.func, updateSliceName: PropTypes.func, toggleExpandSlice: PropTypes.func, forceRefresh: PropTypes.func, editMode: PropTypes.bool, annotationQuery: PropTypes.object, annotationError: PropTypes.object, }; const defaultProps = { forceRefresh: () => ({}), removeSlice: () => ({}), updateSliceName: () => ({}), toggleExpandSlice: () => ({}), editMode: false, }; class SliceHeader extends React.PureComponent { constructor(props) { super(props); this.onSaveTitle = this.onSaveTitle.bind(this); } onSaveTitle(newTitle) { if (this.props.updateSliceName) { this.props.updateSliceName(this.props.slice.slice_id, newTitle); } } render() { const slice = this.props.slice; const isCached = this.props.isCached; const isExpanded = !!this.props.isExpanded; const cachedWhen = moment.utc(this.props.cachedDttm).fromNow(); const refreshTooltip = isCached ? t('Served from data cached %s . Click to force refresh.', cachedWhen) : t('Force refresh data'); const annoationsLoading = t('Annotation layers are still loading.'); const annoationsError = t('One ore more annotation layers failed loading.'); return (