@rebasepro/admin 0.16.0 → 0.16.1-canary.g0d7af95

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.
Files changed (180) hide show
  1. package/dist/{CollectionEditorDialog-D2Vf4C3-.js → CollectionEditorDialog-Dt_Wv20U.js} +7 -3
  2. package/dist/{CollectionEditorDialog-D2Vf4C3-.js.map → CollectionEditorDialog-Dt_Wv20U.js.map} +1 -1
  3. package/dist/{PropertyEditView-D3NBsK9_.js → PropertyEditView-C4IltWX5.js} +2 -2
  4. package/dist/{PropertyEditView-D3NBsK9_.js.map → PropertyEditView-C4IltWX5.js.map} +1 -1
  5. package/dist/{RouterCollectionsStudioView-hPB54l3Q.js → RouterCollectionsStudioView-C-BHWJ0J.js} +4 -4
  6. package/dist/{RouterCollectionsStudioView-hPB54l3Q.js.map → RouterCollectionsStudioView-C-BHWJ0J.js.map} +1 -1
  7. package/dist/SchemaChangeDialog-DceT8QFX.js +394 -0
  8. package/dist/SchemaChangeDialog-DceT8QFX.js.map +1 -0
  9. package/dist/collection_editor/ConfigControllerProvider.d.ts +4 -4
  10. package/dist/collection_editor/_cms_internals.d.ts +23 -23
  11. package/dist/collection_editor/api/index.d.ts +1 -1
  12. package/dist/collection_editor/extensibility_types.d.ts +1 -1
  13. package/dist/collection_editor/index.d.ts +21 -21
  14. package/dist/collection_editor/liveSchemaClient.d.ts +182 -0
  15. package/dist/collection_editor/serializable_types.d.ts +0 -1
  16. package/dist/collection_editor/serializable_utils.d.ts +1 -1
  17. package/dist/collection_editor/types/collection_editor_controller.d.ts +1 -1
  18. package/dist/collection_editor/types/config_controller.d.ts +11 -0
  19. package/dist/collection_editor/ui/collection_editor/AICollectionGeneratorPopover.d.ts +1 -1
  20. package/dist/collection_editor/ui/collection_editor/AIModifiedPathsContext.d.ts +1 -1
  21. package/dist/collection_editor/ui/collection_editor/CollectionEditorDialog.d.ts +4 -4
  22. package/dist/collection_editor/ui/collection_editor/CollectionEditorWelcomeView.d.ts +1 -1
  23. package/dist/collection_editor/ui/collection_editor/CollectionPropertiesEditorForm.d.ts +2 -2
  24. package/dist/collection_editor/ui/collection_editor/CollectionStudioView.d.ts +1 -1
  25. package/dist/collection_editor/ui/collection_editor/CollectionsStudioView.d.ts +2 -2
  26. package/dist/collection_editor/ui/collection_editor/GeneralSettingsForm.d.ts +1 -1
  27. package/dist/collection_editor/ui/collection_editor/PropertyEditView.d.ts +2 -2
  28. package/dist/collection_editor/ui/collection_editor/RouterCollectionStudioView.d.ts +1 -1
  29. package/dist/collection_editor/ui/collection_editor/RouterCollectionsStudioView.d.ts +1 -1
  30. package/dist/collection_editor/ui/collection_editor/SchemaChangeDialog.d.ts +85 -0
  31. package/dist/collection_editor/ui/collection_editor/SubcollectionsEditTab.d.ts +2 -2
  32. package/dist/collection_editor/ui/collection_editor/import/CollectionEditorImportDataPreview.d.ts +1 -1
  33. package/dist/collection_editor/ui/collection_editor/import/CollectionEditorImportMapping.d.ts +1 -1
  34. package/dist/collection_editor/ui/collection_editor/import/clean_import_data.d.ts +1 -1
  35. package/dist/collection_editor/ui/collection_editor/properties/conditions/index.d.ts +6 -6
  36. package/dist/collection_editor/useCollectionEditorController.d.ts +1 -1
  37. package/dist/collection_editor/useCollectionsConfigController.d.ts +1 -1
  38. package/dist/collection_editor/useJsonCollectionsConfigController.d.ts +2 -2
  39. package/dist/collection_editor/useLiveSchemaEditing.d.ts +71 -0
  40. package/dist/collection_editor/useLocalCollectionsConfigController.d.ts +1 -1
  41. package/dist/collection_editor_ui.d.ts +12 -12
  42. package/dist/collection_editor_ui.js +4 -4
  43. package/dist/components/CollectionTableBinding/CollectionTableBinding.d.ts +1 -1
  44. package/dist/components/CollectionTableBinding/PropertyTableCell.d.ts +1 -1
  45. package/dist/components/CollectionTableBinding/fields/TableStorageUpload.d.ts +1 -1
  46. package/dist/components/CollectionTableBinding/index.d.ts +5 -5
  47. package/dist/components/CollectionTableBinding/internal/popup_field/PopupFormField.d.ts +1 -1
  48. package/dist/components/CollectionViewBinding/SlotValue.d.ts +2 -2
  49. package/dist/components/CollectionViewBinding/hooks/useKanbanDragAndDrop.d.ts +1 -1
  50. package/dist/components/DrawerNavigationGroup.d.ts +0 -9
  51. package/dist/components/DrawerNavigationItem.d.ts +0 -4
  52. package/dist/components/EditFormActions.d.ts +1 -1
  53. package/dist/components/EditViewBinding.d.ts +3 -3
  54. package/dist/components/EntityInspector.d.ts +1 -1
  55. package/dist/components/EntityPreviewBinding.d.ts +1 -1
  56. package/dist/components/EntityViewBinding.d.ts +1 -1
  57. package/dist/components/HomePage/index.d.ts +4 -4
  58. package/dist/components/PropertyCollectionView.d.ts +1 -1
  59. package/dist/components/ReferenceWidget.d.ts +1 -1
  60. package/dist/components/RelationSelector.d.ts +0 -2
  61. package/dist/components/admin/index.d.ts +1 -1
  62. package/dist/components/app/AppBar.d.ts +1 -1
  63. package/dist/components/app/index.d.ts +4 -4
  64. package/dist/components/common/index.d.ts +1 -1
  65. package/dist/components/field_configs.d.ts +1 -1
  66. package/dist/components/history/EntityHistoryEntry.d.ts +2 -2
  67. package/dist/components/history/index.d.ts +5 -5
  68. package/dist/components/index.d.ts +45 -45
  69. package/dist/data_export/export/index.d.ts +4 -4
  70. package/dist/data_export/index.d.ts +1 -1
  71. package/dist/data_import/components/DataNewPropertiesMapping.d.ts +1 -1
  72. package/dist/data_import/components/ImportSaveInProgress.d.ts +1 -1
  73. package/dist/data_import/components/index.d.ts +4 -4
  74. package/dist/data_import/hooks/index.d.ts +1 -1
  75. package/dist/data_import/hooks/useImportConfig.d.ts +1 -1
  76. package/dist/data_import/import/ImportCollectionAction.d.ts +1 -1
  77. package/dist/data_import/import/index.d.ts +1 -1
  78. package/dist/data_import/index.d.ts +5 -5
  79. package/dist/data_import/types/index.d.ts +1 -1
  80. package/dist/data_import/utils/file_to_json.d.ts +1 -1
  81. package/dist/data_import/utils/index.d.ts +5 -5
  82. package/dist/editor/components/SlashCommandMenu.d.ts +2 -2
  83. package/dist/editor/components/index.d.ts +5 -5
  84. package/dist/editor/editor.d.ts +2 -2
  85. package/dist/editor/index.d.ts +2 -2
  86. package/dist/editor/nodeViews/ImageComponent.d.ts +1 -1
  87. package/dist/editor/nodeViews/TaskItemComponent.d.ts +1 -1
  88. package/dist/editor/types.d.ts +1 -1
  89. package/dist/{export-oauWlxuu.js → export-CF1-p5nY.js} +2 -2
  90. package/dist/{export-oauWlxuu.js.map → export-CF1-p5nY.js.map} +1 -1
  91. package/dist/form/EntityForm.d.ts +1 -1
  92. package/dist/form/EntityFormActions.d.ts +1 -1
  93. package/dist/form/EntityFormBinding.d.ts +1 -1
  94. package/dist/form/PropertyFieldBinding.d.ts +1 -1
  95. package/dist/form/components/StorageItemPreview.d.ts +1 -1
  96. package/dist/form/components/index.d.ts +6 -6
  97. package/dist/form/field_bindings/ArrayCustomShapedFieldBinding.d.ts +1 -1
  98. package/dist/form/field_bindings/ArrayOfReferencesFieldBinding.d.ts +1 -1
  99. package/dist/form/field_bindings/BinaryFieldBinding.d.ts +1 -1
  100. package/dist/form/field_bindings/BlockFieldBinding.d.ts +1 -1
  101. package/dist/form/field_bindings/DateTimeFieldBinding.d.ts +1 -1
  102. package/dist/form/field_bindings/GeopointFieldBinding.d.ts +1 -1
  103. package/dist/form/field_bindings/KeyValueFieldBinding.d.ts +1 -1
  104. package/dist/form/field_bindings/MapFieldBinding.d.ts +1 -1
  105. package/dist/form/field_bindings/MarkdownEditorFieldBinding.d.ts +2 -2
  106. package/dist/form/field_bindings/MultiSelectFieldBinding.d.ts +1 -1
  107. package/dist/form/field_bindings/MultipleRelationFieldBinding.d.ts +1 -1
  108. package/dist/form/field_bindings/ReadOnlyFieldBinding.d.ts +1 -1
  109. package/dist/form/field_bindings/ReferenceFieldBinding.d.ts +1 -1
  110. package/dist/form/field_bindings/RelationFieldBinding.d.ts +1 -1
  111. package/dist/form/field_bindings/RepeatFieldBinding.d.ts +1 -1
  112. package/dist/form/field_bindings/SelectFieldBinding.d.ts +1 -1
  113. package/dist/form/field_bindings/StorageUploadFieldBinding.d.ts +1 -1
  114. package/dist/form/field_bindings/SwitchFieldBinding.d.ts +1 -1
  115. package/dist/form/field_bindings/TextFieldBinding.d.ts +1 -1
  116. package/dist/form/field_bindings/UserSelectFieldBinding.d.ts +1 -1
  117. package/dist/form/field_bindings/VectorFieldBinding.d.ts +1 -1
  118. package/dist/form/index.d.ts +24 -24
  119. package/dist/{history-C2cqc0bw.js → history-BoT8GhO1.js} +2 -2
  120. package/dist/{history-C2cqc0bw.js.map → history-BoT8GhO1.js.map} +1 -1
  121. package/dist/hooks/index.d.ts +16 -16
  122. package/dist/hooks/navigation/contexts/index.d.ts +3 -3
  123. package/dist/hooks/useBuildSideDialogsController.d.ts +1 -1
  124. package/dist/hooks/useSelectionDialog.d.ts +1 -1
  125. package/dist/{import-Bxv5JPm-.js → import-Dg4X01sA.js} +2 -2
  126. package/dist/{import-Bxv5JPm-.js.map → import-Dg4X01sA.js.map} +1 -1
  127. package/dist/index.d.ts +17 -15
  128. package/dist/index.js +262 -21
  129. package/dist/index.js.map +1 -1
  130. package/dist/preview/PropertyPreview.d.ts +1 -1
  131. package/dist/preview/components/ArrayEnumPreview.d.ts +1 -1
  132. package/dist/preview/components/BooleanPreview.d.ts +1 -1
  133. package/dist/preview/components/ImagePreview.d.ts +1 -1
  134. package/dist/preview/components/ReferencePreview.d.ts +1 -1
  135. package/dist/preview/components/RelationPreview.d.ts +1 -1
  136. package/dist/preview/components/StorageThumbnail.d.ts +1 -1
  137. package/dist/preview/components/UrlComponentPreview.d.ts +2 -2
  138. package/dist/preview/components/UserPreview.d.ts +1 -1
  139. package/dist/preview/index.d.ts +24 -24
  140. package/dist/preview/property_previews/ArrayOfMapsPreview.d.ts +1 -1
  141. package/dist/preview/property_previews/ArrayOfReferencesPreview.d.ts +1 -1
  142. package/dist/preview/property_previews/ArrayOfRelationsPreview.d.ts +1 -1
  143. package/dist/preview/property_previews/ArrayOfStorageComponentsPreview.d.ts +1 -1
  144. package/dist/preview/property_previews/ArrayOfStringsPreview.d.ts +1 -1
  145. package/dist/preview/property_previews/ArrayOneOfPreview.d.ts +1 -1
  146. package/dist/preview/property_previews/ArrayPropertyEnumPreview.d.ts +1 -1
  147. package/dist/preview/property_previews/ArrayPropertyPreview.d.ts +1 -1
  148. package/dist/preview/property_previews/MapPropertyPreview.d.ts +1 -1
  149. package/dist/preview/property_previews/NumberPropertyPreview.d.ts +1 -1
  150. package/dist/preview/property_previews/SkeletonPropertyComponent.d.ts +1 -1
  151. package/dist/preview/property_previews/StringPropertyPreview.d.ts +1 -1
  152. package/dist/preview/util.d.ts +1 -1
  153. package/dist/routes/index.d.ts +2 -2
  154. package/dist/types/components/EntityFormActionsProps.d.ts +2 -2
  155. package/dist/types/components/EntityFormProps.d.ts +3 -3
  156. package/dist/types/components/index.d.ts +3 -3
  157. package/dist/types/fields.d.ts +1 -1
  158. package/dist/types/index.d.ts +2 -2
  159. package/dist/util/index.d.ts +5 -5
  160. package/dist/util/previews.d.ts +2 -2
  161. package/dist/{util-C4qsI1QV.js → util-DUIsQ2zh.js} +132 -9
  162. package/dist/util-DUIsQ2zh.js.map +1 -0
  163. package/package.json +11 -11
  164. package/src/collection_editor/ConfigControllerProvider.tsx +5 -0
  165. package/src/collection_editor/liveSchemaClient.ts +285 -0
  166. package/src/collection_editor/serializable_types.ts +0 -1
  167. package/src/collection_editor/serializable_utils.ts +0 -1
  168. package/src/collection_editor/types/config_controller.tsx +11 -0
  169. package/src/collection_editor/ui/collection_editor/CollectionEditorDialog.tsx +10 -0
  170. package/src/collection_editor/ui/collection_editor/SchemaChangeDialog.tsx +470 -0
  171. package/src/collection_editor/useLiveSchemaEditing.tsx +315 -0
  172. package/src/collection_editor/useLocalCollectionsConfigController.tsx +109 -10
  173. package/src/components/DrawerNavigationGroup.tsx +0 -9
  174. package/src/components/DrawerNavigationItem.tsx +0 -4
  175. package/src/components/RelationSelector.tsx +0 -2
  176. package/src/data_import/utils/data.ts +1 -1
  177. package/src/data_import/utils/file_to_json.ts +0 -3
  178. package/src/index.ts +6 -0
  179. package/src/util/previews.ts +4 -2
  180. package/dist/util-C4qsI1QV.js.map +0 -1
@@ -0,0 +1,470 @@
1
+ /**
2
+ * What a schema change would do, before it does it.
3
+ *
4
+ * The dialog exists because a schema change has three possible verdicts and two
5
+ * of them are refusals. Without a preview, the only way to discover that a
6
+ * change is refused is to press a button on a live database and read what comes
7
+ * back — which is a fine way to learn and a poor way to work.
8
+ *
9
+ * ## What it shows, in the order somebody reads it
10
+ *
11
+ * The verdict first, in a sentence, because it decides whether the rest is
12
+ * worth reading. Then the changes, each with what it does and — when it is
13
+ * refused — what to do instead. Then the things that are easy to skip past and
14
+ * expensive to have skipped: constraints the change asks for that the database
15
+ * will not end up enforcing. The SQL and the file list come last, collapsed,
16
+ * for the reader who wants them; they are the evidence, not the summary.
17
+ *
18
+ * ## Why the button says "Commit and apply"
19
+ *
20
+ * Because that is the order, and the order is the feature. The commit lands
21
+ * first, so a failed apply leaves the repository ahead of the database — the
22
+ * ordinary state of every project between an edit and a deploy, which the next
23
+ * boot reconciles. A button labelled "Save" would be describing a different,
24
+ * worse thing.
25
+ */
26
+ import React, { useState } from "react";
27
+ import {
28
+ Alert,
29
+ Button,
30
+ Chip,
31
+ CircularProgress,
32
+ cls,
33
+ Dialog,
34
+ DialogActions,
35
+ DialogContent,
36
+ DialogTitle,
37
+ Typography
38
+ } from "@rebasepro/ui";
39
+
40
+ import type { LiveSchemaPlan, LiveSchemaResult, WithheldConstraint } from "../../liveSchemaClient";
41
+
42
+ export interface SchemaChangeDialogProps {
43
+ open: boolean;
44
+ /** The collection being changed, for the title. */
45
+ collectionId: string;
46
+ /** `undefined` while the plan is still being fetched. */
47
+ plan?: LiveSchemaPlan;
48
+ /** Set when planning itself failed — a network error, a refusal, a 500. */
49
+ planError?: string;
50
+ /** Set once the change has been applied, which turns this into a receipt. */
51
+ result?: LiveSchemaResult;
52
+ applying: boolean;
53
+ /** Set when the apply threw rather than returning a result. */
54
+ applyError?: string;
55
+ onConfirm: () => void;
56
+ /**
57
+ * Ask again, when planning failed.
58
+ *
59
+ * A dropped connection should cost a click, not the whole wizard. The form
60
+ * is already filled in, and making somebody redo it for a transient failure
61
+ * teaches them to distrust the preview rather than the network.
62
+ */
63
+ onRetry?: () => void;
64
+ /**
65
+ * Write the collection source and leave the database alone.
66
+ *
67
+ * Offered only when the change is refused, and it is what keeps the editor
68
+ * usable while it is. Removing a property is the ordinary case: the ensure
69
+ * path has no `DROP COLUMN`, so a removal can never be applied — and
70
+ * refusing the whole save over it would mean a dev could no longer delete a
71
+ * field from a collection they are still designing.
72
+ *
73
+ * This is exactly what the editor did before live editing existed, so it is
74
+ * not a new hazard; the difference is that it now says what it leaves
75
+ * behind instead of reporting success.
76
+ */
77
+ onSourceOnly?: () => void;
78
+ onClose: () => void;
79
+ /**
80
+ * Why this caller may preview but not apply, when that is the case.
81
+ *
82
+ * A person signed in with an API key, most often. Shown next to a disabled
83
+ * button so the refusal arrives while they are deciding rather than after
84
+ * they have decided.
85
+ */
86
+ applyRefusedBecause?: string;
87
+ /**
88
+ * Where a confirmation would land — `owner/repo` and a branch.
89
+ *
90
+ * On screen before the button, not in the receipt after it. A commit is
91
+ * going somewhere, and which branch it is going to is the one fact somebody
92
+ * cannot recover from being wrong about.
93
+ */
94
+ target?: { repository?: string; branch?: string };
95
+ }
96
+
97
+ type Verdict = LiveSchemaPlan["verdict"];
98
+
99
+ /** What the verdict means, in the words the reader needs rather than the enum's. */
100
+ /**
101
+ * What the verdict means, in the words the reader needs rather than the enum's.
102
+ *
103
+ * `safe` is written twice because the two cases are genuinely different, and
104
+ * saying "can be made against the running database" when nothing will be run is
105
+ * the kind of small lie that teaches people to stop reading. A document
106
+ * database has no table to alter, and a change that needs no DDL on a
107
+ * relational one is in the same position: the commit *is* the change.
108
+ */
109
+ const VERDICT_COPY: Record<Verdict, { title: string; body: string; color: "info" | "warning" | "error" }> = {
110
+ safe: {
111
+ title: "Ready to apply",
112
+ body: "Every change here can be made against the running database.",
113
+ color: "info"
114
+ },
115
+ diverges: {
116
+ title: "This would leave the database out of step",
117
+ body: "The change can be written, but the database will not end up matching it. " +
118
+ "The details below say which part, and what would make it applicable.",
119
+ color: "warning"
120
+ },
121
+ "needs-migration": {
122
+ title: "This needs a migration",
123
+ body: "Some of this cannot be done to a running database at all — it drops or rewrites " +
124
+ "something, and that belongs in a migration somebody has read.",
125
+ color: "error"
126
+ }
127
+ };
128
+
129
+ const VERDICT_CHIP: Record<Verdict, { label: string; scheme: "greenLighter" | "orangeLighter" | "redLighter" }> = {
130
+ safe: { label: "safe", scheme: "greenLighter" },
131
+ diverges: { label: "diverges", scheme: "orangeLighter" },
132
+ "needs-migration": { label: "needs migration", scheme: "redLighter" }
133
+ };
134
+
135
+ const monospace = "font-mono text-xs leading-relaxed";
136
+ const codeBlock = cls(
137
+ monospace,
138
+ "bg-surface-100 dark:bg-surface-800 rounded-md p-3 overflow-x-auto whitespace-pre"
139
+ );
140
+
141
+ /** A disclosure that starts closed. The evidence, for the reader who wants it. */
142
+ function Details({ summary, count, children }: {
143
+ summary: string;
144
+ count: number;
145
+ children: React.ReactNode;
146
+ }) {
147
+ const [open, setOpen] = useState(false);
148
+ if (count === 0) return null;
149
+ return (
150
+ <div>
151
+ <button
152
+ type="button"
153
+ onClick={() => setOpen(o => !o)}
154
+ className="flex items-center gap-2 text-sm text-text-secondary dark:text-text-secondary-dark hover:underline"
155
+ >
156
+ <span className={cls("transition-transform", open && "rotate-90")}>›</span>
157
+ {summary} ({count})
158
+ </button>
159
+ {open && <div className="mt-2">{children}</div>}
160
+ </div>
161
+ );
162
+ }
163
+
164
+ /**
165
+ * What still has to happen after this lands.
166
+ *
167
+ * Above the evidence and below the changes, because it is not a refusal and not
168
+ * a detail: the change will apply, and something outside this dialog still has
169
+ * to be done or a later environment will differ from this one.
170
+ */
171
+ function FollowUp({ items }: { items: string[] }) {
172
+ if (items.length === 0) return null;
173
+ return (
174
+ <Alert color="info">
175
+ <Typography variant="body2" className="font-medium mb-1">
176
+ {items.length === 1 ? "One thing to do afterwards" : "To do afterwards"}
177
+ </Typography>
178
+ <ul className="space-y-2">
179
+ {items.map(item => (
180
+ <li key={item} className="text-sm">{item}</li>
181
+ ))}
182
+ </ul>
183
+ </Alert>
184
+ );
185
+ }
186
+
187
+ /**
188
+ * The destination, short enough to read at a glance.
189
+ *
190
+ * A remote repository already reports itself as `owner/repo`, which is exactly
191
+ * what somebody recognises. A local one reports an absolute path, and the
192
+ * leading directories are the part nobody needs: what matters is which
193
+ * checkout, and its name says that.
194
+ */
195
+ function repositoryLabel(repository: string): string {
196
+ if (!repository.startsWith("/")) return repository;
197
+ return repository.split("/").filter(Boolean).pop() ?? repository;
198
+ }
199
+
200
+ function WithheldConstraints({ constraints }: { constraints: WithheldConstraint[] }) {
201
+ if (constraints.length === 0) return null;
202
+ return (
203
+ <Alert color="warning">
204
+ <Typography variant="body2" className="font-medium mb-1">
205
+ {constraints.length === 1
206
+ ? "One constraint will not be enforced"
207
+ : `${constraints.length} constraints will not be enforced`}
208
+ </Typography>
209
+ <ul className="space-y-2">
210
+ {constraints.map(constraint => (
211
+ <li key={constraint.target} className="text-sm">
212
+ <code className="bg-surface-200 dark:bg-surface-700 px-1 rounded">
213
+ {constraint.target}
214
+ </code>
215
+ <div className="mt-1">{constraint.reason}</div>
216
+ <div className="mt-1 text-text-secondary dark:text-text-secondary-dark">
217
+ {constraint.remedy}
218
+ </div>
219
+ </li>
220
+ ))}
221
+ </ul>
222
+ </Alert>
223
+ );
224
+ }
225
+
226
+ /** The receipt. Shown in place of the plan once the change has been applied. */
227
+ function Applied({ result }: { result: LiveSchemaResult }) {
228
+ return (
229
+ <div className="flex flex-col gap-4">
230
+ <Alert color={result.applied ? "success" : "warning"}>
231
+ <Typography variant="body2">{result.summary}</Typography>
232
+ </Alert>
233
+
234
+ {!result.applied && result.applyError && (
235
+ // Deliberately not an error state. The commit landed, which is
236
+ // the durable half; the database is now behind the repository,
237
+ // which is where every project sits between an edit and a
238
+ // deploy, and boot reconciles it.
239
+ <Alert color="warning">
240
+ <Typography variant="body2" className="font-medium mb-1">
241
+ The database was not changed
242
+ </Typography>
243
+ <Typography variant="body2">{result.applyError}</Typography>
244
+ <Typography variant="body2" className="mt-2">
245
+ The commit is on <code>{result.committed.branch}</code> either way, so the
246
+ change will be applied on the next boot.
247
+ </Typography>
248
+ </Alert>
249
+ )}
250
+
251
+ <WithheldConstraints constraints={result.withheldConstraints ?? []}/>
252
+ <FollowUp items={result.followUp ?? []}/>
253
+
254
+ <div>
255
+ <Typography variant="label" color="secondary">Committed</Typography>
256
+ <div className={cls(codeBlock, "mt-1")}>
257
+ {result.committed.sha.slice(0, 9)} on {result.committed.branch}
258
+ {"\n"}
259
+ {result.committed.files.map(file => ` ${file}`).join("\n")}
260
+ </div>
261
+ </div>
262
+ </div>
263
+ );
264
+ }
265
+
266
+ export function SchemaChangeDialog({
267
+ open,
268
+ collectionId,
269
+ plan,
270
+ planError,
271
+ result,
272
+ applying,
273
+ applyError,
274
+ onConfirm,
275
+ onRetry,
276
+ onSourceOnly,
277
+ onClose,
278
+ applyRefusedBecause,
279
+ target
280
+ }: SchemaChangeDialogProps) {
281
+
282
+ const verdict = plan?.verdict;
283
+ const statements = plan?.statements.length ?? 0;
284
+
285
+ // "Commit" only when we positively know there is nothing to apply: a plan
286
+ // that is going ahead and has no statements. A *refused* plan also has none
287
+ // — because it will not run — and labelling that button "Commit" would be
288
+ // describing the change it is refusing to make. Unknown reads as the fuller
289
+ // action, which is the safer way to be wrong about a label.
290
+ const commitOnly = Boolean(plan?.applicable) && statements === 0;
291
+
292
+ // Described from the plan rather than from an assumption about the engine.
293
+ // A document database runs nothing; so does a relational change that only
294
+ // moves source. Both are a commit, and calling either one "apply" would be
295
+ // describing something that does not happen.
296
+ const copy = verdict === "safe" && commitOnly
297
+ ? {
298
+ title: "Ready to commit",
299
+ body: "This changes what your project declares. Nothing runs against the database — " +
300
+ "there is no schema change to make.",
301
+ color: "info" as const
302
+ }
303
+ : verdict
304
+ ? VERDICT_COPY[verdict]
305
+ : undefined;
306
+
307
+ return (
308
+ <Dialog open={open} onOpenChange={value => { if (!value) onClose(); }} maxWidth="3xl">
309
+ <DialogTitle className="flex items-center gap-2">
310
+ {result ? "Schema change applied" : "Review schema change"}
311
+ <code className="text-sm font-normal text-text-secondary dark:text-text-secondary-dark">
312
+ {collectionId}
313
+ </code>
314
+ </DialogTitle>
315
+
316
+ <DialogContent className="flex flex-col gap-4">
317
+ {planError && (
318
+ <Alert color="error">
319
+ <Typography variant="body2" className="font-medium mb-1">
320
+ The change could not be planned
321
+ </Typography>
322
+ <Typography variant="body2">{planError}</Typography>
323
+ </Alert>
324
+ )}
325
+
326
+ {!plan && !planError && !result && (
327
+ <div className="flex items-center gap-3 py-6">
328
+ <CircularProgress size="small"/>
329
+ <Typography variant="body2" color="secondary">
330
+ Working out what this change would do…
331
+ </Typography>
332
+ </div>
333
+ )}
334
+
335
+ {result && <Applied result={result}/>}
336
+
337
+ {plan && !result && copy && (
338
+ <>
339
+ <Alert color={copy.color}>
340
+ <Typography variant="body2" className="font-medium mb-1">
341
+ {copy.title}
342
+ </Typography>
343
+ <Typography variant="body2">{copy.body}</Typography>
344
+ </Alert>
345
+
346
+ {applyError && (
347
+ <Alert color="error">
348
+ <Typography variant="body2">{applyError}</Typography>
349
+ </Alert>
350
+ )}
351
+
352
+ {plan.changes.length === 0 && (
353
+ <Typography variant="body2" color="secondary">
354
+ Nothing here changes the shape of your data. The collection source
355
+ is still rewritten and committed.
356
+ </Typography>
357
+ )}
358
+
359
+ {!plan.applicable && onSourceOnly && (
360
+ <Typography variant="body2" color="secondary">
361
+ You can still write the change to your collection source and leave
362
+ the database as it is — the editor’s behaviour before this preview
363
+ existed. The column stays, holding whatever is in it, and nothing
364
+ serves it.
365
+ </Typography>
366
+ )}
367
+
368
+ {plan.changes.length > 0 && (
369
+ <ul className="flex flex-col gap-3">
370
+ {plan.changes.map((change, index) => (
371
+ <li
372
+ key={`${change.collection}.${change.property ?? ""}.${index}`}
373
+ className="flex gap-3"
374
+ >
375
+ <Chip
376
+ size="smallest"
377
+ colorScheme={VERDICT_CHIP[change.verdict].scheme}
378
+ className="shrink-0 mt-0.5"
379
+ >
380
+ {VERDICT_CHIP[change.verdict].label}
381
+ </Chip>
382
+ <div className="min-w-0">
383
+ <Typography variant="body2">{change.detail}</Typography>
384
+ {change.remedy && (
385
+ <Typography
386
+ variant="body2"
387
+ color="secondary"
388
+ className="mt-1"
389
+ >
390
+ {change.remedy}
391
+ </Typography>
392
+ )}
393
+ </div>
394
+ </li>
395
+ ))}
396
+ </ul>
397
+ )}
398
+
399
+ <WithheldConstraints constraints={plan.withheldConstraints ?? []}/>
400
+ <FollowUp items={plan.followUp ?? []}/>
401
+
402
+ {applyRefusedBecause && (
403
+ <Alert color="info">
404
+ <Typography variant="body2" className="font-medium mb-1">
405
+ You can preview this change, but not apply it
406
+ </Typography>
407
+ <Typography variant="body2">{applyRefusedBecause}</Typography>
408
+ </Alert>
409
+ )}
410
+
411
+ <Details summary="Statements that will run" count={plan.statements.length}>
412
+ <div className={codeBlock}>{plan.statements.join("\n")}</div>
413
+ </Details>
414
+
415
+ <Details summary="Files that will be committed" count={plan.files.length}>
416
+ <div className={codeBlock}>{plan.files.join("\n")}</div>
417
+ </Details>
418
+
419
+ <Details summary="Commit message" count={plan.message ? 1 : 0}>
420
+ <div className={codeBlock}>{plan.message}</div>
421
+ </Details>
422
+ </>
423
+ )}
424
+ </DialogContent>
425
+
426
+ <DialogActions>
427
+ {!result && target?.repository && (
428
+ <span className={cls(
429
+ monospace,
430
+ "mr-auto text-text-secondary dark:text-text-secondary-dark truncate"
431
+ )}>
432
+ → {repositoryLabel(target.repository)}{target.branch ? ` · ${target.branch}` : ""}
433
+ </span>
434
+ )}
435
+ <Button variant="text" onClick={onClose} disabled={applying}>
436
+ {result ? "Close" : "Cancel"}
437
+ </Button>
438
+ {!result && planError && onRetry && (
439
+ <Button variant="outlined" onClick={onRetry}>
440
+ Try again
441
+ </Button>
442
+ )}
443
+ {!result && plan && !plan.applicable && onSourceOnly && (
444
+ <Button variant="outlined" onClick={onSourceOnly} disabled={applying}>
445
+ Edit source only
446
+ </Button>
447
+ )}
448
+ {!result && (
449
+ <Button
450
+ variant="filled"
451
+ color="primary"
452
+ onClick={onConfirm}
453
+ // `applicable` is the server's word, not a
454
+ // re-derivation from the verdicts on screen:
455
+ // `applySchemaChange` re-checks it before it writes
456
+ // anything, so a button that disagreed would only
457
+ // produce the same refusal one click later. The same
458
+ // goes for the permission — `/apply` checks it too, and
459
+ // this only saves somebody the round trip.
460
+ disabled={!plan?.applicable || applying || Boolean(applyRefusedBecause)}
461
+ >
462
+ {applying
463
+ ? (commitOnly ? "Committing…" : "Applying…")
464
+ : (commitOnly ? "Commit" : "Commit and apply")}
465
+ </Button>
466
+ )}
467
+ </DialogActions>
468
+ </Dialog>
469
+ );
470
+ }