@fusebase/fusebase-dashboards
FuseBase databases UI for React: the databases list and the table screen. It runs on the FuseBase dashboard API through a transport that the host gives.
Install
npm install @fusebase/fusebase-dashboards
Peers: react and react-dom 18 or later. The package does not need Next.js.
@tanstack/react-query 5 is a dependency. If your app has a QueryClientProvider above the screens, the package uses that client. If your app has a different 5.x version, npm installs a second copy, and the package then makes its own QueryClient. To share one client, use the same 5.x version as the package.
Long text cells render markdown with @fusebase/markdown-viewer, loaded only when a table has long text. The viewer has optional dynamic imports (katex, mermaid, dompurify, highlight.js/lib/common). Your bundler must resolve them: install them, or alias them to an empty module (webpack: resolve.alias: { katex: false, ... }). Without them, math, diagrams and code show as plain text.
Long text cells open @milkdown/crepe (the editor of v2 cells) on edit, also as a lazy chunk. Crepe imports dompurify, so do not alias dompurify to an empty module. Math is off in the editor, so a katex alias is safe.
CSS
Import both files once:
import "@fusebase/fusebase-dashboards/tokens.css";
import "@fusebase/fusebase-dashboards/styles.css";
tokens.css has the default --db-* variables. Text uses the font of the host page (--db-font-body is inherit). styles.css styles the components with these variables. All package UI is inside a .db-root element, so a host can change the theme with a rule on .db-root. :root .db-root wins over tokens.css in any import order:
:root .db-root {
--db-page: #101010;
--db-text: #f2f2f2;
}
The table grid scrolls in its own box, at most 70vh high, with a sticky head; it renders only the rows near the scroll position. To change the height, add a rule such as .db-root .db-grid { max-height: 60vh; }.
Usage
import {
createDashboardsClient,
DashboardsProvider,
DatabasesScreen,
TableScreen,
} from "@fusebase/fusebase-dashboards";
const client = createDashboardsClient({
// The dashboard API origin with `/api/v1`, or a backend that forwards there.
baseUrl: "/api/dashboards",
// The host adds credentials or auth headers. The package never calls the global fetch.
fetch: (input, init) => fetch(input, { ...init, credentials: "include" }),
});
export function Databases({ orgId }: { orgId: string }) {
return (
<DashboardsProvider client={client}>
<DatabasesScreen
orgId={orgId}
navigate={(href) => history.pushState(null, "", href)}
/>
</DashboardsProvider>
);
}
baseUrl can be relative in the browser only. In Node, give an absolute URL.
Host contract
DashboardsProvider props:
| Prop | Description |
|---|---|
client | From createDashboardsClient({ baseUrl, fetch }). |
dictionary | Texts that replace the English defaults (defaultDictionary). |
pageSize | Rows per page. If not set, the value the user saved is used. |
loadAssignees | () => Promise<AssigneeOption[]>: the users an assignee cell can hold ({ id, name, email?, client? }). Without it, assignee cells are read-only. |
uploadFiles | (files: File[], context: FileCellContext) => Promise<DashboardFile[]>: uploads the files and returns { name, url, ... } for each. Without it, files cells have no upload control (remove still works). |
filesBaseUrl | Base for a relative file url (v2 stores /uuid/name); Studio passes /box/file. An absolute url is used as it is. |
Screen props:
| Prop | Description |
|---|---|
orgId | Organization id. |
databaseId | TableScreen only. |
tableId | TableScreen, optional. Without it, the screen goes to the first table. |
viewId | TableScreen, optional. Without it, the screen goes to the default view. |
linkComponent | Optional. Your router link, with href and children props. Without it, the package renders <a> that calls navigate. |
navigate | (href, { replace }) => void. replace: true is for redirects. Keep this function stable (for example, useCallback). |
Hrefs have the shape /:orgId/databases/:databaseId/tables/:tableId/views/:viewId (databasesHref, databaseHref, tableHref). If your app has a base path, add it in linkComponent and navigate.
Errors: every failed API call is a DashboardsError with status and message.
The package keeps the rows per page in localStorage under fusebase.dashboards.pageSize.
Embed entry
import {
createDashboardsClient,
DashboardsProvider,
} from "@fusebase/fusebase-dashboards/embed";
@fusebase/fusebase-dashboards/embed is for a page that only shows an embedded table. It does not load the databases list. Both entries share one chunk, so a provider from one entry works with screens from the other.
License
See LICENSE.