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): refactor SettingsStore and useStructureToolSetting #5784

Merged
merged 1 commit into from
Feb 23, 2024

Conversation

cngonzalez
Copy link
Member

@cngonzalez cngonzalez commented Feb 18, 2024

Description

As we move toward different possible solutions for storing user values, and storing additional types of values, we can align our current implementations towards our proposed APIs. This PR is intentionally lightweight:

  1. Renames SettingsStore to KVStore to better reflect the additional kinds of values that may be stored.
  2. Refactors and simplifies Store logic away from namespaces. This may not be permanent but will allow for a simpler introduction of other possible storage solutions for user key-value stores.
  3. Refactors useStructureToolSetting to align with the above.

What to review

The changed files to ensure they're aligned with our style.

Testing

Automated tests were introduced in #5764.
If needed, reviewer can confirm that localStorage and UI behavior remains undisturbed.

@cngonzalez cngonzalez requested a review from a team as a code owner February 18, 2024 17:56
@cngonzalez cngonzalez requested review from binoy14 and removed request for a team February 18, 2024 17:56
Copy link

vercel bot commented Feb 18, 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 Feb 23, 2024 3:06pm
test-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 23, 2024 3:06pm
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
studio-workshop ⬜️ Ignored (Inspect) Visit Preview Feb 23, 2024 3:06pm

Copy link
Contributor

No changes to documentation

Copy link
Contributor

github-actions bot commented Feb 18, 2024

Component Testing Report Updated Feb 23, 2024 3:10 PM (UTC)

File Status Duration Passed Skipped Failed
comments/CommentInput.spec.tsx ✅ Passed (Inspect) 30s 15 0 0
formBuilder/ArrayInput.spec.tsx ✅ Passed (Inspect) 6s 3 0 0
formBuilder/inputs/PortableText/Annotations.spec.tsx ❌ Failed (Inspect) 22s 0 0 3
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) 59s 15 0 0
formBuilder/inputs/PortableText/ObjectBlock.spec.tsx ✅ Passed (Inspect) 59s 18 0 0
formBuilder/inputs/PortableText/Styles.spec.tsx ✅ Passed (Inspect) 12s 6 0 0
formBuilder/inputs/PortableText/Toolbar.spec.tsx ✅ Passed (Inspect) 19s 9 0 0


const set = useCallback(
(newValue: ValueType) => {
setValue(newValue)
settings.set(newValue as any)
KVStore.setKey(KVStoreKey, newValue as string)
Copy link
Member Author

@cngonzalez cngonzalez Feb 18, 2024

Choose a reason for hiding this comment

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

Per my above comment about the JSON typings, this is being cast a string since that's technically what is always getting stored (for now). Should we export the KVStoreValue type so it can be used by all consumers?

() => settingsStore.forNamespace('structure-tool'),
[settingsStore],
)
const KVStoreKey = namespace ? `structure-tool::${namespace}::${key}` : `structure-tool::${key}`
Copy link
Member Author

@cngonzalez cngonzalez Feb 20, 2024

Choose a reason for hiding this comment

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

We're having internal conversations about namespacing, so I don't expect this string interpolation to be permanent, hopefully

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.

Do we also want to move it out of the _legacy folder? I'm not entirely sure why everything was moved in there at the time, but given that we're replacing this with a proper implementation it doesn't feel like it belongs there anymore

packages/sanity/src/core/store/_legacy/kv/types.ts Outdated Show resolved Hide resolved
packages/sanity/src/core/store/_legacy/kv/types.ts Outdated Show resolved Hide resolved
packages/sanity/src/core/store/_legacy/kv/KVStore.ts Outdated Show resolved Hide resolved
@cngonzalez cngonzalez force-pushed the sdx-1098 branch 2 times, most recently from 69dfd13 to 3c4b9cb Compare February 21, 2024 20:38
@cngonzalez
Copy link
Member Author

Updates per feedback:
KVStore -> keyValueStore
directory name key-value (to match API route)
directory out of _legacy
legacy defValue var name changed to defaultValue

Copy link
Contributor

@binoy14 binoy14 left a comment

Choose a reason for hiding this comment

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

One question but LGTM besides that, thanks!

I also don't have full context on the code might be better for @bjoerge to review it as well

@@ -27,7 +27,6 @@ export function InspectDialog(props: InspectDialogProps) {
where the inspect dialog lives.
This also means that when a page is loaded, the state of the tabs remains and doesn't revert to the pane tab */
const [viewModeId, onViewModeChange] = useStructureToolSetting(
'structure-tool',
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't have full context if it's used in multiple places, but the function signature has not changed, won't inspect-view-preferred-view-mode-${paneKey} become the namespace here? Is that expected?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point -- so it looks like the behavior we have in the current version of the studio makes a key like structure-tool::structure-tool::inspect-view (useStructureToolSetting always added the structure-tool namespace). It seems like this was an error.

I can restore this to have the old duplicative behavior to not break anything and we can migrate it when we have a strategy to migrate all old keys.

@binoy14 binoy14 requested a review from bjoerge February 22, 2024 15:13
Merged via the queue into next with commit 74be48b Feb 23, 2024
39 of 40 checks passed
@cngonzalez cngonzalez deleted the sdx-1098 branch February 23, 2024 15:52
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.

3 participants