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
Cache JSON when using pydeck local data #7113
Conversation
|
||
const getProps = ( | ||
elementProps: Partial<DeckGlJsonChartProto> = {}, | ||
initialViewStateProps: Record<string, unknown> = {} | ||
): PropsWithHeight => { | ||
const json = { | ||
initialViewState: { |
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.
just moved this to top of file so I can reuse later in the tests
frontend/lib/src/components/elements/DeckGlJsonChart/DeckGlJsonChart.test.tsx
Fixed
Show resolved
Hide resolved
|
||
const isFullScreen = Boolean(height) | ||
|
||
// Only parse JSON when not transitioning to/from fullscreen, the element id changes, or theme changes |
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.
maybe i should remove this comment since it's not necessary?
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.
You could also add one more sentence here why we need to reparse with these changes
frontend/lib/src/components/elements/DeckGlJsonChart/DeckGlJsonChart.tsx
Outdated
Show resolved
Hide resolved
frontend/lib/src/components/elements/DeckGlJsonChart/DeckGlJsonChart.tsx
Outdated
Show resolved
Hide resolved
frontend/lib/src/components/elements/DeckGlJsonChart/DeckGlJsonChart.tsx
Show resolved
Hide resolved
if ( | ||
element.id !== id || | ||
state.isFullScreen !== currFullScreen || | ||
state.isLightTheme !== hasLightBackgroundColor(theme) |
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.
Why do we need to reparse this when layout changes? Aren't we always adapting the mapStyle below anyways based on the theme?
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.
LGTM if the comments above are checked 👍 This component could probably benefit from a rewrite to functional API sometime later since this is a perfect usecase for useState
with dependencies.
Will fix them. Currently in progress! thanks! |
Ahh, and maybe this would be a good opportunity to also rewrite the unit test of deckgl component to use RTL instead of enzyme (shallow). |
Sounds good. I'll add that to things to do this week |
…oing to make these plain unit tests
deckGL.prop("onViewStateChange")({ | ||
viewState: { pitch: 5, zoom: 5 }, | ||
}) | ||
const state = { |
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.
Changed this test to not involve calling DeckGl methods because that seems odd. So I just changed this test to test our getDerivedStateFromProps
function.
Testing the changing of pydeck with unit testing and RTL is turning out to be a little too difficult as we can click the zoom button but it's not immediately obvious how to check the map changed. That should likely be tested with e2e tests and thus changing this test seems like a reasonable thing from my perspective.
it("should render tooltip", () => { | ||
const props = getProps({ | ||
tooltip: `{"html": "<b>Elevation Value:</b> {elevationValue}", "style": {"color": "white"}}`, | ||
describe("createTooltip", () => { |
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.
Changed this test to not involve calling DeckGl methods because that seems odd. So I just changed this test to test our createTooltip
function.
Testing the changing of pydeck with unit testing and RTL is turning out to be a little too difficult as we can hover but it's not immediately obvious how to check the tooltip existing. That should likely be tested with e2e tests and thus changing this test seems like a reasonable thing from my perspective.
<!--⚠️ BEFORE CONTRIBUTING PLEASE READ OUR CONTRIBUTING GUIDELINES! https://github.com/streamlit/streamlit/wiki/Contributing --> ## Describe your changes - add a protobuf key named element id which is a hash of the pydeck json - add logic to not parse the json again where the json is stored in state - if the hash string is different, then parse it again - if it’s not, use the cached json - add fullScreen and theme to state - if these change, we need to parse the json again to rerender the new map - these changes make the loading slightly longer when rerunning or running the script; however, the experience is significantly better so it's worth to do this. ## GitHub Issue Link (if applicable) streamlit#5532 ## Testing Plan - Explanation of why no additional tests are needed - Unit Tests (JS and/or Python) - will need to add these - E2E Tests - very difficult to add these so will not be adding these. - Any manual testing needed? - yes, i manually tested the test case within the issue 5532. I will grab other use cases from pydeck and make sure they're responsive. This branch: https://github.com/streamlit/streamlit/assets/16749069/130d21ca-efe4-437b-aa6e-fb1a04c6805b Develop: https://github.com/streamlit/streamlit/assets/16749069/275b4e00-4f1d-444e-bf69-f84040c9b86f --- **Contribution License Agreement** By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.
<!--⚠️ BEFORE CONTRIBUTING PLEASE READ OUR CONTRIBUTING GUIDELINES! https://github.com/streamlit/streamlit/wiki/Contributing --> ## Describe your changes - add a protobuf key named element id which is a hash of the pydeck json - add logic to not parse the json again where the json is stored in state - if the hash string is different, then parse it again - if it’s not, use the cached json - add fullScreen and theme to state - if these change, we need to parse the json again to rerender the new map - these changes make the loading slightly longer when rerunning or running the script; however, the experience is significantly better so it's worth to do this. ## GitHub Issue Link (if applicable) streamlit#5532 ## Testing Plan - Explanation of why no additional tests are needed - Unit Tests (JS and/or Python) - will need to add these - E2E Tests - very difficult to add these so will not be adding these. - Any manual testing needed? - yes, i manually tested the test case within the issue 5532. I will grab other use cases from pydeck and make sure they're responsive. This branch: https://github.com/streamlit/streamlit/assets/16749069/130d21ca-efe4-437b-aa6e-fb1a04c6805b Develop: https://github.com/streamlit/streamlit/assets/16749069/275b4e00-4f1d-444e-bf69-f84040c9b86f --- **Contribution License Agreement** By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.
<!--⚠️ BEFORE CONTRIBUTING PLEASE READ OUR CONTRIBUTING GUIDELINES! https://github.com/streamlit/streamlit/wiki/Contributing --> ## Describe your changes - add a protobuf key named element id which is a hash of the pydeck json - add logic to not parse the json again where the json is stored in state - if the hash string is different, then parse it again - if it’s not, use the cached json - add fullScreen and theme to state - if these change, we need to parse the json again to rerender the new map - these changes make the loading slightly longer when rerunning or running the script; however, the experience is significantly better so it's worth to do this. ## GitHub Issue Link (if applicable) streamlit#5532 ## Testing Plan - Explanation of why no additional tests are needed - Unit Tests (JS and/or Python) - will need to add these - E2E Tests - very difficult to add these so will not be adding these. - Any manual testing needed? - yes, i manually tested the test case within the issue 5532. I will grab other use cases from pydeck and make sure they're responsive. This branch: https://github.com/streamlit/streamlit/assets/16749069/130d21ca-efe4-437b-aa6e-fb1a04c6805b Develop: https://github.com/streamlit/streamlit/assets/16749069/275b4e00-4f1d-444e-bf69-f84040c9b86f --- **Contribution License Agreement** By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.
Describe your changes
add a protobuf key named element id which is a hash of the pydeck json
add logic to not parse the json again where the json is stored in state
add fullScreen and theme to state
these changes make the loading slightly longer when rerunning or running the script; however, the experience is significantly better so it's worth to do this.
GitHub Issue Link (if applicable)
#5532
Testing Plan
This branch:
https://github.com/streamlit/streamlit/assets/16749069/130d21ca-efe4-437b-aa6e-fb1a04c6805b
Develop:
https://github.com/streamlit/streamlit/assets/16749069/275b4e00-4f1d-444e-bf69-f84040c9b86f
Contribution License Agreement
By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.