diff --git a/api/src/extensions.ts b/api/src/extensions.ts index 8b31d8326b..9bc2c8ca52 100644 --- a/api/src/extensions.ts +++ b/api/src/extensions.ts @@ -78,10 +78,12 @@ function registerHooks(hooks: string[]) { function registerHook(hook: string) { const hookPath = path.resolve(extensionsPath, 'hooks', hook, 'index.js'); - const hookInstance: HookRegisterFunction | { default?: HookRegisterFunction } = require(hookPath); + const hookInstance: + | HookRegisterFunction + | { default?: HookRegisterFunction } = require(hookPath); let register: HookRegisterFunction = hookInstance as HookRegisterFunction; - if (typeof hookInstance !== "function") { + if (typeof hookInstance !== 'function') { if (hookInstance.default) { register = hookInstance.default; } @@ -108,10 +110,12 @@ function registerEndpoints(endpoints: string[], router: Router) { function registerEndpoint(endpoint: string) { const endpointPath = path.resolve(extensionsPath, 'endpoints', endpoint, 'index.js'); - const endpointInstance: EndpointRegisterFunction | { default?: EndpointRegisterFunction } = require(endpointPath); + const endpointInstance: + | EndpointRegisterFunction + | { default?: EndpointRegisterFunction } = require(endpointPath); let register: EndpointRegisterFunction = endpointInstance as EndpointRegisterFunction; - if (typeof endpointInstance !== "function") { + if (typeof endpointInstance !== 'function') { if (endpointInstance.default) { register = endpointInstance.default; } diff --git a/app/src/interfaces/files/files.vue b/app/src/interfaces/files/files.vue index 729333558c..816816208f 100644 --- a/app/src/interfaces/files/files.vue +++ b/app/src/interfaces/files/files.vue @@ -5,30 +5,25 @@
@@ -41,12 +36,12 @@ @@ -54,7 +49,7 @@ { + const { junctionField } = relationInfo.value; + return ['id', 'type', 'title'].map((key) => `${junctionField}.${key}`); + }); const tableHeaders = ref([ { @@ -146,35 +144,37 @@ export default defineComponent({ { text: i18n.t('title'), // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - value: 'title', + value: relationInfo.value.junctionField + '.' + 'title', align: 'left', sortable: true, width: 250, }, ]); - const { loading, displayItems, error, items } = usePreview( + const { loading, error, items } = usePreview( value, fields, - relationFields, + relationInfo, getNewSelectedItems, getUpdatedItems, getNewItems, getPrimaryKeys ); - const { cancelEdit, stageEdits, editsAtStart, editItem, currentlyEditing } = useEdit( - value, - items, - relationFields, - emitter, - getJunctionFromRelatedId - ); + const { + cancelEdit, + stageEdits, + editsAtStart, + editItem, + currentlyEditing, + editModalActive, + relatedPrimaryKey, + } = useEdit(value, relationInfo, emitter); const { stageSelection, selectModalActive, selectionFilters } = useSelection( value, - displayItems, - relationFields, + items, + relationInfo, emitter ); @@ -186,7 +186,6 @@ export default defineComponent({ tableHeaders, junctionCollection, loading, - displayItems, error, currentlyEditing, cancelEdit, @@ -200,8 +199,10 @@ export default defineComponent({ items, get, onUpload, - relationFields, + relationInfo, editItem, + editModalActive, + relatedPrimaryKey, }; function useUpload() { @@ -214,11 +215,11 @@ export default defineComponent({ if (files.length === 0) return; - const { junctionRelation } = relationFields.value; + const { junctionField } = relationInfo.value; const file = files[0]; const fileAsJunctionRow = { - [junctionRelation]: { + [junctionField]: { id: file.id, title: file.title, type: file.type, 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 49cea41e42..76f944c5a4 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 @@
- {{ $t('create_new') }} + {{ $t('create_new') }} {{ $t('add_existing') }} @@ -45,11 +40,11 @@ - + {{ $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 }; }, });