Really struggling with getting the Admin UI to update after updating the data in a custom field. #2679
-
I have two cases I'm looking at. One is adding a row to an array field from a separate custom text field. The custom text field does a query to a backend server and then I try to add the results of that query as an item in my array field
The second case is I wanted to add a custom cell for collection List views that provided a button that would perform an update. In this case i'm trying to add a "publish" and a "delete" button cell so that these things can be conveniently done from the list page. This time I used the api to update the collection and that worked successfully but I could not find a sensible way to refresh the UI to display the new changes caused by my custom component. Please can someone direct me to a way to trigger an update of the admin ui in a sensible way. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hey @rhysmakesthings — I can hopefully give you some answers here. So, we're about to "flatten" the way that array / block row state is managed to make this all significantly simpler, but for now, the reason your array is not updating in UI is because it maintains its own internal row state in addition to the form state. If you trigger a full refresh of the form after updating a row however, the array field will recalculate its own internal row state and rerender accordingly. This is our suggested approach for now, and I gave an example on how to do this below: Take a shot at this. As I said, we are working on some ways to make updating array-based fields significantly easier, but right now, this is the move. 👍 |
Beta Was this translation helpful? Give feedback.
-
Thanks for the quick reply! Good to hear there are more updates on the way. That seems to work well but only if the array already has a value in it. If I'm starting from an empty array and I add something it doesn't appear to update. I also sometimes get "CastError: Cast to embedded failed for value "1" (type number) at path "myArray" because of ObjectParameterError at model.Query.exec (/node_modules/mongoose/lib/query.js:4789:21)" after I add the first row (don't see an update) and save so maybe I'm missing a step?
I've tried a few different variations on this. id and title are both type string in the field config. Any thoughts on the second case I mention in my original post? The sort button on those pages cause a rerender of the table but they also update the url and it seems only changing the sorting method in the url will trigger the rerender. I'm trying to include a "publish" button in a Cell that grabs the current time and updates the relevant item which I can do in the data using the api but I then want it to update in the admin UI as well. I've just seen that you also provide a way to use a completely custom views.List component which might be the way to go if I want to achieve the publish button and updating the list instead of just using a custom Cell component. Or to display the data in my own custom cell component but that probably wouldn't update the sorting. |
Beta Was this translation helpful? Give feedback.
Seems like the following extra lines were required before replaceState
newState.myArray.initialValue = rowIndex+1
newState.myArray.valid = true
newState.myArray.disableFormData = true
Especially disableFormData seems to be important. Not totally clear what this field does but seems to be working now.