@aglyn/plugins-data 1.14.0 → 1.15.1

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 (42) hide show
  1. package/package.json +12 -10
  2. package/src/lib/artifact/dataset-schema-artifact.server.js +4 -1
  3. package/src/lib/artifact/dataset-schema-artifact.server.js.map +1 -1
  4. package/src/lib/components/data-console-page.js +4 -2
  5. package/src/lib/components/data-console-page.js.map +1 -1
  6. package/src/lib/components/dataset-record-dialog.component.d.ts +22 -0
  7. package/src/lib/components/dataset-record-dialog.component.js +77 -54
  8. package/src/lib/components/dataset-record-dialog.component.js.map +1 -1
  9. package/src/lib/components/dataset-schema-dialog.component.js +29 -47
  10. package/src/lib/components/dataset-schema-dialog.component.js.map +1 -1
  11. package/src/lib/components/host-datasets-card.component.d.ts +12 -0
  12. package/src/lib/components/host-datasets-card.component.js +651 -220
  13. package/src/lib/components/host-datasets-card.component.js.map +1 -1
  14. package/src/lib/components/use-org-sites.d.ts +27 -0
  15. package/src/lib/components/use-org-sites.js +68 -0
  16. package/src/lib/components/use-org-sites.js.map +1 -0
  17. package/src/lib/model/data-record-routes.js +6 -3
  18. package/src/lib/model/data-record-routes.js.map +1 -1
  19. package/src/lib/model/dataset-model-core.d.ts +22 -0
  20. package/src/lib/model/dataset-model-core.js +34 -0
  21. package/src/lib/model/dataset-model-core.js.map +1 -1
  22. package/src/lib/model/dataset-rail.d.ts +88 -0
  23. package/src/lib/model/dataset-rail.js +123 -0
  24. package/src/lib/model/dataset-rail.js.map +1 -0
  25. package/src/lib/model/dataset-record-list.js +17 -2
  26. package/src/lib/model/dataset-record-list.js.map +1 -1
  27. package/src/lib/model/datasets.d.ts +14 -0
  28. package/src/lib/model/datasets.js +10 -0
  29. package/src/lib/model/datasets.js.map +1 -1
  30. package/src/lib/plugin.d.ts +5 -1
  31. package/src/lib/plugin.js +8 -3
  32. package/src/lib/plugin.js.map +1 -1
  33. package/src/lib/record-pages/record-template-section.component.js +12 -1
  34. package/src/lib/record-pages/record-template-section.component.js.map +1 -1
  35. package/src/lib/server/api-v1/datasets.js +6 -1
  36. package/src/lib/server/api-v1/datasets.js.map +1 -1
  37. package/src/lib/server/dataset-drafts.js +2 -0
  38. package/src/lib/server/dataset-drafts.js.map +1 -1
  39. package/src/lib/server/datasets-route.js +2 -1
  40. package/src/lib/server/datasets-route.js.map +1 -1
  41. package/src/lib/site-bundle/datasets-site-bundle.server.js +8 -1
  42. package/src/lib/site-bundle/datasets-site-bundle.server.js.map +1 -1
@@ -17,8 +17,11 @@
17
17
  import { _ as _extends } from "@swc/helpers/_/_extends";
18
18
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
19
19
  import { TransferResumeImport } from "@aglyn/aglyn/app-utils/transfer-resume-import";
20
- import { checkDatasetQuota, checkEntitlement, checkQuota, getCustomFieldType, pluginDocsHelp, useTransferLauncher } from "@aglyn/aglyn";
21
- import { CardDisplay, useConfirmationContext } from "@aglyn/shared-ui-jsx";
20
+ import { checkDatasetQuota, checkEntitlement, checkQuota, getCustomFieldType, PageHeaderActions, PageHeaderRecord, pluginDocsHelp, scopeTokensForHost, useTransferLauncher, visibleToHost } from "@aglyn/aglyn";
21
+ import { nameSearchKey } from "@aglyn/aglyn/app-utils/name-search";
22
+ import { HubSections } from "@aglyn/shared-ui-next/components/hub-tabs";
23
+ import { AppLink, CardDisplay, MdiIcon, useConfirmationContext } from "@aglyn/shared-ui-jsx";
24
+ import { mdiArrowLeft } from "@aglyn/shared-data-mdi";
22
25
  import ListFilterChips from "@aglyn/shared-ui-jsx/components/list-filter-chips.component";
23
26
  import { ListPagination } from "@aglyn/shared-ui-jsx/components/list-pagination.component";
24
27
  import ListQueryNotices, { listQueryRefusals } from "@aglyn/shared-ui-jsx/components/list-query-notices.component";
@@ -28,15 +31,16 @@ import { listFilterGridColumns } from "@aglyn/shared-ui-jsx/const/list-grid-filt
28
31
  import { useListGridFilter } from "@aglyn/shared-ui-jsx/hooks/use-list-grid-filter";
29
32
  import { useSnackbar } from "@aglyn/shared-ui-snackstack";
30
33
  import { Timestamp } from "@aglyn/shared-util-timestamp";
31
- import { Alert, Button, Chip, Dialog, DialogActions, DialogContent, DialogTitle, MenuItem, Stack, TextField, Tooltip, Typography } from "@mui/material";
32
- import { collection, deleteDoc, deleteField, doc, getCountFromServer, getDoc, getDocs, limit, query, where, setDoc, writeBatch } from "firebase/firestore";
34
+ import { Alert, Box, Button, Chip, Dialog, DialogActions, DialogContent, DialogTitle, MenuItem, Stack, TextField, Tooltip, Typography } from "@mui/material";
35
+ import { collection, deleteDoc, deleteField, doc, documentId, endAt, getCountFromServer, getDoc, getDocs, limit, orderBy, query, startAt, where, setDoc, writeBatch } from "firebase/firestore";
36
+ import { useRouter } from "next/navigation";
33
37
  import { useCallback, useEffect, useMemo, useState } from "react";
34
38
  import { useListColumnSort } from "@aglyn/shared-ui-jsx/hooks/use-list-column-sort";
35
- import { useFirestore, useFirestoreCollection, useHostActivityLogger, useOrgDataScope, usePagedCollection, useScopeTokens, useUser } from "@aglyn/tenant-feature-instance";
39
+ import { useFirestore, useFirestoreCollection, useFirestoreDoc, useHostActivityLogger, useOrgDataScope, usePagedCollection, useScopeTokens, useUser } from "@aglyn/tenant-feature-instance";
36
40
  import { listQueryConstraints } from "@aglyn/tenant-feature-instance/hooks/use-list-query";
37
41
  import { authorizedFetch } from "@aglyn/shared-util-http/authorized-token";
38
42
  import { DatasetSchemaDialog } from "./dataset-schema-dialog.component.js";
39
- import { DatasetRecordDialog } from "./dataset-record-dialog.component.js";
43
+ import { DatasetRecordDialog, DatasetRecordFieldList } from "./dataset-record-dialog.component.js";
40
44
  import { DatasetRecordSiteContext } from "./dataset-field-inputs.component.js";
41
45
  import { datasetRecordFilter, planRecordQuery, recordColumn } from "./dataset-record-filter.js";
42
46
  import { coerceDocumentValues, datasetIntegrityUpdate, datasetValueToInput, effectiveDatasetModel, formatDatasetValue, modelFromFieldEntries, validateDocument } from "../model/dataset-models.js";
@@ -47,6 +51,8 @@ import { datasetListScope } from "../model/dataset-record-list.js";
47
51
  import { DATASETS_EXPORT_REFUSAL, DATASETS_VIEW_RECORDS_REFUSAL, DATASETS_WRITE_REFUSAL, useDatasetWritesBlocked } from "./use-dataset-writes-blocked.js";
48
52
  import { DATASET_SAMPLE_RECORD_NOTE, datasetDisplayName, isSampleDatasetRecord, parseDatasetFieldEntries } from "../model/datasets.js";
49
53
  import { datasetTransferResourceKey } from "../transfer/dataset-transfer-key.js";
54
+ import { DATASET_RAIL_GROUP_AT, datasetCreatedLabel, datasetNameMatches, datasetPickerLabelsOf, datasetRailName, datasetRecordTitle, datasetRailSecondary, datasetSharingLabel, datasetSourceLabel, groupDatasetsBySharing, sortDatasetsByName } from "../model/dataset-rail.js";
55
+ import { useOrgSites } from "./use-org-sites.js";
50
56
  /**
51
57
  * The sentence that says who a NEW dataset is shared with, for the card and
52
58
  * for the site Data page's banner above it.
@@ -66,7 +72,20 @@ import { datasetTransferResourceKey } from "../transfer/dataset-transfer-key.js"
66
72
  }
67
73
  };
68
74
  /** 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;
75
+ /**
76
+ * The datasets the rail loads at a time, and the most a delete's reference
77
+ * check walks. "Show more datasets" loads the next window, so the rail
78
+ * reaches every dataset however many there are (AGL-4047).
79
+ */ const DATASET_LIST_WINDOW = 100;
80
+ /**
81
+ * TODO(AGL-4047): switch to true once the `datasets (visibleTo, nameLower)`
82
+ * index is READY and `tools/scripts/backfill-dataset-name-lower.mjs --apply`
83
+ * has run in production. Then the rail is ordered by `nameLower` on the query
84
+ * and the search asks a `nameLower` prefix of the server, rather than the
85
+ * rail walking datasets in document order and matching names among the ones
86
+ * it has loaded. Until both are confirmed, ordering on a field a dataset may
87
+ * lack would leave that dataset off the rail.
88
+ */ const DATASET_NAMES_ON_SERVER = false;
70
89
  /** A dataset read off its document, as the card's rows carry it. */ const datasetRow = (snapshot)=>_extends({
71
90
  $id: snapshot.id
72
91
  }, snapshot.data());
@@ -81,8 +100,9 @@ export function newDatasetSharingNote(siteOnly) {
81
100
  * dark-launch rule as everywhere (no plan, no gate). The host path is
82
101
  * the pre-migration fallback for hosts not yet org-wired.
83
102
  */ export function HostDatasetsCard(props) {
84
- var _datasets_find, _ref, _ref1, _ref2, _ref3;
85
- const { hostId } = props;
103
+ var _ref, _ref1, _ref2, _ref3, _ref4, _ref5;
104
+ const { hostId, basePath, segments } = props;
105
+ const router = useRouter();
86
106
  // `dataScope` is null until the async org lookup settles (AGL-1061), and
87
107
  // for a host with no owning org — there is no host fallback to act on
88
108
  // any more (AGL-1050), so every path built from it is guarded rather
@@ -209,6 +229,24 @@ export function newDatasetSharingNote(siteOnly) {
209
229
  }, [
210
230
  callDatasetApi
211
231
  ]);
232
+ /**
233
+ * The rail's search and its Shared with filter (AGL-4047).
234
+ *
235
+ * The filter is a query clause: one site the reader reaches, asked by that
236
+ * site's scope tokens in place of the page's own, which they sit inside —
237
+ * a site the reader is a member of is one their own tokens already reach,
238
+ * so the narrower query is still one the rules can prove. Offered on the
239
+ * organization Data page only: a site's page already lists that site's.
240
+ */ const [nameSearch, setNameSearch] = useState('');
241
+ const [sharedWith, setSharedWith] = useState('');
242
+ const [railWindow, setRailWindow] = useState(DATASET_LIST_WINDOW);
243
+ const railScope = useMemo(()=>sharedWith && !pageHostId ? scopeTokensForHost(sharedWith) : listScope, [
244
+ sharedWith,
245
+ pageHostId,
246
+ listScope
247
+ ]);
248
+ const serverNameKey = DATASET_NAMES_ON_SERVER ? nameSearchKey(nameSearch) : '';
249
+ const { hostNames, sites: orgSites } = useOrgSites(orgId);
212
250
  const { data: datasetDocs, status: datasetsStatus, /**
213
251
  * The dataset rows are unconfirmed by the server (AGL-1358). The schema
214
252
  * dialog is seeded from one of them and writes the whole `model` plus
@@ -217,26 +255,110 @@ export function newDatasetSharingNote(siteOnly) {
217
255
  * than recomputed there.
218
256
  */ fromCache: datasetsFromCache, listen: datasetsListen } = useFirestoreCollection(()=>// `scopeReady` already implies a non-null `dataScope`; testing it
219
257
  // directly is what lets the compiler see that too.
220
- dataScope && scopeReady ? query(collection(firestore, dataScope[0], dataScope[1], 'datasets'), ...listScope ? [
258
+ dataScope && scopeReady ? query(collection(firestore, dataScope[0], dataScope[1], 'datasets'), ...railScope ? [
221
259
  where('visibleTo', 'array-contains-any', [
222
- ...listScope
260
+ ...railScope
223
261
  ])
224
- ] : [], limit(DATASET_LIST_WINDOW)) : null, [
262
+ ] : [], /*
263
+ * A walk that reaches every dataset (AGL-4047). The document's
264
+ * name is on every dataset, so ordering on it leaves none out,
265
+ * and the automatic index serves it beside the scope clause. One
266
+ * row past the window says whether there are more.
267
+ */ ...DATASET_NAMES_ON_SERVER ? [
268
+ orderBy('nameLower'),
269
+ ...serverNameKey ? [
270
+ startAt(serverNameKey),
271
+ endAt(`${serverNameKey}\uf8ff`)
272
+ ] : []
273
+ ] : [
274
+ orderBy(documentId())
275
+ ], limit(railWindow + 1)) : null, [
225
276
  firestore,
226
277
  dataScope,
227
- listScope,
228
- scopeReady
278
+ railScope,
279
+ scopeReady,
280
+ railWindow,
281
+ serverNameKey
229
282
  ], {
230
283
  idField: '$id'
231
284
  });
232
- const datasets = useMemo(()=>[
285
+ /** The loaded window in name order: what the join dialog and the reference checks read. */ const datasets = useMemo(()=>sortDatasetsByName([
233
286
  ...datasetDocs != null ? datasetDocs : []
234
- ].sort((a, b)=>datasetDisplayName(a).localeCompare(datasetDisplayName(b))), [
235
- datasetDocs
287
+ ].slice(0, railWindow)), [
288
+ datasetDocs,
289
+ railWindow
236
290
  ]);
291
+ const moreDatasets = ((_ref = datasetDocs == null ? void 0 : datasetDocs.length) != null ? _ref : 0) > railWindow;
292
+ /** The rail: the loaded window, narrowed by the search among the names it holds. */ const railDatasets = useMemo(()=>DATASET_NAMES_ON_SERVER ? datasets : datasets.filter((item)=>datasetNameMatches(item, nameSearch)), [
293
+ datasets,
294
+ nameSearch
295
+ ]);
296
+ /**
297
+ * Whether the loaded window is short of everything this page lists: a
298
+ * filter narrowed it, or there are more. A check that must see every
299
+ * dataset — what references a record about to be deleted — reads for
300
+ * itself then.
301
+ */ const railNarrowed = Boolean(pageHostId) || Boolean(sharedWith) || moreDatasets;
302
+ /**
303
+ * The open dataset (AGL-4047): the one the address names, or, on the bare
304
+ * page, none until the page moves to the first. The card is also mounted
305
+ * without an address by callers outside the console's routes, which pick
306
+ * one by state.
307
+ */ const routeDatasetId = basePath ? segments == null ? void 0 : segments[0] : undefined;
308
+ /** The record the address opens on its own page (AGL-4047), beneath its dataset's tab. */ const routeRecordId = basePath && (segments == null ? void 0 : segments[1]) === 'records' ? segments == null ? void 0 : segments[2] : undefined;
237
309
  const [selectedId, setSelectedId] = useState(null);
310
+ const wantedId = (_ref1 = routeDatasetId != null ? routeDatasetId : selectedId) != null ? _ref1 : undefined;
311
+ const listed = wantedId ? datasets.find((item)=>item.$id === wantedId) : undefined;
312
+ const listAnswered = datasetDocs !== undefined;
313
+ /*
314
+ * A dataset the address names that the loaded window does not hold — past
315
+ * the window, outside the filter, or only just created — is read on its
316
+ * own, live, so its tab still opens and a save still seeds from a listener.
317
+ */ const linkedRead = useFirestoreDoc(()=>dataScope && scopeReady && wantedId && listAnswered && !listed ? doc(firestore, dataScope[0], dataScope[1], 'datasets', wantedId) : null, [
318
+ firestore,
319
+ dataScope,
320
+ scopeReady,
321
+ wantedId,
322
+ listAnswered,
323
+ Boolean(listed)
324
+ ]);
325
+ // Keyed by the id it was read under, as the list's rows are.
326
+ const linked = useMemo(()=>!listed && wantedId && linkedRead.data ? _extends({}, linkedRead.data, {
327
+ $id: wantedId
328
+ }) : undefined, [
329
+ listed,
330
+ wantedId,
331
+ linkedRead.data
332
+ ]);
333
+ /** A site's page refuses a dataset that is not shared with the site (#2341). */ const notSharedHere = Boolean(pageHostId && linked && !visibleToHost(linked.visibleTo, pageHostId));
334
+ const notFound = Boolean(wantedId && listAnswered && !listed && !linked && (linkedRead.status === 'error' || linkedRead.status !== 'loading' && !linkedRead.fromCache));
335
+ const selected = (_ref2 = listed != null ? listed : linked && !notSharedHere ? linked : undefined) != null ? _ref2 : wantedId ? undefined : datasets[0];
336
+ /** Which listener the open dataset came from, for the schema dialog's freshness guard. */ const seed = listed || !linked ? {
337
+ fromCache: datasetsFromCache,
338
+ unreadable: datasetsStatus === 'error',
339
+ listen: datasetsListen
340
+ } : {
341
+ fromCache: linkedRead.fromCache,
342
+ unreadable: linkedRead.status === 'error',
343
+ listen: linkedRead.listen
344
+ };
345
+ /** Opens a dataset: its own address on a routed page, the card's state elsewhere. */ const openDataset = useCallback((id)=>{
346
+ if (basePath) router.push(id ? `${basePath}/${id}` : basePath);
347
+ else setSelectedId(id);
348
+ }, [
349
+ basePath,
350
+ router
351
+ ]);
352
+ // The bare page opens the first dataset, as a hub opens its first section,
353
+ // so the rail always has a tab lit and the address names what is open.
354
+ const landing = basePath && !routeDatasetId && datasets[0] ? `${basePath}/${datasets[0].$id}` : null;
355
+ useEffect(()=>{
356
+ if (landing) router.replace(landing);
357
+ }, [
358
+ landing,
359
+ router
360
+ ]);
238
361
  const [schemaOpen, setSchemaOpen] = useState(false);
239
- const selected = (_datasets_find = datasets.find((item)=>item.$id === selectedId)) != null ? _datasets_find : datasets[0];
240
362
  // What this member may do with THIS dataset (AGL-4047): one placed on one site
241
363
  // answers to that site.
242
364
  const blocked = useDatasetWritesBlocked(orgId, selected);
@@ -340,15 +462,36 @@ export function newDatasetSharingNote(siteOnly) {
340
462
  filters: recordPlan.plan.filters,
341
463
  orderBy: recordPlan.plan.orderBy
342
464
  });
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, [
465
+ const { rows: records, hasMore: hasMoreRecords, page: recordPage, setPage: setRecordPage, pageSize: recordPageSize, setPageSize: setRecordPageSize } = usePagedCollection((pageLimit)=>// A record's own page shows no table, so it reads none (AGL-4047).
466
+ dataScope && (selected == null ? void 0 : selected.$id) && !blocked.records && !routeRecordId ? query(collection(firestore, dataScope[0], dataScope[1], 'datasets', selected.$id, 'records'), ...listQueryConstraints(recordPlan.plan), limit(pageLimit)) : null, [
344
467
  firestore,
345
468
  dataScope,
346
469
  selected == null ? void 0 : selected.$id,
347
470
  recordPlanKey,
348
- blocked.records
471
+ blocked.records,
472
+ routeRecordId
349
473
  ], {
350
474
  idField: '$id'
351
475
  });
476
+ /**
477
+ * The record a record's own page opens (AGL-4047), read on its own and live,
478
+ * so a deep link to a record on no loaded page still opens and an edit shows
479
+ * as soon as it lands. Asked only of a member who may view the records.
480
+ */ const routeRecordRead = useFirestoreDoc(()=>dataScope && (selected == null ? void 0 : selected.$id) && routeRecordId && !blocked.records ? doc(firestore, dataScope[0], dataScope[1], 'datasets', selected.$id, 'records', routeRecordId) : null, [
481
+ firestore,
482
+ dataScope,
483
+ selected == null ? void 0 : selected.$id,
484
+ routeRecordId,
485
+ blocked.records
486
+ ]);
487
+ // Keyed by the id it was read under, as the table's rows are.
488
+ const routeRecord = useMemo(()=>routeRecordId && routeRecordRead.data ? _extends({}, routeRecordRead.data, {
489
+ $id: routeRecordId
490
+ }) : null, [
491
+ routeRecordId,
492
+ routeRecordRead.data
493
+ ]);
494
+ const routeRecordMissing = Boolean(routeRecordId && !routeRecord && (routeRecordRead.status === 'error' || routeRecordRead.status !== 'loading' && !routeRecordRead.fromCache));
352
495
  const recordRefusals = useMemo(()=>listQueryRefusals(recordPlan.refused, {
353
496
  fields: recordFilter.fields,
354
497
  headers: recordFilter.headers,
@@ -486,7 +629,7 @@ export function newDatasetSharingNote(siteOnly) {
486
629
  ]);
487
630
  // Entries are human names — "Roast preference" → stable id
488
631
  // `roast_preference` with the pretty name kept for headers (AGL-558).
489
- const creatorEntries = parseDatasetFieldEntries((_ref = creator == null ? void 0 : creator.fields) != null ? _ref : '');
632
+ const creatorEntries = parseDatasetFieldEntries((_ref3 = creator == null ? void 0 : creator.fields) != null ? _ref3 : '');
490
633
  const creatorFields = creatorEntries.map((entry)=>entry.id);
491
634
  const handleCreate = useCallback(async ()=>{
492
635
  // No org, no create. The `else` that used to sit below this was the
@@ -514,7 +657,7 @@ export function newDatasetSharingNote(siteOnly) {
514
657
  });
515
658
  }
516
659
  setCreator(null);
517
- setSelectedId(id);
660
+ openDataset(id);
518
661
  setDatasetCountEpoch((epoch)=>epoch + 1);
519
662
  enqueueSnackbar(`Dataset "${creator.name.trim()}" created`, {
520
663
  variant: 'success',
@@ -533,7 +676,8 @@ export function newDatasetSharingNote(siteOnly) {
533
676
  createdFrom,
534
677
  callDatasetApi,
535
678
  enqueueSnackbar,
536
- logActivity
679
+ logActivity,
680
+ openDataset
537
681
  ]);
538
682
  // Join collection template (AGL-180): extrinsic many-to-many as a
539
683
  // visible, editable collection of FKey pairs — no magic.
@@ -587,7 +731,7 @@ export function newDatasetSharingNote(siteOnly) {
587
731
  });
588
732
  }
589
733
  setJoiner(null);
590
- setSelectedId(id);
734
+ openDataset(id);
591
735
  // A join collection IS a dataset and consumes the same quota.
592
736
  setDatasetCountEpoch((epoch)=>epoch + 1);
593
737
  enqueueSnackbar('Join collection created', {
@@ -600,7 +744,8 @@ export function newDatasetSharingNote(siteOnly) {
600
744
  orgId,
601
745
  createdFrom,
602
746
  callDatasetApi,
603
- enqueueSnackbar
747
+ enqueueSnackbar,
748
+ openDataset
604
749
  ]);
605
750
  const handleDeleteDataset = useCallback(async ()=>{
606
751
  if (!selected) return;
@@ -646,7 +791,7 @@ export function newDatasetSharingNote(siteOnly) {
646
791
  persist: false
647
792
  });
648
793
  }
649
- setSelectedId(null);
794
+ openDataset(null);
650
795
  setDatasetCountEpoch((epoch)=>epoch + 1);
651
796
  enqueueSnackbar('Dataset deleted', {
652
797
  variant: 'success',
@@ -665,7 +810,8 @@ export function newDatasetSharingNote(siteOnly) {
665
810
  hostId,
666
811
  user,
667
812
  enqueueSnackbar,
668
- logActivity
813
+ logActivity,
814
+ openDataset
669
815
  ]);
670
816
  /**
671
817
  * What the selected dataset's references point at beyond this site's list
@@ -677,7 +823,7 @@ export function newDatasetSharingNote(siteOnly) {
677
823
  */ const [outsideTargets, setOutsideTargets] = useState(NO_DATASETS);
678
824
  useEffect(()=>{
679
825
  let active = true;
680
- const missing = pageHostId ? [
826
+ const missing = railNarrowed ? [
681
827
  ...new Set(model.order.map((fieldId)=>{
682
828
  var _model_fields_fieldId_reference, _model_fields_fieldId;
683
829
  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;
@@ -694,7 +840,7 @@ export function newDatasetSharingNote(siteOnly) {
694
840
  active = false;
695
841
  };
696
842
  }, [
697
- pageHostId,
843
+ railNarrowed,
698
844
  model,
699
845
  datasets,
700
846
  firestore,
@@ -793,6 +939,17 @@ export function newDatasetSharingNote(siteOnly) {
793
939
  * this reader. Nothing here queries: `records` is the page (or filter window)
794
940
  * query's answer.
795
941
  */ const [viewerId, setViewerId] = useState(null);
942
+ /**
943
+ * Opens a record (AGL-4047): on its own page beneath the dataset's tab
944
+ * where the Data page is routed, in the View record dialog elsewhere.
945
+ */ const datasetHref = basePath && (selected == null ? void 0 : selected.$id) ? `${basePath}/${selected.$id}` : null;
946
+ const openRecord = useCallback((id)=>{
947
+ if (datasetHref) router.push(`${datasetHref}/records/${encodeURIComponent(id)}`);
948
+ else setViewerId(id);
949
+ }, [
950
+ datasetHref,
951
+ router
952
+ ]);
796
953
  const viewerRecord = useMemo(()=>{
797
954
  var _records_find;
798
955
  return viewerId ? (_records_find = records.find((record)=>record.$id === viewerId)) != null ? _records_find : null : null;
@@ -919,7 +1076,7 @@ export function newDatasetSharingNote(siteOnly) {
919
1076
  enqueueSnackbar,
920
1077
  logActivity
921
1078
  ]);
922
- const handleDeleteRecord = useCallback((record)=>async ()=>{
1079
+ const handleDeleteRecord = useCallback((record, afterDelete)=>async ()=>{
923
1080
  // Datasets whose records this delete rewrites through a reference
924
1081
  // fixup, beside the one the record belongs to. Each has pages of its
925
1082
  // own to refresh (AGL-3113).
@@ -961,7 +1118,7 @@ export function newDatasetSharingNote(siteOnly) {
961
1118
  * what a delete protects. So the page reads the viewer's reach here, once,
962
1119
  * at the moment of the delete, and refuses if it cannot.
963
1120
  */ let referencing = datasets;
964
- if (pageHostId) {
1121
+ if (railNarrowed) {
965
1122
  try {
966
1123
  const reach = await getDocs(query(collection(firestore, dataScope[0], dataScope[1], 'datasets'), ...reachScope ? [
967
1124
  where('visibleTo', 'array-contains-any', [
@@ -1030,10 +1187,11 @@ export function newDatasetSharingNote(siteOnly) {
1030
1187
  variant: 'success',
1031
1188
  persist: false
1032
1189
  });
1190
+ afterDelete == null ? void 0 : afterDelete();
1033
1191
  }, [
1034
1192
  selected,
1035
1193
  datasets,
1036
- pageHostId,
1194
+ railNarrowed,
1037
1195
  reachScope,
1038
1196
  firestore,
1039
1197
  dataScope,
@@ -1165,7 +1323,7 @@ export function newDatasetSharingNote(siteOnly) {
1165
1323
  children: [
1166
1324
  /*#__PURE__*/ _jsx(Button, {
1167
1325
  size: "small",
1168
- onClick: ()=>setViewerId(record.$id),
1326
+ onClick: ()=>openRecord(record.$id),
1169
1327
  children: 'View'
1170
1328
  }),
1171
1329
  /*#__PURE__*/ _jsx(BlockedControl, {
@@ -1197,6 +1355,7 @@ export function newDatasetSharingNote(siteOnly) {
1197
1355
  referenceLabel,
1198
1356
  handleOpenRecord,
1199
1357
  handleDeleteRecord,
1358
+ openRecord,
1200
1359
  recordFilter,
1201
1360
  blocked.writes,
1202
1361
  blocked.writesReason
@@ -1241,199 +1400,463 @@ export function newDatasetSharingNote(siteOnly) {
1241
1400
  pageSorts: recordPageSorts,
1242
1401
  headers: recordSortHeaders
1243
1402
  });
1244
- return /*#__PURE__*/ _jsxs(CardDisplay, {
1245
- header: 'Data',
1403
+ /**
1404
+ * The rail (AGL-4047): one tab per dataset, at the dataset's own address,
1405
+ * with a second line that tells two of one name apart. Past
1406
+ * {@link DATASET_RAIL_GROUP_AT} the tabs are grouped by who they are shared
1407
+ * with, and the organization page offers the Shared with filter.
1408
+ */ const grouped = railDatasets.length > DATASET_RAIL_GROUP_AT;
1409
+ const railSections = useMemo(()=>{
1410
+ if (!basePath) return [];
1411
+ const tab = (item, group)=>_extends({
1412
+ href: `${basePath}/${item.$id}`,
1413
+ label: datasetRailName(item),
1414
+ secondary: datasetRailSecondary(item, {
1415
+ hostNames,
1416
+ grouped
1417
+ })
1418
+ }, group ? {
1419
+ group
1420
+ } : {});
1421
+ if (!grouped) return railDatasets.map((item)=>tab(item));
1422
+ return groupDatasetsBySharing(railDatasets, hostNames).flatMap((group)=>group.datasets.map((item)=>tab(item, group.label)));
1423
+ }, [
1424
+ basePath,
1425
+ railDatasets,
1426
+ hostNames,
1427
+ grouped
1428
+ ]);
1429
+ /** The join dialog's names, told apart where two match (AGL-4047). */ const joinLabels = useMemo(()=>datasetPickerLabelsOf(datasets, hostNames), [
1430
+ datasets,
1431
+ hostNames
1432
+ ]);
1433
+ const offerSharedWith = !pageHostId && orgSites.length > 1 && (datasets.length > DATASET_RAIL_GROUP_AT || Boolean(sharedWith));
1434
+ const sitesByName = useMemo(()=>[
1435
+ ...orgSites
1436
+ ].sort((a, b)=>{
1437
+ var _hostNames_a_$id, _hostNames_b_$id;
1438
+ return ((_hostNames_a_$id = hostNames[a.$id]) != null ? _hostNames_a_$id : '').localeCompare((_hostNames_b_$id = hostNames[b.$id]) != null ? _hostNames_b_$id : '');
1439
+ }), [
1440
+ orgSites,
1441
+ hostNames
1442
+ ]);
1443
+ const railHeader = datasets.length || nameSearch || sharedWith ? /*#__PURE__*/ _jsxs(Stack, {
1444
+ spacing: 1.5,
1445
+ sx: {
1446
+ mb: 1
1447
+ },
1448
+ children: [
1449
+ /*#__PURE__*/ _jsx(TextField, {
1450
+ size: "small",
1451
+ fullWidth: true,
1452
+ placeholder: "Search datasets by name",
1453
+ value: nameSearch,
1454
+ onChange: (event)=>setNameSearch(event.target.value),
1455
+ slotProps: {
1456
+ htmlInput: {
1457
+ 'aria-label': 'Search datasets by name'
1458
+ }
1459
+ }
1460
+ }),
1461
+ offerSharedWith ? /*#__PURE__*/ _jsxs(TextField, {
1462
+ select: true,
1463
+ size: "small",
1464
+ fullWidth: true,
1465
+ label: "Shared with",
1466
+ value: sharedWith,
1467
+ onChange: (event)=>{
1468
+ setSharedWith(event.target.value);
1469
+ setRailWindow(DATASET_LIST_WINDOW);
1470
+ },
1471
+ children: [
1472
+ /*#__PURE__*/ _jsx(MenuItem, {
1473
+ value: "",
1474
+ children: 'Any site'
1475
+ }),
1476
+ sitesByName.map((site)=>/*#__PURE__*/ _jsx(MenuItem, {
1477
+ value: site.$id,
1478
+ children: hostNames[site.$id]
1479
+ }, site.$id))
1480
+ ]
1481
+ }) : null
1482
+ ]
1483
+ }) : null;
1484
+ const railFooter = /*#__PURE__*/ _jsxs(_Fragment, {
1485
+ children: [
1486
+ listAnswered && datasets.length > 0 && railDatasets.length === 0 ? /*#__PURE__*/ _jsx(Typography, {
1487
+ variant: "body2",
1488
+ color: "text.secondary",
1489
+ sx: {
1490
+ px: 2,
1491
+ py: 1
1492
+ },
1493
+ children: moreDatasets ? 'None of the loaded datasets match.' : 'No datasets match.'
1494
+ }) : null,
1495
+ moreDatasets ? /*#__PURE__*/ _jsx(Button, {
1496
+ size: "small",
1497
+ sx: {
1498
+ mt: 1
1499
+ },
1500
+ onClick: ()=>setRailWindow((window)=>window + DATASET_LIST_WINDOW),
1501
+ children: 'Show more datasets'
1502
+ }) : null
1503
+ ]
1504
+ });
1505
+ /** The open dataset's facts, under its name. */ const facts = selected ? [
1506
+ [
1507
+ 'Shared with',
1508
+ datasetSharingLabel(selected, hostNames)
1509
+ ],
1510
+ [
1511
+ 'Fields',
1512
+ String(fields.length)
1513
+ ],
1514
+ [
1515
+ 'Records',
1516
+ blocked.records ? '--' : recordCount.toLocaleString()
1517
+ ],
1518
+ [
1519
+ 'Source',
1520
+ datasetSourceLabel(selected)
1521
+ ],
1522
+ [
1523
+ 'Created',
1524
+ datasetCreatedLabel(selected)
1525
+ ]
1526
+ ] : [];
1527
+ /** Label-over-value facts, under a heading. */ const factsRow = (pairs)=>/*#__PURE__*/ _jsx(Stack, {
1528
+ direction: "row",
1529
+ spacing: 3,
1530
+ useFlexGap: true,
1531
+ sx: {
1532
+ flexWrap: 'wrap',
1533
+ mt: 1
1534
+ },
1535
+ children: pairs.map(([label, value])=>/*#__PURE__*/ _jsxs(Box, {
1536
+ children: [
1537
+ /*#__PURE__*/ _jsx(Typography, {
1538
+ variant: "caption",
1539
+ color: "text.secondary",
1540
+ component: "div",
1541
+ children: label
1542
+ }),
1543
+ /*#__PURE__*/ _jsx(Typography, {
1544
+ variant: "body2",
1545
+ color: "text.primary",
1546
+ component: "div",
1547
+ sx: {
1548
+ overflowWrap: 'anywhere'
1549
+ },
1550
+ children: value
1551
+ })
1552
+ ]
1553
+ }, label))
1554
+ });
1555
+ /**
1556
+ * A record's own page (AGL-4047): back to its dataset, its fields, and
1557
+ * today's record actions with today's gates. It takes the place of the View
1558
+ * record dialog where the Data page is routed.
1559
+ */ const recordTitle = routeRecord ? datasetRecordTitle(model, routeRecord.values) : undefined;
1560
+ const recordPanel = selected && routeRecordId ? /*#__PURE__*/ _jsx(CardDisplay, {
1246
1561
  help: pluginDocsHelp('datasets', {
1247
- anchor: '#filter-records'
1562
+ anchor: '#organization-data-page'
1563
+ }),
1564
+ header: /*#__PURE__*/ _jsxs(Stack, {
1565
+ spacing: 1,
1566
+ sx: {
1567
+ alignItems: 'flex-start'
1568
+ },
1569
+ children: [
1570
+ datasetHref ? /*#__PURE__*/ _jsx(Button, {
1571
+ size: "small",
1572
+ component: AppLink,
1573
+ href: datasetHref,
1574
+ startIcon: /*#__PURE__*/ _jsx(MdiIcon, {
1575
+ path: mdiArrowLeft.path,
1576
+ size: 0.8
1577
+ }),
1578
+ children: datasetRailName(selected)
1579
+ }) : null,
1580
+ recordTitle ? /*#__PURE__*/ _jsx("span", {
1581
+ children: recordTitle
1582
+ }) : null
1583
+ ]
1248
1584
  }),
1249
1585
  contentGutterX: true,
1250
1586
  contentGutterY: true,
1251
- contentBordered: "all",
1252
- children: [
1253
- /*#__PURE__*/ _jsxs(Stack, {
1254
- spacing: 1.5,
1587
+ contentBordered: "top",
1588
+ HeaderProps: {
1589
+ action: routeRecord ? /*#__PURE__*/ _jsxs(Stack, {
1590
+ direction: "row",
1591
+ spacing: 1,
1592
+ useFlexGap: true,
1593
+ sx: {
1594
+ alignItems: 'center',
1595
+ flexWrap: 'wrap',
1596
+ justifyContent: 'flex-end'
1597
+ },
1255
1598
  children: [
1256
- orgId ? /*#__PURE__*/ _jsx(Typography, {
1257
- variant: "caption",
1258
- color: "text.secondary",
1259
- children: newDatasetSharingNote(createsSiteOnly)
1260
- }) : null,
1261
- datasets.length === 0 ? /*#__PURE__*/ _jsx(Typography, {
1262
- variant: "body2",
1263
- color: "text.secondary",
1264
- children: 'Create a dataset, like Products, then add a repeating section ' + 'to any page to show one item per record.'
1265
- }) : /*#__PURE__*/ _jsxs(Stack, {
1266
- direction: "row",
1267
- spacing: 1,
1268
- useFlexGap: true,
1269
- sx: {
1270
- alignItems: 'center',
1271
- flexWrap: 'wrap'
1272
- },
1273
- children: [
1274
- /*#__PURE__*/ _jsx(TextField, {
1275
- select: true,
1276
- size: "small",
1277
- label: "Dataset",
1278
- value: (_ref1 = selected == null ? void 0 : selected.$id) != null ? _ref1 : '',
1279
- onChange: (event)=>setSelectedId(event.target.value),
1280
- sx: {
1281
- minWidth: 180
1282
- },
1283
- children: datasets.map((item)=>/*#__PURE__*/ _jsx(MenuItem, {
1284
- value: item.$id,
1285
- children: datasetDisplayName(item)
1286
- }, item.$id))
1287
- }),
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
- })
1297
- }),
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
- })
1599
+ /*#__PURE__*/ _jsx(BlockedControl, {
1600
+ blocked: blocked.writes,
1601
+ reason: blocked.writesReason,
1602
+ children: /*#__PURE__*/ _jsx(Button, {
1603
+ size: "small",
1604
+ onClick: handleOpenRecord(routeRecord),
1605
+ children: 'Edit record'
1606
+ })
1607
+ }),
1608
+ /*#__PURE__*/ _jsx(BlockedControl, {
1609
+ blocked: blocked.writes,
1610
+ reason: blocked.writesReason,
1611
+ children: /*#__PURE__*/ _jsx(Button, {
1612
+ size: "small",
1613
+ color: "error",
1614
+ onClick: handleDeleteRecord(routeRecord, ()=>{
1615
+ if (datasetHref) router.push(datasetHref);
1306
1616
  }),
1307
- transferTarget ? /*#__PURE__*/ _jsx(TransferResumeImport, _extends({
1308
- target: transferTarget
1309
- }, selected ? {
1310
- title: `Import into ${datasetDisplayName(selected)}`
1311
- } : {}, {
1312
- onFinished: ()=>setRecordCountEpoch((epoch)=>epoch + 1)
1313
- })) : null,
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
- })
1322
- }) : null,
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
- })
1331
- }) : null,
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
- })
1341
- })
1342
- ]
1617
+ children: 'Delete'
1618
+ })
1619
+ })
1620
+ ]
1621
+ }) : undefined,
1622
+ subheader: factsRow([
1623
+ [
1624
+ 'Record ID',
1625
+ routeRecordId
1626
+ ],
1627
+ [
1628
+ 'Dataset',
1629
+ `${datasetRailName(selected)} · ${datasetSharingLabel(selected, hostNames)}`
1630
+ ]
1631
+ ])
1632
+ },
1633
+ children: /*#__PURE__*/ _jsx(Stack, {
1634
+ spacing: 1.5,
1635
+ children: blocked.records ? /*#__PURE__*/ _jsx(Typography, {
1636
+ variant: "body2",
1637
+ color: "text.secondary",
1638
+ children: DATASETS_VIEW_RECORDS_REFUSAL
1639
+ }) : routeRecordMissing ? /*#__PURE__*/ _jsx(Alert, {
1640
+ severity: "info",
1641
+ children: 'This record doesn’t exist, or you can’t open it.'
1642
+ }) : routeRecord ? /*#__PURE__*/ _jsx(DatasetRecordFieldList, {
1643
+ record: routeRecord,
1644
+ model: model,
1645
+ resolveReference: resolveReferenceLabel,
1646
+ divided: true
1647
+ }) : null
1648
+ })
1649
+ }) : null;
1650
+ const panel = notSharedHere ? /*#__PURE__*/ _jsx(Alert, {
1651
+ severity: "info",
1652
+ children: 'This dataset isn’t shared with this site.'
1653
+ }) : notFound ? /*#__PURE__*/ _jsx(Alert, {
1654
+ severity: "info",
1655
+ children: 'This dataset doesn’t exist, or you can’t open it.'
1656
+ }) : recordPanel ? recordPanel : !selected ? listAnswered && datasets.length === 0 && !sharedWith ? /*#__PURE__*/ _jsx(CardDisplay, {
1657
+ contentGutterX: true,
1658
+ contentGutterY: true,
1659
+ children: /*#__PURE__*/ _jsx(Typography, {
1660
+ variant: "body2",
1661
+ color: "text.secondary",
1662
+ children: 'Create a dataset, like Products, then add a repeating section ' + 'to any page to show one item per record.'
1663
+ })
1664
+ }) : null : /*#__PURE__*/ _jsx(CardDisplay, {
1665
+ header: datasetRailName(selected),
1666
+ help: pluginDocsHelp('datasets', {
1667
+ anchor: '#filter-records'
1668
+ }),
1669
+ contentGutterX: true,
1670
+ contentGutterY: true,
1671
+ contentBordered: "top",
1672
+ HeaderProps: {
1673
+ action: /*#__PURE__*/ _jsxs(Stack, {
1674
+ direction: "row",
1675
+ spacing: 1,
1676
+ useFlexGap: true,
1677
+ sx: {
1678
+ alignItems: 'center',
1679
+ flexWrap: 'wrap',
1680
+ justifyContent: 'flex-end'
1681
+ },
1682
+ children: [
1683
+ /*#__PURE__*/ _jsx(BlockedControl, {
1684
+ blocked: blocked.writes,
1685
+ reason: blocked.writesReason,
1686
+ children: /*#__PURE__*/ _jsx(Button, {
1687
+ size: "small",
1688
+ color: "primary",
1689
+ onClick: handleOpenRecord(),
1690
+ children: 'Add record'
1691
+ })
1692
+ }),
1693
+ /*#__PURE__*/ _jsx(BlockedControl, {
1694
+ blocked: blocked.writes && !blocked.sharingOnly,
1695
+ reason: blocked.writesReason,
1696
+ children: /*#__PURE__*/ _jsx(Button, {
1697
+ size: "small",
1698
+ onClick: ()=>setSchemaOpen(true),
1699
+ children: 'Schema'
1700
+ })
1343
1701
  }),
1344
- selected ? /*#__PURE__*/ _jsx(QuotaReadoutComponent, {
1345
- ready: org != null,
1346
- used: recordCount,
1347
- limit: checkQuota(org, 'recordsPerDataset', recordCount).limit,
1348
- noun: "record"
1702
+ transferTarget ? /*#__PURE__*/ _jsx(TransferResumeImport, _extends({
1703
+ target: transferTarget
1704
+ }, selected ? {
1705
+ title: `Import into ${datasetDisplayName(selected)}`
1706
+ } : {}, {
1707
+ onFinished: ()=>setRecordCountEpoch((epoch)=>epoch + 1)
1708
+ })) : null,
1709
+ canImport || transfer && transferTarget && blocked.writes ? /*#__PURE__*/ _jsx(BlockedControl, {
1710
+ blocked: !canImport,
1711
+ reason: blocked.writesReason,
1712
+ children: /*#__PURE__*/ _jsx(Button, {
1713
+ size: "small",
1714
+ onClick: handleImport,
1715
+ children: 'Import'
1716
+ })
1349
1717
  }) : null,
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, {
1355
- children: [
1356
- /*#__PURE__*/ _jsx(ListFilterChips, {
1357
- fields: recordFilter.fields,
1358
- headers: recordFilter.headers,
1359
- clauses: recordClauses,
1360
- onChange: gridFilter.setClauses,
1361
- options: recordFilter.options
1362
- }),
1363
- /*#__PURE__*/ _jsx(ListQueryNotices, {
1364
- refused: recordRefusals,
1365
- notices: [
1366
- ...recordPlan.notices,
1367
- ...recordColumnSort.notices
1368
- ]
1369
- }),
1370
- /*#__PURE__*/ _jsx(ListTable, _extends({
1371
- "aria-label": "Records",
1372
- rows: recordColumnSort.rows,
1373
- columnSort: recordColumnSort,
1374
- columns: recordGridColumns,
1375
- onOpen: (id)=>setViewerId(id),
1376
- // One page of the walk, turned by the footer below: the grid
1377
- // neither slices nor filters it.
1378
- hideFooter: true,
1379
- filterMode: "server",
1380
- filterModel: gridFilter.filterModel,
1381
- onFilterModelChange: gridFilter.onFilterModelChange,
1382
- quickFilter: true
1383
- }, blocked.exports ? {
1384
- slotProps: EXPORT_OFF_TOOLBAR
1385
- } : {}, {
1386
- noRowsLabel: filteringRecords ? 'No records match these filters' : 'No records yet.'
1387
- })),
1388
- /*#__PURE__*/ _jsx(ListPagination, {
1389
- page: recordPage,
1390
- pageSize: recordPageSize,
1391
- rowCount: records.length,
1392
- hasMore: hasMoreRecords,
1393
- onPageChange: setRecordPage,
1394
- onPageSizeChange: setRecordPageSize
1395
- })
1396
- ]
1397
- }) : selected ? /*#__PURE__*/ _jsx(Typography, {
1398
- variant: "body2",
1399
- color: "text.secondary",
1400
- children: 'No records yet.'
1718
+ canExport && (recordCount || records.length) || transfer && blocked.exports ? /*#__PURE__*/ _jsx(BlockedControl, {
1719
+ blocked: blocked.exports,
1720
+ reason: DATASETS_EXPORT_REFUSAL,
1721
+ children: /*#__PURE__*/ _jsx(Button, {
1722
+ size: "small",
1723
+ onClick: handleExport,
1724
+ children: 'Export'
1725
+ })
1401
1726
  }) : null,
1402
- /*#__PURE__*/ _jsxs(Stack, {
1403
- direction: "row",
1404
- spacing: 1,
1405
- useFlexGap: true,
1406
- sx: {
1407
- flexWrap: 'wrap'
1408
- },
1409
- children: [
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
- })
1420
- }),
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
- })
1432
- }) : null
1433
- ]
1727
+ /*#__PURE__*/ _jsx(BlockedControl, {
1728
+ blocked: blocked.deletes,
1729
+ reason: blocked.deletesReason,
1730
+ children: /*#__PURE__*/ _jsx(Button, {
1731
+ size: "small",
1732
+ color: "error",
1733
+ onClick: handleDeleteDataset,
1734
+ children: 'Delete'
1735
+ })
1434
1736
  })
1435
1737
  ]
1436
1738
  }),
1739
+ subheader: factsRow(facts)
1740
+ },
1741
+ children: /*#__PURE__*/ _jsxs(Stack, {
1742
+ spacing: 1.5,
1743
+ children: [
1744
+ selected ? /*#__PURE__*/ _jsx(QuotaReadoutComponent, {
1745
+ ready: org != null,
1746
+ used: recordCount,
1747
+ limit: checkQuota(org, 'recordsPerDataset', recordCount).limit,
1748
+ noun: "record"
1749
+ }) : null,
1750
+ selected && blocked.records ? /*#__PURE__*/ _jsx(Typography, {
1751
+ variant: "body2",
1752
+ color: "text.secondary",
1753
+ children: DATASETS_VIEW_RECORDS_REFUSAL
1754
+ }) : selected && (records.length > 0 || recordPage > 0 || filteringRecords) ? /*#__PURE__*/ _jsxs(_Fragment, {
1755
+ children: [
1756
+ /*#__PURE__*/ _jsx(ListFilterChips, {
1757
+ fields: recordFilter.fields,
1758
+ headers: recordFilter.headers,
1759
+ clauses: recordClauses,
1760
+ onChange: gridFilter.setClauses,
1761
+ options: recordFilter.options
1762
+ }),
1763
+ /*#__PURE__*/ _jsx(ListQueryNotices, {
1764
+ refused: recordRefusals,
1765
+ notices: [
1766
+ ...recordPlan.notices,
1767
+ ...recordColumnSort.notices
1768
+ ]
1769
+ }),
1770
+ /*#__PURE__*/ _jsx(ListTable, _extends({
1771
+ "aria-label": "Records",
1772
+ // Edit and Delete stay in reach when the columns scroll sideways
1773
+ // in the panel beside the rail (AGL-4047).
1774
+ pinActions: true,
1775
+ rows: recordColumnSort.rows,
1776
+ columnSort: recordColumnSort,
1777
+ columns: recordGridColumns,
1778
+ onOpen: (id)=>openRecord(id),
1779
+ // One page of the walk, turned by the footer below: the grid
1780
+ // neither slices nor filters it.
1781
+ hideFooter: true,
1782
+ filterMode: "server",
1783
+ filterModel: gridFilter.filterModel,
1784
+ onFilterModelChange: gridFilter.onFilterModelChange,
1785
+ quickFilter: true
1786
+ }, blocked.exports ? {
1787
+ slotProps: EXPORT_OFF_TOOLBAR
1788
+ } : {}, {
1789
+ noRowsLabel: filteringRecords ? 'No records match these filters' : 'No records yet.'
1790
+ })),
1791
+ /*#__PURE__*/ _jsx(ListPagination, {
1792
+ page: recordPage,
1793
+ pageSize: recordPageSize,
1794
+ rowCount: records.length,
1795
+ hasMore: hasMoreRecords,
1796
+ onPageChange: setRecordPage,
1797
+ onPageSizeChange: setRecordPageSize
1798
+ })
1799
+ ]
1800
+ }) : selected ? /*#__PURE__*/ _jsx(Typography, {
1801
+ variant: "body2",
1802
+ color: "text.secondary",
1803
+ children: 'No records yet.'
1804
+ }) : null
1805
+ ]
1806
+ })
1807
+ });
1808
+ return /*#__PURE__*/ _jsxs(_Fragment, {
1809
+ children: [
1810
+ /*#__PURE__*/ _jsx(PageHeaderActions, {
1811
+ children: /*#__PURE__*/ _jsxs(Stack, {
1812
+ direction: "row",
1813
+ spacing: 1,
1814
+ useFlexGap: true,
1815
+ sx: {
1816
+ flexWrap: 'wrap'
1817
+ },
1818
+ children: [
1819
+ /*#__PURE__*/ _jsx(BlockedControl, {
1820
+ blocked: blocked.creates,
1821
+ reason: DATASETS_WRITE_REFUSAL,
1822
+ children: /*#__PURE__*/ _jsx(Button, {
1823
+ variant: "outlined",
1824
+ color: "primary",
1825
+ onClick: handleOpenCreator,
1826
+ children: 'Add dataset'
1827
+ })
1828
+ }),
1829
+ datasets.length >= 2 ? /*#__PURE__*/ _jsx(BlockedControl, {
1830
+ blocked: blocked.creates,
1831
+ reason: DATASETS_WRITE_REFUSAL,
1832
+ children: /*#__PURE__*/ _jsx(Button, {
1833
+ onClick: ()=>setJoiner({
1834
+ a: '',
1835
+ b: ''
1836
+ }),
1837
+ children: 'Add join collection'
1838
+ })
1839
+ }) : null
1840
+ ]
1841
+ })
1842
+ }),
1843
+ routeRecordId && selected && datasetHref ? /*#__PURE__*/ _jsx(PageHeaderRecord, {
1844
+ title: recordTitle,
1845
+ keepHeading: true,
1846
+ parentTitle: datasetRailName(selected),
1847
+ parentHref: datasetHref
1848
+ }) : /*#__PURE__*/ _jsx(PageHeaderRecord, {
1849
+ title: selected && routeDatasetId ? datasetRailName(selected) : undefined,
1850
+ keepHeading: true
1851
+ }),
1852
+ /*#__PURE__*/ _jsx(HubSections, {
1853
+ sections: railSections,
1854
+ navHeader: "Datasets",
1855
+ railHeader: railHeader,
1856
+ railFooter: railFooter,
1857
+ scrollRail: true,
1858
+ children: panel
1859
+ }),
1437
1860
  /*#__PURE__*/ _jsxs(Dialog, {
1438
1861
  open: Boolean(creator),
1439
1862
  onClose: ()=>setCreator(null),
@@ -1450,9 +1873,17 @@ export function newDatasetSharingNote(siteOnly) {
1450
1873
  gap: 2
1451
1874
  },
1452
1875
  children: [
1876
+ orgId ? /*#__PURE__*/ _jsx(Typography, {
1877
+ variant: "body2",
1878
+ color: "text.secondary",
1879
+ sx: {
1880
+ mt: 1
1881
+ },
1882
+ children: newDatasetSharingNote(createsSiteOnly)
1883
+ }) : null,
1453
1884
  /*#__PURE__*/ _jsx(TextField, {
1454
1885
  label: "Name",
1455
- value: (_ref2 = creator == null ? void 0 : creator.name) != null ? _ref2 : '',
1886
+ value: (_ref4 = creator == null ? void 0 : creator.name) != null ? _ref4 : '',
1456
1887
  onChange: (event)=>setCreator((prev)=>prev ? _extends({}, prev, {
1457
1888
  name: event.target.value
1458
1889
  }) : prev),
@@ -1465,7 +1896,7 @@ export function newDatasetSharingNote(siteOnly) {
1465
1896
  }),
1466
1897
  /*#__PURE__*/ _jsx(TextField, {
1467
1898
  label: "Fields",
1468
- value: (_ref3 = creator == null ? void 0 : creator.fields) != null ? _ref3 : '',
1899
+ value: (_ref5 = creator == null ? void 0 : creator.fields) != null ? _ref5 : '',
1469
1900
  onChange: (event)=>setCreator((prev)=>prev ? _extends({}, prev, {
1470
1901
  fields: event.target.value
1471
1902
  }) : prev),
@@ -1726,7 +2157,7 @@ export function newDatasetSharingNote(siteOnly) {
1726
2157
  }) : prev),
1727
2158
  children: datasets.map((item)=>/*#__PURE__*/ _jsx(MenuItem, {
1728
2159
  value: item.$id,
1729
- children: datasetDisplayName(item)
2160
+ children: joinLabels[item.$id]
1730
2161
  }, item.$id))
1731
2162
  }, side);
1732
2163
  })
@@ -1758,9 +2189,9 @@ export function newDatasetSharingNote(siteOnly) {
1758
2189
  // dialog warns "N documents exist" before a narrowing type change,
1759
2190
  // and 500 was the cap talking, not the collection.
1760
2191
  recordCount: recordCount,
1761
- seedFromCache: datasetsFromCache,
1762
- seedUnreadable: datasetsStatus === 'error',
1763
- seedListen: datasetsListen,
2192
+ seedFromCache: seed.fromCache,
2193
+ seedUnreadable: seed.unreadable,
2194
+ seedListen: seed.listen,
1764
2195
  canChangeSharing: !blocked.creates
1765
2196
  }, blocked.sharingOnly ? {
1766
2197
  sharingOnlyReason: blocked.writesReason