Skip to content

Commit

Permalink
perf(dashboard): decouple redux props from dashboard components (#16421)
Browse files Browse the repository at this point in the history
* perf(dashboard): decouple redux props from dashboard components

* Lint fix

* Dont make copy of filters object

* Remove unnecessary exports
  • Loading branch information
kgabryje authored Aug 26, 2021
1 parent 8ad495a commit f422f1e
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { DndProvider } from 'react-dnd';
import { HTML5Backend } from 'react-dnd-html5-backend';

import Chart from 'src/dashboard/containers/Chart';
import ChartHolder from 'src/dashboard/components/gridComponents/ChartHolder';
import ChartHolderConnected from 'src/dashboard/components/gridComponents/ChartHolder';
import DeleteComponentButton from 'src/dashboard/components/DeleteComponentButton';
import DragDroppable from 'src/dashboard/components/dnd/DragDroppable';
import HoverMenu from 'src/dashboard/components/menu/HoverMenu';
Expand Down Expand Up @@ -71,7 +71,7 @@ describe('ChartHolder', () => {
const wrapper = mount(
<Provider store={mockStore}>
<DndProvider backend={HTML5Backend}>
<ChartHolder {...props} {...overrideProps} />
<ChartHolderConnected {...props} {...overrideProps} />
</DndProvider>
</Provider>,
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { HTML5Backend } from 'react-dnd-html5-backend';

import { act } from 'react-dom/test-utils';
import { MarkdownEditor } from 'src/components/AsyncAceEditor';
import Markdown from 'src/dashboard/components/gridComponents/Markdown';
import MarkdownConnected from 'src/dashboard/components/gridComponents/Markdown';
import MarkdownModeDropdown from 'src/dashboard/components/menu/MarkdownModeDropdown';
import DeleteComponentButton from 'src/dashboard/components/DeleteComponentButton';
import waitForComponentToPaint from 'spec/helpers/waitForComponentToPaint';
Expand Down Expand Up @@ -66,7 +66,7 @@ describe('Markdown', () => {
const wrapper = mount(
<Provider store={mockStore}>
<DndProvider backend={HTML5Backend}>
<Markdown {...props} {...overrideProps} />
<MarkdownConnected {...props} {...overrideProps} />
</DndProvider>
</Provider>,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
import { useTheme } from '@superset-ui/core';
import { useSelector } from 'react-redux';
import { useSelector, connect } from 'react-redux';

import { getChartIdsInFilterScope } from 'src/dashboard/util/activeDashboardFilters';
import Chart from '../../containers/Chart';
Expand Down Expand Up @@ -381,4 +381,10 @@ class ChartHolder extends React.Component {
ChartHolder.propTypes = propTypes;
ChartHolder.defaultProps = defaultProps;

export default ChartHolder;
function mapStateToProps(state) {
return {
directPathToChild: state.dashboardState.directPathToChild,
directPathLastUpdated: state.dashboardState.directPathLastUpdated,
};
}
export default connect(mapStateToProps)(ChartHolder);
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
*/
import React from 'react';
import PropTypes from 'prop-types';

import { connect } from 'react-redux';
import cx from 'classnames';

import { t, SafeMarkdown } from '@superset-ui/core';
import { Logger, LOG_ACTIONS_RENDER_CHART } from 'src/logger/LogUtils';
import { MarkdownEditor } from 'src/components/AsyncAceEditor';
Expand Down Expand Up @@ -366,4 +367,10 @@ class Markdown extends React.PureComponent {
Markdown.propTypes = propTypes;
Markdown.defaultProps = defaultProps;

export default Markdown;
function mapStateToProps(state) {
return {
undoLength: state.dashboardLayout.past.length,
redoLength: state.dashboardLayout.future.length,
};
}
export default connect(mapStateToProps)(Markdown);
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,10 @@ Tabs.propTypes = propTypes;
Tabs.defaultProps = defaultProps;

function mapStateToProps(state) {
return { nativeFilters: state.nativeFilters };
return {
nativeFilters: state.nativeFilters,
directPathToChild: state.dashboardState.directPathToChild,
activeTabs: state.dashboardState.activeTabs,
};
}
export default connect(mapStateToProps)(Tabs);
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ const propTypes = {
};

const defaultProps = {
directPathToChild: [],
directPathLastUpdated: 0,
isComponentVisible: true,
};

Expand All @@ -77,15 +75,9 @@ function mapStateToProps(
const component = dashboardLayout[id];
const props = {
component,
dashboardLayout,
parentComponent: dashboardLayout[parentId],
editMode: dashboardState.editMode,
undoLength: undoableLayout.past.length,
redoLength: undoableLayout.future.length,
filters: getActiveFilters(),
directPathToChild: dashboardState.directPathToChild,
activeTabs: dashboardState.activeTabs,
directPathLastUpdated: dashboardState.directPathLastUpdated,
dashboardId: dashboardInfo.id,
fullSizeChartId: dashboardState.fullSizeChartId,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ let allComponents = {};

// output: { [id_column]: { values, scope } }
export function getActiveFilters() {
return {
...activeFilters,
};
return activeFilters;
}

// currently filter_box is a chart,
Expand Down

0 comments on commit f422f1e

Please sign in to comment.