fix: refresh a group's members on the Groups page after saving it (#12460)

* fix: refresh a group's members on the Groups page after saving it

GroupInfo fetched the members once when it mounted, and the rows are keyed by name, so after adding or removing members the Members column kept the old list until a reload.

* fix: refresh only the saved group's members and drop superseded member loads

Bump a per-group key on save instead of passing the whole groups array, so
saving one group no longer refetches every row's members. GroupInfo now
ignores a getGroup reply once a newer load has started (latestRequest).
This commit is contained in:
Raunak Burrows
2026-11-16 13:08:08 +00:00
committed by GitHub
parent 938c03c501
commit 428a07f5fc
2 changed files with 19 additions and 5 deletions
+10 -3
View File
@@ -3,14 +3,18 @@
import { workspaceStore } from '$lib/stores'
import Popover from './Popover.svelte'
import { untrack } from 'svelte'
import { latestRequest } from '$lib/utils/latestRequest'
interface Props {
name: string
/** Members are refetched whenever this changes. */
reloadKey?: unknown
}
let { name }: Props = $props()
let { name, reloadKey }: Props = $props()
let members: string[] | undefined = $state([])
const memberLoads = latestRequest()
async function loadMembers() {
// FAKE DATA FOR TESTING - Set to false to remove all fake data
@@ -32,13 +36,16 @@
}
}
const isLatest = memberLoads.start()
try {
members = (await GroupService.getGroup({ workspace: $workspaceStore!, name })).members
const result = (await GroupService.getGroup({ workspace: $workspaceStore!, name })).members
if (isLatest()) members = result
} catch (e) {
members = []
if (isLatest()) members = []
}
}
$effect(() => {
reloadKey
$workspaceStore && untrack(() => loadMembers())
})
</script>
@@ -43,6 +43,13 @@
groups = result
}
// Bumped per saved group, so only that group's row refetches its members.
let saveCounts: Record<string, number> = $state({})
function onGroupSaved(name: string): Promise<void> {
saveCounts[name] = (saveCounts[name] ?? 0) + 1
return loadGroups()
}
$effect(() => {
if ($workspaceStore) {
untrack(() => loadGroups())
@@ -50,7 +57,7 @@
})
</script>
<GroupEditorDrawer bind:this={groupEditorDrawer} onSaved={loadGroups} />
<GroupEditorDrawer bind:this={groupEditorDrawer} onSaved={onGroupSaved} />
<AccessDrawer bind:this={accessDrawer} />
{#if $workspaceStore && !$roleCapabilities.visibility.groups}
@@ -130,7 +137,7 @@
</div>
</Cell>
<Cell>
<GroupInfo {name} />
<GroupInfo {name} reloadKey={saveCounts[name]} />
</Cell>
<Cell last actions shouldStopPropagation>
<Dropdown