Skip to content

Commit 854446c

Browse files
committed
Extract config to use in crawl layout.
1 parent 642fbea commit 854446c

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

dash/dash-renderer/src/AppContainer.react.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import APIController from './APIController.react';
55
import Loading from './components/core/Loading.react';
66
import Toolbar from './components/core/Toolbar.react';
77
import Reloader from './components/core/Reloader.react';
8+
import config from './config';
89
import {setHooks, setConfig} from './actions/index';
910
import {type, memoizeWith, identity} from 'ramda';
1011

@@ -35,9 +36,6 @@ class UnconnectedAppContainer extends React.Component {
3536

3637
UNSAFE_componentWillMount() {
3738
const {dispatch} = this.props;
38-
const config = JSON.parse(
39-
document.getElementById('_dash-config').textContent
40-
);
4139

4240
// preset common request params in the config
4341
config.fetch = {

dash/dash-renderer/src/actions/utils.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import {append, concat, has, path, pathOr, type} from 'ramda';
22

3+
import config from '../config';
4+
35
/*
46
* requests_pathname_prefix is the new config parameter introduced in
57
* dash==0.18.0. The previous versions just had url_base_pathname
@@ -54,7 +56,11 @@ export const crawlLayout = (
5456
const newPath = concat(currentPath, propsChildren);
5557
crawlLayout(children, func, newPath);
5658
}
57-
const childrenProps = pathOr([], ['childrenProps'], object);
59+
const childrenProps = pathOr(
60+
[],
61+
['children_props', object.namespace, object.type],
62+
config
63+
);
5864
childrenProps.forEach(childrenProp => {
5965
if (childrenProp.startsWith('[]')) {
6066
let [frontPath, backPath] = childrenProp.split('.');

dash/dash-renderer/src/config.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
type Config = {
2+
url_base_pathname: string;
3+
requests_pathname_prefix: string;
4+
ui: boolean;
5+
props_check: boolean;
6+
show_undo_redo: boolean;
7+
suppress_callback_exceptions: boolean;
8+
update_title: string;
9+
hot_reload?: {
10+
interval: number;
11+
max_retry: number;
12+
};
13+
validation_layout: any;
14+
children_props: {[k: string]: {[k: string]: string[]}};
15+
};
16+
17+
const configElement = document.getElementById('_dash-config');
18+
19+
const config: Config = JSON.parse(
20+
configElement?.textContent ? configElement?.textContent : '{}'
21+
);
22+
23+
export default config;

0 commit comments

Comments
 (0)