flamelink / flamelink-js-sdk

🦊 Official Flamelink JavaScript SDK for both the Firebase Realtime database and Cloud Firestore
https://flamelink.github.io/flamelink-js-sdk
MIT License
43 stars 5 forks source link

updating document after changing locale, creates a new document not linked to the original document. #76

Closed ribalnasr closed 5 years ago

ribalnasr commented 5 years ago

hi,

here's my issue for the day :)

i have a case where users can create announcements, and they can add translations to them. so the process goes as follows:

settings.setLocale('en-US');
content.add({
    schemaKey: 'announcements',
    data: { content: 'SOME_ENGLISH_TEXT'}
})

this will add the announcement to her/his announcements list with these buttons for each one: Edit English and Edit Arabic

when the user clicks on Edit Arabic, we change the locale: settings.setLocale('ar') and then take the user to a form to update the content.

the user will update the form and hit save which will run

content.update({
    schemaKey: 'announcements',
    entryId: 'yBH4nnhZrBXEfFaXMZHU' // ID retrieved from the en-US version
    data: { content: 'SOME_ARABIC_TEXT'}
))

in this case the Arabic version was still not present on update, so we get the following warning:

[FLAMELINK] No entry existed for schema "announcements" with ID "yBH4nnhZrBXEfFaXMZHU" - creating new entry instead.

and the new document created in arabic is not related to the english version.

What i expect to happen in this case, is that the newly created document should have an __flmeta\.flid equal to the entryId sent with the content.update(...).

jperasmus commented 5 years ago

hi, this is a nice one :)

I can see your use case and it makes total sense to me. I'll have to give a bit more thought as to how we need to handle it in the SDK to resemble what happens in the app as close as possible.

The app works like this:

If we want to stick to this flow, we would need to ensure that the SDK checks the available locales as well as whether the current one is the default or not.

jperasmus commented 5 years ago

Hi @ribalnasr just letting you know, I haven't forgotten about this issue, I've been travelling and focusing on other features within the app, but I am going to try and make time this week to look at this one.

ribalnasr commented 5 years ago

great to hear! this will be very useful.

(on another note, i'm planing on working soon on some functions for firestore rules to automatically implement the rules from the fl_permissions collection. unless your team already started working on something similar)

jperasmus commented 5 years ago

That sounds great! I still have an outstanding task to write some documentation around how to do that for Firestore (have a similar article for the Realtime DB), but I haven't gotten to it. Would be great to see your work on this.

ribalnasr commented 5 years ago

Hello! Concerning the rules, please check this issue https://github.com/flamelink/flamelink-js-sdk/issues/86,

As for the initial topic of this thread, any update on this?

jperasmus commented 5 years ago

Hi @ribalnasr

Apologies that it took me so long to give this attention. I've made some changes in v1.0.0-alpha.22 that will handling adding and updating of content in the SDK to be similar to how it is handled in-app at the moment, namely:

When you get a moment, can you please check this release to see if it works for your needs?

ribalnasr commented 5 years ago

This now works as expected.