@rebasepro/cms 0.25.0 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/collection_editor/liveSchemaClient.d.ts +3 -3
- package/dist/collection_editor/liveSchemaClient.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/AICollectionGeneratorPopover.js +1 -1
- package/dist/collection_editor/ui/collection_editor/AICollectionGeneratorPopover.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/SchemaChangeDialog.d.ts +7 -1
- package/dist/collection_editor/ui/collection_editor/SchemaChangeDialog.js +61 -50
- package/dist/collection_editor/ui/collection_editor/SchemaChangeDialog.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/DateTimePropertyField.js +22 -22
- package/dist/collection_editor/ui/collection_editor/properties/DateTimePropertyField.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/NumberPropertyField.js +14 -14
- package/dist/collection_editor/ui/collection_editor/properties/NumberPropertyField.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/StringPropertyField.js +24 -24
- package/dist/collection_editor/ui/collection_editor/properties/StringPropertyField.js.map +1 -1
- package/dist/collection_editor/useLiveSchemaEditing.js +4 -1
- package/dist/collection_editor/useLiveSchemaEditing.js.map +1 -1
- package/dist/components/CollectionTableBinding/fields/TableReferenceField.js +1 -1
- package/dist/components/CollectionTableBinding/fields/TableReferenceField.js.map +1 -1
- package/dist/components/CollectionTableBinding/internal/CollectionTableToolbar.d.ts +1 -2
- package/dist/components/CollectionTableBinding/internal/CollectionTableToolbar.js.map +1 -1
- package/dist/components/CollectionTableBinding/internal/EntityTableCell.d.ts +1 -2
- package/dist/components/CollectionTableBinding/internal/EntityTableCell.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionViewActions.js +1 -1
- package/dist/components/CollectionViewBinding/CollectionViewActions.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionViewBinding.js +2 -28
- package/dist/components/CollectionViewBinding/CollectionViewBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/DefaultCollectionEmptyState.d.ts +12 -0
- package/dist/components/CollectionViewBinding/DefaultCollectionEmptyState.js +33 -0
- package/dist/components/CollectionViewBinding/DefaultCollectionEmptyState.js.map +1 -0
- package/dist/components/CollectionsScopeContext.d.ts +5 -1
- package/dist/components/CollectionsScopeContext.js +10 -2
- package/dist/components/CollectionsScopeContext.js.map +1 -1
- package/dist/components/DefaultAppBar.js +2 -1
- package/dist/components/DefaultAppBar.js.map +1 -1
- package/dist/components/DefaultDrawer.js +16 -4
- package/dist/components/DefaultDrawer.js.map +1 -1
- package/dist/components/DefaultMissingReference.d.ts +8 -0
- package/dist/components/DefaultMissingReference.js +13 -0
- package/dist/components/DefaultMissingReference.js.map +1 -0
- package/dist/components/DeleteEntityDialog.js +9 -9
- package/dist/components/DeleteEntityDialog.js.map +1 -1
- package/dist/components/EntityFormPanel.d.ts +7 -2
- package/dist/components/EntityFormPanel.js +72 -29
- package/dist/components/EntityFormPanel.js.map +1 -1
- package/dist/components/HomePage/ContentHomePage.js +4 -3
- package/dist/components/HomePage/ContentHomePage.js.map +1 -1
- package/dist/components/HomePage/HomePageDnD.js +3 -1
- package/dist/components/HomePage/HomePageDnD.js.map +1 -1
- package/dist/components/HomePage/SmallNavigationCard.js +25 -0
- package/dist/components/HomePage/SmallNavigationCard.js.map +1 -0
- package/dist/components/RebaseAuthGate.js +3 -2
- package/dist/components/RebaseAuthGate.js.map +1 -1
- package/dist/components/RebaseLayout.d.ts +4 -1
- package/dist/components/RebaseLayout.js +7 -1
- package/dist/components/RebaseLayout.js.map +1 -1
- package/dist/components/RebaseShell.d.ts +4 -1
- package/dist/components/RebaseShell.js.map +1 -1
- package/dist/components/ReferenceTable/SelectionTableBinding.js +4 -3
- package/dist/components/ReferenceTable/SelectionTableBinding.js.map +1 -1
- package/dist/components/RelationSelector.js +2 -2
- package/dist/components/RelationSelector.js.map +1 -1
- package/dist/components/SideDialogs.js +10 -4
- package/dist/components/SideDialogs.js.map +1 -1
- package/dist/components/app/Scaffold.js +5 -1
- package/dist/components/app/Scaffold.js.map +1 -1
- package/dist/components/field_configs.js +1 -1
- package/dist/components/history/EntityHistoryView.js +6 -4
- package/dist/components/history/EntityHistoryView.js.map +1 -1
- package/dist/components/history/LastEditedByIndicator.d.ts +2 -1
- package/dist/data_export/export/export.d.ts +2 -13
- package/dist/data_export/export/export.js +1 -36
- package/dist/data_export/export/export.js.map +1 -1
- package/dist/form/EntityForm.d.ts +1 -1
- package/dist/form/EntityForm.js +17 -13
- package/dist/form/EntityForm.js.map +1 -1
- package/dist/form/EntityFormBinding.d.ts +1 -1
- package/dist/form/EntityFormBinding.js +42 -4
- package/dist/form/EntityFormBinding.js.map +1 -1
- package/dist/form/PropertyFieldBinding.js +1 -1
- package/dist/form/components/FieldBlock.d.ts +8 -1
- package/dist/form/components/FieldBlock.js +16 -2
- package/dist/form/components/FieldBlock.js.map +1 -1
- package/dist/form/components/FormSections.js +1 -1
- package/dist/form/components/FormSections.js.map +1 -1
- package/dist/form/components/LabelWithIcon.js +5 -2
- package/dist/form/components/LabelWithIcon.js.map +1 -1
- package/dist/form/field_bindings/DateTimeFieldBinding.js +2 -1
- package/dist/form/field_bindings/DateTimeFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/ReadOnlyFieldBinding.js +28 -1
- package/dist/form/field_bindings/ReadOnlyFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/RelationFieldBinding.js +7 -3
- package/dist/form/field_bindings/RelationFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/SelectFieldBinding.js +63 -42
- package/dist/form/field_bindings/SelectFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/SwitchFieldBinding.js +2 -1
- package/dist/form/field_bindings/SwitchFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/TextFieldBinding.js +8 -6
- package/dist/form/field_bindings/TextFieldBinding.js.map +1 -1
- package/dist/form/form_utils.d.ts +18 -1
- package/dist/form/form_utils.js +38 -2
- package/dist/form/form_utils.js.map +1 -1
- package/dist/form/index.d.ts +1 -1
- package/dist/form/label_placement.d.ts +23 -0
- package/dist/form/label_placement.js +71 -0
- package/dist/form/label_placement.js.map +1 -0
- package/dist/form/resolve_form_properties.d.ts +35 -3
- package/dist/form/resolve_form_properties.js +67 -6
- package/dist/form/resolve_form_properties.js.map +1 -1
- package/dist/hooks/useHistory.d.ts +5 -0
- package/dist/hooks/useHistory.js +22 -6
- package/dist/hooks/useHistory.js.map +1 -1
- package/dist/index.d.ts +50 -0
- package/dist/index.js +34 -7
- package/dist/preview/components/ReferencePreview.js +1 -1
- package/dist/preview/components/ReferencePreview.js.map +1 -1
- package/dist/preview/components/RelationPreview.js +1 -1
- package/dist/preview/components/RelationPreview.js.map +1 -1
- package/dist/types/components/EntityFormProps.d.ts +11 -0
- package/package.json +11 -10
- package/recipes/README.md +131 -0
- package/recipes/bulk-set-status.tsx +62 -0
- package/recipes/calendar-view.tsx +123 -0
- package/recipes/custom-login.tsx +60 -0
- package/recipes/my-preferences.tsx +68 -0
- package/recipes/orders-dashboard.tsx +125 -0
- package/recipes/site-settings.tsx +63 -0
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# Customizing the Rebase admin
|
|
2
|
+
|
|
3
|
+
The admin is built from parts you can use yourself. To customize it, you write
|
|
4
|
+
an ordinary React component and put it in a place. There is nothing else to
|
|
5
|
+
learn: **building blocks** you render, **hooks** for data and the rest of the
|
|
6
|
+
app, and **places** to put a component.
|
|
7
|
+
|
|
8
|
+
If a building block does not do what you need, copy its source into your project
|
|
9
|
+
and change it — every component here is plain React over the hooks below.
|
|
10
|
+
|
|
11
|
+
Each recipe in this folder is a working file with a test in the Rebase
|
|
12
|
+
repository (`packages/cms/test/recipes`). They import only the packages listed
|
|
13
|
+
here, so you can copy one into your project as-is. This folder ships inside
|
|
14
|
+
`@rebasepro/cms`, so the recipes in `node_modules/@rebasepro/cms/recipes`
|
|
15
|
+
always match the version you have installed.
|
|
16
|
+
|
|
17
|
+
## Recipes
|
|
18
|
+
|
|
19
|
+
| Recipe | What it shows |
|
|
20
|
+
|---|---|
|
|
21
|
+
| [Site settings singleton](site-settings.tsx) | One settings record on its own page, created on first save. A page + `EntityFormPanel` at a fixed id. |
|
|
22
|
+
| [Per-user preferences](my-preferences.tsx) | Each user edits their own record, keyed by their uid. |
|
|
23
|
+
| [Bulk set status](bulk-set-status.tsx) | A toolbar button that updates every selected row. |
|
|
24
|
+
| [Calendar view](calendar-view.tsx) | A new view mode for a collection: rows on a month grid. |
|
|
25
|
+
| [Orders dashboard](orders-dashboard.tsx) | A page that reads data, draws a chart and links into the admin. |
|
|
26
|
+
| [Custom login screen](custom-login.tsx) | Replacing a built-in screen through `<Rebase components>`. |
|
|
27
|
+
|
|
28
|
+
## Building blocks
|
|
29
|
+
|
|
30
|
+
Components you render anywhere under `<Rebase>` and a router.
|
|
31
|
+
|
|
32
|
+
| Name | Package | What it is |
|
|
33
|
+
|---|---|---|
|
|
34
|
+
| `CollectionPanel` | `@rebasepro/cms` | A collection's table, cards, board or custom view, with its toolbar, filters and record panel. |
|
|
35
|
+
| `EntityFormPanel` | `@rebasepro/cms` | One record's form: loads it, validates, saves. Given an id no record has yet, it creates it there. |
|
|
36
|
+
| `CollectionsProvider` | `@rebasepro/cms` | Makes collections known to the blocks in a page of your own that has no admin shell around it. |
|
|
37
|
+
| `RebaseAuthGate` | `@rebasepro/cms` | Shows the login screen until someone is signed in, then its children. |
|
|
38
|
+
| `LoginView` | `@rebasepro/app` | The built-in login screen, to frame or reuse. |
|
|
39
|
+
| `Button` | `@rebasepro/ui` | And `Card`, `Typography`, `TextField`, `Select`, `Chip`, `Container`, … — the UI kit the admin is drawn with. Use it so your pages look like the rest. |
|
|
40
|
+
|
|
41
|
+
## Hooks
|
|
42
|
+
|
|
43
|
+
| Name | Package | What it gives you |
|
|
44
|
+
|---|---|---|
|
|
45
|
+
| `useData` | `@rebasepro/app` | The data layer: `useData().collection("orders").find / findById / create / update / delete`. Saves go through the server, so callbacks and security rules apply. |
|
|
46
|
+
| `useCollection` | `@rebasepro/app` | A live list of a collection's rows, re-rendering on change. |
|
|
47
|
+
| `useFetch` | `@rebasepro/app` | One record, live. |
|
|
48
|
+
| `useAuthController` | `@rebasepro/app` | The signed-in `user` (uid, roles), and sign-in / sign-out. |
|
|
49
|
+
| `useSnackbarController` | `@rebasepro/app` | `open({ type, message })` for a toast. |
|
|
50
|
+
| `useSidePanel` | `@rebasepro/cms` | Open any record in the side panel: `open({ path, entityId })`. |
|
|
51
|
+
| `useUrlController` | `@rebasepro/cms` | Admin URLs and navigation: `buildUrlCollectionPath`, `navigate`. |
|
|
52
|
+
| `useCollectionRegistryController` | `@rebasepro/cms` | Look up a collection by slug. |
|
|
53
|
+
| `resolveSelection` | `@rebasepro/cms` | Turn a table selection — ticked rows or "all matching" — into the rows. |
|
|
54
|
+
|
|
55
|
+
## Places
|
|
56
|
+
|
|
57
|
+
| To add… | Put a component in | Recipe |
|
|
58
|
+
|---|---|---|
|
|
59
|
+
| A page | `<RebaseCMS views={[{ slug, name, icon, view }]}>` | site settings, dashboard |
|
|
60
|
+
| A view mode for a collection | `collectionViews={[{ key, name, Builder }]}` + `admin.customViews: ["key"]` | calendar view |
|
|
61
|
+
| A button in a collection's toolbar | `admin.Actions: [Component]` | bulk set status |
|
|
62
|
+
| A button on a record | `admin.entityActions: [{ key, name, onClick }]` | |
|
|
63
|
+
| A tab on a record | `admin.entityViews: [{ key, name, Builder }]` | |
|
|
64
|
+
| How one field is edited or shown | `admin.Field` / `admin.Preview` on the property | |
|
|
65
|
+
| Something beside a built-in part | `<Rebase slots={[{ slot, Component }]}>` (`home.cards`, `form.after`, `collection.toolbar`, …) | |
|
|
66
|
+
| A replacement for a built-in part | `<Rebase components={{ "Auth.LoginView": { Component } }}>` — or `wrap: true` to keep the original inside yours | custom login |
|
|
67
|
+
|
|
68
|
+
## What each place hands your component
|
|
69
|
+
|
|
70
|
+
| Place | Your component receives |
|
|
71
|
+
|---|---|
|
|
72
|
+
| A page (`views`) | Nothing: read what you need with the hooks. It renders inside the admin's router, so `useUrlController().navigate(…)` (or `react-router`) works. |
|
|
73
|
+
| A view mode `Builder` | `CollectionCustomViewParams`: `collection`, `path`, `tableController` (its `data` is the rows the toolbar's search and filters select, `dataLoading`, …), `onEntityClick(entity)` to open a row the way the collection opens rows, `selectionController`, `emptyComponent`. |
|
|
74
|
+
| `admin.Actions` | `CollectionActionsProps`: `path`, `collection`, `selectionController` (`hasSelection`, `selection`, `clearSelection()`), `tableController`, `openNewDocument(defaults?)`. Turn `selection` into rows with `resolveSelection({ selection, accessor: useData().collection(path) })` — it may stand for "every row matching the filter", not only the ticked ones. |
|
|
75
|
+
| `admin.entityViews` `Builder` | `EntityCustomViewParams`: `collection`, the record (`entity`, absent while it is being created), its unsaved values (`modifiedValues`) and the form (`formContext`). |
|
|
76
|
+
| `"Auth.LoginView"` | `{ authController }`. Sign in with `authController.emailPasswordLogin?.(email, password)` (optional: present when email sign-in is enabled); a failure throws and is also on `authController.authProviderError`. Once `authController.user` is set the admin replaces your screen by itself. |
|
|
77
|
+
| Any other override | The props of the part it replaces; with `wrap: true`, those plus `OriginalComponent`. |
|
|
78
|
+
|
|
79
|
+
## Facts that save a trip to the source
|
|
80
|
+
|
|
81
|
+
- **Rows are `Entity` objects.** `useData().collection("orders").find()` resolves to
|
|
82
|
+
`{ data: Entity[], meta }`; a row's fields are on `row.values`, its id is
|
|
83
|
+
`row.id`. `find({ limit, offset, where: { status: ["==", "paid"] }, orderBy: ["createdAt", "desc"] })`.
|
|
84
|
+
- **Dates in `values` are `Date` objects** in the admin, not strings. A
|
|
85
|
+
`columnType: "date"` column (a calendar day) is that day's UTC midnight, so
|
|
86
|
+
read its day with `getUTCDate()`, not `getDate()`, or it lands on the day
|
|
87
|
+
before west of Greenwich. `getDatePropertyTimezone(property)` names the zone
|
|
88
|
+
the admin shows any date property in.
|
|
89
|
+
- **Defaults for a new record:** a property's `defaultValue` applies everywhere a
|
|
90
|
+
record is created; `EntityFormPanel`'s `defaultValues` apply to that form only,
|
|
91
|
+
on top of them.
|
|
92
|
+
- **Enum fields** are `enum: [{ id: "draft", label: "Draft" }, …]` on a string
|
|
93
|
+
property — see `defineCollection` and the collections docs for every property
|
|
94
|
+
option.
|
|
95
|
+
- **A record keyed by its user:** `entityId={useAuthController().user?.uid}`.
|
|
96
|
+
|
|
97
|
+
The override names are `Shell.AppBar`, `Shell.Drawer`, `HomePage`,
|
|
98
|
+
`HomePage.CollectionCard`, `Auth.LoginView`, `Collection.View`,
|
|
99
|
+
`Collection.Table`, `Collection.Card`, `Collection.EmptyState`,
|
|
100
|
+
`Collection.Actions`, `Entity.Form`, `EditView.FormActions`, `Entity.SidePanel`
|
|
101
|
+
and a few more: the full list is `OverridableComponentName` in
|
|
102
|
+
`@rebasepro/cms-types`. A collection can override any `Collection.*` or
|
|
103
|
+
`Entity.*` part for itself alone with `admin.components`.
|
|
104
|
+
|
|
105
|
+
## Copying a built-in part
|
|
106
|
+
|
|
107
|
+
A copy of a built-in part compiles in your project once its relative imports
|
|
108
|
+
point at `@rebasepro/cms` and `@rebasepro/app`: everything it imports is a public
|
|
109
|
+
export. That holds for every part except three, and the three are deliberate.
|
|
110
|
+
|
|
111
|
+
- **`Collection.View`** is the composition of every view mode — list, table,
|
|
112
|
+
cards, board, split — with inline editing, the popup field editor, the delete
|
|
113
|
+
dialog and the view mode's URL state. What it imports is those modes'
|
|
114
|
+
internals. Replace one part of it instead (`Collection.Table`,
|
|
115
|
+
`Collection.Card`, `Collection.Actions`, `Collection.EmptyState`, which all
|
|
116
|
+
copy), add a view mode of your own with `collectionViews`, or wrap it with
|
|
117
|
+
`wrap: true`.
|
|
118
|
+
- **`DetailView`** is the record view's composition: identity bar, tabs,
|
|
119
|
+
inspector and the split list's buttons, around tab ids that are URL values.
|
|
120
|
+
Customize a record with `admin.entityViews`, `admin.entityActions`, the
|
|
121
|
+
`form.*` slots, or the `Entity.Form` and `EditView.FormActions` overrides,
|
|
122
|
+
which copy.
|
|
123
|
+
- **`HomePage`** copies but for its drag-and-drop reordering of cards and
|
|
124
|
+
groups, which has no API of its own to export. A home page of your own
|
|
125
|
+
composes `NavigationGroup`, `NavigationCardBinding` and `FavouritesView` over
|
|
126
|
+
`useNavigationStateController().topLevelNavigation`; to add to the stock one,
|
|
127
|
+
use the `home.cards` slot.
|
|
128
|
+
|
|
129
|
+
`pnpm report:override-copyability` in the Rebase repository lists what each
|
|
130
|
+
part imports that is not public, and a test there fails when a part that copies
|
|
131
|
+
stops copying.
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recipe: a bulk action — set one field on every selected row.
|
|
3
|
+
*
|
|
4
|
+
* A collection's toolbar renders whatever components its `admin.Actions` lists,
|
|
5
|
+
* and hands each the selection and the collection's path. This one appears
|
|
6
|
+
* once rows are ticked and archives them: it reads the selection (which may be
|
|
7
|
+
* "every row matching the filter", not just the ticked ones — `resolveSelection`
|
|
8
|
+
* handles both), updates each row through the data layer, and clears the
|
|
9
|
+
* selection. Saves go through the server, so its callbacks and security rules
|
|
10
|
+
* apply to every row. When one is refused, the rows before it are already
|
|
11
|
+
* archived: it says how many, and leaves the rest selected for another try.
|
|
12
|
+
*
|
|
13
|
+
* To use it: `admin: { Actions: [ArchiveSelectedAction] }` on the collection,
|
|
14
|
+
* or copy it and change `FIELD` / `VALUE` / the label.
|
|
15
|
+
*/
|
|
16
|
+
import React, { useState } from "react";
|
|
17
|
+
import type { CollectionActionsProps } from "@rebasepro/cms-types";
|
|
18
|
+
import { useData, useSnackbarController } from "@rebasepro/app";
|
|
19
|
+
import { resolveSelection } from "@rebasepro/cms";
|
|
20
|
+
import { Button } from "@rebasepro/ui";
|
|
21
|
+
|
|
22
|
+
const FIELD = "status";
|
|
23
|
+
const VALUE = "archived";
|
|
24
|
+
|
|
25
|
+
export function ArchiveSelectedAction({ path, selectionController }: CollectionActionsProps) {
|
|
26
|
+
const data = useData();
|
|
27
|
+
const snackbar = useSnackbarController();
|
|
28
|
+
const [running, setRunning] = useState(false);
|
|
29
|
+
|
|
30
|
+
if (!selectionController.hasSelection) return null;
|
|
31
|
+
|
|
32
|
+
const archive = async () => {
|
|
33
|
+
setRunning(true);
|
|
34
|
+
let rows: Awaited<ReturnType<typeof resolveSelection>> = [];
|
|
35
|
+
let done = 0;
|
|
36
|
+
try {
|
|
37
|
+
const accessor = data.collection(path);
|
|
38
|
+
rows = await resolveSelection({ selection: selectionController.selection, accessor });
|
|
39
|
+
for (const row of rows) {
|
|
40
|
+
await accessor.update(row.id, { [FIELD]: VALUE });
|
|
41
|
+
done++;
|
|
42
|
+
}
|
|
43
|
+
selectionController.clearSelection();
|
|
44
|
+
snackbar.open({ type: "success", message: `Archived ${rows.length} row${rows.length === 1 ? "" : "s"}` });
|
|
45
|
+
} catch (error) {
|
|
46
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
47
|
+
if (done > 0) selectionController.setSelectedEntities(rows.slice(done));
|
|
48
|
+
snackbar.open({
|
|
49
|
+
type: "error",
|
|
50
|
+
message: rows.length > 0 ? `Archived ${done} of ${rows.length} rows. ${reason}` : reason
|
|
51
|
+
});
|
|
52
|
+
} finally {
|
|
53
|
+
setRunning(false);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<Button size={"small"} variant={"outlined"} color={"neutral"} disabled={running} onClick={archive}>
|
|
59
|
+
Archive selected
|
|
60
|
+
</Button>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recipe: a calendar view mode — a collection's rows on a month grid.
|
|
3
|
+
*
|
|
4
|
+
* A custom view mode sits in the collection's view switcher next to table,
|
|
5
|
+
* cards and board. Its `Builder` is handed the live `tableController`, so the
|
|
6
|
+
* toolbar's search and filters drive it, and `onEntityClick`, which opens a
|
|
7
|
+
* row the way the collection opens rows. All this file decides is the layout.
|
|
8
|
+
*
|
|
9
|
+
* To use it:
|
|
10
|
+
* 1. Register it: `<RebaseCMS collectionViews={[calendarView]}>`
|
|
11
|
+
* (or `<Rebase collectionViews>`).
|
|
12
|
+
* 2. Turn it on for a collection: `admin: { customViews: ["calendar"] }`,
|
|
13
|
+
* and `defaultViewMode: "calendar"` to open on it.
|
|
14
|
+
* Change `DATE_FIELD` / `TITLE_FIELD` to your collection's keys.
|
|
15
|
+
*/
|
|
16
|
+
import React, { useMemo, useState } from "react";
|
|
17
|
+
import type { CollectionCustomView, CollectionCustomViewParams } from "@rebasepro/cms-types";
|
|
18
|
+
import type { Entity } from "@rebasepro/types";
|
|
19
|
+
import { Button, Typography } from "@rebasepro/ui";
|
|
20
|
+
import { getDatePropertyTimezone } from "@rebasepro/cms";
|
|
21
|
+
|
|
22
|
+
const DATE_FIELD = "dueDate";
|
|
23
|
+
const TITLE_FIELD = "title";
|
|
24
|
+
|
|
25
|
+
const WEEKDAYS = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
|
|
26
|
+
|
|
27
|
+
function dayKey(date: Date): string {
|
|
28
|
+
return `${date.getFullYear()}-${date.getMonth()}-${date.getDate()}`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The day a stored date falls on, in the zone the admin shows it in: UTC for a
|
|
33
|
+
* `columnType: "date"` column (a calendar day, delivered as that day's UTC
|
|
34
|
+
* midnight — in local time it is the day before west of Greenwich), the
|
|
35
|
+
* property's `timezone` when it declares one, else the browser's.
|
|
36
|
+
*/
|
|
37
|
+
function storedDayKey(date: Date, timeZone: string | undefined): string {
|
|
38
|
+
if (!timeZone) return dayKey(date);
|
|
39
|
+
const parts = new Intl.DateTimeFormat("en-US", { timeZone, year: "numeric", month: "numeric", day: "numeric" })
|
|
40
|
+
.formatToParts(date);
|
|
41
|
+
const part = (type: string) => Number(parts.find(p => p.type === type)?.value);
|
|
42
|
+
return `${part("year")}-${part("month") - 1}-${part("day")}`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** The days shown for a month: whole weeks, Monday first. */
|
|
46
|
+
function monthGrid(month: Date): Date[] {
|
|
47
|
+
const first = new Date(month.getFullYear(), month.getMonth(), 1);
|
|
48
|
+
const start = new Date(first);
|
|
49
|
+
start.setDate(first.getDate() - ((first.getDay() + 6) % 7));
|
|
50
|
+
const days: Date[] = [];
|
|
51
|
+
for (let d = new Date(start); days.length < 42; d.setDate(d.getDate() + 1)) {
|
|
52
|
+
days.push(new Date(d));
|
|
53
|
+
}
|
|
54
|
+
return days;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function CalendarView({ collection, tableController, onEntityClick }: CollectionCustomViewParams) {
|
|
58
|
+
const [month, setMonth] = useState(() => {
|
|
59
|
+
const now = new Date();
|
|
60
|
+
return new Date(now.getFullYear(), now.getMonth(), 1);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const dateProperty = collection.properties[DATE_FIELD];
|
|
64
|
+
const timeZone = dateProperty?.type === "date" ? getDatePropertyTimezone(dateProperty) : undefined;
|
|
65
|
+
|
|
66
|
+
const byDay = useMemo(() => {
|
|
67
|
+
const map = new Map<string, Entity[]>();
|
|
68
|
+
for (const entity of tableController.data ?? []) {
|
|
69
|
+
const raw = entity.values[DATE_FIELD];
|
|
70
|
+
if (raw === null || raw === undefined) continue;
|
|
71
|
+
const date = raw instanceof Date ? raw : new Date(String(raw));
|
|
72
|
+
if (Number.isNaN(date.getTime())) continue;
|
|
73
|
+
const key = storedDayKey(date, timeZone);
|
|
74
|
+
map.set(key, [...(map.get(key) ?? []), entity]);
|
|
75
|
+
}
|
|
76
|
+
return map;
|
|
77
|
+
}, [tableController.data, timeZone]);
|
|
78
|
+
|
|
79
|
+
const shift = (months: number) => setMonth(m => new Date(m.getFullYear(), m.getMonth() + months, 1));
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<div className={"flex flex-col gap-2 p-4 h-full overflow-auto"}>
|
|
83
|
+
<div className={"flex items-center gap-2"}>
|
|
84
|
+
<Button size={"small"} variant={"text"} onClick={() => shift(-1)} aria-label={"Previous month"}>‹</Button>
|
|
85
|
+
<Typography variant={"subtitle1"} className={"min-w-40 text-center"}>
|
|
86
|
+
{month.toLocaleDateString(undefined, { month: "long", year: "numeric" })}
|
|
87
|
+
</Typography>
|
|
88
|
+
<Button size={"small"} variant={"text"} onClick={() => shift(1)} aria-label={"Next month"}>›</Button>
|
|
89
|
+
</div>
|
|
90
|
+
<div className={"grid grid-cols-7 gap-px rounded-lg overflow-hidden border border-hairline bg-hairline"}>
|
|
91
|
+
{WEEKDAYS.map(day => (
|
|
92
|
+
<Typography key={day} variant={"caption"} color={"secondary"}
|
|
93
|
+
className={"bg-surface-raised px-2 py-1"}>{day}</Typography>
|
|
94
|
+
))}
|
|
95
|
+
{monthGrid(month).map(day => (
|
|
96
|
+
<div key={dayKey(day)}
|
|
97
|
+
data-day={dayKey(day)}
|
|
98
|
+
className={"min-h-24 bg-surface-card p-1 flex flex-col gap-1"
|
|
99
|
+
+ (day.getMonth() === month.getMonth() ? "" : " opacity-40")}>
|
|
100
|
+
<Typography variant={"caption"} color={"secondary"}>{day.getDate()}</Typography>
|
|
101
|
+
{(byDay.get(dayKey(day)) ?? []).map(entity => (
|
|
102
|
+
<Button key={String(entity.id)}
|
|
103
|
+
variant={"text"}
|
|
104
|
+
size={"smallest"}
|
|
105
|
+
fullWidth
|
|
106
|
+
onClick={() => onEntityClick?.(entity)}
|
|
107
|
+
className={"justify-start min-w-0"}>
|
|
108
|
+
<span className={"truncate"}>{String(entity.values[TITLE_FIELD] ?? entity.id)}</span>
|
|
109
|
+
</Button>
|
|
110
|
+
))}
|
|
111
|
+
</div>
|
|
112
|
+
))}
|
|
113
|
+
</div>
|
|
114
|
+
</div>
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export const calendarView: CollectionCustomView = {
|
|
119
|
+
key: "calendar",
|
|
120
|
+
name: "Calendar",
|
|
121
|
+
icon: "Calendar",
|
|
122
|
+
Builder: CalendarView
|
|
123
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recipe: your own login screen.
|
|
3
|
+
*
|
|
4
|
+
* Any built-in screen can be replaced or wrapped through `<Rebase components>`.
|
|
5
|
+
* The login screen is `"Auth.LoginView"`, and it is handed the auth controller:
|
|
6
|
+
* sign in with `emailPasswordLogin`, and read a failure from
|
|
7
|
+
* `authProviderError`. Once a user is signed in, the admin renders instead.
|
|
8
|
+
*
|
|
9
|
+
* To use it:
|
|
10
|
+
* <Rebase components={{ "Auth.LoginView": { Component: BrandedLoginView } }} …>
|
|
11
|
+
* Or keep the built-in form and only frame it: `{ Component: …, wrap: true }`
|
|
12
|
+
* hands you the original as `OriginalComponent`.
|
|
13
|
+
*/
|
|
14
|
+
import React, { useState } from "react";
|
|
15
|
+
import type { AuthControllerExtended } from "@rebasepro/cms-types";
|
|
16
|
+
import { Button, Card, TextField, Typography } from "@rebasepro/ui";
|
|
17
|
+
|
|
18
|
+
export function BrandedLoginView({ authController }: { authController: AuthControllerExtended }) {
|
|
19
|
+
const [email, setEmail] = useState("");
|
|
20
|
+
const [password, setPassword] = useState("");
|
|
21
|
+
const [submitting, setSubmitting] = useState(false);
|
|
22
|
+
const [error, setError] = useState<string | undefined>();
|
|
23
|
+
|
|
24
|
+
const signIn = async (event: React.FormEvent) => {
|
|
25
|
+
event.preventDefault();
|
|
26
|
+
if (!authController.emailPasswordLogin) {
|
|
27
|
+
setError("Email sign-in is not enabled.");
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
setSubmitting(true);
|
|
31
|
+
setError(undefined);
|
|
32
|
+
try {
|
|
33
|
+
await authController.emailPasswordLogin(email, password);
|
|
34
|
+
} catch (e) {
|
|
35
|
+
setError(e instanceof Error ? e.message : String(e));
|
|
36
|
+
} finally {
|
|
37
|
+
setSubmitting(false);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const failure = error ?? (authController.authProviderError ? String(authController.authProviderError) : undefined);
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<div className={"min-h-screen flex items-center justify-center bg-surface-frame p-4"}>
|
|
45
|
+
<Card className={"w-full max-w-sm p-6"}>
|
|
46
|
+
<form onSubmit={signIn} className={"flex flex-col gap-4"}>
|
|
47
|
+
<Typography variant={"h5"}>Acme back office</Typography>
|
|
48
|
+
<TextField label={"Email"} type={"email"} value={email} autoFocus
|
|
49
|
+
onChange={e => setEmail(e.target.value)}/>
|
|
50
|
+
<TextField label={"Password"} type={"password"} value={password}
|
|
51
|
+
onChange={e => setPassword(e.target.value)}/>
|
|
52
|
+
{failure && <Typography variant={"body2"} color={"error"} role={"alert"}>{failure}</Typography>}
|
|
53
|
+
<Button type={"submit"} variant={"filled"} disabled={submitting || !email || !password}>
|
|
54
|
+
Sign in
|
|
55
|
+
</Button>
|
|
56
|
+
</form>
|
|
57
|
+
</Card>
|
|
58
|
+
</div>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recipe: per-user settings — each signed-in user edits their own record.
|
|
3
|
+
*
|
|
4
|
+
* The same shape as the site-settings singleton, keyed by the user instead of
|
|
5
|
+
* a constant: the record's id is the user's uid. The first visit creates it.
|
|
6
|
+
*
|
|
7
|
+
* Protect it on the server too: a `securityRules` owner rule (`ownerField:
|
|
8
|
+
* "id"`) makes a user's row readable and writable by that user alone, so the
|
|
9
|
+
* page is a convenience, not the only lock.
|
|
10
|
+
*
|
|
11
|
+
* To use it: put `userPreferencesCollection` in `config/collections`, and add
|
|
12
|
+
* `myPreferencesView` to `<RebaseCMS views={[…]}>`.
|
|
13
|
+
*/
|
|
14
|
+
import React from "react";
|
|
15
|
+
import { defineCollection } from "@rebasepro/cms-types";
|
|
16
|
+
import type { AppView } from "@rebasepro/cms-types";
|
|
17
|
+
import { useAuthController } from "@rebasepro/app";
|
|
18
|
+
import { EntityFormPanel } from "@rebasepro/cms";
|
|
19
|
+
import { Container, Typography } from "@rebasepro/ui";
|
|
20
|
+
|
|
21
|
+
export const userPreferencesCollection = defineCollection({
|
|
22
|
+
name: "User preferences",
|
|
23
|
+
singularName: "Preferences",
|
|
24
|
+
slug: "user_preferences",
|
|
25
|
+
table: "user_preferences",
|
|
26
|
+
properties: {
|
|
27
|
+
id: { name: "User", type: "string", isId: true },
|
|
28
|
+
theme: {
|
|
29
|
+
name: "Theme",
|
|
30
|
+
type: "string",
|
|
31
|
+
enum: [
|
|
32
|
+
{ id: "system", label: "System" },
|
|
33
|
+
{ id: "light", label: "Light" },
|
|
34
|
+
{ id: "dark", label: "Dark" }
|
|
35
|
+
]
|
|
36
|
+
},
|
|
37
|
+
weeklyDigest: { name: "Weekly digest email", type: "boolean" }
|
|
38
|
+
},
|
|
39
|
+
admin: {
|
|
40
|
+
icon: "UserCog",
|
|
41
|
+
hideFromNavigation: true,
|
|
42
|
+
hideIdFromForm: true
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
export function MyPreferencesPage() {
|
|
47
|
+
const { user } = useAuthController();
|
|
48
|
+
if (!user) return null;
|
|
49
|
+
return (
|
|
50
|
+
<Container maxWidth={"3xl"} className={"py-8"}>
|
|
51
|
+
<Typography variant={"h4"} gutterBottom>My preferences</Typography>
|
|
52
|
+
<EntityFormPanel
|
|
53
|
+
// A new user is a new record: remount rather than carry one
|
|
54
|
+
// user's form state into another's.
|
|
55
|
+
key={user.uid}
|
|
56
|
+
collection={userPreferencesCollection}
|
|
57
|
+
entityId={user.uid}
|
|
58
|
+
defaultValues={{ theme: "system", weeklyDigest: true }}/>
|
|
59
|
+
</Container>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export const myPreferencesView: AppView = {
|
|
64
|
+
slug: "me/preferences",
|
|
65
|
+
name: "My preferences",
|
|
66
|
+
icon: "UserCog",
|
|
67
|
+
view: <MyPreferencesPage/>
|
|
68
|
+
};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recipe: a dashboard page — read data, draw it, link into the admin.
|
|
3
|
+
*
|
|
4
|
+
* A page of the admin is a React component on a route. It reads through
|
|
5
|
+
* `useData()` (the same data layer, permissions and server callbacks as the
|
|
6
|
+
* rest of the admin) and can draw with anything: this one uses plain divs so
|
|
7
|
+
* it needs no chart library; swap in recharts or visx if you have one.
|
|
8
|
+
*
|
|
9
|
+
* Grouping happens in the browser, over the first `MAX_ROWS` rows, which is
|
|
10
|
+
* right for a few thousand. The total is counted by the data source, so it
|
|
11
|
+
* stays true past that, and the page says when the groups cover only part of
|
|
12
|
+
* it. For more, add a custom function on the server that runs the `GROUP BY`
|
|
13
|
+
* and call it from here instead.
|
|
14
|
+
*
|
|
15
|
+
* Each bar opens the collection filtered to its group — the filter rides in
|
|
16
|
+
* the URL, as the collection writes it — through the admin's router.
|
|
17
|
+
*
|
|
18
|
+
* To use it: add `ordersDashboardView` to `<RebaseCMS views={[…]}>`. Change
|
|
19
|
+
* `COLLECTION` / `GROUP_FIELD` to your own.
|
|
20
|
+
*/
|
|
21
|
+
import React, { useEffect, useState } from "react";
|
|
22
|
+
import type { AppView } from "@rebasepro/cms-types";
|
|
23
|
+
import { useData } from "@rebasepro/app";
|
|
24
|
+
import { useUrlController } from "@rebasepro/cms";
|
|
25
|
+
import { Card, CircularProgressCenter, Container, Typography } from "@rebasepro/ui";
|
|
26
|
+
|
|
27
|
+
const COLLECTION = "orders";
|
|
28
|
+
const GROUP_FIELD = "status";
|
|
29
|
+
const MAX_ROWS = 5000;
|
|
30
|
+
|
|
31
|
+
type Group = { value: string | null; count: number };
|
|
32
|
+
|
|
33
|
+
/** The collection's URL filtered to one value of `GROUP_FIELD`, as its toolbar writes it. */
|
|
34
|
+
function filteredUrl(collectionUrl: string, value: string | null): string {
|
|
35
|
+
const op = encodeURIComponent("==");
|
|
36
|
+
const encoded = value === null ? "null" : encodeURIComponent(value);
|
|
37
|
+
return `${collectionUrl}?${GROUP_FIELD}_op=${op}&${GROUP_FIELD}_value=${encoded}`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function OrdersDashboard() {
|
|
41
|
+
const data = useData();
|
|
42
|
+
const urls = useUrlController();
|
|
43
|
+
const [groups, setGroups] = useState<Group[] | undefined>();
|
|
44
|
+
const [total, setTotal] = useState(0);
|
|
45
|
+
const [error, setError] = useState<string | undefined>();
|
|
46
|
+
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
let cancelled = false;
|
|
49
|
+
const orders = data.collection(COLLECTION);
|
|
50
|
+
// `count` is optional on an accessor: not every data source can count.
|
|
51
|
+
Promise.all([orders.find({ limit: MAX_ROWS }), orders.count ? orders.count() : undefined])
|
|
52
|
+
.then(([{ data: rows }, counted]) => {
|
|
53
|
+
const counts = new Map<string | null, number>();
|
|
54
|
+
for (const row of rows) {
|
|
55
|
+
const raw = row.values[GROUP_FIELD];
|
|
56
|
+
const value = raw === null || raw === undefined ? null : String(raw);
|
|
57
|
+
counts.set(value, (counts.get(value) ?? 0) + 1);
|
|
58
|
+
}
|
|
59
|
+
if (!cancelled) {
|
|
60
|
+
setTotal(Math.max(counted ?? 0, rows.length));
|
|
61
|
+
setGroups([...counts].map(([value, count]) => ({ value, count })).sort((a, b) => b.count - a.count));
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
.catch((e: unknown) => {
|
|
65
|
+
if (!cancelled) setError(e instanceof Error ? e.message : String(e));
|
|
66
|
+
});
|
|
67
|
+
return () => {
|
|
68
|
+
cancelled = true;
|
|
69
|
+
};
|
|
70
|
+
}, [data]);
|
|
71
|
+
|
|
72
|
+
if (error) return <Typography color={"error"} className={"p-8"}>{error}</Typography>;
|
|
73
|
+
if (!groups) return <CircularProgressCenter/>;
|
|
74
|
+
|
|
75
|
+
const grouped = groups.reduce((sum, g) => sum + g.count, 0);
|
|
76
|
+
const max = Math.max(1, ...groups.map(g => g.count));
|
|
77
|
+
const collectionUrl = urls.buildUrlCollectionPath(COLLECTION);
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<Container maxWidth={"4xl"} className={"py-8 flex flex-col gap-4"}>
|
|
81
|
+
<Typography variant={"h4"}>Orders</Typography>
|
|
82
|
+
<Card className={"p-4 flex flex-col gap-1"}>
|
|
83
|
+
<Typography variant={"caption"} color={"secondary"}>Total</Typography>
|
|
84
|
+
<Typography variant={"stat"}>{total}</Typography>
|
|
85
|
+
{grouped < total && (
|
|
86
|
+
<Typography variant={"caption"} color={"secondary"}>
|
|
87
|
+
{`Grouped over the first ${grouped} of ${total} orders`}
|
|
88
|
+
</Typography>
|
|
89
|
+
)}
|
|
90
|
+
</Card>
|
|
91
|
+
<Card className={"p-4 flex flex-col gap-3"}>
|
|
92
|
+
<Typography variant={"subtitle2"}>By {GROUP_FIELD}</Typography>
|
|
93
|
+
{groups.map(group => {
|
|
94
|
+
const href = filteredUrl(collectionUrl, group.value);
|
|
95
|
+
const label = group.value ?? "—";
|
|
96
|
+
return (
|
|
97
|
+
<a key={label}
|
|
98
|
+
href={href}
|
|
99
|
+
// The href is for "open in a new tab"; a plain
|
|
100
|
+
// click goes through the admin's router instead
|
|
101
|
+
// of reloading the page.
|
|
102
|
+
onClick={(event) => {
|
|
103
|
+
if (event.metaKey || event.ctrlKey || event.shiftKey || event.button !== 0) return;
|
|
104
|
+
event.preventDefault();
|
|
105
|
+
urls.navigate(href);
|
|
106
|
+
}}
|
|
107
|
+
aria-label={`${label}: ${group.count}`}
|
|
108
|
+
className={"grid grid-cols-[8rem_1fr_3rem] items-center gap-3 no-underline"}>
|
|
109
|
+
<Typography variant={"body2"}>{label}</Typography>
|
|
110
|
+
<div className={"h-3 rounded bg-primary/80"} style={{ width: `${(group.count / max) * 100}%` }}/>
|
|
111
|
+
<Typography variant={"body2"} align={"right"}>{group.count}</Typography>
|
|
112
|
+
</a>
|
|
113
|
+
);
|
|
114
|
+
})}
|
|
115
|
+
</Card>
|
|
116
|
+
</Container>
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export const ordersDashboardView: AppView = {
|
|
121
|
+
slug: "dashboards/orders",
|
|
122
|
+
name: "Orders dashboard",
|
|
123
|
+
icon: "ChartBar",
|
|
124
|
+
view: <OrdersDashboard/>
|
|
125
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recipe: a singleton — one settings record, edited on a page of its own.
|
|
3
|
+
*
|
|
4
|
+
* A singleton is not a special kind of collection. It is an ordinary table
|
|
5
|
+
* whose admin page always opens the same row. `EntityFormPanel` given an id
|
|
6
|
+
* edits that record, and creates it under that id the first time, so there is
|
|
7
|
+
* nothing to seed.
|
|
8
|
+
*
|
|
9
|
+
* To use it:
|
|
10
|
+
* 1. Put `siteSettingsCollection` in `config/collections/site_settings.ts`
|
|
11
|
+
* (it is a normal collection: `rebase db push` creates its table).
|
|
12
|
+
* 2. Add `siteSettingsView` to `<RebaseCMS views={[…]}>`.
|
|
13
|
+
*
|
|
14
|
+
* Reading the settings elsewhere is a normal read of row `"site"`.
|
|
15
|
+
*/
|
|
16
|
+
import React from "react";
|
|
17
|
+
import { defineCollection } from "@rebasepro/cms-types";
|
|
18
|
+
import type { AppView } from "@rebasepro/cms-types";
|
|
19
|
+
import { EntityFormPanel } from "@rebasepro/cms";
|
|
20
|
+
import { Container, Typography } from "@rebasepro/ui";
|
|
21
|
+
|
|
22
|
+
/** The one row every visit to the page edits. */
|
|
23
|
+
export const SITE_SETTINGS_ID = "site";
|
|
24
|
+
|
|
25
|
+
export const siteSettingsCollection = defineCollection({
|
|
26
|
+
name: "Site settings",
|
|
27
|
+
singularName: "Site settings",
|
|
28
|
+
slug: "site_settings",
|
|
29
|
+
table: "site_settings",
|
|
30
|
+
properties: {
|
|
31
|
+
id: { name: "ID", type: "string", isId: true },
|
|
32
|
+
siteName: { name: "Site name", type: "string", validation: { required: true } },
|
|
33
|
+
tagline: { name: "Tagline", type: "string" },
|
|
34
|
+
maintenanceMode: { name: "Maintenance mode", type: "boolean" },
|
|
35
|
+
supportEmail: { name: "Support email", type: "string", email: true }
|
|
36
|
+
},
|
|
37
|
+
admin: {
|
|
38
|
+
icon: "Settings",
|
|
39
|
+
// The page below is the way in; a list of one row is not.
|
|
40
|
+
hideFromNavigation: true,
|
|
41
|
+
hideIdFromForm: true
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
export function SiteSettingsPage() {
|
|
46
|
+
return (
|
|
47
|
+
<Container maxWidth={"3xl"} className={"py-8"}>
|
|
48
|
+
<Typography variant={"h4"} gutterBottom>Site settings</Typography>
|
|
49
|
+
<EntityFormPanel
|
|
50
|
+
collection={siteSettingsCollection}
|
|
51
|
+
entityId={SITE_SETTINGS_ID}
|
|
52
|
+
defaultValues={{ siteName: "My site", maintenanceMode: false }}/>
|
|
53
|
+
</Container>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export const siteSettingsView: AppView = {
|
|
58
|
+
slug: "settings/site",
|
|
59
|
+
name: "Site settings",
|
|
60
|
+
icon: "Settings",
|
|
61
|
+
group: "Settings",
|
|
62
|
+
view: <SiteSettingsPage/>
|
|
63
|
+
};
|