CRUD / foldkit-crud
Showing values
How a column shows
Display describes how a selected member formats as text without coupling to a
specific UI library:
const Post = Blog.Post.pipe(
Entity.annotateMembers({
id: Display.of(Display.hidden()), // read, so a row can be opened by it, and not shown
cents: Display.of(Display.number(cents => `$${(cents / 100).toFixed(2)}`)),
}),
)
Display.show(column.display, row[column.key], { yes: 'Live', no: 'Draft' }) // the cell's text| Kind | For |
|---|---|
Text, Number | Raw value or formatted with format |
Flag | Boolean rendered with yes / no words |
Hidden | Selected for IDs or actions; hidden from tables |
Ref | Relation selected with true (shows IDs) |
Nested | Nested Selection columns (one, many, page) |
Display kinds resolve from Display.of metadata, then relation selection, then
schema shape. Define custom kinds such as badges with Display.kind:
const Badge = Display.kind<{ readonly tone: string }>('Badge', {
text: (_, value) => String(value), // fallback text when rendered without a custom cell
})
const Badged = Blog.Post.pipe(
Entity.annotateMembers({ status: Display.of(Badge.of({ tone: 'soft' })) }),
)Badge.is(display) narrows display.data for custom cell renderers in
foldkit-mixins-crud.
A relation picker's choices
Relation pickers pull choices from a Crud.list with a choice mapper so your
server query authorizes which rows appear. Crud.options maps each picker key
on the form to its target Entity's list:
const pickers = Crud.options(EditPostForm, [AuthorList])Placed.view(model, h, { options: pickers(model) }) // with foldkit-mixins-formpickers(model) returns { authorId: [{ value, label }, …] }, matching lists
by target Entity (so one AuthorList serves both authorId and editorId).
Missing target lists or lists lacking choice throw when Crud.options runs.
AuthorList.choices(model) returns one list's choices on its own.
When a picker searches
const AuthorList = Authors.at({
data: Data,
// What the picker's search box holds is the form's; here it is the query's input.
input: model => Option.some({ search: EditPostForm.search(model.editor.form, 'authorId') }),
})
const pickers = Crud.options(EditPostForm, [AuthorList], {
chosen: model => model.editor.form, // the form's Model, wherever the page keeps it
})
const subscriptions = Data.subscriptions({ authors: AuthorList.active, chosen: pickers.active })Passing chosen and wiring pickers.active keeps the currently selected
record loaded and visible at the top of the choices even when a search filter
hides it from AuthorList. Pass more: pickers.more(model) to the form view to
render "Show more" buttons and handle AskedForMore via pickers.ask(model, key)
or Crud.screen:
Placed.view(model, h, { options: pickers(model), more: pickers.more(model) })PostScreen.update(
{ editor: PostEditor, editing: Placed, pickers },
placements.update((model, message) =>
Remote.reduces(message) ? { model: Data.reduce(model, message) } : { model },
),
)