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

Can't set Workflow Status (Draft / Review / Publish) via API #183

Closed ptreitler closed 2 years ago

ptreitler commented 2 years ago

I want to add data to Flamelink in the "Draft" status in my app, but I haven't found a way to do so using the API. I can read the status on my data just fine via _fl_meta_.status, but there doesn't seem to be a way to set this attribute in flamelinkApp.content.add.

I have tried passing it as part of the data:

flamelinkApp.content
      .add({
        schemaKey: "mySchema",
        data: {
          _fl_meta_: {
            status: "draft",
          },
         // ...
        },
      })

...but this seems to get ignored as it doesn't show up in the CMS or the Cloud Firestore.

gitdubz commented 2 years ago

Hi @ptreitler

I just had a quick look and it looks like that status is not assignable via the SDK.

I will update this issue as soon as this has been fixed on the SDK

As a work around until it is updated, you can do the following:

const entry = await flamelinkApp.content
      .add({
        schemaKey: "mySchema",
        data: {
            ...
        },
      })

// NOTE: using the firebaseApp and not the FlamelinkApp below
firebase
    .firestore()
    .collection("fl_content")
    .doc(entry._fl_meta_.docId)
    .update({ "_fl_meta_.status": "draft" });
ptreitler commented 2 years ago

Thanks for the quick reply and workaround @gitdubz, I'll try that in the meantime.

gitdubz commented 2 years ago

Hi @ptreitler

A new version of the sdk has been released (1.0.0-rc.1)

You can update or install the latest (npm install flamelink@next)

https://flamelink.github.io/flamelink-js-sdk/#/content?id=add

you will notice the new status parameter that can be passed

 app.content.add({
  schemaKey: 'blogPost',
    data: {
      title: 'New Post',
    },
    status: 'draft',
 })