added presentable file field fallback
This commit is contained in:
parent
4c14c6cccf
commit
d4a2f05075
|
@ -1,9 +1,10 @@
|
||||||
<script>
|
<script>
|
||||||
import { onMount } from "svelte";
|
import { onMount } from "svelte";
|
||||||
import CommonHelper from "@/utils/CommonHelper";
|
import CommonHelper from "@/utils/CommonHelper";
|
||||||
import tooltip from "@/actions/tooltip";
|
import tooltipAction from "@/actions/tooltip";
|
||||||
|
|
||||||
export let value = "";
|
export let value = "";
|
||||||
|
export let tooltip = "Copy";
|
||||||
export let idleClasses = "ri-file-copy-line txt-sm link-hint";
|
export let idleClasses = "ri-file-copy-line txt-sm link-hint";
|
||||||
export let successClasses = "ri-check-line txt-sm txt-success";
|
export let successClasses = "ri-check-line txt-sm txt-success";
|
||||||
export let successDuration = 500; // ms
|
export let successDuration = 500; // ms
|
||||||
|
@ -34,9 +35,10 @@
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||||
|
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
||||||
<i
|
<i
|
||||||
class={copyTimeout ? successClasses : idleClasses}
|
class={copyTimeout ? successClasses : idleClasses}
|
||||||
aria-label={"Copy"}
|
aria-label={"Copy to clipboard"}
|
||||||
use:tooltip={!copyTimeout ? "Copy" : ""}
|
use:tooltipAction={!copyTimeout ? tooltip : undefined}
|
||||||
on:click|stopPropagation={copy}
|
on:click|stopPropagation={copy}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -2,9 +2,7 @@
|
||||||
import { link } from "svelte-spa-router";
|
import { link } from "svelte-spa-router";
|
||||||
import CommonHelper from "@/utils/CommonHelper";
|
import CommonHelper from "@/utils/CommonHelper";
|
||||||
import tooltip from "@/actions/tooltip";
|
import tooltip from "@/actions/tooltip";
|
||||||
import { hideControls } from "@/stores/app";
|
import { activeCollection } from "@/stores/collections";
|
||||||
import { collections, activeCollection, isCollectionsLoading } from "@/stores/collections";
|
|
||||||
import CollectionUpsertPanel from "@/components/collections/CollectionUpsertPanel.svelte";
|
|
||||||
|
|
||||||
export let collection;
|
export let collection;
|
||||||
export let pinnedIds;
|
export let pinnedIds;
|
||||||
|
|
|
@ -6,13 +6,37 @@
|
||||||
|
|
||||||
export let record;
|
export let record;
|
||||||
|
|
||||||
|
let fileDisplayFields = [];
|
||||||
|
let nonFileDisplayFields = [];
|
||||||
|
|
||||||
$: collection = $collections?.find((item) => item.id == record?.collectionId);
|
$: collection = $collections?.find((item) => item.id == record?.collectionId);
|
||||||
|
|
||||||
$: fileDisplayFields =
|
$: if (collection) {
|
||||||
collection?.schema?.filter((f) => f.presentable && f.type == "file")?.map((f) => f.name) || [];
|
loadDisplayFields();
|
||||||
|
}
|
||||||
|
|
||||||
$: textDisplayFields =
|
function loadDisplayFields() {
|
||||||
collection?.schema?.filter((f) => f.presentable && f.type != "file")?.map((f) => f.name) || [];
|
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>
|
</script>
|
||||||
|
|
||||||
<div class="record-info">
|
<div class="record-info">
|
||||||
|
@ -22,7 +46,7 @@
|
||||||
text: CommonHelper.truncate(
|
text: CommonHelper.truncate(
|
||||||
JSON.stringify(CommonHelper.truncateObject(record), null, 2),
|
JSON.stringify(CommonHelper.truncateObject(record), null, 2),
|
||||||
800,
|
800,
|
||||||
true
|
true,
|
||||||
),
|
),
|
||||||
class: "code",
|
class: "code",
|
||||||
position: "left",
|
position: "left",
|
||||||
|
@ -39,7 +63,7 @@
|
||||||
{/each}
|
{/each}
|
||||||
|
|
||||||
<span class="txt txt-ellipsis">
|
<span class="txt txt-ellipsis">
|
||||||
{CommonHelper.truncate(CommonHelper.displayValue(record, textDisplayFields), 70)}
|
{CommonHelper.truncate(CommonHelper.displayValue(record, nonFileDisplayFields), 70)}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -51,10 +75,6 @@
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
gap: 5px;
|
gap: 5px;
|
||||||
line-height: normal;
|
|
||||||
> * {
|
|
||||||
line-height: inherit;
|
|
||||||
}
|
|
||||||
:global(.thumb) {
|
:global(.thumb) {
|
||||||
box-shadow: none;
|
box-shadow: none;
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,7 +83,7 @@
|
||||||
return { id: f.id, name: f.name };
|
return { id: f.id, name: f.name };
|
||||||
}),
|
}),
|
||||||
hasCreated ? { id: "@created", name: "created" } : [],
|
hasCreated ? { id: "@created", name: "created" } : [],
|
||||||
hasUpdated ? { id: "@updated", name: "updated" } : []
|
hasUpdated ? { id: "@updated", name: "updated" } : [],
|
||||||
);
|
);
|
||||||
|
|
||||||
function updateStoredHiddenColumns() {
|
function updateStoredHiddenColumns() {
|
||||||
|
@ -282,7 +282,7 @@
|
||||||
return Promise.all(promises)
|
return Promise.all(promises)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
addSuccessToast(
|
addSuccessToast(
|
||||||
`Successfully deleted the selected ${totalBulkSelected === 1 ? "record" : "records"}.`
|
`Successfully deleted the selected ${totalBulkSelected === 1 ? "record" : "records"}.`,
|
||||||
);
|
);
|
||||||
|
|
||||||
dispatch("delete", bulkSelected);
|
dispatch("delete", bulkSelected);
|
||||||
|
|
|
@ -76,7 +76,7 @@
|
||||||
filter: filters.join("||"),
|
filter: filters.join("||"),
|
||||||
fields: "*:excerpt(200)",
|
fields: "*:excerpt(200)",
|
||||||
requestKey: null,
|
requestKey: null,
|
||||||
})
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -489,7 +489,7 @@ a,
|
||||||
background: var(--baseAlt2Color);
|
background: var(--baseAlt2Color);
|
||||||
color: var(--txtPrimaryColor);
|
color: var(--txtPrimaryColor);
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
border-radius: 30px;
|
border-radius: 15px;
|
||||||
|
|
||||||
.btn:last-child {
|
.btn:last-child {
|
||||||
margin-right: calc(-0.5 * var(--labelHPadding));
|
margin-right: calc(-0.5 * var(--labelHPadding));
|
||||||
|
|
Loading…
Reference in New Issue