Skip to content

Commit 5bf1eaa

Browse files
authored
Loading component changes (#1080)
* Remove loading_state in favour of Dash context * Add target_components prop to Spinner and Placeholder * Fix tests
1 parent ccba187 commit 5bf1eaa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+457
-1591
lines changed

src/components/accordion/Accordion.js

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import RBAccordion from 'react-bootstrap/Accordion';
55

66
import {parseChildrenToArray, resolveChildProps} from '../../private/util';
77
import {AccordionContext} from '../../private/AccordionContext';
8+
import {getLoadingState} from '../../private/util';
89

910
/**
1011
* A self contained Accordion component. Build up the children using the
@@ -14,7 +15,6 @@ const Accordion = props => {
1415
let {
1516
children,
1617
active_item,
17-
loading_state,
1818
key,
1919
setProps,
2020
class_name,
@@ -70,9 +70,7 @@ const Accordion = props => {
7070
return (
7171
<RBAccordion
7272
key={key}
73-
data-dash-is-loading={
74-
(loading_state && loading_state.is_loading) || undefined
75-
}
73+
data-dash-is-loading={getLoadingState() || undefined}
7674
activeKey={active_item}
7775
defaultActiveKey={start_collapsed ? null : active_item}
7876
alwaysOpen={always_open}
@@ -157,24 +155,6 @@ Accordion.propTypes = {
157155
*/
158156
start_collapsed: PropTypes.bool,
159157

160-
/**
161-
* Object that holds the loading state object coming from dash-renderer
162-
*/
163-
loading_state: PropTypes.shape({
164-
/**
165-
* Determines if the component is loading or not
166-
*/
167-
is_loading: PropTypes.bool,
168-
/**
169-
* Holds which property is loading
170-
*/
171-
prop_name: PropTypes.string,
172-
/**
173-
* Holds the name of the component that is loading
174-
*/
175-
component_name: PropTypes.string
176-
}),
177-
178158
/**
179159
* Used to allow user interactions in this component to be persisted when
180160
* the component - or the page - is refreshed. If `persisted` is truthy and

src/components/accordion/AccordionItem.js

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
33
import {omit} from 'ramda';
44
import RBAccordion from 'react-bootstrap/Accordion';
55

6-
import {stringifyId} from '../../private/util';
6+
import {getLoadingState, stringifyId} from '../../private/util';
77
import {AccordionContext} from '../../private/AccordionContext';
88

99
/**
@@ -12,7 +12,6 @@ import {AccordionContext} from '../../private/AccordionContext';
1212
const AccordionItem = ({
1313
title,
1414
item_id,
15-
loading_state,
1615
class_name,
1716
className,
1817
id,
@@ -31,9 +30,7 @@ const AccordionItem = ({
3130
['setProps', 'persistence', 'persistence_type', 'persisted_props'],
3231
otherProps
3332
)}
34-
data-dash-is-loading={
35-
(loading_state && loading_state.is_loading) || undefined
36-
}
33+
data-dash-is-loading={getLoadingState() || undefined}
3734
>
3835
<RBAccordion.Header onClick={() => toggle(itemID)}>
3936
{title}
@@ -84,25 +81,7 @@ AccordionItem.propTypes = {
8481
* will be set to "item-i" where i is (zero indexed) position of item in list
8582
* items pased to Accordion component.
8683
*/
87-
item_id: PropTypes.string,
88-
89-
/**
90-
* Object that holds the loading state object coming from dash-renderer
91-
*/
92-
loading_state: PropTypes.shape({
93-
/**
94-
* Determines if the component is loading or not
95-
*/
96-
is_loading: PropTypes.bool,
97-
/**
98-
* Holds which property is loading
99-
*/
100-
prop_name: PropTypes.string,
101-
/**
102-
* Holds the name of the component that is loading
103-
*/
104-
component_name: PropTypes.string
105-
})
84+
item_id: PropTypes.string
10685
};
10786

10887
export default AccordionItem;

src/components/alert/Alert.js

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
33
import {omit} from 'ramda';
44
import RBAlert from 'react-bootstrap/Alert';
55
import {bootstrapColors} from '../../private/BootstrapColors';
6+
import {getLoadingState} from '../../private/util';
67

78
/**
89
* Alert allows you to create contextual feedback messages on user actions.
@@ -13,7 +14,6 @@ import {bootstrapColors} from '../../private/BootstrapColors';
1314
const Alert = ({
1415
children,
1516
dismissable,
16-
loading_state,
1717
setProps,
1818
style,
1919
class_name,
@@ -58,9 +58,7 @@ const Alert = ({
5858
['persistence', 'persisted_props', 'persistence_type', 'setProps'],
5959
otherProps
6060
)}
61-
data-dash-is-loading={
62-
(loading_state && loading_state.is_loading) || undefined
63-
}
61+
data-dash-is-loading={getLoadingState() || undefined}
6462
>
6563
{children}
6664
</RBAlert>
@@ -138,24 +136,6 @@ Alert.propTypes = {
138136
*/
139137
duration: PropTypes.number,
140138

141-
/**
142-
* Object that holds the loading state object coming from dash-renderer
143-
*/
144-
loading_state: PropTypes.shape({
145-
/**
146-
* Determines if the component is loading or not
147-
*/
148-
is_loading: PropTypes.bool,
149-
/**
150-
* Holds which property is loading
151-
*/
152-
prop_name: PropTypes.string,
153-
/**
154-
* Holds the name of the component that is loading
155-
*/
156-
component_name: PropTypes.string
157-
}),
158-
159139
/**
160140
* Used to allow user interactions in this component to be persisted when
161141
* the component - or the page - is refreshed. If `persisted` is truthy and

src/components/badge/Badge.js

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {omit} from 'ramda';
44
import RBBadge from 'react-bootstrap/Badge';
55
import Link from '../../private/Link';
66
import {bootstrapColors} from '../../private/BootstrapColors';
7+
import {getLoadingState} from '../../private/util';
78

89
/**
910
* Badges can be used to add counts or labels to other components.
@@ -12,7 +13,6 @@ const Badge = props => {
1213
const {
1314
children,
1415
href,
15-
loading_state,
1616
setProps,
1717
style,
1818
className,
@@ -41,9 +41,7 @@ const Badge = props => {
4141
className={class_name || className}
4242
style={!isBootstrapColor ? {backgroundColor: color, ...style} : style}
4343
{...omit(['setProps'], otherProps)}
44-
data-dash-is-loading={
45-
(loading_state && loading_state.is_loading) || undefined
46-
}
44+
data-dash-is-loading={getLoadingState() || undefined}
4745
>
4846
{children}
4947
</RBBadge>
@@ -118,24 +116,6 @@ Badge.propTypes = {
118116
*/
119117
tag: PropTypes.string,
120118

121-
/**
122-
* Object that holds the loading state object coming from dash-renderer
123-
*/
124-
loading_state: PropTypes.shape({
125-
/**
126-
* Determines if the component is loading or not
127-
*/
128-
is_loading: PropTypes.bool,
129-
/**
130-
* Holds which property is loading
131-
*/
132-
prop_name: PropTypes.string,
133-
/**
134-
* Holds the name of the component that is loading
135-
*/
136-
component_name: PropTypes.string
137-
}),
138-
139119
/**
140120
* If true, the browser will treat this as an external link,
141121
* forcing a page refresh at the new location. If false,

src/components/breadcrumb/Breadcrumb.js

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import PropTypes from 'prop-types';
33
import RBBreadcrumb from 'react-bootstrap/Breadcrumb';
44

55
import Link from '../../private/Link';
6+
import {getLoadingState} from '../../private/util';
67

78
/**
89
* Use breadcrumbs to create a navigation breadcrumb in your app.
910
*/
1011
const Breadcrumb = ({
1112
items,
1213
tag,
13-
loading_state,
1414
class_name,
1515
className,
1616
item_class_name,
@@ -20,9 +20,7 @@ const Breadcrumb = ({
2020
}) => (
2121
<RBBreadcrumb
2222
as={tag}
23-
data-dash-is-loading={
24-
(loading_state && loading_state.is_loading) || undefined
25-
}
23+
data-dash-is-loading={getLoadingState() || undefined}
2624
className={class_name || className}
2725
{...otherProps}
2826
>
@@ -130,25 +128,7 @@ Breadcrumb.propTypes = {
130128
/**
131129
* HTML tag to use for the outer breadcrumb component. Default: "nav".
132130
*/
133-
tag: PropTypes.object,
134-
135-
/**
136-
* Object that holds the loading state object coming from dash-renderer
137-
*/
138-
loading_state: PropTypes.shape({
139-
/**
140-
* Determines if the component is loading or not
141-
*/
142-
is_loading: PropTypes.bool,
143-
/**
144-
* Holds which property is loading
145-
*/
146-
prop_name: PropTypes.string,
147-
/**
148-
* Holds the name of the component that is loading
149-
*/
150-
component_name: PropTypes.string
151-
})
131+
tag: PropTypes.object
152132
};
153133

154134
export default Breadcrumb;

src/components/button/Button.js

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33
import RBButton from 'react-bootstrap/Button';
44
import Link from '../../private/Link';
5+
import {getLoadingState} from '../../private/util';
56

67
/**
78
* A component for creating Bootstrap buttons with different style options. The
@@ -15,7 +16,6 @@ const Button = ({
1516
children,
1617
disabled,
1718
href,
18-
loading_state,
1919
setProps,
2020
target,
2121
type,
@@ -58,9 +58,7 @@ const Button = ({
5858
className={class_name || className}
5959
rel={useLink ? rel : undefined}
6060
{...otherProps}
61-
data-dash-is-loading={
62-
(loading_state && loading_state.is_loading) || undefined
63-
}
61+
data-dash-is-loading={getLoadingState() || undefined}
6462
>
6563
{children}
6664
</RBButton>
@@ -157,24 +155,6 @@ Button.propTypes = {
157155
*/
158156
outline: PropTypes.bool,
159157

160-
/**
161-
* Object that holds the loading state object coming from dash-renderer
162-
*/
163-
loading_state: PropTypes.shape({
164-
/**
165-
* Determines if the component is loading or not
166-
*/
167-
is_loading: PropTypes.bool,
168-
/**
169-
* Holds which property is loading
170-
*/
171-
prop_name: PropTypes.string,
172-
/**
173-
* Holds the name of the component that is loading
174-
*/
175-
component_name: PropTypes.string
176-
}),
177-
178158
/**
179159
* Target attribute to pass on to link if using Button as an external link.
180160
*/

src/components/buttongroup/ButtonGroup.js

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,19 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33
import {omit} from 'ramda';
44
import RBButtonGroup from 'react-bootstrap/ButtonGroup';
5+
import {getLoadingState} from '../../private/util';
56

67
/**
78
* A component for creating groups of buttons. Can be used with `Button` or
89
* `DropdownMenu`.
910
*/
1011
const ButtonGroup = props => {
11-
const {children, loading_state, class_name, className, ...otherProps} = props;
12+
const {children, class_name, className, ...otherProps} = props;
1213
return (
1314
<RBButtonGroup
1415
className={class_name || className}
1516
{...omit(['setProps'], otherProps)}
16-
data-dash-is-loading={
17-
(loading_state && loading_state.is_loading) || undefined
18-
}
17+
data-dash-is-loading={getLoadingState() || undefined}
1918
>
2019
{children}
2120
</RBButtonGroup>
@@ -67,25 +66,7 @@ ButtonGroup.propTypes = {
6766
/**
6867
* Size of button group, options: 'sm', 'md', 'lg'.
6968
*/
70-
size: PropTypes.string,
71-
72-
/**
73-
* Object that holds the loading state object coming from dash-renderer
74-
*/
75-
loading_state: PropTypes.shape({
76-
/**
77-
* Determines if the component is loading or not
78-
*/
79-
is_loading: PropTypes.bool,
80-
/**
81-
* Holds which property is loading
82-
*/
83-
prop_name: PropTypes.string,
84-
/**
85-
* Holds the name of the component that is loading
86-
*/
87-
component_name: PropTypes.string
88-
})
69+
size: PropTypes.string
8970
};
9071

9172
export default ButtonGroup;

0 commit comments

Comments
 (0)