Use primary key as default sort in map layout (#9403)

This commit is contained in:
Oreille
2021-11-03 18:17:51 +01:00
committed by GitHub
parent 99f0c6c65f
commit 013733a8b9
2 changed files with 4 additions and 8 deletions

View File

@@ -46,7 +46,9 @@ export default defineLayout<LayoutOptions, LayoutQuery>({
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<Filter>();

View File

@@ -4,13 +4,7 @@ import { computed, Ref } from 'vue';
export function syncRefProperty<R, T extends keyof R>(ref: Ref<R>, key: T, defaultValue: R[T] | (() => R[T])) {
return computed<R[T]>({
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;