Backend data update - using component events and variable copies

I think I found an elegant way to proceed, essentially based on this post. I’m sharing what I implemented for the community :

Before any change by the user, when the page loads, a workflow is launched to :

  1. Fetch collection A from Supabase
  2. Copy the collection into a list currentAs (meant to represent the last version during user’s edits)

And the AComponent is repeated as an item of the container displaying the A collection data :

  1. Pass down currentAs values as properties for the repeated AComponent

Then, when the user edits a AComponent instance :

  1. AComponent component (not instance) triggers the OnAChanged event, with value :
OnAChanged {
    field: <field_name>,
    value: <field_value>
}
  1. On this event, the AComponent instance (not component) starts workflow to :
  • Change currentA “partially” with :
    • path set to [<item_index>].<Event.field>
    • value set to : <Event.value>
  1. Update A in DB with the new currentA[<item_index>]

All this implies that currentA is initially (at page load) equal to the fetched collection, but after the first user edit, the collection itself is not up to date and the display is maintained with currentA list. The collection needs a page load to be updated.

Note : it must be done in two steps, because it is not possible to select which specific field to update in backend directly with the Database|Update action. Certainly it could be done in one step with REST API Request action.

@aurelie I still have not understood why my "On mounted“ workflow did not trigger, but I’m creating a ticket for that.

1 Like