Add file preview to m2o-fields if the relation is directus_files (#19374)

* add file preview to m2o-fields if the relation is directus_files

* add changeset

* move check to useFile instead of relatedCollection
This commit is contained in:
Daniel Biegler
2023-08-08 20:36:08 +02:00
committed by GitHub
parent 60df20d780
commit a885c7b868
2 changed files with 9 additions and 4 deletions

View File

@@ -0,0 +1,5 @@
---
"@directus/app": patch
---
Added file preview to the drawer if the relation is directus_files

View File

@@ -21,7 +21,7 @@
<div class="drawer-item-content">
<file-preview
v-if="junctionField && file"
v-if="file"
:src="file.src"
:mime="file.type"
:width="file.width"
@@ -237,12 +237,12 @@ const { file } = useFile();
function useFile() {
const isDirectusFiles = computed(() => {
return relatedCollection.value === 'directus_files';
return props.collection === 'directus_files' || relatedCollection.value === 'directus_files';
});
const file = computed(() => {
if (isDirectusFiles.value === false || !initialValues.value || !props.junctionField) return null;
const fileData = initialValues.value?.[props.junctionField];
if (isDirectusFiles.value === false || !initialValues.value) return null;
const fileData = props.junctionField ? initialValues.value?.[props.junctionField] : initialValues.value;
if (!fileData) return null;
const src = `assets/${fileData.id}?key=system-large-contain`;