mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-25 22:27:32 +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:
@@ -55,6 +55,9 @@ interface PluginRow {
|
||||
/** How many `scope:'instance'` settings fields the plugin declares — gates the
|
||||
* "Instance settings" sheet action without a per-plugin fetch. */
|
||||
instanceSettingsCount?: number
|
||||
/** How many `scope:'instance'` actions the plugin declares — a plugin with actions
|
||||
* but no settings fields still needs the sheet action to run them. */
|
||||
instanceActionsCount?: number
|
||||
dependencies?: PluginDependencies
|
||||
dependencyStatus?: DependencyStatus
|
||||
dependencyIssues?: DependencyIssues
|
||||
@@ -591,9 +594,9 @@ export default function MAdminPluginsPanel() {
|
||||
}
|
||||
}
|
||||
|
||||
const openInstanceSettings = (id: string) => {
|
||||
const openInstanceSettings = (p: { id: string; status: string }) => {
|
||||
setMenu(null)
|
||||
settings.open(id)
|
||||
settings.open(p.id, p.status === 'active')
|
||||
}
|
||||
|
||||
const openErrors = (id: string) => {
|
||||
@@ -972,7 +975,7 @@ export default function MAdminPluginsPanel() {
|
||||
onRestart={() => restart(rowMenuPlugin.id)}
|
||||
onErrors={() => openErrors(rowMenuPlugin.id)}
|
||||
onEgress={() => openEgress(rowMenuPlugin.id)}
|
||||
onSettings={() => openInstanceSettings(rowMenuPlugin.id)}
|
||||
onSettings={() => openInstanceSettings(rowMenuPlugin)}
|
||||
onChangeVersion={() => openVersionPicker(rowMenuPlugin)}
|
||||
onUninstall={() => { setMenu(null); setConfirmUninstall(rowMenuPlugin) }} />
|
||||
)}
|
||||
@@ -1127,8 +1130,45 @@ export default function MAdminPluginsPanel() {
|
||||
{f.hint && <span className="mt-1 block font-geist text-[0.625rem] text-m-faint">{f.hint}</span>}
|
||||
</label>
|
||||
))}
|
||||
{(() => {
|
||||
const form = settings.form
|
||||
if (!form || form.actions.length === 0) return null
|
||||
return (
|
||||
<div className="border-t border-[color:var(--m-rowbr)] pt-4">
|
||||
<span className="mb-2 block font-geist text-[0.625rem] font-bold uppercase tracking-wide text-m-faint">
|
||||
{t('admin.plugins.actions')}
|
||||
</span>
|
||||
{!form.active && (
|
||||
<p className="mb-2 font-geist text-[0.625rem] text-m-faint">{t('admin.plugins.actions.inactive')}</p>
|
||||
)}
|
||||
<div className="flex flex-col gap-2">
|
||||
{form.actions.map(a => {
|
||||
const res = settings.actionResult[a.key]
|
||||
return (
|
||||
<div key={a.key} className="flex flex-wrap items-center gap-2">
|
||||
<MAdminButton
|
||||
variant={a.danger ? 'danger' : 'ghost'}
|
||||
busy={settings.runningAction === a.key}
|
||||
disabled={!form.active || settings.runningAction !== null || settings.saving}
|
||||
onClick={() => settings.runAction(a)}
|
||||
>
|
||||
{a.label}
|
||||
</MAdminButton>
|
||||
{a.hint && <span className="font-geist text-[0.625rem] text-m-faint">{a.hint}</span>}
|
||||
{res && (
|
||||
<span aria-live="polite" className={`text-[0.625rem] font-bold ${res.ok ? 'text-[color:var(--m-st-confirmed)]' : 'text-[color:var(--m-st-danger)]'}`}>
|
||||
{res.message || (res.ok ? t('common.success') : t('common.error'))}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})()}
|
||||
{settings.error && <p className="text-[0.6875rem] text-[color:var(--m-st-danger)]">{settings.error}</p>}
|
||||
<MAdminButton disabled={settings.saving} onClick={() => void settings.save()} className="h-[42px] w-full">
|
||||
<MAdminButton disabled={settings.saving || settings.runningAction !== null} onClick={() => void settings.save()} className="h-[42px] w-full">
|
||||
{t('common.save')}
|
||||
</MAdminButton>
|
||||
</div>
|
||||
@@ -1151,6 +1191,18 @@ export default function MAdminPluginsPanel() {
|
||||
danger
|
||||
/>
|
||||
|
||||
{/* Instance action confirm */}
|
||||
<MConfirmSheet
|
||||
open={settings.pendingAction !== null}
|
||||
onClose={settings.cancelPendingAction}
|
||||
onConfirm={settings.confirmPendingAction}
|
||||
title={settings.pendingAction?.label ?? ''}
|
||||
message={t('admin.plugins.actions.confirm')}
|
||||
confirmLabel={settings.pendingAction?.label}
|
||||
cancelLabel={t('common.cancel')}
|
||||
danger
|
||||
/>
|
||||
|
||||
{signatureBlock && (
|
||||
<SignatureBlockSheet
|
||||
data={signatureBlock} entry={regById[signatureBlock.subject.id]} busy={retrusting} t={t}
|
||||
@@ -1409,9 +1461,9 @@ function RowActionsSheet({ p, t, onClose, onRestart, onErrors, onEgress, onSetti
|
||||
{p.enabled === 1 && (
|
||||
<button type="button" className={rowClass} onClick={onRestart}><RotateCw size={16} /> {t('admin.plugins.restart')}</button>
|
||||
)}
|
||||
{/* Only a plugin that DECLARES scope:'instance' fields gets the action — an
|
||||
empty form would invite the admin to configure nothing. */}
|
||||
{(p.instanceSettingsCount ?? 0) > 0 && (
|
||||
{/* A plugin gets the action if it declares scope:'instance' fields OR actions —
|
||||
an action-only plugin still needs the sheet to run them. */}
|
||||
{((p.instanceSettingsCount ?? 0) > 0 || (p.instanceActionsCount ?? 0) > 0) && (
|
||||
<button type="button" className={rowClass} onClick={onSettings}><SlidersHorizontal size={16} /> {t('admin.plugins.instanceSettings')}</button>
|
||||
)}
|
||||
<button type="button" className={rowClass} onClick={onErrors}><Bug size={16} /> {t('admin.plugins.viewErrors')}</button>
|
||||
|
||||
Reference in New Issue
Block a user