ui/format_scope.ts

Shared format_scope callback contract for role-grant-display components.

Role grants and offers carry a scope_id that names a consumer-owned resource (e.g. a classroom uuid). The default render is the truncated uuid. Consumers wire a FormatScope via context to render a human label without per-page lookup or forking the components.

view source

Declarations
#

4 declarations

default_format_scope
#

ui/format_scope.ts view source

(args: { scope_id: string | null; role: string; }): string | null import {default_format_scope} from '@fuzdev/fuz_app/ui/format_scope.js';

Default FormatScope — always returns null so callers fall back to the truncated uuid.

args

type { scope_id: string | null; role: string; }

returns

string | null

format_scope_context
#

ui/format_scope.ts view source

{ get: () => () => FormatScope; set: (value?: (() => FormatScope) | undefined) => () => FormatScope; } import {format_scope_context} from '@fuzdev/fuz_app/ui/format_scope.js';

Svelte context carrying a getter for the consumer's FormatScope. Provisioned by provide_admin_rpc_contexts from its format_scope option. Default getter returns default_format_scope so unprovisioned trees render the truncated uuid.

FormatScope
#

ui/format_scope.ts view source

FormatScope import type {FormatScope} from '@fuzdev/fuz_app/ui/format_scope.js';

Render a {scope_id, role} pair as a human label. Return null to fall back to the truncated scope uuid (truncate_uuid; or a caller-chosen global_label when scope_id is null).

Returning null for unknown scope ids (stale cache, revoked resource) is the recommended pattern — components show the truncated uuid rather than a misleading blank.

(call)

type (args: { scope_id: string | null; role: string; }): string | null

args

type { scope_id: string | null; role: string; }
returns string | null

resolve_scope_label
#

ui/format_scope.ts view source

<G extends string | null>(scope_id: string | null, role: string, format_scope: FormatScope, global_label: G): string | G import {resolve_scope_label} from '@fuzdev/fuz_app/ui/format_scope.js';

Resolve a scope label across the context → truncated-uuid fallback chain.

global_label is returned for scope_id === null. Callers pass null to render no chip (admin tables — global is the implicit default) or 'global' for explicit labels (offer surfaces). The return type propagates null only when global_label is null.

scope_id

type string | null

role

type string

format_scope

global_label

type G

returns

string | G

generics

resolve_scope_label<G extends string | null>
G
constraint string | null

Depends on
#

Imported by
#