synced with master

This commit is contained in:
Gani Georgiev
2023-06-09 13:33:38 +03:00
65 changed files with 2335 additions and 134 deletions
+30 -7
View File
@@ -28,7 +28,7 @@
let recordPreviewPanel;
let recordsList;
let filter = queryParams.get("filter") || "";
let sort = queryParams.get("sort") || "";
let sort = queryParams.get("sort") || "-created";
let selectedCollectionId = queryParams.get("collectionId") || $activeCollection?.id;
$: reactiveParams = new URLSearchParams($querystring);
@@ -46,6 +46,10 @@
reset();
}
$: if ($activeCollection?.id) {
normalizeSort();
}
// keep the url params in sync
$: if (sort || filter || $activeCollection?.id) {
const query = new URLSearchParams({
@@ -63,12 +67,31 @@
filter = "";
sort = "-created";
// clear default sort if created field is not available
if (
$activeCollection?.$isView &&
!CommonHelper.extractColumnsFromQuery($activeCollection.options.query).includes("created")
) {
sort = "";
normalizeSort();
}
// ensures that the sort fields exist in the collection
async function normalizeSort() {
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 = "";
}
}
}
+42 -12
View File
@@ -1417,16 +1417,9 @@ export default class CommonHelper {
continue
}
if (CommonHelper.isEmpty(val)) {
result.push(missingValue);
} else if (typeof val === "boolean") {
result.push(val ? "True" : "False");
} else if (typeof val === "string") {
val = val.indexOf("<") >= 0 ? CommonHelper.plainText(val) : val;
result.push(CommonHelper.truncate(val));
} else {
result.push(val);
}
val = CommonHelper.stringifyValue(val, missingValue)
result.push(val);
}
if (result.length > 0) {
@@ -1447,14 +1440,51 @@ export default class CommonHelper {
];
for (const prop of fallbackProps) {
if (!CommonHelper.isEmpty(model[prop])) {
return model[prop];
let val = CommonHelper.stringifyValue(model[prop], "");
if (val) {
return val;
}
}
return missingValue;
}
/**
* Stringifies the provided value or fallback to missingValue in case it is empty.
*
* @param {Mixed} val
* @param {String} missingValue
* @return {String}
*/
static stringifyValue(val, missingValue = "N/A") {
if (CommonHelper.isEmpty(val)) {
return missingValue;
}
if (typeof val === "boolean") {
return val ? "True" : "False";
}
if (typeof val === "string") {
val = val.indexOf("<") >= 0 ? CommonHelper.plainText(val) : val;
return CommonHelper.truncate(val) || missingValue;
}
if (Array.isArray(val)) {
return val.join(",");
}
if (typeof val === "object") {
try {
return CommonHelper.truncate(JSON.stringify(val)) || missingValue;
} catch (_) {
return missingValue;
}
}
return "" + val;
}
/**
* Rudimentary SELECT query columns extractor.
* Returns an array with the identifier aliases