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

Loading states api #93

Merged
merged 48 commits into from
Feb 28, 2019
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
762b0ba
Pass loading prop down to components instead of rendering div
valentijnnieman Oct 12, 2018
1fb8376
First pass at providing 'loading' prop to dash components
valentijnnieman Oct 30, 2018
5940bb4
Add componentName and propName props to loading object, cleanup
valentijnnieman Nov 6, 2018
5bf3d30
Cleanup
valentijnnieman Nov 6, 2018
a571882
Updated core components tarball
valentijnnieman Nov 7, 2018
1777a94
Change prop names for loading state to be more Pythonic
valentijnnieman Nov 13, 2018
1af20c9
Use latest dcc that fixes Input reliant tests
valentijnnieman Nov 15, 2018
4ddc4b7
Left-over from rebasing
valentijnnieman Nov 15, 2018
02e992a
Update everything to it's latest version expect html-components
valentijnnieman Nov 15, 2018
6acc394
Add tarball back in
valentijnnieman Nov 15, 2018
3264f4b
Change props.status to props.loading_state to be more specific
valentijnnieman Nov 15, 2018
a51dcf9
Pass loading prop down to components instead of rendering div
valentijnnieman Oct 12, 2018
d38fec9
First pass at providing 'loading' prop to dash components
valentijnnieman Oct 30, 2018
96aebf4
Add componentName and propName props to loading object, cleanup
valentijnnieman Nov 6, 2018
72b579d
Cleanup
valentijnnieman Nov 6, 2018
8d5e4af
Updated core components tarball
valentijnnieman Nov 7, 2018
95ed504
Change prop names for loading state to be more Pythonic
valentijnnieman Nov 13, 2018
e1917bf
Rebuild bundles
valentijnnieman Nov 15, 2018
cfe4c40
Fixed simple.py regression
valentijnnieman Nov 15, 2018
6c34ac9
Replace dcc tarball with rc1 version
valentijnnieman Nov 16, 2018
2153923
Try with new componentWillRecieveProps changes in dcc tarball
valentijnnieman Nov 16, 2018
e48348b
Revert everything in dev-requirements except dcc tarball
valentijnnieman Nov 16, 2018
48e0dd4
Revert back to old dev-requirements.txt completely
valentijnnieman Nov 16, 2018
4b43a54
Refactored requestQueue map into forEach
valentijnnieman Nov 27, 2018
8f1cc81
Add tarball back in dev-requirements
valentijnnieman Nov 27, 2018
05955ea
Revert back to old dev-requirements
valentijnnieman Nov 27, 2018
807d6bc
Fix tests by checking if controllerId is null
valentijnnieman Nov 29, 2018
bf97e2b
Remove newlines from NotifyObservers parameters
valentijnnieman Nov 29, 2018
99ef59a
Version bump to 0.16.0
valentijnnieman Nov 29, 2018
cd4a507
Merge branch 'master' of https://github.com/plotly/dash-renderer into…
valentijnnieman Nov 30, 2018
c9f28d2
Change const to let
valentijnnieman Nov 30, 2018
08c4646
Update version to 0.16.0rc1
valentijnnieman Dec 4, 2018
622e912
Revert dcc upgrade in deps
valentijnnieman Dec 17, 2018
91e0a25
Merge branch 'master' of https://github.com/plotly/dash-renderer into…
valentijnnieman Dec 17, 2018
75592f7
Calculate loading_state in TreeContainer so children have access to i…
valentijnnieman Jan 23, 2019
b7f3770
Merge branch 'master' of https://github.com/plotly/dash-renderer into…
valentijnnieman Jan 30, 2019
8c0771b
Add confirm dialog test from DCC
valentijnnieman Jan 31, 2019
a2220fb
Remove dcc test again
valentijnnieman Jan 31, 2019
461d515
Cleanup
valentijnnieman Jan 31, 2019
a0ed549
Only rerender TreeContainer if props are new
valentijnnieman Jan 31, 2019
f692a8d
Release 0.18.0rc3 with more dcc test fixes
valentijnnieman Feb 1, 2019
a1a4531
Remove loading prop from APIcontroller causing unneccesary re-renders
valentijnnieman Feb 7, 2019
e1fb848
Bump rc version
valentijnnieman Feb 7, 2019
8fb0bda
Update package.json as well
valentijnnieman Feb 13, 2019
8751dd4
Reset simple.py
valentijnnieman Feb 21, 2019
94b9259
Refactored recursivelyRender call in TreeContainer
valentijnnieman Feb 21, 2019
0850d4b
Merge branch 'master' of https://github.com/plotly/dash-renderer into…
valentijnnieman Feb 28, 2019
763c5bd
Fix formatting
valentijnnieman Feb 28, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [0.16.0] - 2018-11-30
- Loading states API [#267](https://github.com/plotly/dash/issues/267)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For final merge, needs to be unreleased and version bump reverted in package.json

## [0.15.1] - 2018-11-17
### Fixed
- Fix a bug in the ON_PROP_CHANGE callback where history was not correctly set when acting on more than one component. In particular, the 'undo' button should now work as expected. Fixes [#66](https://github.com/plotly/dash-renderer/issues/66).
Expand Down
2,919 changes: 1,454 additions & 1,465 deletions dash_renderer/dash_renderer.dev.js

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions dash_renderer/dash_renderer.min.js

Large diffs are not rendered by default.

Binary file added dash_renderer/favicon.ico
Binary file not shown.
2 changes: 1 addition & 1 deletion dash_renderer/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.15.1'
__version__ = '0.16.0'
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dash-renderer",
"version": "0.15.0",
"version": "0.16.0",
"description": "render dash components in react",
"main": "src/index.js",
"scripts": {
Expand Down
18 changes: 13 additions & 5 deletions src/APIController.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,13 @@ class UnconnectedContainer extends Component {
dispatch(hydrateInitialOutputs());
}
}

render() {
const {
appLifecycle,
dependenciesRequest,
layoutRequest,
layout,
} = this.props;

if (
layoutRequest.status &&
!contains(layoutRequest.status, [STATUS.OK, 'loading'])
Expand All @@ -99,12 +97,22 @@ class UnconnectedContainer extends Component {
} else if (appLifecycle === getAppState('HYDRATED')) {
return (
<div id="_dash-app-content">
<TreeContainer layout={layout} />
<TreeContainer layout={layout} loading={false} />
</div>
);
}

return <div className="_dash-loading">{'Loading...'}</div>;
if (isEmpty(layout)) {
return (
<div id="_dash-app-content">
<TreeContainer layout={layout} loading={true} />
</div>
);
}
return (
<div id="_dash-app-content">
<TreeContainer layout={layout} loading={true} />
</div>
);
}
}
UnconnectedContainer.propTypes = {
Expand Down
17 changes: 12 additions & 5 deletions src/TreeContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,26 @@ export default class TreeContainer extends Component {
}

render() {
return render(this.props.layout);
return recursivelyRender(this.props.layout, this.props.loading);
}
}

TreeContainer.propTypes = {
layout: PropTypes.object,
loading: PropTypes.bool
};

function render(component) {
function recursivelyRender(component, loading = false) {
if (
R.contains(R.type(component), ['String', 'Number', 'Null', 'Boolean'])
) {
return component;
}

if(R.isEmpty(component)) {
return null;
}

valentijnnieman marked this conversation as resolved.
Show resolved Hide resolved
// Create list of child elements
let children;

Expand Down Expand Up @@ -55,7 +60,9 @@ function render(component) {
children = (Array.isArray(componentProps.children)
? componentProps.children
: [componentProps.children]
).map(render);
).map(child => {
return recursivelyRender(child, loading);
});
}

if (!component.type) {
Expand All @@ -78,9 +85,9 @@ function render(component) {
...children
);

return <NotifyObservers id={componentProps.id}>{parent}</NotifyObservers>;
return <NotifyObservers id={componentProps.id} loading={loading}>{parent}</NotifyObservers>;
}

render.propTypes = {
recursivelyRender.propTypes = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐱

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does 🐱 mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah never mind, I found this again 😸

children: PropTypes.object,
};
39 changes: 36 additions & 3 deletions src/components/core/NotifyObservers.react.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {connect} from 'react-redux';
import {isEmpty} from 'ramda';
import {isNil, contains, isEmpty, forEach} from 'ramda';
import {notifyObservers, updateProps} from '../../actions';
import React from 'react';
import PropTypes from 'prop-types';
import {STATUS} from '../../constants/constants';

/*
* NotifyObservers passes a connected `setProps` handler down to
Expand All @@ -13,6 +14,7 @@ function mapStateToProps(state) {
return {
dependencies: state.dependenciesRequest.content,
paths: state.paths,
requestQueue: state.requestQueue,
};
}

Expand All @@ -27,6 +29,8 @@ function mergeProps(stateProps, dispatchProps, ownProps) {
children: ownProps.children,
dependencies: stateProps.dependencies,
paths: stateProps.paths,
loading: ownProps.loading,
requestQueue: stateProps.requestQueue,

fireEvent: function fireEvent({event}) {
// Update this component's observers with the updated props
Expand All @@ -53,12 +57,33 @@ function NotifyObserversComponent({
children,
id,
paths,

dependencies,

loading,
fireEvent,
setProps,
requestQueue,
}) {
// loading prop coming from TreeContainer
let isLoading = loading;
let loadingProp;
let loadingComponent;

forEach(r => {
const controllerId = isNil(r.controllerId) ? '' : r.controllerId;
if (r.status === 'loading' && contains(id, controllerId)) {
isLoading = true;
[loadingComponent, loadingProp] = r.controllerId.split('.');
}
}, requestQueue);

const thisRequest = requestQueue.filter(r => {
const controllerId = isNil(r.controllerId) ? '' : r.controllerId;
return contains(id, controllerId);
});
if (thisRequest.status === STATUS.OK) {
isLoading = false;
}

const thisComponentTriggersEvents =
dependencies &&
dependencies.find(dependency =>
Expand Down Expand Up @@ -102,6 +127,13 @@ function NotifyObserversComponent({
extraProps.fireEvent = fireEvent;
}

// Set loading state
extraProps.loading_state = {
is_loading: isLoading,
prop_name: loadingProp,
component_name: loadingComponent,
};

if (!isEmpty(extraProps)) {
return React.cloneElement(children, extraProps);
}
Expand All @@ -112,6 +144,7 @@ NotifyObserversComponent.propTypes = {
id: PropTypes.string.isRequired,
children: PropTypes.node.isRequired,
path: PropTypes.array.isRequired,
loading: PropTypes.bool,
};

export default connect(
Expand Down