Skip to content

fix: reactive Activate/Deactivate buttons in plugin-list (closes #179) - #204

Merged
ivdimova merged 1 commit into
devfrom
fix/v0-11-reactive-plugin-buttons
May 12, 2026
Merged

ivdimova merged 1 commit into
devfrom
fix/v0-11-reactive-plugin-buttons

Conversation

@pluginslab

Copy link
Copy Markdown
Owner

Summary

After clicking the Activate (or Deactivate) button on a plugin row in an `ability_result` message, the button label and its target action would stay frozen at the original state. So an Activate click left an "Activate" button on a now-active plugin — clicking it again hit "plugin is already active" instead of deactivating it.

Net: +71 / -20 lines, 2 files touched.

What changed

`MessageItem.jsx`

  • Extracted the inline button JSX into a small `` component
  • Tracks its own `loading` (shows `…`, button disabled) and `override` state
  • After a successful click, looks up the action in a new `INVERSE_ACTIONS` map:
    ```js
    const INVERSE_ACTIONS = {
    'wp-agentic-admin/plugin-activate': { action: 'plugin-deactivate', button_label: 'Deactivate' },
    'wp-agentic-admin/plugin-deactivate': { action: 'plugin-activate', button_label: 'Activate' },
    };
    ```
  • If the action has an inverse, the button flips to it (same plugin slug in `args`, just opposite ability id + label). Adding another reversible pair only needs a new entry in the map.

`ChatContainer.jsx`

  • `handleAction` now `return`s the action result (was `return undefined`). ActionButton reads `result.success` and only flips on real successes — a failed activation doesn't lie about the state.
  • Cancelled confirmations now return `{ success: false, cancelled: true }` instead of undefined.

Behavior matrix

Initial button Click outcome After
Activate (plugin inactive) success Button becomes Deactivate
Deactivate (plugin active) success Button becomes Activate
Activate failure (e.g. plugin not found) Stays Activate
Any user cancels confirmation Stays as it was
Any during run Shows `…`, disabled

Verification

  • `npm test` — 96 passing, unchanged
  • `npm run build` — clean
  • `composer lint` — clean
  • `npx wp-scripts lint-js` — clean (2 pre-existing ChatContainer warnings are not introduced here)

Manual test plan

  • In the running Playground, send "list plugins"
  • Click Activate on Akismet → label flips to Deactivate, click it → flips back to Activate
  • Click Activate on a non-existent plugin (force-edit the action args) → label does NOT flip (error path)
  • During click, see `…` placeholder on the button

🤖 Generated with Claude Code

After clicking the Activate or Deactivate button on a plugin row in an
ability_result message, the button label and target action would stay
frozen at the original state. So an activate click left an "Activate"
button on a now-active plugin — clicking it again hit "plugin is
already active" instead of deactivating it.

Fix: extract the inline button JSX in MessageItem into a small
<ActionButton> component that tracks its own loading state and, for
known mutual-inverse action pairs (plugin-activate ↔ plugin-deactivate),
flips to the inverse after a successful click. Same plugin slug in
args, just opposite ability + label.

Loading state shows '…' on the button and disables it while the
action runs.

handleAction in ChatContainer now returns the action result so
ActionButton can read result.success and only flip on real successes
(failed activations don't lie about the state).

The INVERSE_ACTIONS map is the single source of truth — adding a new
reversible pair (e.g. enable/disable theme) only needs an entry there.

Tests: 96 passing, unchanged.
Build: clean.
Lint: clean (two pre-existing ChatContainer warnings are not from
this PR).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

@ivdimova ivdimova left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ActionButton component with loading state and inverse-action flip is clean. Correctly depends on ChatContainer.jsx return values from #203.

@ivdimova
ivdimova merged commit 1c08e49 into dev May 12, 2026
4 checks passed
@ivdimova
ivdimova deleted the fix/v0-11-reactive-plugin-buttons branch May 12, 2026 21:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants