[#7312] excluded id from the excerpt list
This commit is contained in:
@@ -54,6 +54,7 @@
|
||||
</Field>
|
||||
</div>
|
||||
|
||||
<!-- @todo add warning mentioning that ids take part of the uploaded files path and there could be some filesystem compatibility issues with too loose pattern -->
|
||||
<div class="col-sm-6">
|
||||
<Field class="form-field" name="fields.{key}.pattern" let:uniqueId>
|
||||
<label for={uniqueId}>
|
||||
|
||||
@@ -134,7 +134,7 @@
|
||||
const result = await ApiClient.collection(selectedCollection.id).getList(page, batchSize, {
|
||||
filter: normalizedFilter,
|
||||
sort: sort,
|
||||
fields: "*:excerpt(100)",
|
||||
fields: CommonHelper.getExcerptCollectionFieldsList(selectedCollection),
|
||||
skipTotal: 1,
|
||||
requestKey: uniqueId + "loadImagePicker",
|
||||
});
|
||||
|
||||
@@ -148,6 +148,7 @@
|
||||
|
||||
const listFields = editorFields
|
||||
.map((f) => f.name + ":excerpt(200)")
|
||||
// @todo exclude id and single rel fields from the excerpt list
|
||||
.concat(relFields.map((field) => "expand." + field.name + ".*:excerpt(200)"));
|
||||
if (listFields.length) {
|
||||
listFields.unshift("*");
|
||||
|
||||
@@ -98,7 +98,7 @@
|
||||
ApiClient.collection(collectionId).getFullList({
|
||||
batch: batchSize,
|
||||
filter: filters.join("||"),
|
||||
fields: "*:excerpt(200)",
|
||||
fields: CommonHelper.getExcerptCollectionFieldsList(collection),
|
||||
expand: getExpand(),
|
||||
requestKey: null,
|
||||
}),
|
||||
@@ -162,7 +162,7 @@
|
||||
const result = await ApiClient.collection(collectionId).getList(page, batchSize, {
|
||||
filter: CommonHelper.normalizeSearchFilter(filter, fallbackSearchFields),
|
||||
sort: sort,
|
||||
fields: "*:excerpt(200)",
|
||||
fields: CommonHelper.getExcerptCollectionFieldsList(collection),
|
||||
skipTotal: 1,
|
||||
expand: getExpand(),
|
||||
requestKey: uniqueId + "loadList",
|
||||
@@ -190,7 +190,7 @@
|
||||
|
||||
try {
|
||||
const reloaded = await ApiClient.collection(collectionId).getOne(record.id, {
|
||||
fields: "*:excerpt(200)",
|
||||
fields: CommonHelper.getExcerptCollectionFieldsList(collection),
|
||||
expand: getExpand(),
|
||||
requestKey: uniqueId + "reload" + record.id,
|
||||
});
|
||||
|
||||
@@ -64,10 +64,12 @@
|
||||
|
||||
isLoading = true;
|
||||
|
||||
const fieldCollection = $collections.find((c) => c.id == field.collectionId);
|
||||
|
||||
let expands = [];
|
||||
const presentableRelFields = $collections
|
||||
.find((c) => c.id == field.collectionId)
|
||||
?.fields?.filter((f) => !f.hidden && f.presentable && f.type == "relation");
|
||||
const presentableRelFields = fieldCollection?.fields?.filter(
|
||||
(f) => !f.hidden && f.presentable && f.type == "relation",
|
||||
);
|
||||
for (const field of presentableRelFields) {
|
||||
expands = expands.concat(CommonHelper.getExpandPresentableRelFields(field, $collections, 2));
|
||||
}
|
||||
@@ -84,7 +86,7 @@
|
||||
loadPromises.push(
|
||||
ApiClient.collection(field.collectionId).getFullList(batchSize, {
|
||||
filter: filters.join("||"),
|
||||
fields: "*:excerpt(200)",
|
||||
fields: CommonHelper.getExcerptCollectionFieldsList(fieldCollection),
|
||||
expand: expands.join(","),
|
||||
requestKey: null,
|
||||
}),
|
||||
|
||||
@@ -1774,7 +1774,7 @@ export default class CommonHelper {
|
||||
/**
|
||||
* Returns an array with all public collection identifiers (collection fields + type specific fields).
|
||||
*
|
||||
* @param {[type]} collection The collection to extract identifiers from.
|
||||
* @param {Object} collection The collection to extract identifiers from.
|
||||
* @param {String} prefix Optional prefix for each found identified.
|
||||
* @return {Array}
|
||||
*/
|
||||
@@ -1804,6 +1804,30 @@ export default class CommonHelper {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a wildcard "fields" string with the excerpt modifier applied to all collection fields
|
||||
* (except the primary key and relation fields).
|
||||
*
|
||||
* @param {Object} collection
|
||||
* @param {Number} [maxExcerpt]
|
||||
* @return {String}
|
||||
*/
|
||||
static getExcerptCollectionFieldsList(collection, maxExcerpt = 200) {
|
||||
let result = ["*"];
|
||||
|
||||
const fields = collection?.fields || [];
|
||||
for (const field of fields) {
|
||||
if (field.primaryKey || field.type == "relation") {
|
||||
continue
|
||||
}
|
||||
|
||||
result.push(`${field.name}:excerpt(${maxExcerpt})`);
|
||||
}
|
||||
|
||||
return result.join(",");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates recursively a list with all the autocomplete field keys
|
||||
* for the collectionNameOrId collection.
|
||||
|
||||
Reference in New Issue
Block a user