Skip to content

Commit 0049cab

Browse files
authored
Merge pull request #3175 from plotly/external-children
3.0 RC3 changes.
2 parents 7abf17e + 4336b34 commit 0049cab

File tree

16 files changed

+181
-20
lines changed

16 files changed

+181
-20
lines changed

@plotly/dash-test-components/src/components/ExternalComponent.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33

44

5-
const ExternalComponent = ({ id, text, input_id }) => {
5+
const ExternalComponent = ({ id, text, input_id, extra_component }) => {
66
const ctx = window.dash_component_api.useDashContext();
77
const ExternalWrapper = window.dash_component_api.ExternalWrapper;
88

@@ -15,6 +15,14 @@ const ExternalComponent = ({ id, text, input_id }) => {
1515
value={text}
1616
componentPath={[...ctx.componentPath, 'external']}
1717
/>
18+
{
19+
extra_component &&
20+
<ExternalWrapper
21+
componentType={extra_component.type}
22+
componentNamespace={extra_component.namespace}
23+
componentPath={[...ctx.componentPath, 'extra']}
24+
{...extra_component.props}
25+
/>}
1826
</div>
1927
)
2028
}
@@ -23,6 +31,11 @@ ExternalComponent.propTypes = {
2331
id: PropTypes.string,
2432
text: PropTypes.string,
2533
input_id: PropTypes.string,
34+
extra_component: PropTypes.exact({
35+
type: PropTypes.string,
36+
namespace: PropTypes.string,
37+
props: PropTypes.object,
38+
}),
2639
};
2740

2841
export default ExternalComponent;

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22
All notable changes to `dash` will be documented in this file.
33
This project adheres to [Semantic Versioning](https://semver.org/).
44

5+
## [3.0.0-rc3] - 2025-02-21
6+
7+
## Added
8+
9+
- [#3121](https://github.com/plotly/dash/pull/3121) Restyle and add version checker to dev tools.
10+
- [#3175](https://github.com/plotly/dash/pull/3175) Add `custom_data` hook.
11+
- [#3175](https://github.com/plotly/dash/pull/3175) Improved error for removed Dash app attribute, run_server and long_callback
12+
- [#3175](https://github.com/plotly/dash/pull/3175) Expose `stringifyId` in `window.dash_component_api`.
13+
14+
## Fixed
15+
16+
- [#3175](https://github.com/plotly/dash/pull/3175) Fix `ExternalWrapper` rendering children and support pattern matching ids.
17+
518
## [3.0.0-rc2] - 2025-02-18
619

720
## Added

dash/_callback_context.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,14 @@ def origin(self):
304304
"""
305305
return _get_from_context("origin", "")
306306

307+
@property
308+
@has_context
309+
def custom_data(self):
310+
"""
311+
Custom data set by hooks.custom_data.
312+
"""
313+
return _get_from_context("custom_data", {})
314+
307315

308316
callback_context = CallbackContext()
309317

dash/_dash_renderer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22

3-
__version__ = "2.0.1"
3+
__version__ = "2.0.2"
44

55
_available_react_versions = {"18.3.1", "18.2.0", "16.14.0"}
66
_available_reactdom_versions = {"18.3.1", "18.2.0", "16.14.0"}
@@ -64,7 +64,7 @@ def _set_react_version(v_react, v_reactdom=None):
6464
{
6565
"relative_package_path": "dash-renderer/build/dash_renderer.min.js",
6666
"dev_package_path": "dash-renderer/build/dash_renderer.dev.js",
67-
"external_url": "https://unpkg.com/dash-renderer@2.0.1"
67+
"external_url": "https://unpkg.com/dash-renderer@2.0.2"
6868
"/build/dash_renderer.min.js",
6969
"namespace": "dash",
7070
},

dash/_hooks.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def __init__(self) -> None:
4545
"error": [],
4646
"callback": [],
4747
"index": [],
48+
"custom_data": [],
4849
}
4950
self._js_dist = []
5051
self._css_dist = []
@@ -191,6 +192,28 @@ def wrap(func):
191192

192193
return wrap
193194

195+
def custom_data(
196+
self, namespace: str, priority: _t.Optional[int] = None, final=False
197+
):
198+
"""
199+
Add data to the callback_context.custom_data property under the namespace.
200+
201+
The hook function takes the current context_value and before the ctx is set
202+
and has access to the flask request context.
203+
"""
204+
205+
def wrap(func: _t.Callable[[_t.Dict], _t.Any]):
206+
self.add_hook(
207+
"custom_data",
208+
func,
209+
priority=priority,
210+
final=final,
211+
data={"namespace": namespace},
212+
)
213+
return func
214+
215+
return wrap
216+
194217

195218
hooks = _Hooks()
196219

dash/_obsolete.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# pylint: disable=too-few-public-methods
2+
from .exceptions import ObsoleteAttributeException
3+
4+
5+
class ObsoleteAttribute:
6+
def __init__(self, message: str, exc=ObsoleteAttributeException):
7+
self.message = message
8+
self.exc = exc
9+
10+
11+
class ObsoleteChecker:
12+
_obsolete_attributes = {
13+
"run_server": ObsoleteAttribute("app.run_server has been replaced by app.run"),
14+
"long_callback": ObsoleteAttribute(
15+
"app.long_callback has been removed, use app.callback(..., background=True) instead"
16+
),
17+
}
18+
19+
def __getattr__(self, name: str):
20+
if name in self._obsolete_attributes:
21+
err = self._obsolete_attributes[name]
22+
raise err.exc(err.message)
23+
return getattr(self, name)

dash/dash-renderer/package-lock.json

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

dash/dash-renderer/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dash-renderer",
3-
"version": "2.0.1",
3+
"version": "2.0.2",
44
"description": "render dash components in react",
55
"main": "build/dash_renderer.min.js",
66
"scripts": {
@@ -13,7 +13,7 @@
1313
"build:dev": "webpack",
1414
"build:local": "renderer build local",
1515
"build": "renderer build && npm run prepublishOnly",
16-
"postbuild": "es-check es2018 ../deps/*.js build/*.js",
16+
"postbuild": "es-check es2015 ../deps/*.js build/*.js",
1717
"test": "karma start karma.conf.js --single-run",
1818
"format": "run-s private::format.*",
1919
"lint": "run-s private::lint.* --continue-on-error"

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {getAction} from './constants';
66
import cookie from 'cookie';
77
import {validateCallbacksToLayout} from './dependencies';
88
import {includeObservers, getLayoutCallbacks} from './dependencies_ts';
9-
import {getPath} from './paths';
9+
import {computePaths, getPath} from './paths';
1010

1111
export const onError = createAction(getAction('ON_ERROR'));
1212
export const setAppLifecycle = createAction(getAction('SET_APP_LIFECYCLE'));
@@ -21,6 +21,14 @@ export const updateProps = createAction(getAction('ON_PROP_CHANGE'));
2121
export const insertComponent = createAction(getAction('INSERT_COMPONENT'));
2222
export const removeComponent = createAction(getAction('REMOVE_COMPONENT'));
2323

24+
export const addComponentToLayout = payload => (dispatch, getState) => {
25+
const {paths} = getState();
26+
dispatch(insertComponent(payload));
27+
dispatch(
28+
setPaths(computePaths(payload.component, payload.componentPath, paths))
29+
);
30+
};
31+
2432
export const dispatchError = dispatch => (message, lines) =>
2533
dispatch(
2634
onError({

dash/dash-renderer/src/dashApi.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {DashContext, useDashContext} from './wrapper/DashContext';
33
import {getPath} from './actions/paths';
44
import {getStores} from './utils/stores';
55
import ExternalWrapper from './wrapper/ExternalWrapper';
6+
import {stringifyId} from './actions/dependencies';
67

78
/**
89
* Get the dash props from a component path or id.
@@ -32,5 +33,6 @@ function getLayout(componentPathOrId: string[] | string): any {
3233
ExternalWrapper,
3334
DashContext,
3435
useDashContext,
35-
getLayout
36+
getLayout,
37+
stringifyId
3638
};

0 commit comments

Comments
 (0)