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.
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.
@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.
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.