mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-22 03:50:30 +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:
@@ -81,9 +81,9 @@ function upsert(db: BetterSqlite3.Database, m: PluginManifest): void {
|
||||
// Refresh the settings-page action descriptors from the manifest.
|
||||
db.prepare('DELETE FROM plugin_actions WHERE plugin_id = ?').run(m.id);
|
||||
const insertAction = db.prepare(
|
||||
'INSERT INTO plugin_actions (plugin_id, action_key, label, hint, danger, sort_order) VALUES (?, ?, ?, ?, ?, ?)',
|
||||
'INSERT INTO plugin_actions (plugin_id, action_key, label, hint, danger, scope, sort_order) VALUES (?, ?, ?, ?, ?, ?, ?)',
|
||||
);
|
||||
m.actions.forEach((a, i) => insertAction.run(m.id, a.key, a.label, a.hint ?? null, a.danger ? 1 : 0, i));
|
||||
m.actions.forEach((a, i) => insertAction.run(m.id, a.key, a.label, a.hint ?? null, a.danger ? 1 : 0, a.scope, i));
|
||||
|
||||
// Refresh the settings-field descriptors from the manifest.
|
||||
db.prepare('DELETE FROM plugin_settings_fields WHERE plugin_id = ?').run(m.id);
|
||||
|
||||
@@ -69,6 +69,11 @@ export interface ManifestAction {
|
||||
hint?: string;
|
||||
/** Render as destructive and ask for confirmation before running. */
|
||||
danger?: boolean;
|
||||
/** Which settings form renders the button. `'user'` (default): the user Settings tab,
|
||||
* run as the clicking user. `'instance'`: the admin instance-settings dialog, run as
|
||||
* the clicking admin. The default is `'user'` (not `'instance'` like settings fields)
|
||||
* so every manifest written before scope existed keeps its user-tab buttons. */
|
||||
scope: 'user' | 'instance';
|
||||
}
|
||||
|
||||
/** A routing profile a routeProvider plugin offers — one entry in the planner's
|
||||
@@ -611,15 +616,24 @@ function parseActions(raw: unknown): ManifestAction[] {
|
||||
const out: ManifestAction[] = [];
|
||||
for (const a of raw) {
|
||||
if (!a || typeof a !== 'object') throw new ManifestError('each action must be an object');
|
||||
const { key, label, hint, danger } = a as Record<string, unknown>;
|
||||
const { key, label, hint, danger, scope } = a as Record<string, unknown>;
|
||||
const k = assertSettingKey(String(key ?? ''));
|
||||
if (!k) throw new ManifestError('action must have a "key"');
|
||||
if (out.some((x) => x.key === k)) throw new ManifestError(`duplicate action "${k}"`);
|
||||
if (scope !== undefined && scope !== 'user' && scope !== 'instance') {
|
||||
throw new ManifestError(`action "${k}".scope must be "user" or "instance"`);
|
||||
}
|
||||
// `label ?? k` only defaults on null/undefined — an explicit `label: ''` would pass
|
||||
// straight through and reach the client as an empty button/confirm label (which
|
||||
// MConfirmSheet then refuses to render a confirm button for). Fall back to the key
|
||||
// whenever the label is empty after trimming.
|
||||
const rawLabel = label == null ? '' : String(label);
|
||||
out.push({
|
||||
key: k,
|
||||
label: String(label ?? k).slice(0, 60),
|
||||
label: (rawLabel.trim() === '' ? k : rawLabel).slice(0, 60),
|
||||
hint: hint === undefined ? undefined : String(hint).slice(0, 200),
|
||||
danger: danger === true,
|
||||
scope: scope === 'instance' ? 'instance' : 'user',
|
||||
});
|
||||
}
|
||||
return out;
|
||||
|
||||
Reference in New Issue
Block a user