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

refactor(core): use KeyValueStore for recent searches #5872

Merged
merged 7 commits into from Mar 8, 2024
Merged

Conversation

cngonzalez
Copy link
Member

@cngonzalez cngonzalez commented Feb 28, 2024

Description

This PR refactors the store for recent searches to be aligned with other user settings values (you can see another recent example of this kind of a refactor here: #5784)

The changes are:

  1. Use the useStoredSearch hook which depends on a KeyValueStore backend, which is still currently localStorage. (previously, the recentSearches functions mutated into localStorage directly)
  2. Turn createRecentSearchesStore into useRecentSearchesStore to better deal with asynchronous state coming in the future.
  3. Refactor unit tests to deal with useRecentSearchesStore as a hook with dependencies elsewhere in the Studio.
  4. Refactor search state and components that consume it to use the recentSearchStore hook directly.

What to review

The changed files to look for any gotchas -- and any excessive re-renders or UI bugs. All seem to match the current experience from my checks.

Testing

The recentSearches unit tests were refactored but should still test for the exact same cases. One case was removed -- checking for versions, because this will be handled by KeyValueStore down the line.

E2E UI tests were difficult because the recent search UI intercepts pointer events to some extent.

Copy link

vercel bot commented Feb 28, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
performance-studio ✅ Ready (Inspect) Visit Preview Mar 8, 2024 5:20pm
test-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 8, 2024 5:20pm
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
studio-workshop ⬜️ Ignored (Inspect) Visit Preview Mar 8, 2024 5:20pm

@cngonzalez cngonzalez changed the title Sdx 1135 refactor(core): use KeyValueStore for recent searches Feb 28, 2024
Copy link
Contributor

github-actions bot commented Feb 28, 2024

No changes to documentation

Copy link
Contributor

github-actions bot commented Feb 28, 2024

Component Testing Report Updated Mar 8, 2024 5:23 PM (UTC)

File Status Duration Passed Skipped Failed
comments/CommentInput.spec.tsx ✅ Passed (Inspect) 31s 15 0 0
formBuilder/ArrayInput.spec.tsx ✅ Passed (Inspect) 6s 3 0 0
formBuilder/inputs/PortableText/Annotations.spec.tsx ✅ Passed (Inspect) 12s 3 0 0
formBuilder/inputs/PortableText/copyPaste/CopyPaste.spec.tsx ✅ Passed (Inspect) 12s 4 2 0
formBuilder/inputs/PortableText/Decorators.spec.tsx ✅ Passed (Inspect) 12s 6 0 0
formBuilder/inputs/PortableText/FocusTracking.spec.tsx ✅ Passed (Inspect) 31s 15 0 0
formBuilder/inputs/PortableText/Input.spec.tsx ✅ Passed (Inspect) 1m 1s 15 0 0
formBuilder/inputs/PortableText/ObjectBlock.spec.tsx ✅ Passed (Inspect) 1m 0s 18 0 0
formBuilder/inputs/PortableText/RangeDecoration.spec.tsx ✅ Passed (Inspect) 11s 6 0 0
formBuilder/inputs/PortableText/Styles.spec.tsx ✅ Passed (Inspect) 13s 6 0 0
formBuilder/inputs/PortableText/Toolbar.spec.tsx ❌ Failed (Inspect) 23s 8 0 1

@cngonzalez cngonzalez marked this pull request as ready for review March 4, 2024 14:22
@cngonzalez cngonzalez requested a review from a team as a code owner March 4, 2024 14:22
@cngonzalez cngonzalez requested review from hermanwikner and removed request for a team March 4, 2024 14:22
@cngonzalez cngonzalez marked this pull request as draft March 5, 2024 16:47
@cngonzalez cngonzalez force-pushed the sdx-1135 branch 2 times, most recently from 6f0855d to ece8b23 Compare March 5, 2024 18:20
@cngonzalez cngonzalez marked this pull request as ready for review March 5, 2024 18:21
@cngonzalez cngonzalez marked this pull request as draft March 5, 2024 18:37
@cngonzalez cngonzalez marked this pull request as ready for review March 7, 2024 05:24
@cngonzalez cngonzalez requested a review from a team as a code owner March 7, 2024 05:24
@cngonzalez cngonzalez requested review from juice49 and removed request for a team March 7, 2024 05:24
Copy link
Member

@bjoerge bjoerge left a comment

Choose a reason for hiding this comment

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

LGTM, great work @cngonzalez! Thank you for such an extensive test suite too, really appreciated!

recentTerms = result.current.getRecentSearches()
expect(recentTerms.length).toEqual(2)

/* There's unfortunately a bit of flakiness with the schema
Copy link
Member

Choose a reason for hiding this comment

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

thanks for taking the time to explain <3

@cngonzalez cngonzalez added this pull request to the merge queue Mar 8, 2024
Merged via the queue into next with commit c531a6b Mar 8, 2024
36 checks passed
@cngonzalez cngonzalez deleted the sdx-1135 branch March 8, 2024 17:26
juice49 pushed a commit that referenced this pull request Mar 13, 2024
* refactor(core): create useStoredSearch hook

* refactor: pass useStoredSearch to recentSearchesStore

* refactor(core): convert createRecentSearchesStore to useRecentSearchesStore

* fix(core): use default studio client options

* fix: pass recent terms for more predictable UI behavior

* refactor: remove recent searches from search state and invoke hook wherever needed

* fix: remove typos, spaces
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

2 participants