mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-02 17:26:24 +00:00
Feat/plugin instance actions (#2209)
* feat(shared): scope plugin action descriptors * feat(plugin-sdk): instance-scoped settings actions * feat(plugins): run instance-scoped actions from the admin settings dialog * feat(admin): instance-scoped plugin actions in the settings dialog * fix(plugins): surface instance actions without instance fields and harden the action gate * docs(plugin-sdk): note that hosts before 4.2.0 ignore action scope * fix(admin): open the dialog for instance actions, explain inactive 404s, guard the save window * docs(wiki): plugin pages for instance actions and the admin panel changes
This commit is contained in:
@@ -156,6 +156,32 @@ Declare settings in `trek-plugin.json`; TREK renders the form, you write no sett
|
||||
Any other attribute is **silently dropped at install**. `trek-plugin validate` warns on
|
||||
one (`manifest.settings-known-keys`) so a typo like `"defalt"` doesn't quietly do nothing.
|
||||
|
||||
### Actions
|
||||
|
||||
Up to 8 buttons the host renders on a settings form, declared in `trek-plugin.json`
|
||||
and implemented in `definePlugin({ actions: { <key>: async (ctx) => ({ ok, message }) } })`:
|
||||
|
||||
```json
|
||||
"actions": [
|
||||
{ "key": "testConnection", "label": "Test connection", "hint": "Pings the API." },
|
||||
{ "key": "purgeCache", "label": "Purge cache", "scope": "instance", "danger": true }
|
||||
]
|
||||
```
|
||||
|
||||
| Attribute | Meaning |
|
||||
|---|---|
|
||||
| `scope` | `user` (default) — renders on the user Settings tab and runs as the clicking user. `instance` — renders in the admin instance-settings dialog and runs as the clicking admin. The default differs from settings fields on purpose: existing manifests keep their user-tab buttons. A host older than TREK 4.2.0 (which introduced action scope) ignores this field entirely and renders the button on every user's Settings tab, running it as each user — so if you declare `scope: "instance"`, set the manifest's `trek` range floor to `>=4.2.0` or the button will run in the wrong place on an older host. |
|
||||
| `danger` | Rendered destructive; the host asks for confirmation first. |
|
||||
| `hint` | Shown beside the button (≤ 200 chars). |
|
||||
|
||||
Either way the handler gets the clicking person as acting user: `ctx.config` is the
|
||||
instance config, `ctx.settings.get()` returns their own user value, and trip reads are
|
||||
membership-checked against them. Return `{ ok, message }` or throw to report a failed
|
||||
action (the host shows the message, emoji-stripped, ≤ 200 chars). An instance action is
|
||||
disabled in the dialog until the plugin is active — there is no child process to run it.
|
||||
In the mock host, pass `declaredActions: ['testConnection', { key: 'purgeCache', scope: 'instance' }]`
|
||||
and drive either with `drv.action(key)`.
|
||||
|
||||
`ctx.config` is frozen at activation — the host re-spawns the plugin when the admin
|
||||
saves. `ctx.settings.get()` is live per call and returns `undefined` in a userless
|
||||
context (`onLoad`, jobs, scheduler) — fall back to `ctx.config` there.
|
||||
|
||||
Reference in New Issue
Block a user