Skip to content

Commit 603cbce

Browse files
committed
get_props -> get_layout
1 parent 011ded9 commit 603cbce

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,11 @@ export default class Tabs extends Component {
149149
}
150150
const children = this.parseChildrenToArray();
151151
if (children && children.length) {
152-
const firstChildren = window.dash_clientside.get_props(
153-
children[0].props.componentPath,
154-
'value'
155-
);
152+
const firstChildren = window.dash_clientside.get_layout([
153+
...children[0].props.componentPath,
154+
'props',
155+
'value',
156+
]);
156157
return firstChildren || 'tab-1';
157158
}
158159
return 'tab-1';
@@ -187,9 +188,15 @@ export default class Tabs extends Component {
187188
// enhance Tab components coming from Dash (as dcc.Tab) with methods needed for handling logic
188189
let childProps;
189190

190-
childProps = window.dash_clientside.get_props(
191-
child.props.componentPath
192-
);
191+
if (React.isValidElement(child)) {
192+
childProps = window.dash_clientside.get_layout([
193+
...child.props.componentPath,
194+
'props',
195+
]);
196+
} else {
197+
// In case the selected tab is a string.
198+
childProps = {};
199+
}
193200

194201
if (!childProps.value) {
195202
childProps = {...childProps, value: `tab-${index + 1}`};

dash/dash-renderer/src/utils/clientsideFunctions.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
import {concat, path} from 'ramda';
1+
import {path} from 'ramda';
2+
23
import {updateProps, notifyObservers} from '../actions/index';
34
import {getPath} from '../actions/paths';
45

6+
function getStores() {
7+
const stores = ((window as any).dash_stores =
8+
(window as any).dash_stores || []);
9+
return stores;
10+
}
11+
512
/**
613
* Set the props of a dash component by id or path.
714
*
@@ -12,8 +19,7 @@ function set_props(
1219
idOrPath: string | object | string[],
1320
props: {[k: string]: any}
1421
) {
15-
const ds = ((window as any).dash_stores =
16-
(window as any).dash_stores || []);
22+
const ds = getStores();
1723
for (let y = 0; y < ds.length; y++) {
1824
const {dispatch, getState} = ds[y];
1925
let componentPath;
@@ -64,12 +70,8 @@ const clean_url = (url: string, fallback = 'about:blank') => {
6470
* @param propPath Additional key to get the property instead of plain props.
6571
* @returns
6672
*/
67-
function get_props(
68-
componentPathOrId: string[] | string,
69-
...propPath: string[]
70-
): any {
71-
const ds = ((window as any).dash_stores =
72-
(window as any).dash_stores || []);
73+
function get_layout(componentPathOrId: string[] | string): any {
74+
const ds = getStores();
7375
for (let y = 0; y < ds.length; y++) {
7476
const {paths, layout} = ds[y].getState();
7577
let componentPath;
@@ -78,10 +80,7 @@ function get_props(
7880
} else {
7981
componentPath = componentPathOrId;
8082
}
81-
const props = path(
82-
concat(componentPath, ['props', ...propPath]),
83-
layout
84-
);
83+
const props = path(componentPath, layout);
8584
if (props !== undefined) {
8685
return props;
8786
}
@@ -92,4 +91,4 @@ const dc = ((window as any).dash_clientside =
9291
(window as any).dash_clientside || {});
9392
dc['set_props'] = set_props;
9493
dc['clean_url'] = dc['clean_url'] === undefined ? clean_url : dc['clean_url'];
95-
dc['get_props'] = get_props;
94+
dc['get_layout'] = get_layout;

0 commit comments

Comments
 (0)