diff --git a/src/composables/use-collection/use-collection.test.ts b/src/composables/use-collection/use-collection.test.ts deleted file mode 100644 index e5a1f3bb07..0000000000 --- a/src/composables/use-collection/use-collection.test.ts +++ /dev/null @@ -1,79 +0,0 @@ -import { useCollection } from './use-collection'; -import Vue from 'vue'; -import VueCompositionAPI, { ref } from '@vue/composition-api'; -import useCollectionsStore from '@/stores/collections/'; -import useFieldsStore from '@/stores/fields/'; - -describe('Composables / useCollection', () => { - let req: any = {}; - - beforeAll(() => { - Vue.use(VueCompositionAPI); - }); - - beforeEach(() => { - req = {}; - }); - - it('Gets the collection info from the collections store', () => { - useCollectionsStore(req).state.collections = [ - { - collection: 'files', - test: true, - }, - { - collection: 'another-collection', - test: false, - }, - ] as any; - useFieldsStore(req).state.fields = [ - { - collection: 'files', - field: 'id', - primary_key: true, - test: true, - }, - { - collection: 'another-collection', - field: 'id', - primary_key: true, - test: false, - }, - { - collection: 'files', - field: 'title', - primary_key: false, - test: true, - }, - ] as any; - - const { info, fields, primaryKeyField } = useCollection(ref('files')); - - expect(info.value).toEqual({ - collection: 'files', - test: true, - }); - - expect(fields.value).toEqual([ - { - collection: 'files', - field: 'id', - primary_key: true, - test: true, - }, - { - collection: 'files', - field: 'title', - primary_key: false, - test: true, - }, - ]); - - expect(primaryKeyField.value).toEqual({ - collection: 'files', - field: 'id', - primary_key: true, - test: true, - }); - }); -}); diff --git a/src/composables/use-item/use-item.ts b/src/composables/use-item/use-item.ts index 764adbc813..ff8129467e 100644 --- a/src/composables/use-item/use-item.ts +++ b/src/composables/use-item/use-item.ts @@ -5,8 +5,8 @@ import i18n from '@/lang'; import useCollection from '@/composables/use-collection'; import { AxiosResponse } from 'axios'; -export function useItem(collection: Ref, primaryKey: Ref) { - const { primaryKeyField, softDeleteStatus, statusField } = useCollection(collection); +export function useItem(collection: Ref, primaryKey: Ref) { + const { info: collectionInfo, primaryKeyField, softDeleteStatus, statusField } = useCollection(collection); const item = ref(null); const error = ref(null); @@ -17,6 +17,7 @@ export function useItem(collection: Ref, primaryKey: Ref primaryKey.value === '+'); const isBatch = computed(() => typeof primaryKey.value === 'string' && primaryKey.value.includes(',')); + const isSingle = computed(() => !!collectionInfo.value?.single); const endpoint = computed(() => { return collection.value.startsWith('directus_') @@ -24,6 +25,14 @@ export function useItem(collection: Ref, primaryKey: Ref { + if (isSingle.value) { + return endpoint.value; + } + + return `${endpoint.value}/${primaryKey.value}`; + }); + watch([collection, primaryKey], refresh, { immediate: true }); return { @@ -47,8 +56,7 @@ export function useItem(collection: Ref, primaryKey: Ref, primaryKey: Ref, primaryKey: Ref ({ { name: 'collections-browse', path: '/:collection', - component: CollectionsBrowse, + component: CollectionsBrowseOrDetail, props: (route) => ({ collection: route.params.collection, bookmark: route.query.bookmark, diff --git a/src/modules/collections/routes/browse-or-detail/browse-or-detail.vue b/src/modules/collections/routes/browse-or-detail/browse-or-detail.vue new file mode 100644 index 0000000000..dbceb7df77 --- /dev/null +++ b/src/modules/collections/routes/browse-or-detail/browse-or-detail.vue @@ -0,0 +1,49 @@ + + + diff --git a/src/modules/collections/routes/browse-or-detail/index.ts b/src/modules/collections/routes/browse-or-detail/index.ts new file mode 100644 index 0000000000..63f59d1ec7 --- /dev/null +++ b/src/modules/collections/routes/browse-or-detail/index.ts @@ -0,0 +1,4 @@ +import CollectionsBrowseOrDetail from './browse-or-detail.vue'; + +export { CollectionsBrowseOrDetail }; +export default CollectionsBrowseOrDetail; diff --git a/src/modules/collections/routes/browse-or-detail/readme.md b/src/modules/collections/routes/browse-or-detail/readme.md new file mode 100644 index 0000000000..122c9d56a1 --- /dev/null +++ b/src/modules/collections/routes/browse-or-detail/readme.md @@ -0,0 +1,3 @@ +# Browse or Detail + +Renders either the browse page or the detail page depending on whether or not the collection is a singleton diff --git a/src/modules/collections/routes/browse/browse.vue b/src/modules/collections/routes/browse/browse.vue index 6f8fe5ad82..f5491f3632 100644 --- a/src/modules/collections/routes/browse/browse.vue +++ b/src/modules/collections/routes/browse/browse.vue @@ -133,10 +133,7 @@