Fix Users window data + live-refresh, plus per-window REST clients#177
Merged
Conversation
…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.
Contributor
✅ WordPress Plugin Check Report
📊 ReportAll checks passed! No errors or warnings found. 🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Two visible bugs in the Users window:
TypeError: Failed to construct 'URL': Invalid URL).Both trace to one root cause:
src/posts-window/rest.tshad a module-level_activeWindowIdsingleton 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 nopostsUrl. Same class of bug already had aresolveProfileConfig()band-aid inuser-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 withcreatePostsWindowClient(windowId)/createUsersWindowClient(windowId)/createUserEditClient(windowId). Each returns a client whose methods close over the boundwindowId. Reading the wrong window's config is now structurally impossible.index.tsregistry callbacks build a client perdesktop-mode-{posts,pages,users,user-edit}mount and thread it into the renderer.setActiveWindowId/getActiveWindowId/_activeWindowIddeleted.users-render.ts,user-edit-render.ts,index.ts,tags-cloud.ts,categories-mindmap.ts—clientthreaded through helpers and column-render closures.Users window data fixes
includes/users-window/window.php— switched the list query fromcontext=viewtocontext=edit. WP core only emitsemail,roles, andregistered_dateon/wp/v2/usersin edit context.contexton 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.ts—buildRegisteredCellno longer appends a strayZto ISO strings that already carry a+00:00offset (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— aftersaveUsersucceeds, broadcastsdesktop-mode.user.changedwith{ source, action: 'updated', ids: [userId] }. Mirrors the existingdesktop-mode.post.changedpattern.users-render.ts— subscribes to the channel and patches only the affected row via a newclient.fetchOneUser(id)(no full list re-fetch, no scroll reset, no flicker). Unsubscribes on window-closed.users-rest.ts— addedfetchOneUser(id)that hits/wp/v2/users/<id>with the same_fieldsandcontextwhitelist as the list endpoint.Test plan
npm run build,npm run lint,./node_modules/.bin/tsc --noEmit,npm run test:js— all green (1115/1115 vitest).🤖 Generated with Claude Code