normalized active sort on collection schema change
This commit is contained in:
parent
e4a90f6605
commit
7f06816008
|
@ -46,6 +46,10 @@
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$: if ($activeCollection?.id) {
|
||||||
|
normalizeSort();
|
||||||
|
}
|
||||||
|
|
||||||
// keep the url params in sync
|
// keep the url params in sync
|
||||||
$: if (sort || filter || $activeCollection?.id) {
|
$: if (sort || filter || $activeCollection?.id) {
|
||||||
const query = new URLSearchParams({
|
const query = new URLSearchParams({
|
||||||
|
@ -63,12 +67,31 @@
|
||||||
filter = "";
|
filter = "";
|
||||||
sort = "-created";
|
sort = "-created";
|
||||||
|
|
||||||
// clear default sort if created field is not available
|
normalizeSort();
|
||||||
if (
|
}
|
||||||
$activeCollection?.$isView &&
|
|
||||||
!CommonHelper.extractColumnsFromQuery($activeCollection.options.query).includes("created")
|
// ensures that the sort fields exist in the collection
|
||||||
) {
|
async function normalizeSort() {
|
||||||
sort = "";
|
if (!sort) {
|
||||||
|
return; // nothing to normalize
|
||||||
|
}
|
||||||
|
|
||||||
|
const collectionFields = CommonHelper.getAllCollectionIdentifiers($activeCollection);
|
||||||
|
|
||||||
|
const sortFields = sort.split(",").map((f) => {
|
||||||
|
if (f.startsWith("+") || f.startsWith("-")) {
|
||||||
|
return f.substring(1);
|
||||||
|
}
|
||||||
|
return f;
|
||||||
|
});
|
||||||
|
|
||||||
|
// invalid sort expression or missing sort field
|
||||||
|
if (sortFields.filter((f) => collectionFields.includes(f)).length != sortFields.length) {
|
||||||
|
if (collectionFields.includes("created")) {
|
||||||
|
sort = "-created";
|
||||||
|
} else {
|
||||||
|
sort = "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue