Skip to content
This repository was archived by the owner on Jun 4, 2024. It is now read-only.

Commit fbcb46f

Browse files
Renderer regression (#140)
1 parent c5f7cff commit fbcb46f

File tree

2 files changed

+76
-39
lines changed

2 files changed

+76
-39
lines changed

Diff for: .circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
name: Install dependencies (dash)
4040
command: |
4141
git clone [email protected]:plotly/dash.git
42-
git clone [email protected]:plotly/dash-core-components.git
42+
git clone -b renderer-regression [email protected]:plotly/dash-core-components.git
4343
git clone [email protected]:plotly/dash-html-components.git
4444
git clone [email protected]:plotly/dash-table.git
4545
. venv/bin/activate

Diff for: src/TreeContainer.js

+75-38
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import PropTypes from 'prop-types';
55
import Registry from './registry';
66
import {connect} from 'react-redux';
77
import {
8+
any,
89
contains,
910
filter,
1011
forEach,
@@ -18,7 +19,6 @@ import {
1819
propOr,
1920
type
2021
} from 'ramda';
21-
import {STATUS} from './constants/constants';
2222
import { notifyObservers, updateProps } from './actions';
2323

2424
const SIMPLE_COMPONENT_TYPES = ['String', 'Number', 'Null', 'Boolean'];
@@ -75,38 +75,6 @@ class TreeContainer extends Component {
7575
);
7676
}
7777

78-
getLoadingState(id, requestQueue) {
79-
// loading prop coming from TreeContainer
80-
let isLoading = false;
81-
let loadingProp;
82-
let loadingComponent;
83-
84-
if (requestQueue && requestQueue.filter) {
85-
forEach(r => {
86-
const controllerId = isNil(r.controllerId) ? '' : r.controllerId;
87-
if (r.status === 'loading' && contains(id, controllerId)) {
88-
isLoading = true;
89-
[loadingComponent, loadingProp] = r.controllerId.split('.');
90-
}
91-
}, requestQueue);
92-
93-
const thisRequest = requestQueue.filter(r => {
94-
const controllerId = isNil(r.controllerId) ? '' : r.controllerId;
95-
return contains(id, controllerId);
96-
});
97-
if (thisRequest.status === STATUS.OK) {
98-
isLoading = false;
99-
}
100-
}
101-
102-
// Set loading state
103-
return {
104-
is_loading: isLoading,
105-
prop_name: loadingProp,
106-
component_name: loadingComponent,
107-
};
108-
}
109-
11078
getSetProps() {
11179
return newProps => {
11280
const {
@@ -145,7 +113,10 @@ class TreeContainer extends Component {
145113
}
146114

147115
shouldComponentUpdate(nextProps) {
148-
return nextProps._dashprivate_layout !== this.props._dashprivate_layout;
116+
const { _dashprivate_layout, _dashprivate_loadingState } = nextProps;
117+
118+
return _dashprivate_layout !== this.props._dashprivate_layout ||
119+
_dashprivate_loadingState.is_loading !== this.props._dashprivate_loadingState.is_loading;
149120
}
150121

151122
getLayoutProps() {
@@ -156,23 +127,23 @@ class TreeContainer extends Component {
156127
const {
157128
_dashprivate_dispatch,
158129
_dashprivate_layout,
159-
_dashprivate_requestQueue
130+
_dashprivate_loadingState
160131
} = this.props;
161132

162133
const layoutProps = this.getLayoutProps();
163134

164135
const children = this.getChildren(layoutProps.children);
165-
const loadingState = this.getLoadingState(layoutProps.id, _dashprivate_requestQueue);
166136
const setProps = this.getSetProps(_dashprivate_dispatch);
167137

168-
return this.getComponent(_dashprivate_layout, children, loadingState, setProps);
138+
return this.getComponent(_dashprivate_layout, children, _dashprivate_loadingState, setProps);
169139
}
170140
}
171141

172142
TreeContainer.propTypes = {
173143
_dashprivate_dependencies: PropTypes.any,
174144
_dashprivate_dispatch: PropTypes.func,
175145
_dashprivate_layout: PropTypes.object,
146+
_dashprivate_loadingState: PropTypes.object,
176147
_dashprivate_paths: PropTypes.any,
177148
_dashprivate_requestQueue: PropTypes.object,
178149
};
@@ -194,12 +165,78 @@ function mergeProps(stateProps, dispatchProps, ownProps) {
194165
_dashprivate_dependencies: stateProps.dependencies,
195166
_dashprivate_dispatch: dispatchProps.dispatch,
196167
_dashprivate_layout: ownProps._dashprivate_layout,
197-
_dashprivate_loading: ownProps._dashprivate_loading,
168+
_dashprivate_loadingState: getLoadingState(ownProps._dashprivate_layout, stateProps.requestQueue),
198169
_dashprivate_paths: stateProps.paths,
199170
_dashprivate_requestQueue: stateProps.requestQueue,
200171
};
201172
}
202173

174+
function getLoadingState(layout, requestQueue) {
175+
const ids = isLoadingComponent(layout) ?
176+
getNestedIds(layout) :
177+
(layout && layout.props.id ?
178+
[layout.props.id] :
179+
[]);
180+
181+
let isLoading = false;
182+
let loadingProp;
183+
let loadingComponent;
184+
185+
if (requestQueue) {
186+
forEach(r => {
187+
const controllerId = isNil(r.controllerId) ? '' : r.controllerId;
188+
if (r.status === 'loading' && any(id => contains(id, controllerId), ids)) {
189+
isLoading = true;
190+
[loadingComponent, loadingProp] = r.controllerId.split('.');
191+
}
192+
}, requestQueue);
193+
}
194+
195+
// Set loading state
196+
return {
197+
is_loading: isLoading,
198+
prop_name: loadingProp,
199+
component_name: loadingComponent,
200+
};
201+
}
202+
203+
function getNestedIds(layout) {
204+
const ids = [];
205+
const queue = [layout];
206+
207+
while (queue.length) {
208+
const elementLayout = queue.shift();
209+
210+
const props = elementLayout &&
211+
elementLayout.props;
212+
213+
if (!props) {
214+
continue;
215+
}
216+
217+
const { children, id } = props;
218+
219+
if (id) {
220+
ids.push(id);
221+
}
222+
223+
if (children) {
224+
const filteredChildren = filter(
225+
child => !isSimpleComponent(child) && !isLoadingComponent(child),
226+
Array.isArray(children) ? children : [children]
227+
);
228+
229+
queue.push(...filteredChildren);
230+
}
231+
}
232+
233+
return ids;
234+
}
235+
236+
function isLoadingComponent(layout) {
237+
return Registry.resolve(layout.type, layout.namespace)._dashprivate_isLoadingComponent;
238+
}
239+
203240
export const AugmentedTreeContainer = connect(mapStateToProps, mapDispatchToProps, mergeProps)(TreeContainer);
204241

205242
export default AugmentedTreeContainer;

0 commit comments

Comments
 (0)