Error message appears before user has time to process prompt

Hey, weā€™ve built a plugin that if a certain attribute of a field has been modified we show a prompt and then based on that promptā€™s decision we send a message into slack. Everything is fine except we get a little toast in the bottom right hand saying that itā€™s taking too long. While this is fine for engineers - our editors will likely get spooked by this, and itā€™s kind of untrue - as the editor is processing the prompt.

Screenshot 2024-01-29 at 12.49.17

The specific hook is onBeforeItemUpsert and here is an example of my code (some nested code removed for brevity and sensitive info).

connect({
  renderConfigScreen(ctx) {
    return render(<ConfigScreen ctx={ctx} />)
  },
  // creation and update of records
  onBeforeItemUpsert(item, ctx) {
    return masterMessager(item, ctx, 'created or saved')
  },
  // delete of records
  onBeforeItemsDestroy(items, ctx) {
    return masterMessageLooper(items, ctx, 'Deleted')
  },
  // Publishing records
  onBeforeItemsPublish(items, ctx) {
    return masterMessageLooper(items, ctx, 'Published')
  },
  // Unpublish Publishing records
  onBeforeItemsUnpublish(items, ctx) {
    return masterMessageLooper(items, ctx, 'Unpublished')
  },
})

export async function masterMessager(
  item: ItemUpdateSchema | ItemCreateSchema,
  ctx: OnBootPropertiesAndMethods,
  actionTaken: string,
) {

// some code removed
  const confirmation = await ctx.openConfirm({
    title: `some title`,
    content: `some message`,
    cancel: { label: 'Cancel', value: false },
    choices: [{ label: 'Yes, Save', value: true }],
  })

  if (!confirmation) {
    return false
  }


// some other code removed...

return true
}

If any more info is required please let me know. Thanks!

Hi @neil.gebbie, welcome to the forum and thank you for the detailed report!

As far as I can tell, youā€™re doing everything right. This might be a bug on our end. Let me check with the devs and get back to you as soon as I hear back.

Sorry about that!

@neil.gebbie, I just wanted to let you know that weā€™ve started our investigation into this issue, but we donā€™t have an immediate resolution for it yet. Itā€™s an unintentional side effect (meant to detect slow plugins that do background tasks, which isnā€™t applicable to your use case), but the fix isnā€™t trivial.

Is this blocking work for you? While the devs look into what we can do, can we (as in support staff) maybe help you think of some workarounds, perhapsā€¦? If you can please tell us a bit about your intended use case (what is the prompt supposed to do?), perhaps we can find some other less intrusive/scary way for your users to accomplish the same thing?

Hey, itā€™s probably ok for a few weeks. I can make some changes on my end (Such as putting a little banner above the field or some other alternative). Iā€™ll do my best to explain the use case, and the reason why I couldnā€™t use the solution provided by Dato - as you do provide the functionality about 95%.

We have a radio group ā€œpage_typeā€ (of type string) which is nested inside a ā€œstatic_pageā€ model. Depending on the choice of the page_type in the example below(in my second reply) you would say ā€œAnytime we save/update/publish anything that is ā€œimportantā€ we want to send a slack message via a webhookā€

Now - Dato provides VERY similar functionality but itā€™s missing the granularity of targetting blocks nested inside models. See below:

For me to ā€œavoidā€ having to do the manual plugin work we need an extra filter something like ā€œAdd a Condition ā†’ Trigger only on specific blocks ā†’ Trigger only on specific block choiceā€ or something very granular like that.

Iā€™ve seen this feature request here: Trigger webhook on field change? which I believe will cover our use case, but with all things SWE itā€™s easier said then doneā€¦

We can live with it for now and/or find work arounds if anyone complains. If you need anymore more info let me know. Thanks.

1 Like

Your forum only let me post one image, this is the image I was talking about ā€œan exampleā€:

1 Like

Thank you for the detailed example, @neil.gebbie!

Does this mean that your plugin would pop up a modal asking ā€œDo you want to send a Slack notification?ā€ on every record update? Because you canā€™t tell whether the specific block caused the record update?

A potential workaround (negating the need for a plugin) could be to do what matjack suggested in the other forum thread, to just diff the webhookā€™s payload entity vs its previous_entity to determine if the field/block !== the previous one. Docs for that here: Webhooks ā€” DatoCMS

Weā€™ll still look into the timeout warning (because 5 seconds really isnā€™t a lot of time to answer any sort of modal), but maybe that can help you in the meantime?

Or if I misunderstood where the modal comes in, sorry about that! Please feel free to correct me.

Hey, thanks for your quick replies. This would require us to set up {something in the middle} to transform the webhook payload before it got ā€œpassed onā€ to Slack.

What we have works for the moment, Iā€™m likely not going to change it. The prompt is a ā€œnice to haveā€ - it wasnā€™t part of the requirements from our editors, but itā€™s a nice touch to what weā€™re trying to do. I can likely just replace it with toast, a banner, or a conditionally shown banner based on the selection, all good.

1 Like