Intevel / nuxt-directus

🐰 Easily integrate Directus to your Nuxt application.
https://nuxt-directus.de/
MIT License
269 stars 49 forks source link

cant retrieve folders from directus #246

Closed PhilipZi closed 8 months ago

PhilipZi commented 8 months ago

the library wont let me retrieve my folders from directus.

see my code:

const { getItems } = useDirectusItems();

export const useBlockStore = defineStore("blocks", {
  state: () => ({
    blockContent: [],
  }),

  actions: {
    async updateContent() {
      try {
        this.blockContent = await getItems({
          collection: "support_portal",
          params: { fields: ["*.*.*.*"] },
        });
      } catch (e) {}
    },
  },
});

This is my code to reach a collection called support portal. This works. But i cant reach folders inside this collection nor can i reach folders created by me and directly speaking to them, i need somethins else than " collection" i guess. somethins like "folders" which i can filter threw. Do you have some ideas? Is there a solution?

This is my data structure. I would like to reach block_hero_banner and some other blocks which are coming next to block_hero_banner. see my image:

Bildschirmfoto 2024-02-15 um 17 16 47

Hope you can help me.

casualmatt commented 8 months ago

Hi @PhilipZi, Can you send a link to a repo or Stackblitz to make it easier for us to help you? What version of the module are you using 5.x or 6.x?

Btw, a query like this: "..." will use a lot of resources; I would highly discourage wildcard usage, even if you use Directus+Postgress, and particularly if you use other DB.

PhilipZi commented 8 months ago

Hey Matt, thanks for the quick reply! Its on gitlab and i cant really share the repo unfortunately. Bildschirmfoto 2024-02-15 um 18 15 31

i am using 1.3 anyhow? If you mean the nuxt-directus lib? I can provide you more code snippets if this helps? What you saw earlier is a snippet from a pinia store. It works as it is shown the only thing i need is to reach the folder and the collections inside that folder which is nested in one collection. It would also help if i can just reach collections inside of folders.

PhilipZi commented 8 months ago

Bildschirmfoto 2024-02-15 um 18 19 58

actually i am using 5.6 xD i screen shot the wrong dep.

PhilipZi commented 8 months ago

I also set the public accessibility for directus_folders and directus_collections to visibile/readable

sandros94 commented 8 months ago

If I understand correctly the folders endpoint they are meant for files and not collections. Official docs:

Folders can be used to organize files within the platform. Folders are virtual, and aren't mirrored within the storage adapter.

But in your screenshot above:

Bildschirmfoto 2024-02-15 um 17 16 47

It seems like you are referring to folders for collections and not files? If this is the case I'm not sure if they can be used in the API/SDK or they are just a visual representation of the Directus app

PhilipZi commented 8 months ago

thanks Sandros, this is actually correct, but when i speak to the support_portal collection for example i wont be able to reach block_hero_banner, its not shown in the api even if i put away the folder. You got me right there. This is my main issue. later on i wanna have multiple collections inside support_portal which i would like to generate with one request if possible.

PhilipZi commented 8 months ago

To make it more clear is there a build in function to reach the folders content? It seams via @directus/sdk lib i could reach these? See my sceenshot.

Bildschirmfoto 2024-02-16 um 08 55 22

here it seems to be possible to reach the folders. but in nuxt-directus this option is not documented or working. I need to use nuxt-directus lib because with the other lib nuxt-images wont get rendered in webp format...

would be happy if someone can help out.

casualmatt commented 8 months ago

Yes, but that is the virtual folder that Directus uses; it's just a table in the DB called directus_folders. In any case, you can't use readFolders for a folder table that you created; it works only with Directus own folder system.

If you want to use the SDK, you could try the 6.x version of the module that is in development and directly works with the SDK, but version 5.x is based on Directus API non SDK:

sandros94 commented 8 months ago

Also, as @casualmatt mentioned, the 6.x currently available in pre-release under nuxt-directus-next already has support for @directus/sdk and @nuxt/image.

Again, the folders you are mentioning (in /admin/settings/data-model if your Directus App), as far as I remember, aren't the folders under the readFolders composable from the SDK. Did you double check your permissions for the block_hero_banner collection, and have a valid relation from support_portal and a junction M2A collection (that is missing from the information provided so far)?

Please refer to the official docs on how to build reusable page components. If you are going to use nuxt-directud-next you can also use clients (our docs about the SDK are still being drafted).

casualmatt commented 8 months ago

@PhilipZi We are not able to reproduce your issue/request. For now, I will close the issue as "Not planned/stale". If, in the future, you are able to provide a Stackblitz link, we will go over it again and try to help you.

PhilipZi commented 8 months ago

Thanks a lot guys i understand now. I found a way around. Much appreciate you help.