Skip to content

Commit 9f318ec

Browse files
authored
Merge pull request #153 from plotly/chriddyp-dev-tools
another round of dev-tools edits
2 parents e9a6a64 + d342c71 commit 9f318ec

File tree

4 files changed

+40
-29
lines changed

4 files changed

+40
-29
lines changed

src/TreeContainer.js

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
contains,
88
filter,
99
forEach,
10+
has,
1011
isEmpty,
1112
isNil,
1213
keysIn,
@@ -25,6 +26,29 @@ import { assertPropTypes } from 'check-prop-types';
2526
const SIMPLE_COMPONENT_TYPES = ['String', 'Number', 'Null', 'Boolean'];
2627
const isSimpleComponent = component => contains(type(component), SIMPLE_COMPONENT_TYPES)
2728

29+
function validateComponent(componentDefinition) {
30+
if (type(componentDefinition) === 'Array') {
31+
throw new Error(
32+
'The children property of a component is a list of lists, instead '+
33+
'of just a list. ' +
34+
'Check the component that has the following contents, ' +
35+
'and remove of the levels of nesting: \n' +
36+
JSON.stringify(componentDefinition, null, 2)
37+
);
38+
}
39+
if (type(componentDefinition) === 'Object' &&
40+
!(has('namespace', componentDefinition) &&
41+
has('type', componentDefinition) &&
42+
has('props', componentDefinition))) {
43+
throw new Error(
44+
'An object was provided as `children` instead of a component, ' +
45+
'string, or number (or list of those). ' +
46+
'Check the children property that looks something like:\n' +
47+
JSON.stringify(componentDefinition, null, 2)
48+
);
49+
}
50+
}
51+
2852
const createContainer = component => isSimpleComponent(component) ?
2953
component :
3054
(<AugmentedTreeContainer
@@ -72,21 +96,9 @@ class TreeContainer extends Component {
7296
if (isSimpleComponent(_dashprivate_layout)) {
7397
return _dashprivate_layout;
7498
}
99+
validateComponent(_dashprivate_layout);
75100

76-
if (!_dashprivate_layout.type) {
77-
/* eslint-disable no-console */
78-
console.error(type(_dashprivate_layout), _dashprivate_layout);
79-
/* eslint-enable no-console */
80-
throw new Error('component.type is undefined');
81-
}
82-
if (!_dashprivate_layout.namespace) {
83-
/* eslint-disable no-console */
84-
console.error(type(_dashprivate_layout), _dashprivate_layout);
85-
/* eslint-enable no-console */
86-
throw new Error('component.namespace is undefined');
87-
}
88-
89-
const element = Registry.resolve(_dashprivate_layout.type, _dashprivate_layout.namespace);
101+
const element = Registry.resolve(_dashprivate_layout);
90102

91103
const layout = omit(['children'], _dashprivate_layout.props);
92104

@@ -178,7 +190,8 @@ TreeContainer.propTypes = {
178190
};
179191

180192
function isLoadingComponent(layout) {
181-
return Registry.resolve(layout.type, layout.namespace)._dashprivate_isLoadingComponent;
193+
validateComponent(layout);
194+
return Registry.resolve(layout)._dashprivate_isLoadingComponent;
182195
}
183196

184197
function getNestedIds(layout) {

src/components/error/FrontEnd/FrontEndError.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@
8484

8585
background-color: white;
8686
border: 2px solid #dfe8f3;
87-
border-radius: 0px 0px 4px 4px;
8887
color: #506784;
8988
overflow: scroll;
89+
white-space: pre-wrap;
9090
}
9191

9292
.dash-fe-error__curved {

src/components/error/GlobalErrorOverlay.react.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, {Component} from 'react';
22
import PropTypes from 'prop-types';
3+
import {concat} from 'ramda';
34

45
import './GlobalErrorOverlay.css';
56
import {FrontEndErrorContainer} from './FrontEnd/FrontEndErrorContainer.react';
@@ -14,14 +15,10 @@ export default class GlobalErrorOverlay extends Component {
1415

1516
let frontEndErrors;
1617
if (toastsEnabled) {
17-
let errors = [];
18-
if (error.frontEnd.length) {
19-
errors = error.frontEnd;
20-
}
21-
22-
error.backEnd.forEach(backEndError => {
23-
errors.push(backEndError);
24-
});
18+
const errors = concat(
19+
error.frontEnd,
20+
error.backEnd
21+
);
2522

2623
frontEndErrors = (
2724
<FrontEndErrorContainer errors={errors} resolve={resolve} />

src/registry.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
'use strict';
22

33
export default {
4-
resolve: (componentName, namespace) => {
4+
resolve: (component) => {
5+
const {type, namespace} = component;
6+
57
const ns = window[namespace]; /* global window: true */
68

79
if (ns) {
8-
if (ns[componentName]) {
9-
return ns[componentName];
10+
if (ns[type]) {
11+
return ns[type];
1012
}
1113

12-
throw new Error(`Component ${componentName} not found in
13-
${namespace}`);
14+
throw new Error(`Component ${type} not found in ${namespace}`);
1415
}
1516

1617
throw new Error(`${namespace} was not found.`);

0 commit comments

Comments
 (0)