Question related to Setparams i.r.t. having to save

Situation:

We have a SetParamsButton (longpull = True) which takes long as it gathers information through different API calls.
It works well, but it doens’t save the result, i have to save the results once again manually before you refresh. Otherwise you have to call the method again.

How can I force the SetParamsButton to save the set params?

Hey Johan you may be able to use the api module to set the params of the current entity, something along these lines:


class Controller(ViktorController):
    ...
    
    def set_params(params, entity_id, **kwargs):
        new_params = ...
        
        entity = api.get_entity(entity_id)
        params = entity.last_saved_params
        params = ... # merge params with new_params
        entity.set_params(params)  # creates a new revision
        return SetParamsResult(new_params)

Thanks i’ll give it a try next week.

It seems to work. It shows i have to save, but if i refresh it was already saved (due to the entity.set_params(params))

Still i wonder, why doesn’t the SetParamsResult do the same thing?
It feels like you set it twice, why?

Good question, I did not consider this before but you may be right that from a developer perspective this could feel like a duplicate step in some cases. However, from a user perspective it may not always be clear that an entity revision is created while iterating on a certain design.

Hi Johan,

Could you elaborate a bit more on why you think that immediately ‘saving’ after the set-params is the best solution? If users click the button often, you would get of lot of revisions that might clutter your revision history.

Do users forget to save often? Is it expected by the user that the button click also does a ‘save’ action?

Given the fact that you probably don’t want to re-compute it every time, you could potentially use the Storage as well to avoid the many different API calls. Then it is simply saved to storage, but not as a new revision.

Does this use case for SetParams followed by a ‘Save’ happen more often in your apps/flows?

We don’t really use revisions that often. At least I don’t know any user that resets to an older revision.

But sometimes the results of the setparams button in a long call isn’t visible directly in the UI and you have to refresh to see it.
Sometimes it is visible but you have to press Save to make the changes permanent.

Usually it is nice to explicitely save instead of doing it for the user.
However sometimes the differences aren’t visible and we just want to make sure it is saved.

With regard to the Storage, we use it for external analysis a lot. But not for API calls etc. if not needed to prevent complexity in the tests. We still have to write a script to get all storage files to be mocked for our automatic end-point tests.

Cool,

Thanks for elaborating! We’ll take this into account in potential additions/simplifications.