Suggestions

View as Markdown

Proposed edits you can review, accept or reject.

Assignee
Mira Patel
Project
EU invoicingAuto
Labels

When to use

Proposed edits you can review, accept or reject. Use Diff instead when people only read the change.

Usage

import { Suggest, type SuggestStatus } from "./ui/uicontext/components/Suggest.ts"
const Message = UiSchema.TaggedEnum({	RequestedAssignee: { value: Schema.String },	DismissedAssignee: {},})export const AssigneeSuggestion = (h: Html.H<typeof Message.Type>, status: SuggestStatus) =>	Suggest(h, {		props: {			id: "pay-415-assignee",			field: "Assignee",			value: { value: "mira", label: "Mira Patel" },			status,			reason: "Mira changed the invoice template on Tuesday.",		},		onEmit: {			// set the assignee, then pass `status: "accepted"`			RequestedAccept: ({ value }) => Message.RequestedAssignee({ value }),			RequestedDismiss: () => Message.DismissedAssignee(),			RequestedUndo: () => undefined,			RequestedOpenWhy: () => undefined,			RequestedAction: () => undefined,		},	})

Examples

An offer, with the change

As a card, a suggestion holds a bigger proposal and shows the change in its detail slot.

Juno

Move Thursday's standup so Lena can join?

Lena has a customer call 9:30–10:15 every Thursday this month.

− Thu 9:45–10:00  Standup
+ Thu 10:30–10:45 Standup

API reference

Props

Suggest props
NameTypeDefaultDescription
agentIdstring—This suggestion's id for agents, unique on the page; suggestion:<id> when left out
idrequiredstring—Identifies the suggestion in the events it sends
fieldrequiredstring—The property it would set: "Assignee"
valuerequiredSuggestValue—The value it would set, with its label and glyph
alternativesSuggestValue[]—Other values the model considered, offered after the main one
statusrequiredSuggestStatus—Where it stands: processing, pending, accepted, auto-applied, dismissed, undone, stale or unavailable
reasonstring—The model's reason; leave out until loaded (the chip reports RequestedOpenWhy)
reasonLoadingboolean—The reason is being fetched: Why shows a placeholder
sourcestring—What made it: "Triage Intelligence"
canCan(["accept"])—"accept" shows Accept; leave it out of the list for a viewer, or the agent that made it. Allowed when left out.
acceptLabelstring"Accept"The accept button's label; "Accept" by default
dismissLabelstring"Dismiss"The dismiss button's label; "Dismiss" by default
reapplystring—An undone suggestion may be applied again: the button's label ("Apply again"); it asks with RequestedAccept
titlestring—A card's heading: "Want me to look into this?"
layout"chip" | "card""chip"A compact chip beside the property, or a card with a title and actions; "chip" by default
actions{ id, label }[]—More choices on a card: "Don't suggest in this channel"
noticestring—Why the last request was refused, as a sentence

Events

Suggest events
EventPayloadDescription
RequestedAccept{ id: string; value: string }The person accepted the suggested value or an alternative
RequestedDismiss{ id: string }The person dismissed the suggestion
RequestedUndo{ id: string }Undo an auto-applied value: the app clears or restores the property
RequestedOpenWhy{ id: string }The reason was asked for; load it if reason is missing
RequestedAction{ id: string; action: string }The person picked one of a card's actions

Slots

detail

Keyboard and accessibility

  • Accept and Dismiss are buttons, and Why opens a popover with the reason that closes with Escape.
  • Accepting, undoing and a refusal are announced as they happen.
  • Agents see the field, the value and why it's suggested; accepting or dismissing must name the suggestion they read.

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/suggestions

Source