CRUD / foldkit-crud

Sorting a list

Sort keeps your Model state, clickable table headers, and server query input in sync:

ts
import { Sort } from 'foldkit-crud'

const PostSort = Sort.make(['title', 'created']) // the orders offered, by name

const PostsQuery = Query.make('Posts', {
  Input: { sort: PostSort.Schema },
  Result: Query.connection(Blog.Post),
})
// Model: `postSort: PostSort.Schema`, starting at `PostSort.none`
// update: `SortedPosts` toggles `postSort` by the column the Message carries
ts
PostSort.toggle(model.postSort, 'title') // asc, then desc, then the server's own order
PostSort.inputs(model.postSort, (_, column) => Message.SortedPosts({ column }))

Sort names order keys rather than raw database columns. Map those keys on the query with Query.orderBy(Order.chosen(input.sort, { title: Post.fields.title })) (foldkit-entity) so client placement matches the server, or on the server with foldkit-remote-drizzle's sortTerms(sort, { title: posts.title }).

Typed ids

Branded Entity id schemas flow through helpers.open(id), target(model), removers (id: 'id', or (id: PostId) => ({ id, reason: 'spam' })), and list rows (row.id).

Limits

  • Filter and sort state stays in your Model: lists read your Model's query input so changing search or sort loads that connection through Remote.
  • Headless: draw lists and details with foldkit-mixins-crud (or columns + Display.show), and editors with Crud.editorView over foldkit-mixins-form (or EditPostForm.controls).
  • One editor per form: create and edit flows with different schemas or declared writes use two editors.

Next