@aglyn/plugins-data 1.0.0-beta.285 → 1.0.0-beta.287

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aglyn/plugins-data",
3
- "version": "1.0.0-beta.285",
3
+ "version": "1.0.0-beta.287",
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.0.0-beta.285",
29
- "@aglyn/shared-data-mdi": "1.0.0-beta.285",
30
- "@aglyn/shared-ui-jsx": "1.0.0-beta.285",
31
- "@aglyn/shared-ui-snackstack": "1.0.0-beta.285",
32
- "@aglyn/shared-util-http": "1.0.0-beta.285",
33
- "@aglyn/shared-util-timestamp": "1.0.0-beta.285",
34
- "@aglyn/tenant-data-admin": "1.0.0-beta.285",
35
- "@aglyn/tenant-feature-instance": "1.0.0-beta.285",
36
- "@aglyn/tenant-runtime": "1.0.0-beta.285",
28
+ "@aglyn/aglyn": "1.0.0-beta.287",
29
+ "@aglyn/shared-data-mdi": "1.0.0-beta.287",
30
+ "@aglyn/shared-ui-jsx": "1.0.0-beta.287",
31
+ "@aglyn/shared-ui-snackstack": "1.0.0-beta.287",
32
+ "@aglyn/shared-util-http": "1.0.0-beta.287",
33
+ "@aglyn/shared-util-timestamp": "1.0.0-beta.287",
34
+ "@aglyn/tenant-data-admin": "1.0.0-beta.287",
35
+ "@aglyn/tenant-feature-instance": "1.0.0-beta.287",
36
+ "@aglyn/tenant-runtime": "1.0.0-beta.287",
37
37
  "@swc/helpers": "0.5.23"
38
38
  },
39
39
  "peerDependencies": {
@@ -28,7 +28,7 @@ import { listFilterGridColumns } from "@aglyn/shared-ui-jsx/const/list-grid-filt
28
28
  import { useListGridFilter } from "@aglyn/shared-ui-jsx/hooks/use-list-grid-filter";
29
29
  import { useSnackbar } from "@aglyn/shared-ui-snackstack";
30
30
  import { Timestamp } from "@aglyn/shared-util-timestamp";
31
- import { Button, Dialog, DialogActions, DialogContent, DialogTitle, MenuItem, Stack, TextField, Typography } from "@mui/material";
31
+ import { Alert, Button, Chip, Dialog, DialogActions, DialogContent, DialogTitle, MenuItem, Stack, TextField, Tooltip, Typography } from "@mui/material";
32
32
  import { collection, deleteDoc, deleteField, doc, getCountFromServer, 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";
@@ -42,7 +42,7 @@ 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 { datasetDisplayName, parseDatasetFieldEntries } from "../model/datasets.js";
45
+ import { DATASET_SAMPLE_RECORD_NOTE, datasetDisplayName, isSampleDatasetRecord, parseDatasetFieldEntries } from "../model/datasets.js";
46
46
  import { datasetTransferResourceKey } from "../transfer/dataset-transfer-key.js";
47
47
  /**
48
48
  * The sentence that says who a NEW dataset is shared with, for the card and
@@ -751,11 +751,13 @@ export function newDatasetSharingNote(siteOnly) {
751
751
  // Flag non-conforming stored values (AGL-178 policy: type changes
752
752
  // never rewrite documents; the editor surfaces the mismatch).
753
753
  const errors = record ? validateDocument(model, (_record_values = record.values) != null ? _record_values : {}) : {};
754
- setEditor({
754
+ setEditor(_extends({
755
755
  id: (_ref = record == null ? void 0 : record.$id) != null ? _ref : null,
756
756
  values,
757
757
  errors
758
- });
758
+ }, isSampleDatasetRecord(record) ? {
759
+ sample: true
760
+ } : {}));
759
761
  }, [
760
762
  org,
761
763
  recordCount,
@@ -781,7 +783,9 @@ export function newDatasetSharingNote(siteOnly) {
781
783
  const recordRef = doc(firestore, dataScope[0], dataScope[1], 'datasets', selected.$id, 'records', editor.id);
782
784
  await setDoc(recordRef, _extends({
783
785
  values: coerced
784
- }, datasetIntegrityUpdate(model, coerced, deleteField()), {
786
+ }, datasetIntegrityUpdate(model, coerced, deleteField()), editor.sample ? {
787
+ sample: deleteField()
788
+ } : {}, {
785
789
  updatedAt: Timestamp.now()
786
790
  }), {
787
791
  mergeFields: [
@@ -789,7 +793,10 @@ export function newDatasetSharingNote(siteOnly) {
789
793
  'referencedIds',
790
794
  'filterKeys',
791
795
  'filterValues',
792
- 'updatedAt'
796
+ 'updatedAt',
797
+ ...editor.sample ? [
798
+ 'sample'
799
+ ] : []
793
800
  ]
794
801
  });
795
802
  await announceRecords(selected.$id);
@@ -1003,9 +1010,13 @@ export function newDatasetSharingNote(siteOnly) {
1003
1010
  * column holds the keyboard's way in (`View`, a real button) beside Edit
1004
1011
  * and Delete, and a press anywhere in it never opens the row.
1005
1012
  */ const recordGridColumns = useMemo(()=>listFilterGridColumns([
1006
- ...fields.map((fieldId)=>{
1013
+ ...fields.map((fieldId, column)=>{
1007
1014
  var _ref;
1008
1015
  const field = model.fields[fieldId];
1016
+ const shown = (row)=>{
1017
+ var _row_values, _row_values1;
1018
+ return (field == null ? void 0 : field.type) === 'reference' ? referenceLabel(fieldId, (_row_values = row.values) == null ? void 0 : _row_values[fieldId]) || '--' : field ? formatDatasetValue(field, (_row_values1 = row.values) == null ? void 0 : _row_values1[fieldId]) || '--' : '--';
1019
+ };
1009
1020
  return {
1010
1021
  field: recordColumn(fieldId),
1011
1022
  headerName: (_ref = field == null ? void 0 : field.name) != null ? _ref : fieldId,
@@ -1013,10 +1024,32 @@ export function newDatasetSharingNote(siteOnly) {
1013
1024
  description: field == null ? void 0 : field.description,
1014
1025
  flex: 1,
1015
1026
  minWidth: 140,
1016
- renderCell: ({ row })=>{
1017
- var _row_values, _row_values1;
1018
- return (field == null ? void 0 : field.type) === 'reference' ? referenceLabel(fieldId, (_row_values = row.values) == null ? void 0 : _row_values[fieldId]) || '--' : field ? formatDatasetValue(field, (_row_values1 = row.values) == null ? void 0 : _row_values1[fieldId]) || '--' : '--';
1019
- }
1027
+ renderCell: ({ row })=>// A sample a site start seeded says so beside its first value (AGL-4065).
1028
+ column === 0 && isSampleDatasetRecord(row) ? /*#__PURE__*/ _jsxs(Stack, {
1029
+ direction: "row",
1030
+ spacing: 1,
1031
+ sx: {
1032
+ alignItems: 'center',
1033
+ height: '100%',
1034
+ minWidth: 0
1035
+ },
1036
+ children: [
1037
+ /*#__PURE__*/ _jsx(Typography, {
1038
+ variant: "body2",
1039
+ noWrap: true,
1040
+ children: shown(row)
1041
+ }),
1042
+ /*#__PURE__*/ _jsx(Tooltip, {
1043
+ title: DATASET_SAMPLE_RECORD_NOTE,
1044
+ children: /*#__PURE__*/ _jsx(Chip, {
1045
+ label: "Sample",
1046
+ size: "small",
1047
+ variant: "outlined",
1048
+ color: "info"
1049
+ })
1050
+ })
1051
+ ]
1052
+ }) : shown(row)
1020
1053
  };
1021
1054
  }),
1022
1055
  listActionsColumn((record)=>/*#__PURE__*/ _jsxs(Stack, {
@@ -1333,156 +1366,162 @@ export function newDatasetSharingNote(siteOnly) {
1333
1366
  /*#__PURE__*/ _jsx(DialogTitle, {
1334
1367
  children: (editor == null ? void 0 : editor.id) ? 'Edit record' : 'New record'
1335
1368
  }),
1336
- /*#__PURE__*/ _jsx(DialogContent, {
1369
+ /*#__PURE__*/ _jsxs(DialogContent, {
1337
1370
  sx: {
1338
1371
  display: 'flex',
1339
1372
  flexDirection: 'column',
1340
1373
  gap: 2
1341
1374
  },
1342
- children: /*#__PURE__*/ _jsx(DatasetRecordSiteContext.Provider, {
1343
- value: recordSite,
1344
- children: fields.map((fieldId, index)=>{
1345
- var _ref;
1346
- var _field_validation_options, _field_validation;
1347
- const field = model.fields[fieldId];
1348
- if (!field) return null;
1349
- const value = (_ref = editor == null ? void 0 : editor.values[fieldId]) != null ? _ref : '';
1350
- const error = editor == null ? void 0 : editor.errors[fieldId];
1351
- const label = field.required ? `${field.name} *` : field.name;
1352
- const setValue = (nextValue)=>setEditor((prev)=>prev ? _extends({}, prev, {
1353
- values: _extends({}, prev.values, {
1354
- [fieldId]: nextValue
1355
- }),
1356
- errors: _extends({}, prev.errors, {
1357
- [fieldId]: ''
1358
- })
1359
- }) : prev);
1360
- const common = {
1361
- label,
1362
- value,
1363
- size: 'small',
1364
- autoFocus: index === 0,
1365
- error: Boolean(error),
1366
- helperText: error || field.description,
1367
- sx: index === 0 ? {
1368
- mt: 1
1369
- } : undefined,
1370
- onChange: (event)=>setValue(event.target.value)
1371
- };
1372
- // Custom field types (AGL-434): the declaring plugin's Input
1373
- // takes over; values stay in input form (strings) so the
1374
- // existing coerce/validate pipeline is unchanged.
1375
- const customFieldType = getCustomFieldType(field.customType);
1376
- if (customFieldType == null ? void 0 : customFieldType.Input) {
1377
- const CustomInput = customFieldType.Input;
1378
- return /*#__PURE__*/ _jsxs(Stack, {
1375
+ children: [
1376
+ (editor == null ? void 0 : editor.sample) ? /*#__PURE__*/ _jsx(Alert, {
1377
+ severity: "info",
1378
+ children: DATASET_SAMPLE_RECORD_NOTE
1379
+ }) : null,
1380
+ /*#__PURE__*/ _jsx(DatasetRecordSiteContext.Provider, {
1381
+ value: recordSite,
1382
+ children: fields.map((fieldId, index)=>{
1383
+ var _ref;
1384
+ var _field_validation_options, _field_validation;
1385
+ const field = model.fields[fieldId];
1386
+ if (!field) return null;
1387
+ const value = (_ref = editor == null ? void 0 : editor.values[fieldId]) != null ? _ref : '';
1388
+ const error = editor == null ? void 0 : editor.errors[fieldId];
1389
+ const label = field.required ? `${field.name} *` : field.name;
1390
+ const setValue = (nextValue)=>setEditor((prev)=>prev ? _extends({}, prev, {
1391
+ values: _extends({}, prev.values, {
1392
+ [fieldId]: nextValue
1393
+ }),
1394
+ errors: _extends({}, prev.errors, {
1395
+ [fieldId]: ''
1396
+ })
1397
+ }) : prev);
1398
+ const common = {
1399
+ label,
1400
+ value,
1401
+ size: 'small',
1402
+ autoFocus: index === 0,
1403
+ error: Boolean(error),
1404
+ helperText: error || field.description,
1379
1405
  sx: index === 0 ? {
1380
1406
  mt: 1
1381
1407
  } : undefined,
1382
- children: [
1383
- /*#__PURE__*/ _jsx(CustomInput, {
1384
- value: value,
1385
- label: common.label,
1386
- onChange: (next)=>setValue(String(next != null ? next : ''))
1387
- }),
1388
- error || field.description ? /*#__PURE__*/ _jsx(Typography, {
1389
- variant: "caption",
1390
- color: error ? 'error' : 'text.secondary',
1391
- children: error || field.description
1392
- }) : null
1393
- ]
1394
- }, fieldId);
1395
- }
1396
- // Typed inputs per FT.Tag (AGL-179).
1397
- if (field.type === 'bool') {
1398
- return /*#__PURE__*/ _jsxs(TextField, _extends({}, common, {
1399
- select: true,
1400
- children: [
1401
- /*#__PURE__*/ _jsx(MenuItem, {
1402
- value: "",
1403
- children: '—'
1404
- }),
1405
- /*#__PURE__*/ _jsx(MenuItem, {
1406
- value: "true",
1407
- children: 'Yes'
1408
- }),
1409
- /*#__PURE__*/ _jsx(MenuItem, {
1410
- value: "false",
1411
- children: 'No'
1412
- })
1413
- ]
1414
- }), fieldId);
1415
- }
1416
- if (field.type === 'text' && ((_field_validation = field.validation) == null ? void 0 : (_field_validation_options = _field_validation.options) == null ? void 0 : _field_validation_options.length)) {
1417
- return /*#__PURE__*/ _jsxs(TextField, _extends({}, common, {
1418
- select: true,
1419
- children: [
1420
- /*#__PURE__*/ _jsx(MenuItem, {
1421
- value: "",
1422
- children: '—'
1423
- }),
1424
- field.validation.options.map((option)=>/*#__PURE__*/ _jsx(MenuItem, {
1425
- value: option,
1426
- children: option
1427
- }, option))
1428
- ]
1429
- }), fieldId);
1430
- }
1431
- if (field.type === 'reference') {
1432
- var _refOptions_fieldId;
1433
- var _field_reference;
1434
- const options = (_refOptions_fieldId = refOptions[fieldId]) != null ? _refOptions_fieldId : [];
1435
- const multiple = Boolean((_field_reference = field.reference) == null ? void 0 : _field_reference.multiple);
1436
- const selectedIds = value.split(',').map((part)=>part.trim()).filter(Boolean);
1437
- return /*#__PURE__*/ _jsxs(TextField, _extends({}, common, {
1438
- select: true,
1439
- value: multiple ? selectedIds : value,
1440
- slotProps: {
1441
- select: multiple ? {
1442
- multiple: true,
1443
- onChange: (event)=>setValue(event.target.value.join(', '))
1444
- } : undefined
1445
- },
1446
- children: [
1447
- multiple ? null : /*#__PURE__*/ _jsx(MenuItem, {
1448
- value: "",
1449
- children: '—'
1450
- }),
1451
- options.map((option)=>/*#__PURE__*/ _jsx(MenuItem, {
1452
- value: option.id,
1453
- children: option.label
1454
- }, option.id))
1455
- ]
1456
- }), fieldId);
1457
- }
1458
- if (field.type === 'int32' || field.type === 'int64' || field.type === 'float') {
1459
- return /*#__PURE__*/ _jsx(TextField, _extends({}, common, {
1460
- type: "number"
1461
- }), fieldId);
1462
- }
1463
- if (field.type === 'timestamp') {
1464
- return /*#__PURE__*/ _jsx(TextField, _extends({}, common, {
1465
- type: "datetime-local",
1466
- slotProps: {
1467
- inputLabel: {
1468
- shrink: true
1408
+ onChange: (event)=>setValue(event.target.value)
1409
+ };
1410
+ // Custom field types (AGL-434): the declaring plugin's Input
1411
+ // takes over; values stay in input form (strings) so the
1412
+ // existing coerce/validate pipeline is unchanged.
1413
+ const customFieldType = getCustomFieldType(field.customType);
1414
+ if (customFieldType == null ? void 0 : customFieldType.Input) {
1415
+ const CustomInput = customFieldType.Input;
1416
+ return /*#__PURE__*/ _jsxs(Stack, {
1417
+ sx: index === 0 ? {
1418
+ mt: 1
1419
+ } : undefined,
1420
+ children: [
1421
+ /*#__PURE__*/ _jsx(CustomInput, {
1422
+ value: value,
1423
+ label: common.label,
1424
+ onChange: (next)=>setValue(String(next != null ? next : ''))
1425
+ }),
1426
+ error || field.description ? /*#__PURE__*/ _jsx(Typography, {
1427
+ variant: "caption",
1428
+ color: error ? 'error' : 'text.secondary',
1429
+ children: error || field.description
1430
+ }) : null
1431
+ ]
1432
+ }, fieldId);
1433
+ }
1434
+ // Typed inputs per FT.Tag (AGL-179).
1435
+ if (field.type === 'bool') {
1436
+ return /*#__PURE__*/ _jsxs(TextField, _extends({}, common, {
1437
+ select: true,
1438
+ children: [
1439
+ /*#__PURE__*/ _jsx(MenuItem, {
1440
+ value: "",
1441
+ children: '—'
1442
+ }),
1443
+ /*#__PURE__*/ _jsx(MenuItem, {
1444
+ value: "true",
1445
+ children: 'Yes'
1446
+ }),
1447
+ /*#__PURE__*/ _jsx(MenuItem, {
1448
+ value: "false",
1449
+ children: 'No'
1450
+ })
1451
+ ]
1452
+ }), fieldId);
1453
+ }
1454
+ if (field.type === 'text' && ((_field_validation = field.validation) == null ? void 0 : (_field_validation_options = _field_validation.options) == null ? void 0 : _field_validation_options.length)) {
1455
+ return /*#__PURE__*/ _jsxs(TextField, _extends({}, common, {
1456
+ select: true,
1457
+ children: [
1458
+ /*#__PURE__*/ _jsx(MenuItem, {
1459
+ value: "",
1460
+ children: '—'
1461
+ }),
1462
+ field.validation.options.map((option)=>/*#__PURE__*/ _jsx(MenuItem, {
1463
+ value: option,
1464
+ children: option
1465
+ }, option))
1466
+ ]
1467
+ }), fieldId);
1468
+ }
1469
+ if (field.type === 'reference') {
1470
+ var _refOptions_fieldId;
1471
+ var _field_reference;
1472
+ const options = (_refOptions_fieldId = refOptions[fieldId]) != null ? _refOptions_fieldId : [];
1473
+ const multiple = Boolean((_field_reference = field.reference) == null ? void 0 : _field_reference.multiple);
1474
+ const selectedIds = value.split(',').map((part)=>part.trim()).filter(Boolean);
1475
+ return /*#__PURE__*/ _jsxs(TextField, _extends({}, common, {
1476
+ select: true,
1477
+ value: multiple ? selectedIds : value,
1478
+ slotProps: {
1479
+ select: multiple ? {
1480
+ multiple: true,
1481
+ onChange: (event)=>setValue(event.target.value.join(', '))
1482
+ } : undefined
1483
+ },
1484
+ children: [
1485
+ multiple ? null : /*#__PURE__*/ _jsx(MenuItem, {
1486
+ value: "",
1487
+ children: '—'
1488
+ }),
1489
+ options.map((option)=>/*#__PURE__*/ _jsx(MenuItem, {
1490
+ value: option.id,
1491
+ children: option.label
1492
+ }, option.id))
1493
+ ]
1494
+ }), fieldId);
1495
+ }
1496
+ if (field.type === 'int32' || field.type === 'int64' || field.type === 'float') {
1497
+ return /*#__PURE__*/ _jsx(TextField, _extends({}, common, {
1498
+ type: "number"
1499
+ }), fieldId);
1500
+ }
1501
+ if (field.type === 'timestamp') {
1502
+ return /*#__PURE__*/ _jsx(TextField, _extends({}, common, {
1503
+ type: "datetime-local",
1504
+ slotProps: {
1505
+ inputLabel: {
1506
+ shrink: true
1507
+ }
1469
1508
  }
1470
- }
1471
- }), fieldId);
1472
- }
1473
- if (field.type === 'coordinates') {
1474
- return /*#__PURE__*/ _jsx(TextField, _extends({}, common, {
1475
- helperText: error || field.description || 'lat, lon'
1476
- }), fieldId);
1477
- }
1478
- if (field.type === 'sorted') {
1479
- return /*#__PURE__*/ _jsx(TextField, _extends({}, common, {
1480
- helperText: error || field.description || 'Comma-separated list'
1481
- }), fieldId);
1482
- }
1483
- return /*#__PURE__*/ _jsx(TextField, _extends({}, common), fieldId);
1509
+ }), fieldId);
1510
+ }
1511
+ if (field.type === 'coordinates') {
1512
+ return /*#__PURE__*/ _jsx(TextField, _extends({}, common, {
1513
+ helperText: error || field.description || 'lat, lon'
1514
+ }), fieldId);
1515
+ }
1516
+ if (field.type === 'sorted') {
1517
+ return /*#__PURE__*/ _jsx(TextField, _extends({}, common, {
1518
+ helperText: error || field.description || 'Comma-separated list'
1519
+ }), fieldId);
1520
+ }
1521
+ return /*#__PURE__*/ _jsx(TextField, _extends({}, common), fieldId);
1522
+ })
1484
1523
  })
1485
- })
1524
+ ]
1486
1525
  }),
1487
1526
  /*#__PURE__*/ _jsxs(DialogActions, {
1488
1527
  children: [