Skip to content

Groups: refresh member list after adding a member - #2936

Merged
corsacca merged 2 commits into
DiscipleTools:developfrom
EthanW96:fix/group-member-list-refresh
Sep 29, 2026
Merged

corsacca merged 2 commits into
DiscipleTools:developfrom
EthanW96:fix/group-member-list-refresh

Conversation

@EthanW96

Copy link
Copy Markdown
Collaborator

Fixes #2935

Problem

Members added to a group from the Member List tile (Select or Create) didn't appear until a page reload. The tile in dt-groups/groups.js only redraws on dt-post-connection-added / dt-post-connection-created, and nothing has triggered those events since the connection fields moved to web components in #2650.

Changes

dt-groups/groups.js only:

  • Redraw on dt:post:update. ComponentService dispatches this after each save, with the saved record. The Member List now redraws when the save touched members or leaders. This covers both Select (the typeahead in the add-member modal) and Create (details.js calls _select() on the same <dt-connection name="members"> after create_post). The new row gets the existing leader toggle and remove button, which already use delegated handlers.
  • Default post.members to []. After the last member is removed, the saved record has no members key, so populateMembersList() would throw.
  • Check member.data.milestones the same way member.data.overall_status is already checked.

I left the old dt-post-connection-* listeners in place, since a plugin could still trigger them.

Testing

On a group record:

  • Select an existing contact: they appear in the Member List right away, and the member count updates.
  • Create a new contact from the tile: they appear right away.
  • Toggle leader on the newly added member without reloading: it saves and the list re-sorts.
  • Remove members down to zero: the empty-list message shows and there are no console errors.
  • Edit an unrelated field (e.g. group status): the Member List doesn't redraw.

The Member List tile renders the `members` connection itself and only
redrew on `dt-post-connection-added` / `dt-post-connection-created`.
Nothing has fired those events since the move to web components (DiscipleTools#2650),
so members added via Select or Create did not appear until a page reload.

Listen for `dt:post:update`, which ComponentService dispatches with the
saved record, and redraw when `members` or `leaders` changed.

Also guard against a missing `members` field (after removing the last
member) and missing `data.milestones` on a member.

Fixes DiscipleTools#2935
@corsacca

Copy link
Copy Markdown
Member

Hey @EthanW96 Thanks!

One small issue: the list and the modal can get out of sync
The PR makes adds in the modal update the list, but removals from the list still don't update the modal's :

Group has members A and B. Click the row × on B. API.update_post deletes B, but the component's value is still [A, B] in the modal.
Open Select and add C.
dt-connection._select sends the component's whole value ([A, B, C]), and convertValue('dt-connection') sends every item without a delete flag. B is quietly added back.
With this PR, B now reappears in the list right away. B also stays shown as selected in the modal, so it can't be re-picked from search.

Removing a member with the row x saves through jQuery and redraws the
list, but left the add-member modal's <dt-connection> holding the old
value. Its next save sends that whole value, which silently re-added
the removed member.

Set the component's value from post.members whenever the list is
populated. Setting value directly does not fire change, so this does
not trigger a save.
@EthanW96

Copy link
Copy Markdown
Collaborator Author

Thanks @corsacca, good catch. I reproduced it: the row × removes B through API.update_post, but the modal's still holds [A, B], so the next _select sends B again without a delete flag and B gets re-added.

Fixed in 83e10fa. populateMembersList() now also sets the modal component's value from post.members, converted with ComponentService.convertApiValue. Every path that changes the list ends in populateMembersList(): page load, the row ×, the leader toggle, and the new dt:post:update listener.

Setting value directly doesn't dispatch change, so it doesn't trigger a save. This is the same approach details.js uses to put the saved value back into dt-multi-text after dt:post:update.

Tested with your steps: remove B, then Select C. The list shows A and C, B stays removed after a reload, and B can be found and picked again from the modal's search.

Let me know if that doesn't work correctly or there is a better pattern to follow.

@corsacca

Copy link
Copy Markdown
Member

thank you @EthanW96!

@corsacca
corsacca merged commit 3cd5865 into DiscipleTools:develop Sep 29, 2026
2 of 3 checks passed
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.

Group Member List doesn't update after adding a member until the page is reloaded

2 participants