added presentable file field fallback
This commit is contained in:
@@ -6,13 +6,37 @@
|
||||
|
||||
export let record;
|
||||
|
||||
let fileDisplayFields = [];
|
||||
let nonFileDisplayFields = [];
|
||||
|
||||
$: collection = $collections?.find((item) => item.id == record?.collectionId);
|
||||
|
||||
$: fileDisplayFields =
|
||||
collection?.schema?.filter((f) => f.presentable && f.type == "file")?.map((f) => f.name) || [];
|
||||
$: if (collection) {
|
||||
loadDisplayFields();
|
||||
}
|
||||
|
||||
$: textDisplayFields =
|
||||
collection?.schema?.filter((f) => f.presentable && f.type != "file")?.map((f) => f.name) || [];
|
||||
function loadDisplayFields() {
|
||||
const fields = collection?.schema || [];
|
||||
|
||||
// reset
|
||||
fileDisplayFields = fields.filter((f) => f.presentable && f.type == "file").map((f) => f.name);
|
||||
nonFileDisplayFields = fields.filter((f) => f.presentable && f.type != "file").map((f) => f.name);
|
||||
|
||||
// fallback to the first single file field that accept images
|
||||
// if no presentable field is available
|
||||
if (!fileDisplayFields.length && !nonFileDisplayFields.length) {
|
||||
const fallbackFileField = fields.find((f) => {
|
||||
return (
|
||||
f.type == "file" &&
|
||||
f.options?.maxSelect == 1 &&
|
||||
f.options?.mimeTypes?.find((t) => t.startsWith("image/"))
|
||||
);
|
||||
});
|
||||
if (fallbackFileField) {
|
||||
fileDisplayFields.push(fallbackFileField.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="record-info">
|
||||
@@ -22,7 +46,7 @@
|
||||
text: CommonHelper.truncate(
|
||||
JSON.stringify(CommonHelper.truncateObject(record), null, 2),
|
||||
800,
|
||||
true
|
||||
true,
|
||||
),
|
||||
class: "code",
|
||||
position: "left",
|
||||
@@ -39,7 +63,7 @@
|
||||
{/each}
|
||||
|
||||
<span class="txt txt-ellipsis">
|
||||
{CommonHelper.truncate(CommonHelper.displayValue(record, textDisplayFields), 70)}
|
||||
{CommonHelper.truncate(CommonHelper.displayValue(record, nonFileDisplayFields), 70)}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@@ -51,10 +75,6 @@
|
||||
max-width: 100%;
|
||||
min-width: 0;
|
||||
gap: 5px;
|
||||
line-height: normal;
|
||||
> * {
|
||||
line-height: inherit;
|
||||
}
|
||||
:global(.thumb) {
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@
|
||||
return { id: f.id, name: f.name };
|
||||
}),
|
||||
hasCreated ? { id: "@created", name: "created" } : [],
|
||||
hasUpdated ? { id: "@updated", name: "updated" } : []
|
||||
hasUpdated ? { id: "@updated", name: "updated" } : [],
|
||||
);
|
||||
|
||||
function updateStoredHiddenColumns() {
|
||||
@@ -282,7 +282,7 @@
|
||||
return Promise.all(promises)
|
||||
.then(() => {
|
||||
addSuccessToast(
|
||||
`Successfully deleted the selected ${totalBulkSelected === 1 ? "record" : "records"}.`
|
||||
`Successfully deleted the selected ${totalBulkSelected === 1 ? "record" : "records"}.`,
|
||||
);
|
||||
|
||||
dispatch("delete", bulkSelected);
|
||||
|
||||
@@ -76,7 +76,7 @@
|
||||
filter: filters.join("||"),
|
||||
fields: "*:excerpt(200)",
|
||||
requestKey: null,
|
||||
})
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user