yunohost-admin icon indicating copy to clipboard operation
yunohost-admin copied to clipboard

add action

Open Axolotle opened this issue 2 years ago • 0 comments

Implementation of actions in config panels for the web admin.

Changelog

  • add config actions:

    • add new <button-item> component to render an arg type ="button"
    • <config-panel> component now handle config and action submission and emit the proper (filtered) form and id (+ action if it's an action):
      • an action will receive a form containing only values specified in its args prop
      • a config apply will receive everything except values present in action sections
    • top level views can now listen to the submit event and call appropriate routes to trigger a config change or an action
    • an action or a config apply will then update the current panel config values only, any changes in other panels will stay. We may need to revert this if some panels are expected to modify other panels values.
  • rework a bit the core arg to web-admin field/component:

    • <markdown-item>, <read-only-alert-item> and <button-item> now renders without any "wrapper" (was in a <form-field> before)
    • add a new "wrapper" <read-only-field> that will just display any value of an arg with readonly = true
    • rework <file-item> to avoid promises handling in expression evaluations(visible/enabled). Its value is now an object containing the File and other needed props for removal/current, and now also contains the file content (fetched asynchronously). This may be a problem for large files since its content will stay in the form but we may leverage this by adding a new arg prop like context = false to instruct not to fetch the File content.
    • visible and enabled are now computed properties of fields/components to be more "Vue" style (you can simply do <component v-if="field.visible" disabled="!field.enabled">), those properties are evaluated at each form item modification like before.
      • if someone set an arg visible prop to false or '"false"' it will simply be set to false instead of a computed getter

PR Status

Should work on the web-admin but still some stuff to do on the core side to work with CLI, for example:

  • implement readonly for args to display a non-interactive value (simple display for all args types?).
  • implement args prop of type = "button" to filter what arguments are given to the associated function.
  • actions resulting in errors are not displayed (wrong response HTTP code)

Also i've experienced some weird behaviors with the API/core:

  • arg type = "text" will double \ns at each config change (probably a faulty replace)
  • looks like i can't set an hour above 12 in an arg type = "date"
  • i get an error while trying to remove an uploaded file, not sure if it's a regression due to my changes, will investigate. I get this:
DEBUG - + ynh_secure_remove --file=/ynh-dev/temp/file.txt
DEBUG - + ynh_delete_file_checksum --file=/ynh-dev/temp/file.txt --update_only
WARNING - Invalid argument: --

How to test

require: https://github.com/YunoHost/yunohost/pull/1436

go to a domain's config panel and click on button and checkbox. Since the api always return a valid HTTP code, errors are not displayed. But you can check the console to see what's going on.

image action in domain config

image readonly args

Axolotle avatar Feb 09 '22 18:02 Axolotle