diff --git a/dev/test-studio/structure/resolveStructure.ts b/dev/test-studio/structure/resolveStructure.ts index bd001f6c17a..0c4c34b3d9b 100644 --- a/dev/test-studio/structure/resolveStructure.ts +++ b/dev/test-studio/structure/resolveStructure.ts @@ -411,6 +411,17 @@ export const structure: StructureResolver = (S, {schema, documentStore, i18n}) = S.divider(), + S.listItem() + .title('Default ordering test') + .id('default-ordering') + .child(() => + S.documentTypeList('species') + .defaultOrdering([{field: 'species', direction: 'asc'}]) + .title('Species') + .id('default-ordering-list') + .filter('_type == $type'), + ), + ...S.documentTypeListItems() .filter((listItem) => { const id = listItem.getId() diff --git a/packages/sanity/src/core/store/key-value/localStorageSWR.ts b/packages/sanity/src/core/store/key-value/localStorageSWR.ts index 366e428e926..c9390d5953b 100644 --- a/packages/sanity/src/core/store/key-value/localStorageSWR.ts +++ b/packages/sanity/src/core/store/key-value/localStorageSWR.ts @@ -10,12 +10,14 @@ import {type KeyValueStore, type KeyValueStoreValue} from './types' */ export function withLocalStorageSWR(wrappedStore: KeyValueStore): KeyValueStore { function getKey(key: string) { - return merge(of(localStoreStorage.getKey(key)), wrappedStore.getKey(key)).pipe( - distinctUntilChanged(isEqual), - tap((value) => { - localStoreStorage.setKey(key, value) - }), - ) + return merge( + of(localStoreStorage.getKey(key)), + wrappedStore.getKey(key).pipe( + tap((wrappedStoreValue) => { + localStoreStorage.setKey(key, wrappedStoreValue) + }), + ), + ).pipe(distinctUntilChanged(isEqual)) } function setKey(key: string, nextValue: KeyValueStoreValue) { localStoreStorage.setKey(key, nextValue) diff --git a/packages/sanity/src/structure/useStructureToolSetting.ts b/packages/sanity/src/structure/useStructureToolSetting.ts index 42a60c9f8e0..8610c64642a 100644 --- a/packages/sanity/src/structure/useStructureToolSetting.ts +++ b/packages/sanity/src/structure/useStructureToolSetting.ts @@ -1,5 +1,6 @@ import {useCallback, useMemo} from 'react' import {useObservable} from 'react-rx' +import {map} from 'rxjs/operators' import {useKeyValueStore} from 'sanity' const STRUCTURE_TOOL_NAMESPACE = 'studio.structure-tool' @@ -17,8 +18,10 @@ export function useStructureToolSetting( const keyValueStoreKey = [STRUCTURE_TOOL_NAMESPACE, namespace, key].filter(Boolean).join('.') const value$ = useMemo(() => { - return keyValueStore.getKey(keyValueStoreKey) - }, [keyValueStore, keyValueStoreKey]) + return keyValueStore + .getKey(keyValueStoreKey) + .pipe(map((value) => (value === null ? defaultValue : value))) + }, [defaultValue, keyValueStore, keyValueStoreKey]) const value = useObservable(value$, defaultValue) as ValueType const set = useCallback(