-
-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updates for dash 3 #499
Closed
Closed
Updates for dash 3 #499
Changes from 13 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
aa2b717
updates for dash 3 - persistence, loading, dashprivate_layout
AnnMarieW 0bb88c1
change prop from required to optional so default can be set.
AnnMarieW 9b6f087
fix default props
AnnMarieW a0895ac
updated stepper
AnnMarieW de71432
handle components like dcc.loading
AnnMarieW 46cc48c
handle components like Checkbox and refactor dash3 utilities
AnnMarieW c4d80d9
updates for dash 3 - persistence, loading, dashprivate_layout
AnnMarieW 0aae73d
change prop from required to optional so default can be set.
AnnMarieW 56201ee
fix default props
AnnMarieW 4ada77c
updated stepper
AnnMarieW 6422feb
handle components like dcc.loading
AnnMarieW a5fce26
handle components like Checkbox and refactor dash3 utilities
AnnMarieW b54e17b
Merge remote-tracking branch 'origin/update-for-dash-3-0' into update…
AnnMarieW bbb2a15
fix getLoadingStateChildren after review
AnnMarieW aa986b4
update Hovercard to remove dashprivate
AnnMarieW ee3e9e7
update Menu to remove dashprivate
AnnMarieW 29e7181
update Popover to remove dashprivate
AnnMarieW 6901204
update Timeline to remove dashprivate
AnnMarieW 1361186
update Stepper
AnnMarieW 70aefe3
update Combobox components
AnnMarieW f5938b9
update react 18.3 check
AnnMarieW 8af9abb
fix typo
AnnMarieW 9503d92
update data-dash-is-loading
AnnMarieW 9596c6a
update defaultProps and persistence
AnnMarieW fefd7cf
bump to require dash 3
AnnMarieW 6298050
bump to require dash 3
AnnMarieW fea7ec5
revert requirements for dash 3 for dmc pre-release
AnnMarieW c17eef8
add changelog
AnnMarieW File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/** | ||
* Utility functions to support both Dash 2 and Dash 3 components | ||
* | ||
* For more details, refer to the Dash documentation: | ||
* Dash 3 for Component Developers - https://dash.plotly.com/dash-3-for-component-developers | ||
*/ | ||
import React from "react"; | ||
import { DashBaseProps } from "props/dash"; | ||
|
||
/** check for dash version */ | ||
export const isDash3 = (): boolean => { | ||
return !!(window as any).dash_component_api; | ||
}; | ||
|
||
/** Apply persistence settings based on React version */ | ||
export const setPersistence = (Component: any, props: string[] = ["value"]): void => { | ||
const persistence = { persisted_props: props, persistence_type: "local" }; | ||
|
||
if (parseFloat(React.version) < 18.3) { | ||
Component.defaultProps = persistence; | ||
} else { | ||
Component.dashPersistence = persistence; | ||
} | ||
}; | ||
|
||
/** Get the loading state for the current component */ | ||
export const getLoadingState = (loading_state?: DashBaseProps["loading_state"]): boolean => { | ||
return isDash3() | ||
? (window as any).dash_component_api.useDashContext().useLoading() | ||
: loading_state?.is_loading ?? false; | ||
}; | ||
|
||
/** Get layout information for a child component */ | ||
export const getChildLayout = (child: any): { type: any; props: any } => { | ||
if (isDash3()) { | ||
return (window as any).dash_component_api.getLayout(child.props.componentPath); | ||
} | ||
|
||
return { | ||
type: child.props?._dashprivate_layout?.type, | ||
props: child.props?._dashprivate_layout?.props, | ||
}; | ||
}; | ||
|
||
/** Get only the props of a child component */ | ||
export const getChildProps = (child: any): any => getChildLayout(child).props; | ||
|
||
/** Get the loading state of child components */ | ||
export const getLoadingStateChildren = ( | ||
loading_state?: DashBaseProps["loading_state"], | ||
children?: any | ||
): boolean => { | ||
if (isDash3()) { | ||
const ctx = (window as any).dash_component_api.useDashContext(); | ||
const childArray = React.Children.toArray(children); | ||
|
||
// Get loading states for all children | ||
const loadingStates = childArray.map((child: any) => | ||
ctx.useLoading({ rawPath: child.props?.componentPath }) | ||
); | ||
|
||
return loadingStates.some(Boolean); // Check if any child is loading | ||
} | ||
|
||
return loading_state?.is_loading ?? false; // Dash 2 fallback | ||
}; | ||
|
||
|
||
|
||
/** Apply props to a Dash component, handling Dash 2 & Dash 3 compatibility */ | ||
export const applyDashProps = (component: any, props: Record<string, any>) => { | ||
if (isDash3()) { | ||
return React.cloneElement(component, { ...props }); | ||
} | ||
|
||
if (component.props?._dashprivate_layout?.props) { | ||
Object.assign(component.props._dashprivate_layout.props, props); | ||
} | ||
|
||
return component; | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if you use
some
here rather thanmap
you can benefit from short-circuit evaluation. I.e. you're returntrue
the first time you encounter a loading child rather than callinguseLoading
on all children then callingsome
on the resultant array.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Updated 🙂