williaster commented on a change in pull request #3581: Dashboard refactory
URL:
https://github.com/apache/incubator-superset/pull/3581#discussion_r147904699
##########
File path: superset/assets/javascripts/dashboard/components/Dashboard.jsx
##########
@@ -0,0 +1,334 @@
+import React from 'react';
+import PropTypes from 'prop-types';
+
+import AlertsWrapper from '../../components/AlertsWrapper';
+import GridLayout from './GridLayout';
+import Header from './Header';
+import DashboardAlert from './DashboardAlert';
+import { getExploreUrl } from '../../explore/exploreUtils';
+import { areObjectsEqual } from '../../reduxUtils';
+import { t } from '../../locales';
+
+import '../../../stylesheets/dashboard.css';
+
+const propTypes = {
+ actions: PropTypes.object,
+ initMessages: PropTypes.array,
+ dashboard: PropTypes.object.isRequired,
+ slices: PropTypes.object,
+ datasources: PropTypes.object,
+ filters: PropTypes.object,
+ refresh: PropTypes.bool,
+ timeout: PropTypes.number,
+ userId: PropTypes.string,
+ isStarred: PropTypes.bool,
+ isFiltersChanged: PropTypes.bool,
+ updateDashboardTitle: PropTypes.func,
+ readFilters: PropTypes.func,
+ fetchFaveStar: PropTypes.func,
+ saveFaveStar: PropTypes.func,
+ renderSlices: PropTypes.func,
+ startPeriodicRender: PropTypes.func,
+ getFormDataExtra: PropTypes.func,
+ fetchSlice: PropTypes.func,
+ saveSlice: PropTypes.func,
+ removeSlice: PropTypes.func,
+ removeChart: PropTypes.func,
+ toggleExpandSlice: PropTypes.func,
+ updateDashboardLayout: PropTypes.func,
+ addSlicesToDashboard: PropTypes.func,
+ addFilter: PropTypes.func,
+ clearFilter: PropTypes.func,
+ removeFilter: PropTypes.func,
+};
+
+const defaultProps = {
+ initMessages: [],
+ dashboard: {},
+ slices: {},
+ datasources: {},
+ filters: {},
+ timeout: 60,
+ userId: '',
+ isStarred: false,
+ isFiltersChanged: false,
+};
+
+class Dashboard extends React.PureComponent {
+ constructor(props) {
+ super(props);
+ this.refreshTimer = null;
+ this.firstLoad = true;
+
+ // alert for unsaved changes
+ this.state = {
+ alert: null,
+ };
+ }
+
+ componentDidMount() {
+ this.loadPreSelectFilters();
+ this.firstLoad = false;
+ this.bindResizeToWindowResize();
+ }
+
+ componentWillReceiveProps(nextProps) {
+ // check filters is changed
+ if (!areObjectsEqual(nextProps.filters, this.props.filters)) {
+ this.renderUnsavedChangeAlert();
+ }
+ }
+
+ componentDidUpdate(prevProps) {
+ if (!areObjectsEqual(prevProps.filters, this.props.filters) &&
this.props.refresh) {
+ Object.keys(this.props.filters).forEach(sliceId =>
(this.refreshExcept(sliceId)));
+ }
+ }
+
+ onBeforeUnload(hasChanged) {
+ if (hasChanged) {
+ window.addEventListener('beforeunload', this.unload);
+ } else {
+ window.removeEventListener('beforeunload', this.unload);
+ }
+ }
+
+ onChange() {
+ this.onBeforeUnload(true);
+ this.renderUnsavedChangeAlert();
+ }
+
+ onSave() {
+ this.onBeforeUnload(false);
+ this.setState({
+ alert: '',
+ });
+ }
+
+ // return charts in array
+ getAllSlices() {
+ return Object.keys(this.props.slices).map(key => (this.props.slices[key]));
+ }
+
+ getFormDataExtra(slice) {
+ const formDataExtra = Object.assign({}, slice.formData);
+ const extraFilters = this.effectiveExtraFilters(slice.slice_id);
+ formDataExtra.filters = formDataExtra.filters.concat(extraFilters);
+ return formDataExtra;
+ }
+
+ unload() {
+ const message = t('You have unsaved changes.');
+ window.event.returnValue = message; // Gecko + IE
+ return message; // Gecko + Webkit, Safari, Chrome etc.
+ }
+
+ fetchSlice(slice, force = false) {
+ return this.props.actions.runQuery(
+ this.getFormDataExtra(slice), force, this.props.timeout, slice.chartKey);
Review comment:
nit new line for `)`
----------------------------------------------------------------
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