Frontend
Panels in a page of your own
You do not need the whole admin to show one table. <CollectionPanel> takes
a table by its slug and works anywhere under <Rebase> and a React Router
router, with no <RebaseCMS>, <RebaseNavigation> or <RebaseShell>:
import { Rebase, useRebaseAuthController } from "@rebasepro/app";import { CollectionPanel } from "@rebasepro/cms";// Plus BrowserRouter, or any other router, from "react-router".
export function App() { const authController = useRebaseAuthController({ client });
return ( <Rebase client={client} authController={authController}> <BrowserRouter> <MyPageLayout> <CollectionPanel collection="posts"/> </MyPageLayout> </BrowserRouter> </Rebase> );}A record opens over your page, in a side panel or a dialog, and never by URL:
no admin route serves the page, so full_screen and split open as a side
panel, and useUrlController().routesMounted is false for your own
components there. Any router works: a plain <BrowserRouter>, a
<MemoryRouter>, or a data router. A router is still required. A data router
also lets a record with unsaved changes stop in-app navigation; under the
others only the browser’s leave-page prompt guards it. Wrap the panel in <RebaseAuthGate> if the page
should show Rebase’s sign-in first.
What a panel shows
Section titled “What a panel shows”A panel draws the table as the admin does — from the descriptor the server
serves, with any customizeTable you registered. These props narrow it to what
your page needs; none of them changes the table’s own page in the admin.
import { CollectionPanel } from "@rebasepro/cms";import { Button } from "@rebasepro/ui";
<CollectionPanel collection="orders" viewMode="table" fields={["number", "customer", "status", "total"]} where={{ status: ["==", "pending"] }} orderBy="placed_at:desc" toolbar="compact" rowActions={(order, id) => ( <Button size="small" onClick={() => update("orders", id, { status: "shipped" })}>Ship</Button> )} onRowClick={(order, id) => setSelected(id)} className="max-h-[480px]"/>collection takes the table’s slug, as here, or an external collection
(defineFirestoreCollection) as a value; path names it too, and addresses a
nested collection by its full path.
fields— the properties it shows, in this order, and nothing else. In the table they are the columns. In the list, on a card and on a kanban card they are what the row’s places — title, image, subtitle, status, date, relation chips, the list’s columns — are filled from, earlier ones first; a place none of them fills stays empty. For this panel it wins overpropertiesOrder, the column order a user saved andlistProperties. Column widths a user drags still persist; the order is yours, so columns are not dragged.toolbar—"full", the default;"compact", which is search, the view-mode switch and New (where the person may create);"none"(ornull) for none; or one composed of its pieces:CollectionToolbar(withstartandend),CollectionSearchBar,CollectionFiltersButton,CollectionViewModeToggleandCollectionAddButton. They read the panel they are drawn in, and throw anywhere else. Plugin slots and theCollection.Actionsoverride live in the default toolbar.onRowClick— called with the clicked row and its id instead of the panel opening it, from a row, a card, a kanban card and the edit action. The row is the one the server sends, the shapeuseRows,useRowand<FieldValue>take: exactly its columns, ISO date strings (YYYY-MM-DDfor a date-only column), and a belongsTo relation as its foreign key (customerId). A relation the panel loaded the target of arrives nested under its name, as REST’sincludereturns it (order.customeris the customer’s row); its foreign key is there too. The id is the string the admin addresses the record by — its primary key, a composite one’s parts joined by:::— whichhighlightedIdsanduseSidePanel().opentake.row.idis the record’sidcolumn, where the table has one, with that column’s type:5for an integer key, whose id is"5".rowActions— your own JSX on every row, card and kanban card, handed the row and its id: an “Approve”, a “Ship”. In the table it is the last column, always visible; on a list row, a card and a kanban card it sits beside the collection’s own actions. A click on it does not open the record, and it draws again with your component’s state, so asavingflag disables it.orderBy— the order the rows open in,"placed_at:desc"or["placed_at", "desc"]. The person can still sort by another column.highlightedIds— the ids of the rows drawn as selected, the one a page shows beside the list, say:highlightedIds={selected ? [selected] : []}.[]draws none. Without it the panel highlights the row last opened. Ids are compared as strings, so an integer key’s5and"5"are one row.where— which rows it holds, asuseRowstakes it:where={{ status: ["==", "pending"] }}. Filters the person sets on other fields combine with it, and its own fields cannot be changed or cleared from the toolbar. It follows the prop, so a tab bar or a clicked chart bar can drive it from state. It goes over the collection’sfixedFilter, field by field.viewMode— the mode it opens in, over the one in the URL and the one the person last picked. They can still switch.title={false}— no title above the panel, nor the list view’s own heading.updateUrl— off by default: the panel neither reads nor writes the page’s__view, filter and sort parameters.
The collection’s entityActions draw on every row, card and kanban card, as
buttons when declared collapsed: false and in the row’s menu otherwise — an
“Approve” on every card is one action.
A panel sizes to its rows. With no height from its parent, or only a
max-height, a short collection draws its toolbar and rows and a long one
scrolls inside the space it has, up to the window’s height. Give it a height to
fill it. It lays itself out by its own width, not the window’s: in a narrow
column it uses its compact layout, whatever the screen.
fieldOrder in the table’s customizeTable reorders and never hides: a field
it leaves out is drawn after the ones it names. To keep one out of the list
everywhere, set hidden: true on its field options; to show only some in one
place, pass fields.
One record’s form
Section titled “One record’s form”<RecordForm> does the same for one record’s form (it was EntityFormPanel
before 0.29; that name still works and warns once). It loads the record
by id, saves it through <Rebase>’s data layer as the admin’s own
form does, and calls onSaved after every save with the saved record as the
server sends the row, row, and its id. Omit id to create a
record. onClose is called when the form asks to be left, for example after
its record is deleted:
<RecordForm collection="posts" id={postId} onSaved={({ id }) => console.log("saved", id)} onClose={() => navigate("/posts")}/>Like CollectionPanel, the form and RecordDetail take a table by its slug
(path="posts" works too). Every table the server serves is known to them,
under <RebaseCMS>, under a CollectionsProvider, or with no scope above, in
which case the panel brings its own. An external collection is handed over as
a value. One named by a path nothing serves says the record is not found.
If someone else deletes the record while the form is open, the form keeps
what was typed and says the record was deleted elsewhere. Its “Save as new”
action turns it into a form that creates a new record with those values;
onSaved then reports the new record.
The form can show
part of a record, or lay it out your way. fields shows only the fields it
names, in that order; sections and the rail keep their grouping. Children
replace the generated fields with your own JSX, in which
<FormField name="…"/> draws one field with the label, size and rules the
generated form gives it:
import { RecordForm, FormField } from "@rebasepro/cms";
<RecordForm collection="orders" id={orderId}> <div className="grid grid-cols-2 gap-4"> <FormField name="customer"/> <FormField name="status"/> </div> <FormField name="notes"/></RecordForm>compact is the dense form for a side card or a 350–700px panel: no rail
beside the fields (what it holds folds into the column), no record metadata,
medium-height controls and tighter padding:
<RecordForm collection="orders" id={orderId} fields={["status", "notes"]} compact/>.
Either way the form validates only the fields it shows; the server still
checks the whole record. A form that creates a record and leaves out a
required field with no default value says so when it opens: an error names the
field, and Save stays blocked until the field is shown or given a default.
collectionOverrides changes the presentation for this form only, as it does for
CollectionPanel.
Each form scopes its DOM ids, so two forms can share a page. To find a field
from a test, select [data-form-field="title"] inside the form’s
[data-form-path="posts"].
<RecordDetail> is the read-only twin of RecordForm. It loads the
record by id and draws it as the admin’s record page does: the same
sections and labels, with each value as its preview, so an enum shows as its
chip, a date in its timezone and a relation as its target’s title. It takes
fields and collectionOverrides as the form does, and leaves out the fields
the form leaves out: one a conditions.hidden rule hides for this record, and
one the signed-in user may not read.
import { RecordDetail } from "@rebasepro/cms";
<RecordDetail collection="orders" id={orderId} fields={["customer", "status", "total"]}/><FieldValue> draws one value the same way, inside your own JSX: hand it the
value as the server sends it. A belongsTo arrives as its foreign key
(order.customerId), so field="customer" value={order.customerId} draws the
related record’s title; naming the foreign key itself, field="customerId",
does the same. It needs the table known above it, by <RebaseCMS> or a
CollectionsProvider. An unknown collection or field throws an error
that names it.
import { useRows } from "@rebasepro/app";import { FieldValue } from "@rebasepro/cms";
function OrderList() { const { rows } = useRows("orders", { limit: 20 }); return rows.map(order => ( <div key={String(order.id)} className="flex gap-4"> <FieldValue collection="orders" field="customer" value={order.customerId}/> <FieldValue collection="orders" field="status" value={order.status}/> <FieldValue collection="orders" field="placedAt" value={order.placedAt}/> </div> ));}Several panels in one scope
Section titled “Several panels in one scope”The three panels bring their own CollectionsProvider when none is above them. That is
the step underneath, and you can mount it yourself to share one scope between
several panels, or to use the lower-level pieces (CollectionViewBinding,
useSidePanel) under it. It takes the same inputs as <RebaseCMS>:
import { CollectionPanel, CollectionsProvider } from "@rebasepro/cms";import { postsCms } from "./cms/posts";
const tableCustomizations = [postsCms];
<CollectionsProvider tableCustomizations={tableCustomizations}> <CollectionPanel collection="posts"/> <CollectionPanel collection="authors"/></CollectionsProvider>CollectionsProvider holds a registry of the tables the server serves, with
your tableCustomizations and any externalCollections, your plugins’
modifyCollection and injectCollections applied as in the admin, plus the
side panels and dialogs records open in, and the unsaved-changes guard. Keep
the arrays stable: a module constant, or useMemo. tables replaces the
served tables with descriptors you pass, for embedding and tests.
- Customizing the admin: the places a component of yours can go, and the recipes built from these panels.
- Hooks:
useRows,useRow,useRowCount,useAggregateanduseRowWrites, the rows these panels andFieldValueread. - Component overrides: replace the view or the form a panel draws.