Skip to content
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

Data picker - code cleanup #5705

Merged
merged 7 commits into from
May 21, 2024
Merged

Data picker - code cleanup #5705

merged 7 commits into from
May 21, 2024

Conversation

bkrmendy
Copy link
Contributor

@bkrmendy bkrmendy commented May 17, 2024

Problem

The data picker control is structured in a way that makes it hard to use for use cases other than picking data for properties

Fix

This PR refactors the data picker so that both the variables it displays and the callback that's called when a variable is clicked are passed in from the call site. This way, we can provide the variables that make sense for properties, map expression values or child nodes.

Commit Details

  • the UpdateMapExpression action is removed and its functionality is rolled into ReplaceElementInScope
  • Two new modes are added to ElementReplacementPath to cater to properties and mapped expression, and the ReplaceElementInScope action is updated to interpret these modes
  • useDataPickerButton and DataPickerComponent are refactored so that the variable options to display and the callback that's called when an option is picked are passed in from the outside
  • DataPickerType and useDataPickerButtonListSource are removed, because the functionality they implemented is superseded by passing in the variables and the callback

Out of scope

#5684 mentions updating the logic that gets the runtime value of variables. This PR doesn't directly fix that, but since the logic related to variables is contained in useVariablesInScopeForSelectedElement, this PR unblocks making this change (because with this, the various call sites in different contexts can pass in whatever variables they deem fit).

Manual Tests

I hereby swear that:

  • I opened a hydrogen project and it loaded
  • I could navigate to various routes in Preview mode

Related to #5684

Copy link
Contributor

github-actions bot commented May 21, 2024

Try me

Copy link

relativeci bot commented May 21, 2024

#12538 Bundle Size — 62.13MiB (~-0.01%).

ec629af(current) vs 6339ece master#12534(baseline)

Warning

Bundle contains 52 duplicate packages – View duplicate packages

Bundle metrics  Change 2 changes Improvement 1 improvement
                 Current
#12538
     Baseline
#12534
Improvement  Initial JS 45.21MiB(~-0.01%) 45.21MiB
No change  Initial CSS 0B 0B
Change  Cache Invalidation 22.71% 21.44%
No change  Chunks 30 30
No change  Assets 33 33
No change  Modules 4288 4288
No change  Duplicate Modules 519 519
No change  Duplicate Code 31.01% 31.01%
No change  Packages 449 449
No change  Duplicate Packages 52 52
Bundle size by type  Change 2 changes Improvement 2 improvements
                 Current
#12538
     Baseline
#12534
Improvement  JS 62.12MiB (~-0.01%) 62.13MiB
Improvement  HTML 10.94KiB (-0.34%) 10.97KiB

Bundle analysis reportBranch fix/data-picker-cleanupProject dashboard

Copy link
Contributor

github-actions bot commented May 21, 2024

Performance test results:
(Chart1)
(Chart2)

Comment on lines -484 to -485
background: currentExpressionExactMatch ? colorTheme.primary.value : undefined,
color: currentExpressionExactMatch ? colorTheme.white.value : undefined,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the data picker UX isn't final yet, I didn't fix this up

@bkrmendy bkrmendy marked this pull request as ready for review May 21, 2024 09:42
return element
}
const replacementPath = action.replacementPath
if (replacementPath.type === 'replace-child-with-uid') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use a switch statement here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for calling it out, neither is ideal so I refactored it to a switch + helper functions in 0b1d170

@bkrmendy bkrmendy merged commit d266b88 into master May 21, 2024
13 checks passed
@bkrmendy bkrmendy deleted the fix/data-picker-cleanup branch May 21, 2024 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants