From b0f3b5bc3cf23f7e0c12433c7b255347cf2ffc42 Mon Sep 17 00:00:00 2001 From: Guilhem Lemouel Date: Wed, 11 Nov 2026 07:32:14 -0800 Subject: [PATCH] feat: grant and revoke from one row button in the grant navigator Co-Authored-By: Claude Opus 5.5 --- .../src/lib/components/AccessDrawer.svelte | 22 +- .../src/lib/components/DrillPicker.svelte | 310 +++++++++++---- .../components/access/GrantNavigator.svelte | 375 ++++++++++++++---- frontend/src/lib/components/access/access.ts | 21 +- .../components/common/button/Button.svelte | 8 +- frontend/src/lib/components/drillPicker.ts | 13 + 6 files changed, 587 insertions(+), 162 deletions(-) diff --git a/frontend/src/lib/components/AccessDrawer.svelte b/frontend/src/lib/components/AccessDrawer.svelte index 1d5302a1cb..0c91dbf08d 100644 --- a/frontend/src/lib/components/AccessDrawer.svelte +++ b/frontend/src/lib/components/AccessDrawer.svelte @@ -224,13 +224,29 @@ return `${principal} is a member of ${node.key}, so ${principal} can write every item under ${node.key}/, including items added later.` } - /** Grants on the item itself. What its folder or space gives is said once, on that row. */ + /** Grants on the item itself, which decide whether its level reads as its own. */ function itemGrants(item: AccessItem): string[] { return item.reasons.flatMap((r) => r.type === 'user' ? ['Shared directly'] : r.type === 'group' ? [viaLabel(`g/${r.group}`)] : [] ) } + /** Every reason the item is held: its own grants, then its folder or space. */ + function itemReasons(item: AccessItem): string[] { + const labels = item.reasons.map((r) => + r.type === 'user' + ? 'Shared directly' + : r.type === 'group' + ? viaLabel(`g/${r.group}`) + : r.type === 'folder' + ? `Through f/${r.folder}` + : r.type === 'group_path' + ? `Through g/${r.group}` + : 'Own path' + ) + return [...new Set(labels)] + } + function levelClass(item: AccessItem, grants: string[], owner: AccessOwnerNode): string { if (!grants.length) return 'text-hint' return item.write && owner.whole && !owner.write ? 'font-semibold text-emphasis' : '' @@ -364,7 +380,7 @@ {/snippet} {#snippet content()} {#if access} - + {/if} {/snippet} @@ -526,7 +542,7 @@ >{item.write ? 'Write' : 'Read'} - {grants.join(', ')} + {itemReasons(item).join(', ')} {@const own = ownItemGrant(item)} {#if own !== undefined} diff --git a/frontend/src/lib/components/DrillPicker.svelte b/frontend/src/lib/components/DrillPicker.svelte index ad55f4e042..4f6ac6fc6d 100644 --- a/frontend/src/lib/components/DrillPicker.svelte +++ b/frontend/src/lib/components/DrillPicker.svelte @@ -13,7 +13,8 @@ level *up*. Filter (internal or `externalFilter`) is global across all leaves and ignores the current scope. --> @@ -534,99 +607,166 @@ leaves and ignores the current scope. +
{ setHoverHighlight(key) tooltipEnter(e.currentTarget as HTMLElement, leaf) }} + onmousemove={leafActions && !isHl ? () => setHoverHighlight(key) : undefined} onmouseleave={tooltipLeave} > - e.preventDefault()} - onclickcapture={(e: MouseEvent) => { - // Capture, not a delegated onclick: the picker is portalled outside the app root, - // where a delegated handler runs after SvelteKit's link handler has already - // followed the href, too late for preventDefault to keep a plain click on `pick`. - if (href && isNewTabClick(e)) return - e.preventDefault() - pick(leaf, e.metaKey || e.ctrlKey) - }} + +
- {@render defaultLeafIcon(leaf)} - -
e.preventDefault()} + onclickcapture={inert + ? undefined + : (e: MouseEvent) => { + // Capture, not a delegated onclick: the picker is portalled outside the app root, + // where a delegated handler runs after SvelteKit's link handler has already + // followed the href, too late for preventDefault to keep a plain click on `pick`. + if (href && isNewTabClick(e)) return + e.preventDefault() + pick(leaf, e.metaKey || e.ctrlKey) + }} > - {#if leaf.secondary} -
{leaf.label}
-
- {secondary ?? leaf.secondary} -
- {:else} -
- {secondary ?? leaf.label} -
+ {@render defaultLeafIcon(leaf)} + +
+ {#if leaf.secondary} +
{leaf.label}
+
+ {secondary ?? leaf.secondary} +
+ {:else} +
+ {secondary ?? leaf.label} +
+ {/if} +
+ + {#if leafActions} + + {#if badge} + {badge.label} + {/if} + + {:else if leafBadge || leafAction} + +
+ {#if action} + + + {/if} + {#if badge} +
+ {badge.label} +
+ {/if} +
+ {/if} +
+ {#if actions.length} + +
+ {#if mainAction && !done} + + + + {/if}
- - - {#if leafBadge || leafAction} - -
- {#if action} - - - {/if} - {#if badge} -
- {badge.label} -
- {/if} + {/if} + {#if done} + +
+ + {done}
{/if}
diff --git a/frontend/src/lib/components/access/GrantNavigator.svelte b/frontend/src/lib/components/access/GrantNavigator.svelte index 75899c09ab..1010aed63e 100644 --- a/frontend/src/lib/components/access/GrantNavigator.svelte +++ b/frontend/src/lib/components/access/GrantNavigator.svelte @@ -1,18 +1,21 @@ @@ -245,20 +459,41 @@ Picking a row grants the principal read on it; the "All of f/x" row grants the w {/snippet} -
+ diff --git a/frontend/src/lib/components/access/access.ts b/frontend/src/lib/components/access/access.ts index 1d62d52d33..08d8df97bb 100644 --- a/frontend/src/lib/components/access/access.ts +++ b/frontend/src/lib/components/access/access.ts @@ -1,7 +1,26 @@ -import { GranularAclService } from '$lib/gen' +import { + GranularAclService, + type BrowseAccessFoldersResponse, + type BrowseAccessItemsResponse +} from '$lib/gen' export type GrantLevel = 'none' | 'read' | 'write' +/** Where the Grant navigator reads and changes grants. Without one it uses the API, in the + * operating workspace. */ +export type GrantSource = { + /** The caller's own `u/` space, listed first. */ + ownSpace: string + folders: () => Promise + items: (query: { + prefix?: string + search?: string + offset?: number + }) => Promise + /** Sets the principal's own entry, as `setGrant` does. */ + set: (kind: string, path: string, level: GrantLevel) => Promise +} + type AclKind = Parameters[0]['kind'] export const KIND_LABELS: Record = { diff --git a/frontend/src/lib/components/common/button/Button.svelte b/frontend/src/lib/components/common/button/Button.svelte index 9a3b9fe6ac..e514c0686f 100644 --- a/frontend/src/lib/components/common/button/Button.svelte +++ b/frontend/src/lib/components/common/button/Button.svelte @@ -516,9 +516,11 @@ 'rounded-md m-0 p-0 center-center h-full', variant === 'border' ? 'border-0 border-r border-y ' : 'border-0', 'rounded-r-md !rounded-l-none', - size === 'xs2' || size === 'xs' || unifiedSize === 'md' || unifiedSize === 'sm' - ? '!w-8' - : '!w-10', + unifiedSize === 'xs' || unifiedSize === '2xs' + ? '!w-6' + : size === 'xs2' || size === 'xs' || unifiedSize === 'md' || unifiedSize === 'sm' + ? '!w-8' + : '!w-10', dropdownBtnClasses )} > diff --git a/frontend/src/lib/components/drillPicker.ts b/frontend/src/lib/components/drillPicker.ts index 71e13742e0..79093d8425 100644 --- a/frontend/src/lib/components/drillPicker.ts +++ b/frontend/src/lib/components/drillPicker.ts @@ -32,6 +32,19 @@ export type DrillLeaf = { disabled?: boolean } +/** Something a leaf row offers (see the picker's `leafActions`). */ +export type DrillLeafAction = { + label: string + icon?: DrillIcon + /** What running it does, shown under its label in the row's dropdown. */ + hint?: string + /** The row's button, with the others in its dropdown; the first one is otherwise. */ + preferred?: boolean + loading?: boolean + disabled?: boolean + run: () => void +} + /** Branch node — interior entry the user drills into. */ export type DrillBranch = { type: 'branch'