@aglyn/plugins-data 1.12.0 → 1.13.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.
Files changed (32) hide show
  1. package/package.json +10 -10
  2. package/src/lib/components/dataset-schema-dialog.component.d.ts +14 -0
  3. package/src/lib/components/dataset-schema-dialog.component.js +150 -117
  4. package/src/lib/components/dataset-schema-dialog.component.js.map +1 -1
  5. package/src/lib/components/host-datasets-card.component.js +71 -34
  6. package/src/lib/components/host-datasets-card.component.js.map +1 -1
  7. package/src/lib/components/use-dataset-writes-blocked.d.ts +49 -12
  8. package/src/lib/components/use-dataset-writes-blocked.js +87 -19
  9. package/src/lib/components/use-dataset-writes-blocked.js.map +1 -1
  10. package/src/lib/declarations.d.ts +25 -0
  11. package/src/lib/declarations.js +37 -0
  12. package/src/lib/declarations.js.map +1 -0
  13. package/src/lib/model/data-permissions.d.ts +34 -0
  14. package/src/lib/model/data-permissions.js +108 -0
  15. package/src/lib/model/data-permissions.js.map +1 -0
  16. package/src/lib/model/dataset-access.d.ts +22 -0
  17. package/src/lib/model/dataset-access.js +30 -0
  18. package/src/lib/model/dataset-access.js.map +1 -0
  19. package/src/lib/plugin.js +4 -1
  20. package/src/lib/plugin.js.map +1 -1
  21. package/src/lib/server/dataset-access.server.d.ts +40 -0
  22. package/src/lib/server/dataset-access.server.js +47 -0
  23. package/src/lib/server/dataset-access.server.js.map +1 -0
  24. package/src/lib/server/dataset-figures.js +12 -0
  25. package/src/lib/server/dataset-figures.js.map +1 -1
  26. package/src/lib/server/datasets-route.js +61 -15
  27. package/src/lib/server/datasets-route.js.map +1 -1
  28. package/src/lib/transfer/dataset-transfer-access.server.d.ts +23 -0
  29. package/src/lib/transfer/dataset-transfer-access.server.js +45 -0
  30. package/src/lib/transfer/dataset-transfer-access.server.js.map +1 -0
  31. package/src/lib/transfer/dataset-transfer-resource.js +2 -1
  32. package/src/lib/transfer/dataset-transfer-resource.js.map +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aglyn/plugins-data",
3
- "version": "1.12.0",
3
+ "version": "1.13.0",
4
4
  "license": "Apache-2.0",
5
5
  "homepage": "https://aglyn.com",
6
6
  "repository": {
@@ -25,15 +25,15 @@
25
25
  "./package.json": "./package.json"
26
26
  },
27
27
  "dependencies": {
28
- "@aglyn/aglyn": "1.12.0",
29
- "@aglyn/shared-data-mdi": "1.12.0",
30
- "@aglyn/shared-ui-jsx": "1.12.0",
31
- "@aglyn/shared-ui-snackstack": "1.12.0",
32
- "@aglyn/shared-util-http": "1.12.0",
33
- "@aglyn/shared-util-timestamp": "1.12.0",
34
- "@aglyn/tenant-data-admin": "1.12.0",
35
- "@aglyn/tenant-feature-instance": "1.12.0",
36
- "@aglyn/tenant-runtime": "1.12.0",
28
+ "@aglyn/aglyn": "1.13.0",
29
+ "@aglyn/shared-data-mdi": "1.13.0",
30
+ "@aglyn/shared-ui-jsx": "1.13.0",
31
+ "@aglyn/shared-ui-snackstack": "1.13.0",
32
+ "@aglyn/shared-util-http": "1.13.0",
33
+ "@aglyn/shared-util-timestamp": "1.13.0",
34
+ "@aglyn/tenant-data-admin": "1.13.0",
35
+ "@aglyn/tenant-feature-instance": "1.13.0",
36
+ "@aglyn/tenant-runtime": "1.13.0",
37
37
  "@swc/helpers": "0.5.23"
38
38
  },
39
39
  "peerDependencies": {
@@ -35,6 +35,20 @@ export interface DatasetSchemaDialogProps {
35
35
  seedUnreadable?: boolean;
36
36
  /** That listener, so a save waits on that read alone (AGL-4135). */
37
37
  seedListen?: ListenHandle | null;
38
+ /**
39
+ * Whether this member may change who the dataset is shared with: "Manage
40
+ * data" with every site in reach. A site's verdict writes the dataset and never
41
+ * moves it, so someone it admits reads the sharing instead (AGL-4047).
42
+ */
43
+ canChangeSharing?: boolean;
44
+ /**
45
+ * Why this member may change who the dataset is shared with and nothing else
46
+ * here, or absent where they may change it all (AGL-4047): a site that narrows
47
+ * them takes the dataset's schema and records, and sharing is not among those.
48
+ * The schema shows switched off, with this reason, and a save writes the
49
+ * sharing alone.
50
+ */
51
+ sharingOnlyReason?: string;
38
52
  onClose: () => void;
39
53
  }
40
54
  /**
@@ -19,7 +19,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
19
19
  import { getCustomFieldType, listCustomFieldTypes, describeScope, HOST_ACCESS_ROLES, hostScopeToken, narrowsScope, scopeCovers, ORG_SCOPE_TOKEN, scopeToStore, storedScope, visibleToHost } from "@aglyn/aglyn";
20
20
  import { useConfirmationContext } from "@aglyn/shared-ui-jsx";
21
21
  import { useSnackbar } from "@aglyn/shared-ui-snackstack";
22
- import { Button, Checkbox, Alert, Chip, Dialog, DialogActions, DialogContent, DialogTitle, FormControlLabel, IconButton, MenuItem, Select, Stack, TextField, Typography } from "@mui/material";
22
+ import { Button, Checkbox, Alert, Box, Chip, Dialog, DialogActions, DialogContent, DialogTitle, FormControlLabel, IconButton, MenuItem, Select, Stack, TextField, Typography } from "@mui/material";
23
23
  import { collection, doc, limit, query, updateDoc, where } from "firebase/firestore";
24
24
  import { useCallback, useEffect, useState } from "react";
25
25
  import { useFirestore, useFirestoreCollection, useOrgDataScope, useScopeTokens, useUser, writeGuardedBySeed } from "@aglyn/tenant-feature-instance";
@@ -27,6 +27,21 @@ import { DATASET_AUTHORABLE_FIELD_TYPES, DATASET_FIELD_TYPES, DATASET_FIELD_TYPE
27
27
  import { datasetDisplayName, defaultDatasetFieldId, validateDatasetFieldId } from "../model/datasets.js";
28
28
  import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-pages/record-pages.js";
29
29
  /** Types surfaced in the picker; the rest exist for compat, not authoring. */ const AUTHORABLE_TYPES = DATASET_AUTHORABLE_FIELD_TYPES;
30
+ /** The dialog's schema controls, switched off together where only the sharing is this member's. */ function SchemaControls(props) {
31
+ return props.locked ? /*#__PURE__*/ _jsx(Box, {
32
+ component: "fieldset",
33
+ disabled: true,
34
+ sx: {
35
+ border: 0,
36
+ m: 0,
37
+ p: 0,
38
+ minWidth: 0
39
+ },
40
+ children: props.children
41
+ }) : /*#__PURE__*/ _jsx(_Fragment, {
42
+ children: props.children
43
+ });
44
+ }
30
45
  /**
31
46
  * Model builder (AGL-178): edits the AGL-177 typed model on a dataset —
32
47
  * singular/plural display names (dod.ts Schema.Name), add/edit/remove/
@@ -39,7 +54,7 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
39
54
  */ export function DatasetSchemaDialog(props) {
40
55
  var _ref, _ref1, _ref2, _ref3, _ref4, _editorDefinition_slugFrom, _ref5, _ref6, _find, _ref7, _ref8, _ref9, _ref10;
41
56
  var _editorDefinition_reference, _editorDefinition_reference1, _editorDefinition_reference2, _editorDefinition_reference3, _editorDefinition_validation;
42
- const { hostId, dataset, datasets, recordCount, seedFromCache, seedUnreadable, seedListen, onClose } = props;
57
+ const { hostId, dataset, datasets, recordCount, seedFromCache, seedUnreadable, seedListen, canChangeSharing = true, sharingOnlyReason, onClose } = props;
43
58
  // Org-shared data root (AGL-237/239). Null until the async org lookup
44
59
  // settles (AGL-1061), and for a host with no owning org. Saving is held
45
60
  // on it rather than redirected: the host path this used to fall back to
@@ -287,7 +302,7 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
287
302
  * picked, or more sites than one query can match — refuses the save rather
288
303
  * than substituting a scope: the org token would share the collection with
289
304
  * every site, and anything narrower would drop sites somebody picked.
290
- */ const scopeWrite = orgId && viewerOrgWide && scopeChanged ? scopeToStore(visibleTo) : null;
305
+ */ const scopeWrite = orgId && viewerOrgWide && canChangeSharing && scopeChanged ? scopeToStore(visibleTo) : null;
291
306
  if (scopeWrite == null ? void 0 : scopeWrite.problem) {
292
307
  return void enqueueSnackbar(scopeWrite.problem, {
293
308
  variant: 'warning',
@@ -309,6 +324,8 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
309
324
  }).then(()=>true).catch(()=>false);
310
325
  if (!proceed) return;
311
326
  }
327
+ // Nothing of theirs to write when the sharing did not move.
328
+ if (sharingOnlyReason && !(scopeWrite == null ? void 0 : scopeWrite.scope)) return void onClose();
312
329
  if (!model.order.length) {
313
330
  return void enqueueSnackbar('A collection needs at least one field', {
314
331
  variant: 'warning',
@@ -335,7 +352,9 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
335
352
  unreadable: seedUnreadable,
336
353
  fromCache: seedFromCache,
337
354
  listen: seedListen
338
- }, async ()=>void await updateDoc(doc(firestore, dataScope[0], dataScope[1], 'datasets', dataset.$id), _extends({
355
+ }, async ()=>void await updateDoc(doc(firestore, dataScope[0], dataScope[1], 'datasets', dataset.$id), sharingOnlyReason ? (scopeWrite == null ? void 0 : scopeWrite.scope) ? {
356
+ visibleTo: scopeWrite.scope
357
+ } : {} : _extends({
339
358
  model,
340
359
  names: {
341
360
  singular: names.singular.trim(),
@@ -357,7 +376,7 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
357
376
  persist: false
358
377
  });
359
378
  }
360
- enqueueSnackbar('Schema saved', {
379
+ enqueueSnackbar(sharingOnlyReason ? 'Sharing saved' : 'Schema saved', {
361
380
  variant: 'success',
362
381
  persist: false
363
382
  });
@@ -371,6 +390,8 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
371
390
  names,
372
391
  visibleTo,
373
392
  viewerOrgWide,
393
+ canChangeSharing,
394
+ sharingOnlyReason,
374
395
  orgHostList,
375
396
  confirm,
376
397
  firestore,
@@ -405,32 +426,39 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
405
426
  gap: 2
406
427
  },
407
428
  children: [
408
- /*#__PURE__*/ _jsxs(Stack, {
409
- direction: "row",
410
- spacing: 1,
411
- sx: {
412
- mt: 1
413
- },
414
- children: [
415
- /*#__PURE__*/ _jsx(TextField, {
416
- size: "small",
417
- label: "Singular name",
418
- value: names.singular,
419
- onChange: (event)=>setNames((prev)=>_extends({}, prev, {
420
- singular: event.target.value
421
- })),
422
- helperText: "e.g. Product"
423
- }),
424
- /*#__PURE__*/ _jsx(TextField, {
425
- size: "small",
426
- label: "Plural name",
427
- value: names.plural,
428
- onChange: (event)=>setNames((prev)=>_extends({}, prev, {
429
- plural: event.target.value
430
- })),
431
- helperText: "e.g. Products (shown as the title)"
432
- })
433
- ]
429
+ sharingOnlyReason ? /*#__PURE__*/ _jsx(Alert, {
430
+ severity: "info",
431
+ children: sharingOnlyReason
432
+ }) : null,
433
+ /*#__PURE__*/ _jsx(SchemaControls, {
434
+ locked: Boolean(sharingOnlyReason),
435
+ children: /*#__PURE__*/ _jsxs(Stack, {
436
+ direction: "row",
437
+ spacing: 1,
438
+ sx: {
439
+ mt: 1
440
+ },
441
+ children: [
442
+ /*#__PURE__*/ _jsx(TextField, {
443
+ size: "small",
444
+ label: "Singular name",
445
+ value: names.singular,
446
+ onChange: (event)=>setNames((prev)=>_extends({}, prev, {
447
+ singular: event.target.value
448
+ })),
449
+ helperText: "e.g. Product"
450
+ }),
451
+ /*#__PURE__*/ _jsx(TextField, {
452
+ size: "small",
453
+ label: "Plural name",
454
+ value: names.plural,
455
+ onChange: (event)=>setNames((prev)=>_extends({}, prev, {
456
+ plural: event.target.value
457
+ })),
458
+ helperText: "e.g. Products (shown as the title)"
459
+ })
460
+ ]
461
+ })
434
462
  }),
435
463
  orgId ? /*#__PURE__*/ _jsxs(Stack, {
436
464
  spacing: 0.5,
@@ -444,7 +472,7 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
444
472
  variant: "body2",
445
473
  color: "text.secondary",
446
474
  children: 'Checking your access…'
447
- }) : viewerOrgWide ? /*#__PURE__*/ _jsxs(_Fragment, {
475
+ }) : viewerOrgWide && canChangeSharing ? /*#__PURE__*/ _jsxs(_Fragment, {
448
476
  children: [
449
477
  scopeUnset ? /*#__PURE__*/ _jsx(Alert, {
450
478
  severity: "warning",
@@ -524,99 +552,104 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
524
552
  })
525
553
  ]
526
554
  }) : null,
527
- /*#__PURE__*/ _jsx(Stack, {
528
- spacing: 0.5,
529
- children: model.order.map((fieldId, index)=>{
530
- var _DATASET_FIELD_TYPE_LABELS_field_type;
531
- var _field_validation;
532
- const field = model.fields[fieldId];
533
- if (!field) return null;
534
- return /*#__PURE__*/ _jsxs(Stack, {
535
- direction: "row",
536
- spacing: 1,
537
- sx: {
538
- alignItems: 'center',
539
- px: 1,
540
- py: 0.5,
541
- border: '1px solid',
542
- borderColor: 'divider',
543
- borderRadius: 1
544
- },
545
- children: [
546
- /*#__PURE__*/ _jsxs(Stack, {
555
+ /*#__PURE__*/ _jsxs(SchemaControls, {
556
+ locked: Boolean(sharingOnlyReason),
557
+ children: [
558
+ /*#__PURE__*/ _jsx(Stack, {
559
+ spacing: 0.5,
560
+ children: model.order.map((fieldId, index)=>{
561
+ var _DATASET_FIELD_TYPE_LABELS_field_type;
562
+ var _field_validation;
563
+ const field = model.fields[fieldId];
564
+ if (!field) return null;
565
+ return /*#__PURE__*/ _jsxs(Stack, {
566
+ direction: "row",
567
+ spacing: 1,
547
568
  sx: {
548
- flex: 1,
549
- minWidth: 0
569
+ alignItems: 'center',
570
+ px: 1,
571
+ py: 0.5,
572
+ border: '1px solid',
573
+ borderColor: 'divider',
574
+ borderRadius: 1
550
575
  },
551
576
  children: [
552
- /*#__PURE__*/ _jsxs(Typography, {
553
- variant: "body2",
554
- noWrap: true,
577
+ /*#__PURE__*/ _jsxs(Stack, {
578
+ sx: {
579
+ flex: 1,
580
+ minWidth: 0
581
+ },
555
582
  children: [
556
- field.name,
557
- /*#__PURE__*/ _jsx(Typography, {
558
- component: "span",
583
+ /*#__PURE__*/ _jsxs(Typography, {
584
+ variant: "body2",
585
+ noWrap: true,
586
+ children: [
587
+ field.name,
588
+ /*#__PURE__*/ _jsx(Typography, {
589
+ component: "span",
590
+ variant: "caption",
591
+ color: "text.secondary",
592
+ children: ` · ${fieldId}`
593
+ })
594
+ ]
595
+ }),
596
+ field.description ? /*#__PURE__*/ _jsx(Typography, {
559
597
  variant: "caption",
560
598
  color: "text.secondary",
561
- children: ` · ${fieldId}`
562
- })
599
+ noWrap: true,
600
+ children: field.description
601
+ }) : null
563
602
  ]
564
603
  }),
565
- field.description ? /*#__PURE__*/ _jsx(Typography, {
566
- variant: "caption",
567
- color: "text.secondary",
568
- noWrap: true,
569
- children: field.description
570
- }) : null
604
+ /*#__PURE__*/ _jsx(Chip, {
605
+ size: "small",
606
+ label: (_DATASET_FIELD_TYPE_LABELS_field_type = DATASET_FIELD_TYPE_LABELS[field.type]) != null ? _DATASET_FIELD_TYPE_LABELS_field_type : field.type
607
+ }),
608
+ field.required || ((_field_validation = field.validation) == null ? void 0 : _field_validation.required) ? /*#__PURE__*/ _jsx(Chip, {
609
+ size: "small",
610
+ color: "primary",
611
+ label: "required"
612
+ }) : null,
613
+ /*#__PURE__*/ _jsx(IconButton, {
614
+ size: "small",
615
+ disabled: index === 0,
616
+ onClick: moveField(fieldId, -1),
617
+ "aria-label": "Move up",
618
+ children: '▲'
619
+ }),
620
+ /*#__PURE__*/ _jsx(IconButton, {
621
+ size: "small",
622
+ disabled: index === model.order.length - 1,
623
+ onClick: moveField(fieldId, 1),
624
+ "aria-label": "Move down",
625
+ children: '▼'
626
+ }),
627
+ /*#__PURE__*/ _jsx(Button, {
628
+ size: "small",
629
+ onClick: openFieldEditor(fieldId),
630
+ children: 'Edit'
631
+ }),
632
+ /*#__PURE__*/ _jsx(Button, {
633
+ size: "small",
634
+ color: "error",
635
+ onClick: handleFieldRemove(fieldId),
636
+ children: 'Remove'
637
+ })
571
638
  ]
572
- }),
573
- /*#__PURE__*/ _jsx(Chip, {
574
- size: "small",
575
- label: (_DATASET_FIELD_TYPE_LABELS_field_type = DATASET_FIELD_TYPE_LABELS[field.type]) != null ? _DATASET_FIELD_TYPE_LABELS_field_type : field.type
576
- }),
577
- field.required || ((_field_validation = field.validation) == null ? void 0 : _field_validation.required) ? /*#__PURE__*/ _jsx(Chip, {
578
- size: "small",
579
- color: "primary",
580
- label: "required"
581
- }) : null,
582
- /*#__PURE__*/ _jsx(IconButton, {
583
- size: "small",
584
- disabled: index === 0,
585
- onClick: moveField(fieldId, -1),
586
- "aria-label": "Move up",
587
- children: '▲'
588
- }),
589
- /*#__PURE__*/ _jsx(IconButton, {
590
- size: "small",
591
- disabled: index === model.order.length - 1,
592
- onClick: moveField(fieldId, 1),
593
- "aria-label": "Move down",
594
- children: '▼'
595
- }),
596
- /*#__PURE__*/ _jsx(Button, {
597
- size: "small",
598
- onClick: openFieldEditor(fieldId),
599
- children: 'Edit'
600
- }),
601
- /*#__PURE__*/ _jsx(Button, {
602
- size: "small",
603
- color: "error",
604
- onClick: handleFieldRemove(fieldId),
605
- children: 'Remove'
606
- })
607
- ]
608
- }, fieldId);
609
- })
610
- }),
611
- /*#__PURE__*/ _jsx(Button, {
612
- size: "small",
613
- variant: "outlined",
614
- color: "primary",
615
- onClick: openFieldEditor(null),
616
- sx: {
617
- alignSelf: 'flex-start'
618
- },
619
- children: 'Add field'
639
+ }, fieldId);
640
+ })
641
+ }),
642
+ /*#__PURE__*/ _jsx(Button, {
643
+ size: "small",
644
+ variant: "outlined",
645
+ color: "primary",
646
+ onClick: openFieldEditor(null),
647
+ sx: {
648
+ alignSelf: 'flex-start'
649
+ },
650
+ children: 'Add field'
651
+ })
652
+ ]
620
653
  })
621
654
  ]
622
655
  }),
@@ -631,7 +664,7 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
631
664
  color: "primary",
632
665
  disabled: !dataScope,
633
666
  onClick: handleSave,
634
- children: 'Save schema'
667
+ children: sharingOnlyReason ? 'Save sharing' : 'Save schema'
635
668
  })
636
669
  ]
637
670
  })