diff --git a/app/src/layouts/map/index.ts b/app/src/layouts/map/index.ts index fd7758b7a1..c6095a2b1b 100644 --- a/app/src/layouts/map/index.ts +++ b/app/src/layouts/map/index.ts @@ -46,7 +46,9 @@ export default defineLayout({ const page = syncRefProperty(layoutQuery, 'page', 1); const limit = syncRefProperty(layoutQuery, 'limit', 1000); - const sort = syncRefProperty(layoutQuery, 'sort', [fieldsInCollection.value?.[0]?.field]); + const sort = syncRefProperty(layoutQuery, 'sort', () => + primaryKeyField.value ? [primaryKeyField.value?.field] : [] + ); const locationFilter = ref(); diff --git a/app/src/utils/sync-ref-property.ts b/app/src/utils/sync-ref-property.ts index 5534258984..e03cdc15ef 100644 --- a/app/src/utils/sync-ref-property.ts +++ b/app/src/utils/sync-ref-property.ts @@ -4,13 +4,7 @@ import { computed, Ref } from 'vue'; export function syncRefProperty(ref: Ref, key: T, defaultValue: R[T] | (() => R[T])) { return computed({ get: () => { - if (ref.value?.[key]) { - return ref.value[key]; - } - - if (isFunction(defaultValue)) return defaultValue(); - - return defaultValue; + return ref.value?.[key] ?? (isFunction(defaultValue) ? defaultValue() : defaultValue); }, set: (value: R[T]) => { ref.value = Object.assign({}, ref.value, { [key]: value }) as R;