@aglyn/plugins-data 1.20.3 → 1.22.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aglyn/plugins-data",
3
- "version": "1.20.3",
3
+ "version": "1.22.0",
4
4
  "license": "Apache-2.0",
5
5
  "homepage": "https://aglyn.com",
6
6
  "repository": {
@@ -25,17 +25,17 @@
25
25
  "./package.json": "./package.json"
26
26
  },
27
27
  "dependencies": {
28
- "@aglyn/aglyn": "1.20.3",
29
- "@aglyn/shared-data-mdi": "1.20.3",
30
- "@aglyn/shared-ui-jsx": "1.20.3",
31
- "@aglyn/shared-ui-next": "1.20.3",
32
- "@aglyn/shared-ui-snackstack": "1.20.3",
33
- "@aglyn/shared-util-http": "1.20.3",
34
- "@aglyn/shared-util-timestamp": "1.20.3",
35
- "@aglyn/tenant-data-admin": "1.20.3",
36
- "@aglyn/tenant-feature-instance": "1.20.3",
37
- "@aglyn/tenant-runtime": "1.20.3",
38
- "@swc/helpers": "0.5.23"
28
+ "@aglyn/aglyn": "1.22.0",
29
+ "@aglyn/shared-data-mdi": "1.22.0",
30
+ "@aglyn/shared-ui-jsx": "1.22.0",
31
+ "@aglyn/shared-ui-next": "1.22.0",
32
+ "@aglyn/shared-ui-snackstack": "1.22.0",
33
+ "@aglyn/shared-util-http": "1.22.0",
34
+ "@aglyn/shared-util-timestamp": "1.22.0",
35
+ "@aglyn/tenant-data-admin": "1.22.0",
36
+ "@aglyn/tenant-feature-instance": "1.22.0",
37
+ "@aglyn/tenant-runtime": "1.22.0",
38
+ "@swc/helpers": "0.5.24"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "@mui/material": "^9.3.1",
@@ -51,16 +51,6 @@ export interface DatasetSchemaDialogProps {
51
51
  sharingOnlyReason?: string;
52
52
  onClose: () => void;
53
53
  }
54
- /**
55
- * Model builder (AGL-178): edits the AGL-177 typed model on a dataset —
56
- * singular/plural display names (dod.ts Schema.Name), add/edit/remove/
57
- * reorder fields, per-field type/required/default/description/validation.
58
- * Schema-change policies (documented per the issue): type changes never
59
- * rewrite documents — non-conforming values surface in the editor when it
60
- * validates (AGL-179); removed fields leave orphaned values that strip
61
- * lazily on next document save; fieldIds are stable keys — only display
62
- * names rename.
63
- */
64
54
  export declare function DatasetSchemaDialog(props: DatasetSchemaDialogProps): import("react").JSX.Element;
65
55
  export declare namespace DatasetSchemaDialog {
66
56
  var displayName: string;
@@ -25,6 +25,8 @@ import { Button, Checkbox, Alert, Box, Chip, Dialog, DialogActions, DialogConten
25
25
  import { doc, updateDoc } from "firebase/firestore";
26
26
  import { useCallback, useEffect, useMemo, useState } from "react";
27
27
  import { useFirestore, useOrgDataScope, useScopeTokens, useUser, writeGuardedBySeed } from "@aglyn/tenant-feature-instance";
28
+ import { isSeedChecking, seedCheckingText, useHeldSave, useSeedEdits } from "@aglyn/tenant-feature-instance/hooks/use-seed-edits";
29
+ import { seedEditsBetween } from "@aglyn/tenant-feature-instance/hooks/use-seed-draft";
28
30
  import { DATASET_AUTHORABLE_FIELD_TYPES, DATASET_FIELD_TYPES, DATASET_FIELD_TYPE_LABELS, effectiveDatasetModel } from "../model/dataset-models.js";
29
31
  import { datasetDisplayName, datasetNameLower, defaultDatasetFieldId, validateDatasetFieldId } from "../model/datasets.js";
30
32
  import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-pages/record-pages.js";
@@ -73,16 +75,7 @@ import { datasetPickerLabelsOf } from "../model/dataset-rail.js";
73
75
  ...picked
74
76
  ].sort().join(',')}`;
75
77
  }
76
- /**
77
- * Model builder (AGL-178): edits the AGL-177 typed model on a dataset —
78
- * singular/plural display names (dod.ts Schema.Name), add/edit/remove/
79
- * reorder fields, per-field type/required/default/description/validation.
80
- * Schema-change policies (documented per the issue): type changes never
81
- * rewrite documents — non-conforming values surface in the editor when it
82
- * validates (AGL-179); removed fields leave orphaned values that strip
83
- * lazily on next document save; fieldIds are stable keys — only display
84
- * names rename.
85
- */ export function DatasetSchemaDialog(props) {
78
+ export function DatasetSchemaDialog(props) {
86
79
  var _ref, _ref1, _ref2, _ref3, _ref4, _ref5, _editorDefinition_slugFrom, _ref6, _ref7, _find, _ref8, _ref9, _ref10, _ref11;
87
80
  var _editorDefinition_reference, _editorDefinition_reference1, _editorDefinition_reference2, _editorDefinition_reference3, _editorDefinition_validation;
88
81
  const { hostId, dataset, datasets, recordCount, seedFromCache, seedUnreadable, seedListen, canChangeSharing = true, sharingOnlyReason, onClose } = props;
@@ -157,18 +150,21 @@ import { datasetPickerLabelsOf } from "../model/dataset-rail.js";
157
150
  }, [
158
151
  sharingDraft
159
152
  ]);
160
- const [model, setModel] = useState({
161
- fields: {},
162
- order: []
163
- });
164
- const [names, setNames] = useState({
165
- singular: '',
166
- plural: ''
167
- });
168
- useEffect(()=>{
153
+ /*
154
+ * The schema and the names, kept as EDITS over the dataset (AGL-4047).
155
+ * They used to be reset from every snapshot of it, so the server's answer
156
+ * landing after a keystroke took what was typed; now a key the reader
157
+ * changed keeps their value and every other key follows the dataset, and
158
+ * Save is held until the server has answered (`checkingText`).
159
+ */ const schemaSeed = useMemo(()=>{
169
160
  var _ref, _ref1;
170
161
  var _dataset_names, _dataset_names1;
171
- if (!dataset) return;
162
+ if (!dataset) return {
163
+ fields: {},
164
+ order: [],
165
+ singular: '',
166
+ plural: ''
167
+ };
172
168
  // The fourth copy of the AGL-1466 substitution (AGL-1484), and the seed
173
169
  // half of it. Persisting the default on open was the other option and
174
170
  // AGL-1466 ruled it out: opening a dialog would write, the AGL-1042
@@ -178,19 +174,64 @@ import { datasetPickerLabelsOf } from "../model/dataset-rail.js";
178
174
  // for why the pair is the safety property. The sharing is seeded by the
179
175
  // effect below.
180
176
  const effective = effectiveDatasetModel(dataset);
181
- setModel({
177
+ return {
182
178
  fields: JSON.parse(JSON.stringify(effective.fields)),
183
179
  order: [
184
180
  ...effective.order
185
- ]
186
- });
187
- setNames({
181
+ ],
188
182
  singular: (_ref = (_dataset_names = dataset.names) == null ? void 0 : _dataset_names.singular) != null ? _ref : '',
189
183
  plural: (_ref1 = (_dataset_names1 = dataset.names) == null ? void 0 : _dataset_names1.plural) != null ? _ref1 : datasetDisplayName(dataset)
190
- });
184
+ };
191
185
  }, [
192
186
  dataset
193
187
  ]);
188
+ const schema = useSeedEdits(schemaSeed);
189
+ const { fields: modelFields, order: modelOrder, singular, plural } = schema.values;
190
+ const model = useMemo(()=>({
191
+ fields: modelFields,
192
+ order: modelOrder
193
+ }), [
194
+ modelFields,
195
+ modelOrder
196
+ ]);
197
+ const names = useMemo(()=>({
198
+ singular,
199
+ plural
200
+ }), [
201
+ singular,
202
+ plural
203
+ ]);
204
+ const { edit: editSchema, discard: discardSchema } = schema;
205
+ const setModel = useCallback((next)=>editSchema((values)=>{
206
+ const previous = {
207
+ fields: values.fields,
208
+ order: values.order
209
+ };
210
+ return seedEditsBetween(values, _extends({}, values, typeof next === 'function' ? next(previous) : next));
211
+ }), [
212
+ editSchema
213
+ ]);
214
+ const setNames = useCallback((next)=>editSchema((values)=>{
215
+ const previous = {
216
+ singular: values.singular,
217
+ plural: values.plural
218
+ };
219
+ return seedEditsBetween(values, _extends({}, values, typeof next === 'function' ? next(previous) : next));
220
+ }), [
221
+ editSchema
222
+ ]);
223
+ // Fresh edits for each dataset the dialog is opened on.
224
+ const datasetId = dataset == null ? void 0 : dataset.$id;
225
+ useEffect(()=>{
226
+ discardSchema();
227
+ }, [
228
+ datasetId,
229
+ discardSchema
230
+ ]);
231
+ const checkingText = isSeedChecking({
232
+ fromCache: seedFromCache,
233
+ unreadable: seedUnreadable
234
+ }) ? seedCheckingText('collection schema') : undefined;
194
235
  /*
195
236
  * The sharing, seeded for this dataset and again only when its STORED
196
237
  * sharing moves, not on every snapshot of it (AGL-4047). A save writes the
@@ -283,6 +324,7 @@ import { datasetPickerLabelsOf } from "../model/dataset-rail.js";
283
324
  }));
284
325
  setFieldEditor(null);
285
326
  }, [
327
+ setModel,
286
328
  fieldEditor,
287
329
  model,
288
330
  recordCount,
@@ -310,6 +352,7 @@ import { datasetPickerLabelsOf } from "../model/dataset-rail.js";
310
352
  };
311
353
  });
312
354
  }, [
355
+ setModel,
313
356
  model,
314
357
  confirm
315
358
  ]);
@@ -325,7 +368,9 @@ import { datasetPickerLabelsOf } from "../model/dataset-rail.js";
325
368
  return _extends({}, prev, {
326
369
  order
327
370
  });
328
- }), []);
371
+ }), [
372
+ setModel
373
+ ]);
329
374
  const handleSave = useCallback(async ()=>{
330
375
  var _storedScope;
331
376
  if (!dataset || !dataScope) return;
@@ -500,6 +545,15 @@ import { datasetPickerLabelsOf } from "../model/dataset-rail.js";
500
545
  // field; live-validate the draft so the input and Save button can react.
501
546
  const isNewField = fieldEditor != null && fieldEditor.fieldId == null;
502
547
  const fieldIdError = fieldEditor && isNewField ? validateDatasetFieldId(fieldEditor.idDraft, new Set(model.order.map((id)=>id.toLowerCase()))) : null;
548
+ // A press while Save is held is kept, and saves once confirmed (AGL-4047).
549
+ const held = useHeldSave(handleSave, {
550
+ checking: Boolean(checkingText),
551
+ subject: 'collection schema',
552
+ onRefused: (message)=>enqueueSnackbar(message, {
553
+ variant: 'warning',
554
+ persist: false
555
+ })
556
+ });
503
557
  return /*#__PURE__*/ _jsxs(_Fragment, {
504
558
  children: [
505
559
  /*#__PURE__*/ _jsxs(Dialog, {
@@ -695,6 +749,15 @@ import { datasetPickerLabelsOf } from "../model/dataset-rail.js";
695
749
  }),
696
750
  /*#__PURE__*/ _jsxs(DialogActions, {
697
751
  children: [
752
+ checkingText ? /*#__PURE__*/ _jsx(Typography, {
753
+ variant: "body2",
754
+ color: "text.secondary",
755
+ role: "status",
756
+ sx: {
757
+ mr: 'auto'
758
+ },
759
+ children: checkingText
760
+ }) : null,
698
761
  /*#__PURE__*/ _jsx(Button, {
699
762
  onClick: onClose,
700
763
  children: 'Cancel'
@@ -702,9 +765,9 @@ import { datasetPickerLabelsOf } from "../model/dataset-rail.js";
702
765
  /*#__PURE__*/ _jsx(Button, {
703
766
  variant: "contained",
704
767
  color: "primary",
705
- disabled: !dataScope,
706
- onClick: handleSave,
707
- children: sharingOnlyReason ? 'Save sharing' : 'Save schema'
768
+ disabled: !dataScope || held.saving,
769
+ onClick: held.press,
770
+ children: held.saving ? 'Saving…' : sharingOnlyReason ? 'Save sharing' : 'Save schema'
708
771
  })
709
772
  ]
710
773
  })