digital-cowboy-91 / directus-extensions-dcb-tree-view-bundle

9 stars 1 forks source link

Issue on installation: Invalid collection structure #1

Closed madc closed 1 month ago

madc commented 2 months ago

Dcp Tree View: 1.0.0-rc.1 Directus: 10.13.1

Installed via Directus Marketplace on a Cloudron instance.

We just installed the bundle into a fresh installation, containing only a pages collection. We followed the instructions in the first video, but there seems to be an issue while or after creating the helper collection (pages_meta). It does not auto-select the newly created collection and does not switch to the new layout. After reloading the page this message is show:

image

The console (Firefox) shows the following message: image

Settings: image

image

Please let me know, what additional information or support I can provide to tackle this.

madc commented 2 months ago

On page_meta it shows the following message:

image

digital-cowboy-91 commented 2 months ago

Hi Matt thanks for opening this issue.

  1. The error you are getting is comming from Zod where we can clearly see that Zod was expecting pages_meta but received null. In the background I do validation of fields to ensure the schema is correct before any further processing. This error indicates that layout options are probably missing the collection name to be set, but your other screen shows, that it actually is being set.

Q: Could you click on Related Collection dropdown in Layout Options and ensure, there is a collection called Pages Meta?

  1. I have spin up directus containers locally for version 10.12, 10.12.1, 10.13 and 10.13.1 (all as is) and couldn't replicate the issue.

Q: What DB have you used for this test?

  1. Your last screenshot says that relationship for Rel Parent has not been configured properly.

Q1: Could you please edit this collection, open the configuration of rel parent and take a screenshot of Relationship tab?

Q2: After that, could you potentially remove that field and recreate it manually with following settings?

  1. Interface: Many to One
  2. Key: rel_parent
  3. Related Collection: pages_meta
  4. Continue to Advanced Field Creation Mode
  5. Relationship: check Add O2M to "pages_meta"
  6. Relationship: select or create field name rels_children
  7. Save and refresh the pages layout
digital-cowboy-91 commented 2 months ago

@guidomallee given the information you've shared here I start to think, this might be related to DB type. Could you confirm what DB are you using?

guidomallee commented 2 months ago

@pticon91 I'm on Directus Professional Cloud. Couldn't find so quickly which database Directus Cloud is using under the hood...

digital-cowboy-91 commented 2 months ago

@guidomallee would you be able to create a new relationship in pages_meta with key hello for M2O and 'world' for O2M (as mentioned above) and share API response for /fields/pages_meta and relations/pages_meta ? So I could see if theres any significant difference in payload.

Meanwhile I'll spinup at least PG DB.

digital-cowboy-91 commented 2 months ago

I was able to replicate the issue with postgres . Thank you both for the report I'll try to fix it as soon as possible.

guidomallee commented 2 months ago

Thanks! I assume my test won't be of any use then, correct?

Really looking forward to using your extension - precisely what we need! Thank you for all efforts :)

digital-cowboy-91 commented 2 months ago

Thanks! I assume my test won't be of any use then, correct?

Really looking forward to using your extension - precisely what we need! Thank you for all efforts :)

Correct, but thanks. Also I hope this extension will be of any use for you! Cheers

digital-cowboy-91 commented 2 months ago

I've just released v1.0.1 should be in marketplace in few hours. I'll close this issue once you confirm it works for you.

madc commented 2 months ago

That was quick! I was able to get it to work with your new version, but there are still some issue.

My pages collection was empty, when I went through the setup process. That results in this message: image

When I create a new page, it the message persists and the new page is not shown. I can than switch to the traditional table layout and manually create a page_meta record and then it works:

image

madc commented 2 months ago

It would also be interesting, what the reason for the pages_meta table are.

digital-cowboy-91 commented 2 months ago

Well, now that's the thing that admin should ensure. This extension helps you to populate collection only when running for the first time, but when you create a new page you must create a new item in meta as well (manually or using Flows). So if you didn't do that, I recommend to mark the meta field as required and allow create option only. I am unable to do that programatically. I tried to add a hook to the bundle but this hook didn't have an access to layout options, so it couldn't read what collection should be tracked and to which collection it should populate data automatically.

Or if this is not your case, elaborate more on what's happenning please.

digital-cowboy-91 commented 2 months ago

It would also be interesting, what the reason for the pages_meta table are.

1. Less complex code: The first version of the extension has been creating columns directly into main collection and I even let admins to name the columns freely. However after sometime I've realised that this decision raised unnecessary complexity in the code and was generating "false" updates in the tracking collection as well. 2. Preventing false updates: If you decide to use updated_at field from main collection on your frontend, this field will be reflecting updates to the content only. This is actually visible in my videos. I've chosen the updated_at field in secondary label on purpose, to show that everytime when I save changes the original collection is not impacted. 3. Clearer seperation (of concerns?) + easier extendiblity: If you use this extension, your original collection is updated with connector field only and if uninstall the extension you will have to remove just meta collection and job is done. Another benefit is that the meta collection could be used for other fields like SEO. Even tough I do the validation of fields, I validate only fields required for composing the hierarchy and path, so I don't mind if admin injects another fields to that collection until they don't change the schema of existing fields (some tweaks like hiding or sorting fields are allowed).

digital-cowboy-91 commented 1 month ago

I am closing this issue in favor of v1.0.1