@aglyn/plugins-data 1.11.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 (35) 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 +238 -86
  6. package/src/lib/components/host-datasets-card.component.js.map +1 -1
  7. package/src/lib/components/use-dataset-writes-blocked.d.ts +84 -0
  8. package/src/lib/components/use-dataset-writes-blocked.js +129 -0
  9. package/src/lib/components/use-dataset-writes-blocked.js.map +1 -0
  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/model/dataset-record-list.d.ts +16 -0
  20. package/src/lib/model/dataset-record-list.js +16 -2
  21. package/src/lib/model/dataset-record-list.js.map +1 -1
  22. package/src/lib/plugin.js +4 -1
  23. package/src/lib/plugin.js.map +1 -1
  24. package/src/lib/server/dataset-access.server.d.ts +40 -0
  25. package/src/lib/server/dataset-access.server.js +47 -0
  26. package/src/lib/server/dataset-access.server.js.map +1 -0
  27. package/src/lib/server/dataset-figures.js +12 -0
  28. package/src/lib/server/dataset-figures.js.map +1 -1
  29. package/src/lib/server/datasets-route.js +61 -15
  30. package/src/lib/server/datasets-route.js.map +1 -1
  31. package/src/lib/transfer/dataset-transfer-access.server.d.ts +23 -0
  32. package/src/lib/transfer/dataset-transfer-access.server.js +45 -0
  33. package/src/lib/transfer/dataset-transfer-access.server.js.map +1 -0
  34. package/src/lib/transfer/dataset-transfer-resource.js +2 -1
  35. package/src/lib/transfer/dataset-transfer-resource.js.map +1 -1
@@ -29,7 +29,7 @@ import { useListGridFilter } from "@aglyn/shared-ui-jsx/hooks/use-list-grid-filt
29
29
  import { useSnackbar } from "@aglyn/shared-ui-snackstack";
30
30
  import { Timestamp } from "@aglyn/shared-util-timestamp";
31
31
  import { Alert, Button, Chip, Dialog, DialogActions, DialogContent, DialogTitle, MenuItem, Stack, TextField, Tooltip, Typography } from "@mui/material";
32
- import { collection, deleteDoc, deleteField, doc, getCountFromServer, getDocs, limit, query, where, setDoc, writeBatch } from "firebase/firestore";
32
+ import { collection, deleteDoc, deleteField, doc, getCountFromServer, getDoc, getDocs, limit, query, where, setDoc, writeBatch } from "firebase/firestore";
33
33
  import { useCallback, useEffect, useMemo, useState } from "react";
34
34
  import { useListColumnSort } from "@aglyn/shared-ui-jsx/hooks/use-list-column-sort";
35
35
  import { useFirestore, useFirestoreCollection, useHostActivityLogger, useOrgDataScope, usePagedCollection, useScopeTokens, useUser } from "@aglyn/tenant-feature-instance";
@@ -42,6 +42,9 @@ import { datasetRecordFilter, planRecordQuery, recordColumn } from "./dataset-re
42
42
  import { coerceDocumentValues, datasetIntegrityUpdate, datasetValueToInput, effectiveDatasetModel, formatDatasetValue, modelFromFieldEntries, validateDocument } from "../model/dataset-models.js";
43
43
  import { fillRecordAddresses } from "../record-pages/record-pages.js";
44
44
  import { planReferenceFixups, referencingFieldIds, restrictedDeleteMessage } from "../model/dataset-record-delete-plan.js";
45
+ import { BlockedControl } from "@aglyn/shared-ui-jsx/components/blocked-control.component";
46
+ import { datasetListScope } from "../model/dataset-record-list.js";
47
+ import { DATASETS_EXPORT_REFUSAL, DATASETS_VIEW_RECORDS_REFUSAL, DATASETS_WRITE_REFUSAL, useDatasetWritesBlocked } from "./use-dataset-writes-blocked.js";
45
48
  import { DATASET_SAMPLE_RECORD_NOTE, datasetDisplayName, isSampleDatasetRecord, parseDatasetFieldEntries } from "../model/datasets.js";
46
49
  import { datasetTransferResourceKey } from "../transfer/dataset-transfer-key.js";
47
50
  /**
@@ -52,6 +55,21 @@ import { datasetTransferResourceKey } from "../transfer/dataset-transfer-key.js"
52
55
  * sharing is "Only the site they were created in". Everywhere else a new
53
56
  * dataset starts on All sites: the org Data page has no site to limit it to.
54
57
  */ /** The records walk serves no header order: every header sorts the page. */ const NO_QUERY_SORTS = [];
58
+ /** The grid's own Export and Print, off for a member without "Export data" (AGL-4047). */ const EXPORT_OFF_TOOLBAR = {
59
+ toolbar: {
60
+ csvOptions: {
61
+ disableToolbarButton: true
62
+ },
63
+ printOptions: {
64
+ disableToolbarButton: true
65
+ }
66
+ }
67
+ };
68
+ /** Stable, so an empty answer does not re-render the card. */ const NO_DATASETS = [];
69
+ /** The most datasets the card lists, and the most a delete's reference check walks. */ const DATASET_LIST_WINDOW = 100;
70
+ /** A dataset read off its document, as the card's rows carry it. */ const datasetRow = (snapshot)=>_extends({
71
+ $id: snapshot.id
72
+ }, snapshot.data());
55
73
  export function newDatasetSharingNote(siteOnly) {
56
74
  return siteOnly ? 'Datasets belong to your organization. Your default sharing starts a ' + 'new one on this site only — use Schema to share it with more.' : 'Datasets belong to your organization. A new one is shared with ' + 'every site — use Schema to narrow that.';
57
75
  }
@@ -77,14 +95,30 @@ export function newDatasetSharingNote(siteOnly) {
77
95
  // rules a scoped member's UNFILTERED list is rejected outright —
78
96
  // Firestore fails the whole query if any candidate would fail — so
79
97
  // without this the Data page errors rather than showing fewer rows.
80
- // Org-wide members get no filter: they read everything, and adding one
81
- // would hide any dataset the AGL-1040 backfill missed.
82
98
  const { tokens: scopeTokens, orgWide: viewerOrgWide, loaded: scopeLoaded } = useScopeTokens(orgId);
83
- // Every dataset this card can now reach is an org dataset, and org
84
- // datasets are all scoped (AGL-1041) — so the filter turns purely on
85
- // whether the VIEWER is org-wide. It used to also ask whether an org had
86
- // resolved, for the sake of unscoped rows on the host path.
87
- const needsScope = !viewerOrgWide;
99
+ /**
100
+ * The site whose Data page this is, or undefined on the organization Data
101
+ * page. The explicit `orgId` is that page's own scope and already wins over
102
+ * `hostId` when the org is resolved, so it wins here too, even if a caller
103
+ * hands the card both.
104
+ */ const pageHostId = props.orgId ? undefined : hostId || undefined;
105
+ // What the VIEWER reaches: their scope tokens, or no filter for an org-wide
106
+ // member, who reads everything. Every dataset here is an org dataset, and
107
+ // org datasets are all scoped (AGL-1041).
108
+ const reachScope = viewerOrgWide ? null : scopeTokens;
109
+ /**
110
+ * What this page lists (AGL-4047): a site's Data page shows that site's and
111
+ * the workspace-wide datasets, whoever is looking, as every other site
112
+ * surface does. It used to ask only the viewer's reach, so an owner, who
113
+ * reaches everything, saw every site's datasets on every site. The
114
+ * organization Data page lists the viewer's reach.
115
+ */ const listScope = useMemo(()=>datasetListScope({
116
+ hostId: pageHostId,
117
+ memberScope: reachScope
118
+ }), [
119
+ pageHostId,
120
+ reachScope
121
+ ]);
88
122
  // Two answers must be in before listing: the org path (AGL-1061) and the
89
123
  // viewer's scope tokens (AGL-1047). `useScopeTokens` reports org-wide
90
124
  // while loading, so without `scopeLoaded` a scoped collaborator's first
@@ -104,11 +138,8 @@ export function newDatasetSharingNote(siteOnly) {
104
138
  *
105
139
  * `/api/orgs/datasets` stamps a new dataset with the org's Default sharing,
106
140
  * and that setting can only narrow to a site the request names — so a
107
- * create that names none lands on All sites whatever the org chose. The
108
- * explicit `orgId` is the org Data page's own scope and already wins over
109
- * `hostId` when the org is resolved, so it wins here too: a create made
110
- * there names no site, even if a caller hands the card both.
111
- */ const createdFromHostId = props.orgId ? undefined : hostId || undefined;
141
+ * create that names none lands on All sites whatever the org chose.
142
+ */ const createdFromHostId = pageHostId;
112
143
  const createdFrom = useMemo(()=>createdFromHostId ? {
113
144
  hostId: createdFromHostId
114
145
  } : {}, [
@@ -186,13 +217,14 @@ export function newDatasetSharingNote(siteOnly) {
186
217
  * than recomputed there.
187
218
  */ fromCache: datasetsFromCache, listen: datasetsListen } = useFirestoreCollection(()=>// `scopeReady` already implies a non-null `dataScope`; testing it
188
219
  // directly is what lets the compiler see that too.
189
- dataScope && scopeReady ? query(collection(firestore, dataScope[0], dataScope[1], 'datasets'), ...needsScope ? [
190
- where('visibleTo', 'array-contains-any', scopeTokens)
191
- ] : [], limit(100)) : null, [
220
+ dataScope && scopeReady ? query(collection(firestore, dataScope[0], dataScope[1], 'datasets'), ...listScope ? [
221
+ where('visibleTo', 'array-contains-any', [
222
+ ...listScope
223
+ ])
224
+ ] : [], limit(DATASET_LIST_WINDOW)) : null, [
192
225
  firestore,
193
226
  dataScope,
194
- needsScope,
195
- scopeTokens,
227
+ listScope,
196
228
  scopeReady
197
229
  ], {
198
230
  idField: '$id'
@@ -205,6 +237,9 @@ export function newDatasetSharingNote(siteOnly) {
205
237
  const [selectedId, setSelectedId] = useState(null);
206
238
  const [schemaOpen, setSchemaOpen] = useState(false);
207
239
  const selected = (_datasets_find = datasets.find((item)=>item.$id === selectedId)) != null ? _datasets_find : datasets[0];
240
+ // What this member may do with THIS dataset (AGL-4047): one placed on one site
241
+ // answers to that site.
242
+ const blocked = useDatasetWritesBlocked(orgId, selected == null ? void 0 : selected.visibleTo);
208
243
  // Typed model (AGL-179): drives headers, cell rendering, and the
209
244
  // document form; v1 datasets get a derived all-text model.
210
245
  const model = useMemo(()=>effectiveDatasetModel(selected != null ? selected : {}), [
@@ -305,11 +340,12 @@ export function newDatasetSharingNote(siteOnly) {
305
340
  filters: recordPlan.plan.filters,
306
341
  orderBy: recordPlan.plan.orderBy
307
342
  });
308
- const { rows: records, hasMore: hasMoreRecords, page: recordPage, setPage: setRecordPage, pageSize: recordPageSize, setPageSize: setRecordPageSize } = usePagedCollection((pageLimit)=>dataScope && (selected == null ? void 0 : selected.$id) ? query(collection(firestore, dataScope[0], dataScope[1], 'datasets', selected.$id, 'records'), ...listQueryConstraints(recordPlan.plan), limit(pageLimit)) : null, [
343
+ const { rows: records, hasMore: hasMoreRecords, page: recordPage, setPage: setRecordPage, pageSize: recordPageSize, setPageSize: setRecordPageSize } = usePagedCollection((pageLimit)=>dataScope && (selected == null ? void 0 : selected.$id) && !blocked.records ? query(collection(firestore, dataScope[0], dataScope[1], 'datasets', selected.$id, 'records'), ...listQueryConstraints(recordPlan.plan), limit(pageLimit)) : null, [
309
344
  firestore,
310
345
  dataScope,
311
346
  selected == null ? void 0 : selected.$id,
312
- recordPlanKey
347
+ recordPlanKey,
348
+ blocked.records
313
349
  ], {
314
350
  idField: '$id'
315
351
  });
@@ -390,7 +426,7 @@ export function newDatasetSharingNote(siteOnly) {
390
426
  // above, which is the PICKER value and is null until the user chooses.
391
427
  const countedDatasetId = selected == null ? void 0 : selected.$id;
392
428
  useEffect(()=>{
393
- if (!dataScope || !countedDatasetId) return;
429
+ if (!dataScope || !countedDatasetId || blocked.records) return;
394
430
  let active = true;
395
431
  void getCountFromServer(collection(firestore, dataScope[0], dataScope[1], 'datasets', countedDatasetId, 'records')).then((snapshot)=>{
396
432
  if (active) {
@@ -409,7 +445,8 @@ export function newDatasetSharingNote(siteOnly) {
409
445
  firestore,
410
446
  dataScope,
411
447
  countedDatasetId,
412
- recordCountEpoch
448
+ recordCountEpoch,
449
+ blocked.records
413
450
  ]);
414
451
  // Pending, denied, or answered about the PREVIOUS selection, the loaded
415
452
  // rows stand in. They can only UNDERSTATE (same collections, capped),
@@ -630,6 +667,46 @@ export function newDatasetSharingNote(siteOnly) {
630
667
  enqueueSnackbar,
631
668
  logActivity
632
669
  ]);
670
+ /**
671
+ * What the selected dataset's references point at beyond this site's list
672
+ * (AGL-4047). A dataset this site sees can name a target another site holds;
673
+ * the schema dialog warns about exactly that, and a cell still labels the
674
+ * row it points at, so the target has to be known even though the site's
675
+ * list does not show it. Read one by one, and only when there is one; a
676
+ * target the viewer may not read stays unknown.
677
+ */ const [outsideTargets, setOutsideTargets] = useState(NO_DATASETS);
678
+ useEffect(()=>{
679
+ let active = true;
680
+ const missing = pageHostId ? [
681
+ ...new Set(model.order.map((fieldId)=>{
682
+ var _model_fields_fieldId_reference, _model_fields_fieldId;
683
+ return (_model_fields_fieldId = model.fields[fieldId]) == null ? void 0 : (_model_fields_fieldId_reference = _model_fields_fieldId.reference) == null ? void 0 : _model_fields_fieldId_reference.datasetId;
684
+ }).filter((id)=>Boolean(id)))
685
+ ].filter((id)=>!datasets.some((item)=>item.$id === id)) : [];
686
+ if (!missing.length || !dataScope) {
687
+ setOutsideTargets(NO_DATASETS);
688
+ return;
689
+ }
690
+ void Promise.all(missing.map((id)=>getDoc(doc(firestore, dataScope[0], dataScope[1], 'datasets', id)).then((snapshot)=>snapshot.exists() ? datasetRow(snapshot) : null, ()=>null))).then((rows)=>{
691
+ if (active) setOutsideTargets(rows.filter(Boolean));
692
+ });
693
+ return ()=>{
694
+ active = false;
695
+ };
696
+ }, [
697
+ pageHostId,
698
+ model,
699
+ datasets,
700
+ firestore,
701
+ dataScope
702
+ ]);
703
+ const knownDatasets = useMemo(()=>outsideTargets.length ? [
704
+ ...datasets,
705
+ ...outsideTargets
706
+ ] : datasets, [
707
+ datasets,
708
+ outsideTargets
709
+ ]);
633
710
  // Reference pickers (AGL-180): load target-collection rows for every
634
711
  // reference field in the model (id -> display label).
635
712
  const [refOptions, setRefOptions] = useState({});
@@ -646,7 +723,7 @@ export function newDatasetSharingNote(siteOnly) {
646
723
  void Promise.all(referenceFields.map(async (fieldId)=>{
647
724
  var _reference_displayFieldId, _ref;
648
725
  const reference = model.fields[fieldId].reference;
649
- const target = datasets.find((item)=>item.$id === reference.datasetId);
726
+ const target = knownDatasets.find((item)=>item.$id === reference.datasetId);
650
727
  const displayFieldId = (_reference_displayFieldId = reference.displayFieldId) != null ? _reference_displayFieldId : effectiveDatasetModel(target != null ? target : {}).order[0];
651
728
  const snapshot = await getDocs(query(collection(firestore, dataScope[0], dataScope[1], 'datasets', reference.datasetId, 'records'), limit(200))).catch(()=>null);
652
729
  const options = ((_ref = snapshot == null ? void 0 : snapshot.docs) != null ? _ref : []).map((docSnapshot)=>{
@@ -669,7 +746,7 @@ export function newDatasetSharingNote(siteOnly) {
669
746
  };
670
747
  }, [
671
748
  model,
672
- datasets,
749
+ knownDatasets,
673
750
  firestore,
674
751
  dataScope
675
752
  ]);
@@ -873,11 +950,32 @@ export function newDatasetSharingNote(siteOnly) {
873
950
  * fails open is worse than no check, because the UI then tells the user
874
951
  * the record is safe to remove.
875
952
  *
876
- * ⚠️ Reaches the collections in `datasets`, which is this viewer's
877
- * scoped, capped picker window. A referencing collection shared with no
878
- * site this member can see is one the client may not read at all, so it
879
- * is not consulted; only a server route could close that.
880
- */ for (const other of datasets){
953
+ * ⚠️ Reaches the collections in this viewer's scoped, capped window. A
954
+ * referencing collection shared with no site this member can see is one
955
+ * the client may not read at all, so it is not consulted; only a server
956
+ * route could close that.
957
+ *
958
+ * On a site's Data page that window is NOT the list (AGL-4047). The list
959
+ * is the site's, and a dataset another site holds can reference a row of
960
+ * one shared with both: narrowing what the page shows must not narrow
961
+ * what a delete protects. So the page reads the viewer's reach here, once,
962
+ * at the moment of the delete, and refuses if it cannot.
963
+ */ let referencing = datasets;
964
+ if (pageHostId) {
965
+ try {
966
+ const reach = await getDocs(query(collection(firestore, dataScope[0], dataScope[1], 'datasets'), ...reachScope ? [
967
+ where('visibleTo', 'array-contains-any', [
968
+ ...reachScope
969
+ ])
970
+ ] : [], limit(DATASET_LIST_WINDOW)));
971
+ referencing = reach.docs.map(datasetRow);
972
+ } catch (unused) {
973
+ return void enqueueSnackbar('Cannot delete: the datasets that may reference this record could ' + 'not be checked, so removing it could break them. Nothing was ' + 'deleted.', {
974
+ variant: 'error'
975
+ });
976
+ }
977
+ }
978
+ for (const other of referencing){
881
979
  const otherModel = effectiveDatasetModel(other);
882
980
  if (!referencingFieldIds(otherModel, selected.$id).length) continue;
883
981
  let snapshot;
@@ -935,6 +1033,8 @@ export function newDatasetSharingNote(siteOnly) {
935
1033
  }, [
936
1034
  selected,
937
1035
  datasets,
1036
+ pageHostId,
1037
+ reachScope,
938
1038
  firestore,
939
1039
  dataScope,
940
1040
  announceRecords,
@@ -946,14 +1046,17 @@ export function newDatasetSharingNote(siteOnly) {
946
1046
  * matched and written on the server, through the same record writes as
947
1047
  * every other create and update, and the export streams the fields the
948
1048
  * person picks. Outside the console shell there is no launcher, and no
949
- * Import or Export to offer. Inside it, Import is offered to a member who
950
- * may import (Manage data) and Export to any member who can see the
951
- * dataset (AGL-3546) — the transfer routes' own rule.
1049
+ * Import or Export to offer. Inside it, Import is on for a member who may
1050
+ * write this dataset and switched off with the permission named for one who
1051
+ * may not, and Export likewise for "Export data", for a member who can see it
1052
+ * (AGL-3546, AGL-4047) — the transfer routes' own rule.
952
1053
  */ const transfer = useTransferLauncher();
953
- const transferTarget = (selected == null ? void 0 : selected.$id) ? {
1054
+ const transferTarget = (selected == null ? void 0 : selected.$id) ? _extends({
954
1055
  resource: datasetTransferResourceKey(selected.$id),
955
1056
  scope: 'org'
956
- } : null;
1057
+ }, blocked.known ? {
1058
+ importAllowed: !blocked.writes
1059
+ } : {}) : null;
957
1060
  const canImport = Boolean(transfer && transferTarget && transfer.can('import', transferTarget));
958
1061
  const canExport = Boolean(transfer && transferTarget && transfer.can('export', transferTarget));
959
1062
  const handleImport = useCallback(()=>{
@@ -1065,16 +1168,24 @@ export function newDatasetSharingNote(siteOnly) {
1065
1168
  onClick: ()=>setViewerId(record.$id),
1066
1169
  children: 'View'
1067
1170
  }),
1068
- /*#__PURE__*/ _jsx(Button, {
1069
- size: "small",
1070
- onClick: handleOpenRecord(record),
1071
- children: 'Edit'
1171
+ /*#__PURE__*/ _jsx(BlockedControl, {
1172
+ blocked: blocked.writes,
1173
+ reason: blocked.writesReason,
1174
+ children: /*#__PURE__*/ _jsx(Button, {
1175
+ size: "small",
1176
+ onClick: handleOpenRecord(record),
1177
+ children: 'Edit'
1178
+ })
1072
1179
  }),
1073
- /*#__PURE__*/ _jsx(Button, {
1074
- size: "small",
1075
- color: "error",
1076
- onClick: handleDeleteRecord(record),
1077
- children: 'Delete'
1180
+ /*#__PURE__*/ _jsx(BlockedControl, {
1181
+ blocked: blocked.writes,
1182
+ reason: blocked.writesReason,
1183
+ children: /*#__PURE__*/ _jsx(Button, {
1184
+ size: "small",
1185
+ color: "error",
1186
+ onClick: handleDeleteRecord(record),
1187
+ children: 'Delete'
1188
+ })
1078
1189
  })
1079
1190
  ]
1080
1191
  }), {
@@ -1086,7 +1197,9 @@ export function newDatasetSharingNote(siteOnly) {
1086
1197
  referenceLabel,
1087
1198
  handleOpenRecord,
1088
1199
  handleDeleteRecord,
1089
- recordFilter
1200
+ recordFilter,
1201
+ blocked.writes,
1202
+ blocked.writesReason
1090
1203
  ]);
1091
1204
  /*
1092
1205
  * EVERY HEADER SORTS — THE PAGE ON SCREEN (AGL-3680). A record's values are
@@ -1172,16 +1285,24 @@ export function newDatasetSharingNote(siteOnly) {
1172
1285
  children: datasetDisplayName(item)
1173
1286
  }, item.$id))
1174
1287
  }),
1175
- /*#__PURE__*/ _jsx(Button, {
1176
- size: "small",
1177
- color: "primary",
1178
- onClick: handleOpenRecord(),
1179
- children: 'Add record'
1288
+ /*#__PURE__*/ _jsx(BlockedControl, {
1289
+ blocked: blocked.writes,
1290
+ reason: blocked.writesReason,
1291
+ children: /*#__PURE__*/ _jsx(Button, {
1292
+ size: "small",
1293
+ color: "primary",
1294
+ onClick: handleOpenRecord(),
1295
+ children: 'Add record'
1296
+ })
1180
1297
  }),
1181
- /*#__PURE__*/ _jsx(Button, {
1182
- size: "small",
1183
- onClick: ()=>setSchemaOpen(true),
1184
- children: 'Schema'
1298
+ /*#__PURE__*/ _jsx(BlockedControl, {
1299
+ blocked: blocked.writes && !blocked.sharingOnly,
1300
+ reason: blocked.writesReason,
1301
+ children: /*#__PURE__*/ _jsx(Button, {
1302
+ size: "small",
1303
+ onClick: ()=>setSchemaOpen(true),
1304
+ children: 'Schema'
1305
+ })
1185
1306
  }),
1186
1307
  transferTarget ? /*#__PURE__*/ _jsx(TransferResumeImport, _extends({
1187
1308
  target: transferTarget
@@ -1190,21 +1311,33 @@ export function newDatasetSharingNote(siteOnly) {
1190
1311
  } : {}, {
1191
1312
  onFinished: ()=>setRecordCountEpoch((epoch)=>epoch + 1)
1192
1313
  })) : null,
1193
- canImport ? /*#__PURE__*/ _jsx(Button, {
1194
- size: "small",
1195
- onClick: handleImport,
1196
- children: 'Import'
1314
+ canImport || transfer && transferTarget && blocked.writes ? /*#__PURE__*/ _jsx(BlockedControl, {
1315
+ blocked: !canImport,
1316
+ reason: blocked.writesReason,
1317
+ children: /*#__PURE__*/ _jsx(Button, {
1318
+ size: "small",
1319
+ onClick: handleImport,
1320
+ children: 'Import'
1321
+ })
1197
1322
  }) : null,
1198
- canExport && (recordCount || records.length) ? /*#__PURE__*/ _jsx(Button, {
1199
- size: "small",
1200
- onClick: handleExport,
1201
- children: 'Export'
1323
+ canExport && (recordCount || records.length) || transfer && blocked.exports ? /*#__PURE__*/ _jsx(BlockedControl, {
1324
+ blocked: blocked.exports,
1325
+ reason: DATASETS_EXPORT_REFUSAL,
1326
+ children: /*#__PURE__*/ _jsx(Button, {
1327
+ size: "small",
1328
+ onClick: handleExport,
1329
+ children: 'Export'
1330
+ })
1202
1331
  }) : null,
1203
- /*#__PURE__*/ _jsx(Button, {
1204
- size: "small",
1205
- color: "error",
1206
- onClick: handleDeleteDataset,
1207
- children: 'Delete'
1332
+ /*#__PURE__*/ _jsx(BlockedControl, {
1333
+ blocked: blocked.deletes,
1334
+ reason: blocked.deletesReason,
1335
+ children: /*#__PURE__*/ _jsx(Button, {
1336
+ size: "small",
1337
+ color: "error",
1338
+ onClick: handleDeleteDataset,
1339
+ children: 'Delete'
1340
+ })
1208
1341
  })
1209
1342
  ]
1210
1343
  }),
@@ -1214,7 +1347,11 @@ export function newDatasetSharingNote(siteOnly) {
1214
1347
  limit: checkQuota(org, 'recordsPerDataset', recordCount).limit,
1215
1348
  noun: "record"
1216
1349
  }) : null,
1217
- selected && (records.length > 0 || recordPage > 0 || filteringRecords) ? /*#__PURE__*/ _jsxs(_Fragment, {
1350
+ selected && blocked.records ? /*#__PURE__*/ _jsx(Typography, {
1351
+ variant: "body2",
1352
+ color: "text.secondary",
1353
+ children: DATASETS_VIEW_RECORDS_REFUSAL
1354
+ }) : selected && (records.length > 0 || recordPage > 0 || filteringRecords) ? /*#__PURE__*/ _jsxs(_Fragment, {
1218
1355
  children: [
1219
1356
  /*#__PURE__*/ _jsx(ListFilterChips, {
1220
1357
  fields: recordFilter.fields,
@@ -1230,7 +1367,7 @@ export function newDatasetSharingNote(siteOnly) {
1230
1367
  ...recordColumnSort.notices
1231
1368
  ]
1232
1369
  }),
1233
- /*#__PURE__*/ _jsx(ListTable, {
1370
+ /*#__PURE__*/ _jsx(ListTable, _extends({
1234
1371
  "aria-label": "Records",
1235
1372
  rows: recordColumnSort.rows,
1236
1373
  columnSort: recordColumnSort,
@@ -1242,9 +1379,12 @@ export function newDatasetSharingNote(siteOnly) {
1242
1379
  filterMode: "server",
1243
1380
  filterModel: gridFilter.filterModel,
1244
1381
  onFilterModelChange: gridFilter.onFilterModelChange,
1245
- quickFilter: true,
1382
+ quickFilter: true
1383
+ }, blocked.exports ? {
1384
+ slotProps: EXPORT_OFF_TOOLBAR
1385
+ } : {}, {
1246
1386
  noRowsLabel: filteringRecords ? 'No records match these filters' : 'No records yet.'
1247
- }),
1387
+ })),
1248
1388
  /*#__PURE__*/ _jsx(ListPagination, {
1249
1389
  page: recordPage,
1250
1390
  pageSize: recordPageSize,
@@ -1267,20 +1407,28 @@ export function newDatasetSharingNote(siteOnly) {
1267
1407
  flexWrap: 'wrap'
1268
1408
  },
1269
1409
  children: [
1270
- /*#__PURE__*/ _jsx(Button, {
1271
- size: "small",
1272
- variant: "outlined",
1273
- color: "primary",
1274
- onClick: handleOpenCreator,
1275
- children: 'Add dataset'
1410
+ /*#__PURE__*/ _jsx(BlockedControl, {
1411
+ blocked: blocked.creates,
1412
+ reason: DATASETS_WRITE_REFUSAL,
1413
+ children: /*#__PURE__*/ _jsx(Button, {
1414
+ size: "small",
1415
+ variant: "outlined",
1416
+ color: "primary",
1417
+ onClick: handleOpenCreator,
1418
+ children: 'Add dataset'
1419
+ })
1276
1420
  }),
1277
- datasets.length >= 2 ? /*#__PURE__*/ _jsx(Button, {
1278
- size: "small",
1279
- onClick: ()=>setJoiner({
1280
- a: '',
1281
- b: ''
1282
- }),
1283
- children: 'Add join collection'
1421
+ datasets.length >= 2 ? /*#__PURE__*/ _jsx(BlockedControl, {
1422
+ blocked: blocked.creates,
1423
+ reason: DATASETS_WRITE_REFUSAL,
1424
+ children: /*#__PURE__*/ _jsx(Button, {
1425
+ size: "small",
1426
+ onClick: ()=>setJoiner({
1427
+ a: '',
1428
+ b: ''
1429
+ }),
1430
+ children: 'Add join collection'
1431
+ })
1284
1432
  }) : null
1285
1433
  ]
1286
1434
  })
@@ -1601,11 +1749,11 @@ export function newDatasetSharingNote(siteOnly) {
1601
1749
  })
1602
1750
  ]
1603
1751
  }),
1604
- /*#__PURE__*/ _jsx(DatasetSchemaDialog, {
1752
+ /*#__PURE__*/ _jsx(DatasetSchemaDialog, _extends({
1605
1753
  hostId: hostId,
1606
1754
  orgId: orgId != null ? orgId : undefined,
1607
1755
  dataset: schemaOpen && selected ? selected : null,
1608
- datasets: datasets,
1756
+ datasets: knownDatasets,
1609
1757
  // The dataset's documents, not the loaded window (AGL-1716) — the
1610
1758
  // dialog warns "N documents exist" before a narrowing type change,
1611
1759
  // and 500 was the cap talking, not the collection.
@@ -1613,8 +1761,12 @@ export function newDatasetSharingNote(siteOnly) {
1613
1761
  seedFromCache: datasetsFromCache,
1614
1762
  seedUnreadable: datasetsStatus === 'error',
1615
1763
  seedListen: datasetsListen,
1764
+ canChangeSharing: !blocked.creates
1765
+ }, blocked.sharingOnly ? {
1766
+ sharingOnlyReason: blocked.writesReason
1767
+ } : {}, {
1616
1768
  onClose: ()=>setSchemaOpen(false)
1617
- })
1769
+ }))
1618
1770
  ]
1619
1771
  });
1620
1772
  }