Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relations support in components/dynamic zones #132

Open
omikulcik opened this issue Oct 2, 2023 · 22 comments · Fixed by #136 · May be fixed by #158
Open

Relations support in components/dynamic zones #132

omikulcik opened this issue Oct 2, 2023 · 22 comments · Fixed by #136 · May be fixed by #158
Labels
issue: feature request Issue suggesting a new feature

Comments

@omikulcik
Copy link
Collaborator

Currently the plugin does not support versioning of relations. When a new version of content is created it's relations should be persisted. If the relation is also versioned and new version was created it's id should be updated.

@omikulcik omikulcik added the issue: feature request Issue suggesting a new feature label Oct 2, 2023
@Sklico
Copy link

Sklico commented Oct 17, 2023

@omikulcik could you please reopen this issue ? I think it's not done. It somehow works for direct relations on the model, but it doesn't work for relations in components / dynamic zone. At this moment, when you have some relations in components / dynamic zone, after create a new version, those relations are not persisted / transferred to the new version and they are just empty.

Thanks

@omikulcik
Copy link
Collaborator Author

@Sklico Sure, will reopen and try thinking of a solution to also support relations in the components. It is quite complex.

@omikulcik omikulcik reopened this Oct 17, 2023
@martincapek martincapek changed the title Relations support Relations support in components/dynamic zones Oct 18, 2023
@ziermach
Copy link

ziermach commented Dec 5, 2023

any update on this?

@ziermach
Copy link

ziermach commented Dec 5, 2023

when i publish another locale the relations always getting removed.
Is this an bug or missing feature how should this work?

@ShipleyC95
Copy link
Collaborator

@ziermach I have been working on a fix for Dynamic Zones, hoping to open the PR soon. @omikulcik is right, it is complicated 😅

@omikulcik
Copy link
Collaborator Author

omikulcik commented Dec 11, 2023

I started working on support of relations inside components last week. @ShipleyC95 how far are you? I guess we should sync so both of us do not work on the same thing. By the ways, it is amazing that you want to contribute! :)

@ShipleyC95
Copy link
Collaborator

@omikulcik
My implementation is a bit of a mess right now but the gist of my solution was to /server/services/content-types.js and in getUpdatableRelations, if the attribute type is dynamiczone iterate over its components, get the model and recursively call getUpdateableRelations but instead of just pushing the key, it pushes result.push({ [key]: relations })

Then inside the manageRelations function, using the result from getUpdateableRelations, data drive the findOne query.

Then I'm currently working on a function to call recursively that will put all the connections back together instead of the

updatableRelations.forEach((rel) => {
    const prevRel = previousVersion[rel];
    ...
    connects[rel] = { connect: mergedConnects };
 });

I'm hoping this is the right approach! I also spotted that in server/register.js that the relation update middleware is only being called on publish, so I've added PUT "/content-manager/collection-types/:model/:id" to that file as well.

@ShipleyC95
Copy link
Collaborator

By the ways, it is amazing that you want to contribute! :)

Happy to contribute, that's part of the joys of open-source 😁

@hafizasadabbas
Copy link

🌟 Appreciation and Update Request 🌟

Hey @ShipleyC95 and @omikulcik,

Firstly, a huge shoutout to both of you for tackling the dynamiczone relations issue! Your dedication and collaborative spirit are truly commendable. 🙌

I'm currently in the midst of an upgrade and your work on supporting relations inside components is crucial for my progress. Thank you for taking on this challenge!

@ShipleyC95, could you please provide an update on your progress?
@omikulcik, Any updates on your end?

Looking forward to hearing from both of you soon! 🚀

Cheers.

@omikulcik
Copy link
Collaborator Author

@ShipleyC95 Your solution also makes sense to me. I am only not sure about calling the middleware also on PUT because then a relation that is not yet published could be assigned If I am right.

It seems that you have gotten further than I did. Could you please submit a draft pr orupload your branch and we could split who does which part? You can do it all yourself if that is more comfortable for you. I just think that we should either cooperate or work on different features.

@hafizasadabbas Thank you for your support! :) I hope that the information in the previous paragraph helps you.

@ShipleyC95
Copy link
Collaborator

@hafizasadabbas @omikulcik
I'm quite close to getting it to work, however, I've just got a couple of mapping issues to handle and then I've got some hard-coded stuff for my particular use case that I have to make generic again; so I'm not currently in a position to open a draft PR but I'm hoping to be able to do so today.

@omikulcik; concerning the PUT request I noticed that if you create a brand new page, save it and don't publish it, then make a change and save it again, all the relations are removed. I hadn't considered the case of draft relations, so that's something you could potentially look into?

@omikulcik
Copy link
Collaborator Author

@ShipleyC95 Sure, that sounds good.

@ShipleyC95
Copy link
Collaborator

@omikulcik Would that make more sense under a separate issue or just under this one? (Happy to create one if needed)

@omikulcik
Copy link
Collaborator Author

@ShipleyC95 In think in this one it is ok :)

@ShipleyC95
Copy link
Collaborator

ShipleyC95 commented Dec 14, 2023

Hey, @omikulcik I've got Dynamic Zones working. Had a slight complication with the root relationships in doing so but have fixed it. I can submit a draft PR, however I don't have permissions to publish my branch, could you grant them please?

There will still be some tidying up to do but wanted to give you visibility on my implementations so far.

(Apologies for no update yesterday, hit a couple of snags along the way)

@hafizasadabbas
Copy link

@ShipleyC95 Can I see your work as I mentioned it's crucial for my progress and I think it will take time to merge. I am also working on a patch to fix it.

@omikulcik
Copy link
Collaborator Author

@ShipleyC95 I have given you write access to this repo. However, I believe, you could make a fork of this repo and then request a PR but nevermind. I am looking forward to seeing your implementation! :)

@ShipleyC95
Copy link
Collaborator

Thanks @omikulcik for granting permissions. I wasn't aware that forking -> PR was required, my apologies!

@hafizasadabbas the draft PR is open now

@omikulcik
Copy link
Collaborator Author

No worries. I will check the PR today.

@hafizasadabbas
Copy link

@ShipleyC95 appreciate your work but after applying your code it stops carrying forward the second dynamiczone component when I make the version. Can you please reproduce it on your side?

@omikulcik
Copy link
Collaborator Author

@hafizasadabbas we are just solving that. You can get more updates in #158

@bgarcia-kaliop
Copy link

Hi guys,
any news on this fix ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue: feature request Issue suggesting a new feature
Projects
None yet
6 participants