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

Update a value in a document after scheduling #66

Open
alexeygolev opened this issue May 5, 2023 · 1 comment
Open

Update a value in a document after scheduling #66

alexeygolev opened this issue May 5, 2023 · 1 comment

Comments

@alexeygolev
Copy link

We need to update a document after we schedule it (similar to updating before publishing using a custom document action) but the onHandle approach doesn’t seem to work because the ScheduleAction has a dialog and my custom onHandle is called when the dialog is opened so before the schedule date is set. We need to update a “publishedAt” and a couple of other field on our documents when a document is scheduled to reflect the scheduled date. Is there a way to do it that I’m missing?

I tried the following approaches:

  • Wrapping the ScheduleAction into a custom one and using onHandle
  • Wrapping the ScheduleAction into a custom one and passing a custom onComplete. This "almost worked" as I could query the Scheduling API for the current document and get the executeAt date. This method breaks if the schedule is updated in the calendar tool though as it doesn't use the document action so I have no way to hook into it.
  • Wrapping the document into a custom input and poll for scheduling. This doesn't seem like sane solution
  • Setup an external serverless function to query the Scheduling API every minute and update the documents that are being scheduled. This is how our scheduling was implemented for v2 (using the calendar plugin). However it's not very reliable as if our serverless function fails the document will be published with wrong content.
  • Using the events that you put on window and updating documents accordingly. I'm not sure where this could belong within the studio and also the events are clearly private and can change breaking my implementation.

This problem is pretty much locking us out of updating to v3. We have to update some fields on publishing and as the calendar plugin doesn’t work with v3 and the scheduled publishing plugin doesn’t allow us to hook into it we’re unfortunately stuck with v2.

@alexeygolev
Copy link
Author

Played around with the last option (hooking into the window events that you use internally) — I setup up my listeners in a custom studio layout component (that just returns the default rendered studio and has a useEffect to set up the listeners). This actually works except for the scheduleDelete event. All other events either pass the scheduleId in their schedules[].details that I can then use to query the document id or they pass the documentId itself. Although scheduleDelete passes the scheduleId I can't get the document id from it as the schedule no longer exist.
Maybe the event types can be exposed publicly and documentId can be added to the scheduleDelete event? This just about covers my use case with minimal changes to the plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant