williaster commented on a change in pull request #3581: Dashboard refactory
URL:
https://github.com/apache/incubator-superset/pull/3581#discussion_r147906435
##########
File path: superset/assets/javascripts/dashboard/components/SliceHeader.jsx
##########
@@ -0,0 +1,128 @@
+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,
+ formDataExtra: PropTypes.object,
+ removeSlice: PropTypes.func.isRequired,
+ updateSliceName: PropTypes.func,
+ toggleExpandSlice: PropTypes.func,
+ forceRefresh: PropTypes.func,
+};
+
+class SliceHeader extends React.PureComponent {
+ onSaveTitle(newTitle) {
+ if (this.props.updateSliceName) {
+ this.props.updateSliceName(this.props.slice.slice_id, newTitle);
+ }
+ }
+
+ render() {
+ const slice = this.props.slice;
+ const isCached = slice.is_cached;
+ const isExpanded = !!this.props.isExpanded;
+ const cachedWhen = moment.utc(slice.cached_dttm).fromNow();
+ const refreshTooltip = isCached ?
+ t('Served from data cached %s . Click to force refresh.', cachedWhen) :
+ t('Force refresh data');
+
+ return (
+ <div className="row chart-header">
+ <div className="col-md-12">
+ <div className="header">
+ <EditableTitle
+ title={slice.slice_name}
+ canEdit={!!this.props.updateSliceName}
+ onSaveTitle={this.onSaveTitle.bind(this)}
+ noPermitTooltip={'You don\'t have the rights to alter this
dashboard.'}
+ />
+ </div>
+ <div className="chart-controls">
+ <div id={'controls_' + slice.slice_id} className="pull-right">
+ <a>
+ <TooltipWrapper
+ placement="top"
+ label="move"
+ tooltip={t('Move chart')}
+ >
+ <i className="fa fa-arrows drag" />
+ </TooltipWrapper>
+ </a>
+ <a
+ className={`refresh ${isCached ? 'danger' : ''}`}
+ onClick={() => (this.props.forceRefresh())}
Review comment:
you should create a `this.handleRefresh` / don't create new funcs in the
render (ditto for other clicks below)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services