Skip to content

Fix Users window data + live-refresh, plus per-window REST clients#177

Merged
AllTerrainDeveloper merged 1 commit into
trunkfrom
fix-user-role-changes
May 12, 2026
Merged

Fix Users window data + live-refresh, plus per-window REST clients#177
AllTerrainDeveloper merged 1 commit into
trunkfrom
fix-user-role-changes

Conversation

@AllTerrainDeveloper
Copy link
Copy Markdown
Collaborator

@AllTerrainDeveloper AllTerrainDeveloper commented May 12, 2026

Why

Two visible bugs in the Users window:

  1. Clicking Edit user → opening the User-edit window broke the Users window's Refresh button (TypeError: Failed to construct 'URL': Invalid URL).
  2. The All-users table was missing Email, Role, and Registered date for every row.

Both trace to one root cause: src/posts-window/rest.ts had a module-level _activeWindowId singleton that every renderer in the bundle wrote to. Opening User-edit repointed it to 'desktop-mode-user-edit', so any later Users-window REST call read the user-edit config blob — which has no postsUrl. Same class of bug already had a resolveProfileConfig() band-aid in user-edit-render.ts; this PR removes the singleton instead.

What changed

Per-window REST client factory

  • rest.ts, users-rest.ts, user-edit-rest.ts — free function exports replaced with createPostsWindowClient(windowId) / createUsersWindowClient(windowId) / createUserEditClient(windowId). Each returns a client whose methods close over the bound windowId. Reading the wrong window's config is now structurally impossible.
  • index.ts registry callbacks build a client per desktop-mode-{posts,pages,users,user-edit} mount and thread it into the renderer. setActiveWindowId / getActiveWindowId / _activeWindowId deleted.
  • users-render.ts, user-edit-render.ts, index.ts, tags-cloud.ts, categories-mindmap.tsclient threaded through helpers and column-render closures.

Users window data fixes

  • includes/users-window/window.php — switched the list query from context=view to context=edit. WP core only emits email, roles, and registered_date on /wp/v2/users in edit context.
  • Same file — widened the schema context on all five custom REST fields (desktop_mode_user_stats, desktop_mode_last_login, desktop_mode_presence, desktop_mode_can_edit, desktop_mode_assignable_roles) to ['view','edit','embed'] so they survive the context switch. Without this the Actions column and stats went blank.
  • users-render.tsbuildRegisteredCell no longer appends a stray Z to ISO strings that already carry a +00:00 offset (the registered_date format in edit context). It now relative-formats correctly instead of falling through to the raw ISO.

Live refresh after profile save

  • user-edit-render.ts — after saveUser succeeds, broadcasts desktop-mode.user.changed with { source, action: 'updated', ids: [userId] }. Mirrors the existing desktop-mode.post.changed pattern.
  • users-render.ts — subscribes to the channel and patches only the affected row via a new client.fetchOneUser(id) (no full list re-fetch, no scroll reset, no flicker). Unsubscribes on window-closed.
  • users-rest.ts — added fetchOneUser(id) that hits /wp/v2/users/<id> with the same _fields and context whitelist as the list endpoint.

Test plan

  • Open Users window. Verify Email, Role, Registered date, Actions, Content, and Last login dots all populate for every row.
  • Click a row → User-edit window opens. Switch back to Users window and click Refresh — no console error, list reloads.
  • In the User-edit window, change a user's role and save. Switch to the Users window — that row's role chip updates in place; other rows don't flicker.
  • Change the email field too. Save. Verify the Users window row updates.
  • npm run build, npm run lint, ./node_modules/.bin/tsc --noEmit, npm run test:js — all green (1115/1115 vitest).

🤖 Generated with Claude Code

Open WordPress Playground Preview
…t interface

- Merged multiple user-related functions into a `UsersWindowClient` interface for better organization and usability.
- Removed redundant helper functions and integrated their logic directly into the client methods.
- Updated the fetch logic to use a single `shellFetch` method for all API calls.
- Adjusted tests to utilize the new client structure, ensuring all user-related operations are encapsulated within the client.
- Removed deprecated `getConfig` and `setActiveWindowId` calls from tests and replaced them with client methods.
@AllTerrainDeveloper AllTerrainDeveloper changed the title Refactor Users REST client: consolidate functions into a single client interface Fix Users window data + live-refresh, plus per-window REST clients May 12, 2026
@github-actions
Copy link
Copy Markdown
Contributor

✅ WordPress Plugin Check Report

✅ Status: Passed

📊 Report

All checks passed! No errors or warnings found.


🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check

@AllTerrainDeveloper AllTerrainDeveloper enabled auto-merge (squash) May 12, 2026 11:43
@AllTerrainDeveloper AllTerrainDeveloper merged commit 109c641 into trunk May 12, 2026
5 checks passed
@AllTerrainDeveloper AllTerrainDeveloper deleted the fix-user-role-changes branch May 12, 2026 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant