ljharb commented on a change in pull request #3581: Dashboard refactory
URL: 
https://github.com/apache/incubator-superset/pull/3581#discussion_r147521011
 
 

 ##########
 File path: superset/assets/javascripts/dashboard/components/GridCell.jsx
 ##########
 @@ -0,0 +1,108 @@
+/* eslint-disable react/no-danger */
+import React from 'react';
+import PropTypes from 'prop-types';
+
+import SliceHeader from './SliceHeader';
+import ChartContainer from '../../chart/ChartContainer';
+
+import '../../../stylesheets/dashboard.css';
+
+const propTypes = {
+  timeout: PropTypes.number,
+  datasource: PropTypes.object,
+  isLoading: PropTypes.bool,
+  isExpanded: PropTypes.bool,
+  widgetHeight: PropTypes.number,
+  widgetWidth: PropTypes.number,
+  fetchSlice: PropTypes.func,
+  removeSlice: PropTypes.func.isRequired,
+  updateSliceName: PropTypes.func,
+  toggleExpandSlice: PropTypes.func,
+  slice: PropTypes.object,
+  chartKey: PropTypes.string,
+  formData: PropTypes.object,
+  filters: PropTypes.object,
+  addFilter: PropTypes.func,
+  clearFilter: PropTypes.func,
+  removeFilter: PropTypes.func,
+  exploreChartUrl: PropTypes.string,
+  exportCSVUrl: PropTypes.string,
+};
+
+class GridCell extends React.PureComponent {
+  getDescriptionId(slice) {
+    return 'description_' + slice.slice_id;
+  }
+
+  getHeaderId(slice) {
+    return 'header_' + slice.slice_id;
+  }
+
+  width() {
+    return this.props.widgetWidth - 10;
+  }
+
+  height(slice) {
+    const widgetHeight = this.props.widgetHeight;
+    const headerId = this.getHeaderId(slice);
+    const descriptionId = this.getDescriptionId(slice);
+    const headerHeight = this.refs[headerId] ? 
this.refs[headerId].offsetHeight : 30;
+    let descriptionHeight = 0;
+    if (this.props.isExpanded && this.refs[descriptionId]) {
+      descriptionHeight = this.refs[descriptionId].offsetHeight + 10;
+    }
+    return widgetHeight - headerHeight - descriptionHeight;
+  }
+
+  render() {
+    const slice = this.props.slice;
+    return (
+      <div className="slice-cell" id={`${slice.slice_id}-cell`}>
+        <div ref={this.getHeaderId(slice)}>
+          <SliceHeader
+            slice={slice}
+            exploreChartUrl={this.props.exploreChartUrl}
+            exportCSVUrl={this.props.exportCSVUrl}
+            isExpanded={this.props.isExpanded}
+            removeSlice={this.props.removeSlice}
+            updateSliceName={this.props.updateSliceName}
+            toggleExpandSlice={this.props.toggleExpandSlice}
+            forceRefresh={() => this.props.fetchSlice(true)}
+          />
+        </div>
+        <div
+          className="slice_description bs-callout bs-callout-default"
+          style={this.props.isExpanded ? {} : { display: 'none' }}
+          ref={this.getDescriptionId(slice)}
+          dangerouslySetInnerHTML={{ __html: slice.description_markeddown }}
+        />
+        <div className="row chart-container">
+          <input type="hidden" value="false" />
+          <div
+            id={'token_' + slice.slice_id}
+            className={`token col-md-12 ${this.props.isLoading ? 'is-loading' 
: ''}`}
+          >
+            <ChartContainer
 
 Review comment:
   Generally you can go with either "only redux at the top", or "redux in every 
component that needs it". The downsides of the former is that every dependency 
of the bottom of the chain has to be passed down through every item in the 
chain - which forces the intervening components to have knowledge of the 
implementation details of the leaves.

----------------------------------------------------------------
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

Reply via email to