Skip to content

Admin panel

Fields

Each column of a table is a field in the CMS. What the field is follows from the column: its type, its validation and its storage rules, all declared in backend/schema. How the field looks is yours to change, per field, in customizeTable.

This table is used in the examples below:

// backend/schema/products.ts
import { defineTable, col } from "@rebasepro/server/schema";
export const products = defineTable("products", {
columns: {
id: col.uuid().primaryKey().defaultRandom(),
name: col.text().notNull().validate({ min: 2, max: 200 }),
description: col.text(),
body: col.text(),
supportEmail: col.text().validate({ email: true }),
website: col.text().validate({ url: true }),
category: col.enum(["electronics", "clothing", "home"]).notNull(),
locales: col.text({ enum: ["es", "en", "fr"] }).array(),
price: col.numeric({ precision: 10, scale: 2 }).notNull(),
stock: col.integer().default(0),
onSale: col.boolean().default(false),
launchDay: col.date(),
availableAt: col.timestamp({ withTimezone: true }),
ownerId: col.uuid().userId(),
createdAt: col.timestamp({ withTimezone: true }).notNull().onCreateNow(),
createdBy: col.uuid().onCreateUser(),
},
rls: "admin-only",
});

With no frontend file, every column already has a field. This customization changes some of them:

// frontend/src/cms/products.tsx
import { customizeTable } from "@rebasepro/cms";
import type { products } from "../../../backend/schema/products";
export const productsCms = customizeTable<typeof products>("products", {
fields: {
description: { multiline: true },
body: { name: "Product page", markdown: true },
website: { urlPreview: true },
category: {
enumLabels: {
electronics: { label: "Electronics", color: "blueDark" },
clothing: { label: "Clothing", color: "pink" },
},
enumOrder: ["home", "electronics", "clothing"],
},
locales: {
enumLabels: { es: "Spanish", en: "English", fr: "French" },
},
price: { format: { style: "currency", currency: "EUR" } },
stock: { format: { notation: "compact" }, columnWidth: 90 },
availableAt: { timezone: "Europe/Madrid" },
},
});

A col.text(), col.varchar({ length }), col.char({ length }) or col.uuid() column is a text input. varchar(n) and char(n) cap its length at n, and .validate({ min, max, length, matches }) adds the rules the form checks before it saves.

multiline: true makes it a text area that grows with its content.

markdown: true makes it a markdown editor with a toolbar and a preview.

.validate({ email: true }) on the column gives an email input, validated as an email. It is a fact about the data, so it is declared on the column, where the server checks it too.

.validate({ url: true }) gives a URL input, validated as a URL, with a link preview. urlPreview changes only the preview: true for a link, or "image", "video", "audio" or "file" to show the media inline.

A text or uuid column marked .userId() holds a user’s id, and is a picker of the project’s users: their names, emails and avatars, offered to whoever may write the table. ownerId above is one. So is each item of a col.text().userId().array().

previewAsTag: true draws the value as a chip outside the form. clearable: true adds a control that sets it to null. referenceTo: "<slug>" treats the value as the key of a record in another collection, on any data source, and draws a reference picker; see Firestore.

A col.enum([...]) is a select, drawn elsewhere as a coloured chip. So is a text or number column with .oneOf([...]). Each value is labelled from its identifier (needs_review reads “Needs Review”) and given a colour seeded by the value, the same on every load.

enumLabels names labels and colours for some values; a value it leaves out keeps its derived label and colour. Each entry is a string, or { label, color?, disabled? }: color is a chip colour key such as "green" or "orangeDark", and disabled keeps the value visible but stops it being picked. enumOrder sets the order values are offered in, and the order of kanban columns. Both are checked against the column: a value the column cannot hold is a type error.

An array of a closed set, col.text({ enum: [...] }).array(), is a multi-select over one text[] column. enumLabels written on the array apply to its items.

Every integer, serial, real, doublePrecision and numeric column is a number input. Integer and serial columns accept whole numbers only, and .validate({ min, max, moreThan, lessThan, positive, negative }) adds bounds.

format writes the number out, without changing what is stored: style ("decimal", "currency", "percent"), currency (with "currency"), locale, minimumFractionDigits, maximumFractionDigits, and notation: "compact", which writes 12000 as 12K in a narrow column. clearable adds a control that sets the value to null.

A col.boolean() is a switch.

A col.timestamp({ withTimezone: true }) is a date and time picker, a col.date() a date picker and a col.time() a time of day. mode switches between "date" and "date_time", and timezone shows and picks the value in a fixed IANA zone ("Europe/Madrid") rather than the viewer’s.

A column stamped by the server, .onCreateNow() or .onUpdateNow(), is read-only, shown in the record’s metadata block and left out of the default table columns. .onCreateUser() and .onUpdateUser() columns are read-only: the server writes the acting user’s id, whatever the request says.

A col.storage({ … }) column is an upload field with a preview, and .multiple() makes it a multi-file field. The bucket, the path, the accepted types and the size limit are declared on the column; the functions that run in the browser are added with storage in customizeTable. See File uploads.

An array column (<item>.array()) is a repeatable list of the item’s field. A jsonb column with a json.* shape is a group of typed fields, lists and blocks; one without a shape is a key/value editor. See Arrays and JSON.

A belongsTo is a picker of the related row, shown in place of its foreign-key column; a to-many relation is a tab of the record. A text column with referenceTo is a picker too.

See Relations in the panel.

A col.geopoint() is a latitude and longitude field. A col.vector({ dimensions }) is a vector input; clearable is its one option. A col.bytea() is a binary field, read and written as base64. None of them has type-specific options beyond those every field takes.

Whatever the column type:

  • name and description replace the derived label and add help text.
  • hidden keeps the field out of the table and card views, and hiddenInForm keeps it off the form. Neither changes what the API reads or writes; to keep a value from a caller, use field access.
  • readOnly draws the value as text; disabled greys out the control, and as { disabledMessage, clearOnDisabled } says why and clears the value.
  • columnWidth sets the table column’s width; span sets how many of the form’s four grid columns the field takes (see Form layout).
  • filterOperators narrows the filter operators offered for the field, and [] turns filtering on it off. The operators offered are those the data source can run, the type’s defaults and this list, intersected: you can only restrict.
  • filledByServer lets a create leave the field empty, for a server hook to fill. A column marked .serverDefault() already is; the option overrides the table.
  • Field, Preview and Filter replace the form control, the drawing outside the form and the filter control with your own components; customProps is handed to them untouched. See Custom fields.
  • propertyConfig names a field type registered on <Rebase propertyConfigs>.
  • conditions and dynamicProps change the field from the record’s own values; see conditional fields.
  • metadata is yours.

Every option, with its type, is in the customizeTable reference.