Skip to content

Commit 74b2c36

Browse files
Rework dash-renderer setProps (plotly#478)
1 parent 3c91ea7 commit 74b2c36

14 files changed

+209
-83
lines changed

packages/dash-core-components/dash_core_components/dash_core_components.dev.js

Lines changed: 166 additions & 43 deletions
Large diffs are not rendered by default.

packages/dash-core-components/dash_core_components/dash_core_components.dev.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/dash-core-components/dash_core_components/dash_core_components.min.js

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/dash-core-components/dash_core_components/dash_core_components.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/dash-core-components/dash_core_components/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
"prettier": "^1.14.2",
7474
"react": "^16.6.1",
7575
"react-dom": "^16.6.1",
76+
"react-dot-fragment": "^0.2.8",
7677
"style-loader": "^0.23.1",
7778
"styled-jsx": "^3.1.1",
7879
"webpack": "^4.25.1",
Binary file not shown.

packages/dash-core-components/package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/dash-core-components/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
"prettier": "^1.14.2",
7474
"react": "^16.6.1",
7575
"react-dom": "^16.6.1",
76+
"react-dot-fragment": "^0.2.8",
7677
"style-loader": "^0.23.1",
7778
"styled-jsx": "^3.1.1",
7879
"webpack": "^4.25.1",

packages/dash-core-components/src/components/ConfirmDialog.react.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export default class ConfirmDialog extends Component {
1313
this.state = {
1414
displayed: props.displayed,
1515
};
16-
this._update();
1716
}
1817

1918
_setStateAndProps(value) {
@@ -58,6 +57,10 @@ export default class ConfirmDialog extends Component {
5857
this._update();
5958
}
6059

60+
componentDidMount() {
61+
this._update();
62+
}
63+
6164
render() {
6265
return null;
6366
}

packages/dash-core-components/src/components/ConfirmDialogProvider.react.js

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {clone} from 'ramda';
12
import React from 'react';
23
import PropTypes from 'prop-types';
34

@@ -31,20 +32,18 @@ export default class ConfirmDialogProvider extends React.Component {
3132
const displayed = this.state.displayed;
3233

3334
// Will lose the previous onClick of the child
34-
const wrapClick = child =>
35-
React.cloneElement(child, {
36-
onClick: () => {
37-
const update = {displayed: true};
38-
this.setState(update);
39-
if (setProps) {
40-
setProps(update);
41-
}
42-
},
43-
});
35+
const wrapClick = child => {
36+
const props = clone(child.props);
37+
props._dashprivate_layout.props.onClick = () => {
38+
const update = {displayed: true};
39+
this.setState(update);
40+
if (setProps) {
41+
setProps(update);
42+
}
43+
};
4444

45-
const realChild = children.props
46-
? children.props.children
47-
: children.map(e => e.props.children);
45+
return React.cloneElement(child, props);
46+
};
4847

4948
return (
5049
<div
@@ -53,9 +52,9 @@ export default class ConfirmDialogProvider extends React.Component {
5352
(loading_state && loading_state.is_loading) || undefined
5453
}
5554
>
56-
{realChild && realChild.length
57-
? realChild.map(wrapClick)
58-
: wrapClick(realChild)}
55+
{Array.isArray(children)
56+
? children.map(wrapClick)
57+
: wrapClick(children)}
5958
<ConfirmDialog {...this.props} displayed={displayed} />
6059
</div>
6160
);

packages/dash-core-components/src/components/Tab.react.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3+
import Fragment from 'react-dot-fragment';
34

4-
const Tab = ({children}) => <div>{children}</div>;
5+
const Tab = ({children}) => <Fragment>{children}</Fragment>;
56

67
/**
78
* Part of dcc.Tabs - this is the child Tab component used to render a tabbed page.

packages/dash-core-components/src/components/Tabs.react.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,11 @@ export default class Tabs extends Component {
204204
// props we want are lying a bit deeper - which means they
205205
// are coming from Dash
206206
R.isNil(child.props.disabled) &&
207-
child.props.children &&
208-
child.props.children.props
207+
child.props._dashprivate_layout &&
208+
child.props._dashprivate_layout.props
209209
) {
210210
// props are coming from Dash
211-
childProps = child.props.children.props;
211+
childProps = child.props._dashprivate_layout.props;
212212
} else {
213213
// else props are coming from React (Demo.react.js, or Tabs.test.js)
214214
childProps = child.props;
@@ -222,6 +222,7 @@ export default class Tabs extends Component {
222222
if (childProps.value === this.state.selected) {
223223
selectedTab = child;
224224
}
225+
225226
return (
226227
<EnhancedTab
227228
key={index}
@@ -247,9 +248,7 @@ export default class Tabs extends Component {
247248
});
248249
}
249250

250-
const selectedTabContent = !R.isNil(selectedTab)
251-
? selectedTab.props.children
252-
: '';
251+
const selectedTabContent = !R.isNil(selectedTab) ? selectedTab : '';
253252

254253
const tabContainerClass = this.props.vertical
255254
? 'tab-container tab-container--vert'

packages/dash-core-components/test/test_integration.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,8 +1264,6 @@ def on_click(n_clicks):
12641264
time.sleep(2)
12651265

12661266
self.driver.switch_to.alert.accept()
1267-
time.sleep(2)
1268-
self.driver.switch_to.alert.accept()
12691267

12701268
def test_empty_graph(self):
12711269
app = dash.Dash(__name__)

packages/dash-core-components/test/unit/Tabs.test.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,7 @@ describe('Tabs handle Tab selection logic', () => {
177177
});
178178
test('Tab can be clicked and will display its content', () => {
179179
tabs.find('[value="tab-2"]').simulate('click');
180-
const renderedContent = tabs.find('.tab-content > div').html();
181-
expect(renderedContent).toEqual('<div>Tab 2 child</div>');
182-
});
183-
test('Tab without value will still be clickable', () => {
184-
tabs.find('[value="tab-2"]').simulate('click');
185-
const renderedContent = tabs.find('.tab-content > div').html();
180+
const renderedContent = tabs.find(Tab).html();
186181
expect(renderedContent).toEqual('<div>Tab 2 child</div>');
187182
});
188183
});

0 commit comments

Comments
 (0)