From 9c8b144453d8f6158332c408bce284d60f6fe7d1 Mon Sep 17 00:00:00 2001 From: Nitwel Date: Wed, 14 Oct 2020 23:38:10 +0200 Subject: [PATCH 1/5] support junction fields --- app/src/interfaces/files/files.vue | 6 +-- .../interfaces/many-to-many/many-to-many.vue | 24 ++++----- app/src/interfaces/many-to-many/options.vue | 35 ++++--------- .../interfaces/many-to-many/use-actions.ts | 20 ++----- app/src/interfaces/many-to-many/use-edit.ts | 52 ++++++++----------- .../interfaces/many-to-many/use-preview.ts | 39 ++++++++++---- .../interfaces/many-to-many/use-selection.ts | 19 +++---- 7 files changed, 89 insertions(+), 106 deletions(-) diff --git a/app/src/interfaces/files/files.vue b/app/src/interfaces/files/files.vue index 5db7f7a33d..e4f2ca262e 100644 --- a/app/src/interfaces/files/files.vue +++ b/app/src/interfaces/files/files.vue @@ -45,7 +45,7 @@ :collection="relationFields.junctionCollection" :primary-key="currentlyEditing || '+'" :edits="editsAtStart" - :related-primary-key="relationFields.relationPkField" + :related-primary-key="relationFields.relationPkField || '+'" :junction-field="relationFields.junctionRelation" @input="stageEdits" @update:active="cancelEdit" @@ -165,10 +165,8 @@ export default defineComponent({ const { cancelEdit, stageEdits, editsAtStart, editItem, currentlyEditing } = useEdit( value, - items, relationFields, - emitter, - getJunctionFromRelatedId + emitter ); const { stageSelection, selectModalActive, selectionFilters } = useSelection( diff --git a/app/src/interfaces/many-to-many/many-to-many.vue b/app/src/interfaces/many-to-many/many-to-many.vue index af3de9b0e6..21f23e5254 100644 --- a/app/src/interfaces/many-to-many/many-to-many.vue +++ b/app/src/interfaces/many-to-many/many-to-many.vue @@ -5,7 +5,7 @@
@@ -46,9 +46,9 @@ - + {{ $t('interfaces.one-to-many.no_collection') }}

{{ $t('select_fields') }}

@@ -20,7 +22,6 @@ import { defineComponent, PropType, computed } from '@vue/composition-api'; import { useRelationsStore } from '@/stores/'; import { Relation, Collection } from '@/types'; import { useCollectionsStore } from '../../stores'; - export default defineComponent({ props: { collection: { @@ -51,7 +52,6 @@ export default defineComponent({ setup(props, { emit }) { const collectionsStore = useCollectionsStore(); const relationsStore = useRelationsStore(); - const fields = computed({ get() { return props.value?.fields; @@ -63,41 +63,26 @@ export default defineComponent({ }); }, }); - - const relatedCollection = computed(() => { + const junctionCollection = computed(() => { if (!props.fieldData || !props.relations || props.relations.length === 0) return null; - const { field } = props.fieldData; - const junctionRelation = props.relations.find( (relation) => relation.one_collection === props.collection && relation.one_field === field ); - - if (junctionRelation === undefined) return; - - const relatedCollection = props.relations.find( - (relation) => - relation.one_collection !== props.collection && - relation.many_field === junctionRelation.junction_field - ); - - return relatedCollection?.one_collection || null; + return junctionRelation?.many_collection || null; }); - - const relatedCollectionExists = computed(() => { + const junctionCollectionExists = computed(() => { return !!collectionsStore.state.collections.find( - (collection) => collection.collection === relatedCollection.value + (collection) => collection.collection === junctionCollection.value ); }); - - return { fields, relatedCollection, relatedCollectionExists }; + return { fields, junctionCollection, junctionCollectionExists }; }, });