@aglyn/plugins-data 1.20.1 → 1.20.2
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 +11 -11
- package/src/lib/components/dataset-schema-dialog.component.js +20 -2
- package/src/lib/components/dataset-schema-dialog.component.js.map +1 -1
- package/src/lib/components/host-datasets-card.component.js +27 -4
- package/src/lib/components/host-datasets-card.component.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aglyn/plugins-data",
|
|
3
|
-
"version": "1.20.
|
|
3
|
+
"version": "1.20.2",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"homepage": "https://aglyn.com",
|
|
6
6
|
"repository": {
|
|
@@ -25,16 +25,16 @@
|
|
|
25
25
|
"./package.json": "./package.json"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@aglyn/aglyn": "1.20.
|
|
29
|
-
"@aglyn/shared-data-mdi": "1.20.
|
|
30
|
-
"@aglyn/shared-ui-jsx": "1.20.
|
|
31
|
-
"@aglyn/shared-ui-next": "1.20.
|
|
32
|
-
"@aglyn/shared-ui-snackstack": "1.20.
|
|
33
|
-
"@aglyn/shared-util-http": "1.20.
|
|
34
|
-
"@aglyn/shared-util-timestamp": "1.20.
|
|
35
|
-
"@aglyn/tenant-data-admin": "1.20.
|
|
36
|
-
"@aglyn/tenant-feature-instance": "1.20.
|
|
37
|
-
"@aglyn/tenant-runtime": "1.20.
|
|
28
|
+
"@aglyn/aglyn": "1.20.2",
|
|
29
|
+
"@aglyn/shared-data-mdi": "1.20.2",
|
|
30
|
+
"@aglyn/shared-ui-jsx": "1.20.2",
|
|
31
|
+
"@aglyn/shared-ui-next": "1.20.2",
|
|
32
|
+
"@aglyn/shared-ui-snackstack": "1.20.2",
|
|
33
|
+
"@aglyn/shared-util-http": "1.20.2",
|
|
34
|
+
"@aglyn/shared-util-timestamp": "1.20.2",
|
|
35
|
+
"@aglyn/tenant-data-admin": "1.20.2",
|
|
36
|
+
"@aglyn/tenant-feature-instance": "1.20.2",
|
|
37
|
+
"@aglyn/tenant-runtime": "1.20.2",
|
|
38
38
|
"@swc/helpers": "0.5.23"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
@@ -175,8 +175,8 @@ import { datasetPickerLabelsOf } from "../model/dataset-rail.js";
|
|
|
175
175
|
// rules refuse that write from anyone who is not org-wide, and it
|
|
176
176
|
// repairs only what somebody happens to look at — a repair mechanism
|
|
177
177
|
// wearing a UI. `handleSave` reads the SAME helper; see the note there
|
|
178
|
-
// for why the pair is the safety property.
|
|
179
|
-
|
|
178
|
+
// for why the pair is the safety property. The sharing is seeded by the
|
|
179
|
+
// effect below.
|
|
180
180
|
const effective = effectiveDatasetModel(dataset);
|
|
181
181
|
setModel({
|
|
182
182
|
fields: JSON.parse(JSON.stringify(effective.fields)),
|
|
@@ -191,6 +191,24 @@ import { datasetPickerLabelsOf } from "../model/dataset-rail.js";
|
|
|
191
191
|
}, [
|
|
192
192
|
dataset
|
|
193
193
|
]);
|
|
194
|
+
/*
|
|
195
|
+
* The sharing, seeded for this dataset and again only when its STORED
|
|
196
|
+
* sharing moves, not on every snapshot of it (AGL-4047). A save writes the
|
|
197
|
+
* schema before the route answers for the sharing, so a refused sharing
|
|
198
|
+
* change still brings a fresh dataset, and seeding from it put the choice
|
|
199
|
+
* back on the stored one while the refusal was said: the choice being
|
|
200
|
+
* refused is the one to keep.
|
|
201
|
+
*/ const storedSharing = useMemo(()=>dataset ? sharingChoiceOf(dataset) : null, [
|
|
202
|
+
dataset
|
|
203
|
+
]);
|
|
204
|
+
const storedSharingKey = dataset ? `${dataset.$id}|${sharingChoiceKey(storedSharing)}` : null;
|
|
205
|
+
useEffect(()=>{
|
|
206
|
+
if (storedSharingKey === null) return;
|
|
207
|
+
setSharing(storedSharing);
|
|
208
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- `storedSharing` is read through its key
|
|
209
|
+
}, [
|
|
210
|
+
storedSharingKey
|
|
211
|
+
]);
|
|
194
212
|
// Per-field editor (null fieldId = new field). `idDraft`/`idTouched` back
|
|
195
213
|
// the editable Reference ID (AGL-578): for a new field the draft follows
|
|
196
214
|
// the display name until the user edits it; existing fields keep the id
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/data/src/lib/components/dataset-schema-dialog.component.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n'use client'\n\nimport {\n getCustomFieldType,\n listCustomFieldTypes,\n describeSharing,\n narrowsScope,\n scopeSharingOf,\n sharingCovers,\n sharingFromChoice,\n storedScope,\n visibleToHost,\n} from '@aglyn/aglyn'\nimport { useConfirmationContext } from '@aglyn/shared-ui-jsx'\nimport {\n SiteSharingField,\n type SiteSharingValue,\n} from '@aglyn/shared-ui-jsx/components/site-sharing-field.component'\nimport { authorizedFetch } from '@aglyn/shared-util-http/authorized-token'\nimport { useSnackbar } from '@aglyn/shared-ui-snackstack'\nimport {\n Button,\n Checkbox,\n Alert,\n Box,\n Chip,\n Dialog,\n DialogActions,\n DialogContent,\n DialogTitle,\n FormControlLabel,\n IconButton,\n MenuItem,\n Stack,\n TextField,\n Typography,\n} from '@mui/material'\nimport { doc, updateDoc } from 'firebase/firestore'\nimport { type ReactNode, useCallback, useEffect, useMemo, useState } from 'react'\nimport {\n useFirestore,\n useOrgDataScope,\n useScopeTokens,\n useUser,\n writeGuardedBySeed,\n type ListenHandle,\n} from '@aglyn/tenant-feature-instance'\nimport { DATASET_AUTHORABLE_FIELD_TYPES, DATASET_FIELD_TYPES, DATASET_FIELD_TYPE_LABELS, type DatasetFieldDefinition, type DatasetFieldType, type DatasetModel, effectiveDatasetModel } from '../model/dataset-models'\nimport { datasetDisplayName, datasetNameLower, defaultDatasetFieldId, validateDatasetFieldId } from '../model/datasets'\nimport { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from '../record-pages/record-pages'\nimport { useOrgSites } from './use-org-sites'\nimport { type DatasetRailEntry, datasetPickerLabelsOf } from '../model/dataset-rail'\n\n/** Types surfaced in the picker; the rest exist for compat, not authoring. */\nconst AUTHORABLE_TYPES = DATASET_AUTHORABLE_FIELD_TYPES\n\nexport interface DatasetSchemaDialogProps {\n /** Host context; resolves the owning org for the data scope. */\n hostId?: string\n /** Direct org scope (AGL-239): wins over `hostId` resolution when set. */\n orgId?: string\n dataset: {\n $id: string\n displayName?: string\n fields?: string[]\n model?: DatasetModel\n names?: { singular?: string; plural?: string }\n } | null\n /** All host collections, for reference-field target pickers (AGL-180). */\n datasets?: Array<{\n $id: string\n displayName?: string\n fields?: string[]\n model?: DatasetModel\n }>\n recordCount: number\n /**\n * The listener that produced `dataset` has NOT been confirmed by the\n * server (AGL-1358). Required rather than optional on purpose: the\n * listener lives in the parent card, so this dialog cannot compute the\n * verdict, and an optional prop a caller forgets is a guard that is off\n * while looking present — which is exactly how AGL-1356 stayed open.\n */\n seedFromCache: boolean\n /** That listener FAILED (`status === 'error'`). */\n seedUnreadable?: boolean\n /** That listener, so a save waits on that read alone (AGL-4135). */\n seedListen?: ListenHandle | null\n /**\n * Whether this member may change who the dataset is shared with: \"Manage\n * data\" with every site in reach. A site's verdict writes the dataset and never\n * moves it, so someone it admits reads the sharing instead (AGL-4047).\n */\n canChangeSharing?: boolean\n /**\n * Why this member may change who the dataset is shared with and nothing else\n * here, or absent where they may change it all (AGL-4047): a site that narrows\n * them takes the dataset's schema and records, and sharing is not among those.\n * The schema shows switched off, with this reason, and a save writes the\n * sharing alone.\n */\n sharingOnlyReason?: string\n onClose: () => void\n}\n\n/** The dialog's schema controls, switched off together where only the sharing is this member's. */\nfunction SchemaControls(props: { locked: boolean; children: ReactNode }) {\n return props.locked ? (\n <Box component=\"fieldset\" disabled sx={{ border: 0, m: 0, p: 0, minWidth: 0 }}>\n {props.children}\n </Box>\n ) : (\n <>{props.children}</>\n )\n}\n\n/**\n * How a dataset is shared, as the choice the sharing field edits, or null where\n * it stores no sharing (AGL-1484). The seed and the save both read it from here,\n * so a dialog nobody touched compares equal to its own document and writes none.\n */\nfunction sharingChoiceOf(dataset: unknown): SiteSharingValue | null {\n const sharing = scopeSharingOf(dataset as Record<string, unknown> | null)\n if (sharing.mode === 'all') return { mode: 'all' }\n if (sharing.mode === 'selected') return { mode: 'selected', hostIds: sharing.hostIds }\n if (sharing.mode === 'allExcept') return { mode: 'allExcept', exceptHostIds: sharing.exceptHostIds }\n return null\n}\n\n/** Two choices compare by what they pick, in any order. */\nfunction sharingChoiceKey(choice: SiteSharingValue | null): string {\n if (!choice) return 'unset'\n if (choice.mode === 'all') return 'all'\n const picked = choice.mode === 'selected' ? choice.hostIds : choice.exceptHostIds\n return `${choice.mode}:${[...picked].sort().join(',')}`\n}\n\n/**\n * Model builder (AGL-178): edits the AGL-177 typed model on a dataset —\n * singular/plural display names (dod.ts Schema.Name), add/edit/remove/\n * reorder fields, per-field type/required/default/description/validation.\n * Schema-change policies (documented per the issue): type changes never\n * rewrite documents — non-conforming values surface in the editor when it\n * validates (AGL-179); removed fields leave orphaned values that strip\n * lazily on next document save; fieldIds are stable keys — only display\n * names rename.\n */\nexport function DatasetSchemaDialog(props: DatasetSchemaDialogProps) {\n const {\n hostId,\n dataset,\n datasets,\n recordCount,\n seedFromCache,\n seedUnreadable,\n seedListen,\n canChangeSharing = true,\n sharingOnlyReason,\n onClose,\n } = props\n // Org-shared data root (AGL-237/239). Null until the async org lookup\n // settles (AGL-1061), and for a host with no owning org. Saving is held\n // on it rather than redirected: the host path this used to fall back to\n // is now denied by the rules outright (AGL-1050), so a save there would\n // fail loudly instead of quietly — but it should not be attempted at all.\n const { scope: dataScope, orgId } = useOrgDataScope({\n hostId,\n orgId: props.orgId,\n })\n const firestore = useFirestore()\n const { enqueueSnackbar } = useSnackbar()\n const { confirm } = useConfirmationContext()\n\n // Sharing scope (AGL-1044) — org datasets only; the legacy host path is\n // site-private by construction.\n // `orgWide` reads TRUE while the member doc loads (AGL-1047), which would\n // offer a scoped collaborator the sharing field for a beat before replacing\n // it with the read-only summary — and offering a control the AGL-1041\n // rules will reject is the thing the branch below exists to avoid. Hold\n // the whole block until `loaded` rather than flash the wrong one.\n const { orgWide: viewerOrgWide, loaded: scopeLoaded } = useScopeTokens(\n orgId ?? undefined,\n )\n // Sites in this org, for naming what a narrowing would cost: the Data\n // card's own query (`useOrgSites`), so the two share one listener.\n const { sites: orgHostList, ready: sitesReady, hostNames } = useOrgSites(orgId)\n const { data: user } = useUser()\n const sharingSites = useMemo(\n () => orgHostList.map((host) => ({ id: host.$id, name: host.name ?? host.subdomain ?? host.$id })),\n [orgHostList],\n )\n /**\n * Who this dataset is shared with, as edited here. Null while the dataset\n * stores NO scope (AGL-1484) — as opposed to storing `['org']`.\n *\n * The dialog used to render the two identically, which for a dataset is a\n * worse lie than it was for a media file: `orgs/{orgId}/datasets` is read\n * with `array-contains-any` in `resolve-dataset.ts` and in the console's\n * own `organizations.ts`, so an unstamped dataset is matched by no reader\n * in the product. It renders on no site and is missing from the reference\n * cards even for an org-wide member — while this control said \"All sites\".\n */\n const [sharing, setSharing] = useState<SiteSharingValue | null>(null)\n const scopeUnset = sharing === null\n /**\n * What the choice would write, or why it cannot be. The same answer the\n * `set-sharing` route gives from the workspace's sites, which it reads for\n * itself: the sites a choice leaves out stay known here even where this member\n * can't name them, so they aren't taken for sites that are gone.\n */\n const sharingDraft = useMemo(() => {\n if (!sharing) return null\n const leftOut = sharing.mode === 'allExcept' ? sharing.exceptHostIds : []\n return sharingFromChoice(sharing, [...orgHostList.map((host) => host.$id), ...leftOut])\n }, [sharing, orgHostList])\n // Nothing to say about leaving sites out until the sites have been read.\n const sharingProblem = sharing?.mode !== 'allExcept' || sitesReady ? (sharingDraft?.problem ?? null) : null\n /** The dataset as this choice would leave it, for what depends on where it is. */\n const sharingPreview = useMemo(() => sharingDraft?.fields ?? { visibleTo: [] as string[] }, [sharingDraft])\n\n const [model, setModel] = useState<DatasetModel>({ fields: {}, order: [] })\n const [names, setNames] = useState<{ singular: string; plural: string }>({\n singular: '',\n plural: '',\n })\n useEffect(() => {\n if (!dataset) return\n // The fourth copy of the AGL-1466 substitution (AGL-1484), and the seed\n // half of it. Persisting the default on open was the other option and\n // AGL-1466 ruled it out: opening a dialog would write, the AGL-1042\n // rules refuse that write from anyone who is not org-wide, and it\n // repairs only what somebody happens to look at — a repair mechanism\n // wearing a UI. `handleSave` reads the SAME helper; see the note there\n // for why the pair is the safety property.\n setSharing(sharingChoiceOf(dataset))\n const effective = effectiveDatasetModel(dataset)\n setModel({\n fields: JSON.parse(JSON.stringify(effective.fields)),\n order: [...effective.order],\n })\n setNames({\n singular: dataset.names?.singular ?? '',\n plural: dataset.names?.plural ?? datasetDisplayName(dataset),\n })\n }, [dataset])\n\n // Per-field editor (null fieldId = new field). `idDraft`/`idTouched` back\n // the editable Reference ID (AGL-578): for a new field the draft follows\n // the display name until the user edits it; existing fields keep the id\n // frozen (idTouched=true, input disabled).\n const [fieldEditor, setFieldEditor] = useState<{\n fieldId: string | null\n definition: DatasetFieldDefinition\n optionsText: string\n idDraft: string\n idTouched: boolean\n } | null>(null)\n\n const openFieldEditor = useCallback(\n (fieldId: string | null) => () => {\n const definition: DatasetFieldDefinition = fieldId\n ? JSON.parse(JSON.stringify(model.fields[fieldId]))\n : { name: '', type: 'text' }\n setFieldEditor({\n fieldId,\n definition,\n optionsText: (definition.validation?.options ?? []).join(', '),\n idDraft: fieldId ?? '',\n idTouched: fieldId != null,\n })\n },\n [model],\n )\n\n const handleFieldSave = useCallback(async () => {\n if (!fieldEditor) return\n const definition = { ...fieldEditor.definition }\n if (!definition.name.trim()) return\n definition.name = definition.name.trim()\n // Descriptions (AGL-560) surface as hints wherever the field appears;\n // blank ones are dropped so the model doesn't accrete empty strings.\n const description = definition.description?.trim()\n if (description) definition.description = description\n else delete definition.description\n const options = fieldEditor.optionsText\n .split(',')\n .map((option) => option.trim())\n .filter(Boolean)\n definition.validation = {\n ...(definition.validation ?? {}),\n ...(options.length ? { options } : {}),\n }\n if (!options.length) delete definition.validation.options\n if (!Object.keys(definition.validation).length) delete definition.validation\n\n let fieldId = fieldEditor.fieldId\n if (!fieldId) {\n // New field: the reference id comes from the (editable) draft, which\n // defaulted from the display name. Validate before it becomes a key.\n const id = fieldEditor.idDraft.trim()\n const idError = validateDatasetFieldId(\n id,\n new Set(model.order.map((existing) => existing.toLowerCase())),\n )\n if (idError) {\n return void enqueueSnackbar(idError, {\n variant: 'warning',\n persist: false,\n })\n }\n fieldId = id\n } else if (\n recordCount > 0 &&\n model.fields[fieldId] &&\n model.fields[fieldId].type !== definition.type\n ) {\n // Documented policy: changing a type never rewrites documents;\n // existing values that no longer conform get flagged when edited.\n const confirmed = await confirm({\n title: 'Change field type?',\n description:\n `${recordCount} document${recordCount === 1 ? '' : 's'} exist. ` +\n 'Stored values are not rewritten — ones that no longer match ' +\n `\"${DATASET_FIELD_TYPE_LABELS[definition.type]}\" will be flagged ` +\n 'when documents are next edited.',\n confirmationText: 'Change type',\n })\n .then(() => true)\n .catch(() => false)\n if (!confirmed) return\n }\n setModel((prev) => ({\n fields: { ...prev.fields, [fieldId as string]: definition },\n order: prev.order.includes(fieldId as string)\n ? prev.order\n : [...prev.order, fieldId as string],\n }))\n setFieldEditor(null)\n }, [fieldEditor, model, recordCount, confirm, enqueueSnackbar])\n\n const handleFieldRemove = useCallback(\n (fieldId: string) => async () => {\n const confirmed = await confirm({\n title: `Remove field \"${model.fields[fieldId]?.name ?? fieldId}\"?`,\n description:\n 'Existing documents keep their stored value until they are next ' +\n 'saved (it is stripped then). Bindings using this field stop ' +\n 'resolving.',\n confirmationText: 'Remove',\n confirmationButtonProps: { color: 'error' },\n })\n .then(() => true)\n .catch(() => false)\n if (!confirmed) return\n setModel((prev) => {\n const fields = { ...prev.fields }\n delete fields[fieldId]\n return { fields, order: prev.order.filter((id) => id !== fieldId) }\n })\n },\n [model, confirm],\n )\n\n const moveField = useCallback(\n (fieldId: string, delta: number) => () =>\n setModel((prev) => {\n const index = prev.order.indexOf(fieldId)\n const target = index + delta\n if (index < 0 || target < 0 || target >= prev.order.length) return prev\n const order = [...prev.order]\n order.splice(index, 1)\n order.splice(target, 0, fieldId)\n return { ...prev, order }\n }),\n [],\n )\n\n const handleSave = useCallback(async () => {\n if (!dataset || !dataScope) return\n /**\n * What the document actually carries, nothing when it carries nothing\n * (AGL-1484) — matching the seed above, through the same helper.\n *\n * The pairing is the whole safety property, not tidiness. Both sides\n * used to substitute `[ORG_SCOPE_TOKEN]`, so an unset dataset compared\n * equal to itself and merely OPENING the dialog wrote nothing; the\n * damage was confined to the screen. Correcting the seed alone would\n * make `scopeChanged` true for every unset dataset the moment its\n * dialog opened, turning a lie on screen into a write nobody asked for\n * — one the AGL-1041 rules then reject for any member who is not\n * org-wide, failing the WHOLE schema save with it.\n *\n * Nothing is also the honest previous value in the other direction: a\n * deliberate save of exactly `['org']` on an unset dataset used to\n * compare equal to the default and be dropped, and that is the one save\n * an unstamped dataset most needs to land.\n */\n const scopeChanged = sharingChoiceKey(sharingChoiceOf(dataset)) !== sharingChoiceKey(sharing)\n /**\n * The sharing this save writes, or null when it writes none.\n *\n * Only an org-wide member may change it — the route and the AGL-1041 rules\n * refuse anyone else, and it is written through the route because a marker\n * is the server's alone (AGL-4047).\n *\n * A choice that cannot be stored — \"Selected sites\" with no site picked, or\n * more sites than one query can match, or nothing left out, or everything —\n * refuses the save rather than substituting a scope: the org token would\n * share the collection with every site, and anything narrower would drop\n * sites somebody picked.\n */\n const sharingWrite = orgId && viewerOrgWide && canChangeSharing && scopeChanged ? sharing : null\n if (sharingWrite && sharingDraft?.problem) {\n return void enqueueSnackbar(sharingDraft.problem, {\n variant: 'warning',\n persist: false,\n })\n }\n const previousScope: string[] = storedScope((dataset as { visibleTo?: string[] }).visibleTo) ?? []\n const nextScope: readonly string[] = sharingPreview.visibleTo\n if (scopeChanged && narrowsScope(previousScope, nextScope)) {\n // Narrowing takes a dataset away from sites whose pages may bind it,\n // and a repeatable bound to a dataset it can no longer see renders\n // nothing (AGL-1039). Name the cost before paying it.\n const losing = orgHostList\n .filter((host) => visibleToHost(previousScope, host.$id))\n .filter((host) => !visibleToHost(nextScope, host.$id))\n .map((host) => host.name ?? host.subdomain ?? host.$id)\n const proceed = await confirm({\n title: 'Limit which sites can use this collection?',\n description: losing.length\n ? `${losing.join(', ')} will stop seeing this collection. Pages ` +\n 'that repeat over it will render nothing. No data is deleted.'\n : 'No site loses access, so nothing breaks today.',\n confirmationText: 'Limit access',\n })\n .then(() => true)\n .catch(() => false)\n if (!proceed) return\n }\n // Nothing of theirs to write when the sharing did not move.\n if (sharingOnlyReason && !sharingWrite) return void onClose()\n if (!model.order.length) {\n return void enqueueSnackbar('A collection needs at least one field', {\n variant: 'warning',\n persist: false,\n })\n }\n /**\n * Refuse the write when the seeding listener is unconfirmed (AGL-1358).\n *\n * Everything below is seeded from `dataset` and written back whole, so\n * `updateDoc` field-level merging protects nothing — the untouched\n * fields are all in the payload. Two of them make a stale seed worse\n * than an inconvenience:\n *\n * - `visibleTo` is the AGL-1041/1042 scoping PREDICATE. Rewriting it\n * from a cached seed re-exposes a collection that was narrowed, or\n * hides one that was widened, and the confirmation above is computed\n * against `previousScope` read from that same stale seed — so it does\n * not even warn about the sites it is really taking access from.\n * - `model` is the entire schema. A cached seed reinstates fields that\n * were deleted and drops fields that were added.\n *\n * The schema goes first, because who may write it depends on where the\n * dataset sits as it stands, the question the rule asks of this one save.\n */\n let sharingRefusal: string | null = null\n await writeGuardedBySeed(\n {\n subject: 'collection schema',\n unreadable: seedUnreadable,\n fromCache: seedFromCache,\n listen: seedListen,\n },\n async () => {\n if (!sharingOnlyReason) {\n await updateDoc(\n doc(firestore, dataScope[0], dataScope[1], 'datasets', dataset.$id),\n {\n model,\n names: {\n singular: names.singular.trim(),\n plural: names.plural.trim(),\n },\n // The name's search key moves with it (AGL-4047).\n ...(names.plural.trim()\n ? {\n displayName: names.plural.trim(),\n nameLower: datasetNameLower(names.plural),\n }\n : {}),\n // v1 compat: keep the flat column list mirroring the model order\n // so unmigrated consumers (AGL-103 bindings) keep working.\n fields: model.order,\n },\n )\n }\n if (sharingWrite) {\n const response = await authorizedFetch(user, '/api/orgs/datasets', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n orgId,\n action: 'set-sharing',\n datasetId: dataset.$id,\n choice: sharingWrite,\n }),\n })\n if (!response.ok) {\n const payload = await response.json().catch(() => ({}))\n sharingRefusal = String(payload?.error ?? 'The sharing could not be changed.')\n }\n }\n },\n )\n .then((result) => {\n // A refusal leaves the dialog open with the edited schema intact.\n if (!result.ok) {\n return void enqueueSnackbar(result.message, {\n variant: 'warning',\n persist: false,\n })\n }\n if (sharingRefusal) {\n return void enqueueSnackbar(\n sharingOnlyReason ? sharingRefusal : `Schema saved. Its sharing didn’t change: ${sharingRefusal}`,\n { variant: 'warning', persist: false },\n )\n }\n enqueueSnackbar(sharingOnlyReason ? 'Sharing saved' : 'Schema saved', { variant: 'success', persist: false })\n onClose()\n })\n .catch(() =>\n enqueueSnackbar('An error has occurred', { variant: 'error' }),\n )\n }, [\n dataset,\n model,\n names,\n sharing,\n sharingDraft,\n sharingPreview,\n user,\n viewerOrgWide,\n canChangeSharing,\n sharingOnlyReason,\n orgHostList,\n confirm,\n firestore,\n dataScope,\n orgId,\n seedFromCache,\n seedUnreadable,\n seedListen,\n enqueueSnackbar,\n onClose,\n ])\n\n const editorDefinition = fieldEditor?.definition\n // Reference ID editing (AGL-578): the id is editable only while creating a\n // field; live-validate the draft so the input and Save button can react.\n const isNewField = fieldEditor != null && fieldEditor.fieldId == null\n const fieldIdError =\n fieldEditor && isNewField\n ? validateDatasetFieldId(\n fieldEditor.idDraft,\n new Set(model.order.map((id) => id.toLowerCase())),\n )\n : null\n\n return (\n <>\n <Dialog\n open={Boolean(dataset)}\n onClose={onClose}\n maxWidth=\"sm\"\n fullWidth\n >\n <DialogTitle>{`Schema — ${datasetDisplayName(dataset)}`}</DialogTitle>\n <DialogContent\n sx={{ display: 'flex', flexDirection: 'column', gap: 2 }}\n >\n {sharingOnlyReason ? <Alert severity=\"info\">{sharingOnlyReason}</Alert> : null}\n <SchemaControls locked={Boolean(sharingOnlyReason)}>\n <Stack direction=\"row\" spacing={1} sx={{ mt: 1 }}>\n <TextField\n size=\"small\"\n label=\"Singular name\"\n value={names.singular}\n onChange={(event) =>\n setNames((prev) => ({ ...prev, singular: event.target.value }))\n }\n helperText=\"e.g. Product\"\n />\n <TextField\n size=\"small\"\n label=\"Plural name\"\n value={names.plural}\n onChange={(event) =>\n setNames((prev) => ({ ...prev, plural: event.target.value }))\n }\n helperText=\"e.g. Products (shown as the title)\"\n />\n </Stack>\n </SchemaControls>\n {/* Sharing scope (AGL-1044). Org datasets only; the legacy host\n path is site-private already. Read-only for scoped members —\n the rules deny them the write and it would fail the whole\n document, so a control that always errors is worse than the\n value. */}\n {orgId ? (\n <Stack spacing={0.5}>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {'Shared with'}\n </Typography>\n {!scopeLoaded ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'Checking your access…'}\n </Typography>\n ) : viewerOrgWide && canChangeSharing ? (\n <>\n {/*\n The state this dialog used to hide (AGL-1484), in the\n words the folder dialog and the media drawer already\n use. It costs a sentence, and it is the difference\n between reading \"All sites\" off a collection no site can\n see and being told to choose. No choice shows as picked\n until someone picks one.\n */}\n {scopeUnset ? (\n <Alert severity=\"warning\">\n {'This collection has never been shared. Nothing is ' +\n 'stored, so it is hidden from every site and any ' +\n 'page repeating over it renders nothing. Choose who ' +\n 'it is shared with to fix that.'}\n </Alert>\n ) : null}\n <SiteSharingField\n value={sharing}\n onChange={setSharing}\n sites={sharingSites}\n sitesReady={sitesReady}\n problem={sharingProblem}\n />\n {/* Says what sharing does NOT do, which is the part\n people get wrong (AGL-1046). It controls which sites\n may use the data; it is not a permission on the rows\n a published page already renders. */}\n <Typography variant=\"caption\" color=\"text.secondary\">\n {\n 'Sites you exclude cannot see or use this dataset — in the console or on their pages.'\n }\n </Typography>\n </>\n ) : (\n <Typography variant=\"body2\">\n {/*\n A scoped collaborator cannot fix this — the AGL-1041\n rules deny them the write — but they are the ones who\n notice a repeatable rendering nothing on their site, so\n they get the reason rather than `describeScope`'s \"No\n sites\", which reads like a setting somebody chose\n (AGL-1484).\n */}\n {scopeUnset\n ? 'Never shared — hidden from every site'\n : describeSharing(\n dataset as Record<string, unknown> | null,\n Object.fromEntries(\n sharingSites.map((site) => [site.id, site.name]),\n ),\n )}\n </Typography>\n )}\n </Stack>\n ) : null}\n <SchemaControls locked={Boolean(sharingOnlyReason)}>\n <Stack spacing={0.5}>\n {model.order.map((fieldId, index) => {\n const field = model.fields[fieldId]\n if (!field) return null\n return (\n <Stack\n key={fieldId}\n direction=\"row\"\n spacing={1}\n sx={{\n alignItems: 'center',\n px: 1,\n py: 0.5,\n border: '1px solid',\n borderColor: 'divider',\n borderRadius: 1,\n }}\n >\n <Stack sx={{ flex: 1, minWidth: 0 }}>\n <Typography variant=\"body2\" noWrap>\n {field.name}\n <Typography\n component=\"span\"\n variant=\"caption\"\n color=\"text.secondary\"\n >\n {` · ${fieldId}`}\n </Typography>\n </Typography>\n {field.description ? (\n <Typography\n variant=\"caption\"\n color=\"text.secondary\"\n noWrap\n >\n {field.description}\n </Typography>\n ) : null}\n </Stack>\n <Chip\n size=\"small\"\n label={DATASET_FIELD_TYPE_LABELS[field.type] ?? field.type}\n />\n {field.required || field.validation?.required ? (\n <Chip size=\"small\" color=\"primary\" label=\"required\" />\n ) : null}\n <IconButton\n size=\"small\"\n disabled={index === 0}\n onClick={moveField(fieldId, -1)}\n aria-label=\"Move up\"\n >\n {'▲'}\n </IconButton>\n <IconButton\n size=\"small\"\n disabled={index === model.order.length - 1}\n onClick={moveField(fieldId, 1)}\n aria-label=\"Move down\"\n >\n {'▼'}\n </IconButton>\n <Button size=\"small\" onClick={openFieldEditor(fieldId)}>\n {'Edit'}\n </Button>\n <Button\n size=\"small\"\n color=\"error\"\n onClick={handleFieldRemove(fieldId)}\n >\n {'Remove'}\n </Button>\n </Stack>\n )\n })}\n </Stack>\n <Button\n size=\"small\"\n variant=\"outlined\"\n color=\"primary\"\n onClick={openFieldEditor(null)}\n sx={{ alignSelf: 'flex-start' }}\n >\n {'Add field'}\n </Button>\n </SchemaControls>\n </DialogContent>\n <DialogActions>\n <Button onClick={onClose}>{'Cancel'}</Button>\n {/* Held until the data scope resolves (AGL-1061) — a save in that\n window writes the schema to the legacy host path. */}\n <Button\n variant=\"contained\"\n color=\"primary\"\n disabled={!dataScope}\n onClick={handleSave}\n >\n {sharingOnlyReason ? 'Save sharing' : 'Save schema'}\n </Button>\n </DialogActions>\n </Dialog>\n\n <Dialog\n open={Boolean(fieldEditor)}\n onClose={() => setFieldEditor(null)}\n maxWidth=\"xs\"\n fullWidth\n >\n <DialogTitle>\n {fieldEditor?.fieldId ? 'Edit field' : 'New field'}\n </DialogTitle>\n <DialogContent\n sx={{ display: 'flex', flexDirection: 'column', gap: 2 }}\n >\n <TextField\n size=\"small\"\n label=\"Display name\"\n value={editorDefinition?.name ?? ''}\n autoFocus\n onChange={(event) => {\n const name = event.target.value\n setFieldEditor((prev) => {\n if (!prev) return prev\n const next = {\n ...prev,\n definition: { ...prev.definition, name },\n }\n // The reference id follows the display name until the user\n // edits it (new fields only) — AGL-578.\n if (prev.fieldId == null && !prev.idTouched) {\n next.idDraft = defaultDatasetFieldId(\n name,\n new Set(model.order.map((id) => id.toLowerCase())),\n )\n }\n return next\n })\n }}\n sx={{ mt: 1 }}\n helperText=\"Shown to people editing records and wherever the field appears\"\n />\n <TextField\n size=\"small\"\n label=\"Reference ID\"\n value={\n isNewField\n ? (fieldEditor?.idDraft ?? '')\n : (fieldEditor?.fieldId ?? '')\n }\n disabled={!isNewField}\n onChange={(event) =>\n setFieldEditor((prev) =>\n prev\n ? { ...prev, idDraft: event.target.value, idTouched: true }\n : prev,\n )\n }\n error={Boolean(fieldIdError)}\n helperText={\n isNewField\n ? (fieldIdError ??\n 'Stable key used in bindings ({{item.id}}), forms, and imports. Auto-filled from the display name — edit to override. Fixed once the field is created.')\n : 'Reference IDs are stable keys and cannot change after creation'\n }\n />\n <TextField\n size=\"small\"\n label=\"Description\"\n multiline\n minRows={2}\n value={editorDefinition?.description ?? ''}\n onChange={(event) =>\n setFieldEditor((prev) =>\n prev\n ? {\n ...prev,\n definition: {\n ...prev.definition,\n description: event.target.value,\n },\n }\n : prev,\n )\n }\n helperText=\"What this field is for — shown as a hint wherever the field appears\"\n />\n <TextField\n select\n size=\"small\"\n label=\"Type\"\n value={\n editorDefinition?.customType\n ? `custom:${editorDefinition.customType}`\n : (editorDefinition?.type ?? 'text')\n }\n onChange={(event) =>\n setFieldEditor((prev) => {\n if (!prev) return prev\n const selected = event.target.value\n // Custom field types (AGL-434): ride a base storage type\n // and stamp customType so the record editor + validators\n // pick up the plugin behavior.\n if (selected.startsWith('custom:')) {\n const fieldType = getCustomFieldType(selected.slice(7))\n if (!fieldType) return prev\n return {\n ...prev,\n definition: {\n ...prev.definition,\n type: fieldType.baseType as DatasetFieldType,\n customType: fieldType.name,\n },\n }\n }\n const definition = {\n ...prev.definition,\n type: selected as DatasetFieldType,\n }\n delete definition.customType\n return { ...prev, definition }\n })\n }\n >\n {(fieldEditor?.fieldId &&\n editorDefinition &&\n !AUTHORABLE_TYPES.includes(editorDefinition.type)\n ? DATASET_FIELD_TYPES\n : AUTHORABLE_TYPES\n ).map((type) => (\n <MenuItem key={type} value={type}>\n {DATASET_FIELD_TYPE_LABELS[type]}\n </MenuItem>\n ))}\n {listCustomFieldTypes().map((fieldType) => (\n <MenuItem\n key={`custom:${fieldType.name}`}\n value={`custom:${fieldType.name}`}\n >\n {`${fieldType.label} (${fieldType.pluginId})`}\n </MenuItem>\n ))}\n </TextField>\n {editorDefinition?.customType === RECORD_PAGE_ADDRESS_FIELD_TYPE ? (\n <TextField\n select\n size=\"small\"\n label=\"Fill in from\"\n value={editorDefinition.slugFrom ?? ''}\n onChange={(event) =>\n setFieldEditor((prev) => {\n if (!prev) return prev\n const definition = { ...prev.definition }\n if (event.target.value) definition.slugFrom = event.target.value\n else delete definition.slugFrom\n return { ...prev, definition }\n })\n }\n helperText=\"An empty address fills in from this field once, and stays put when the record is renamed\"\n >\n <MenuItem value=\"\">Nothing — type each address</MenuItem>\n {model.order\n .filter(\n (fieldId) =>\n fieldId !== fieldEditor?.fieldId &&\n model.fields[fieldId]?.type === 'text' &&\n !isRecordAddressField(model.fields[fieldId]),\n )\n .map((fieldId) => (\n <MenuItem key={fieldId} value={fieldId}>\n {model.fields[fieldId]?.name ?? fieldId}\n </MenuItem>\n ))}\n </TextField>\n ) : null}\n {editorDefinition?.type === 'reference' ? (\n <>\n <TextField\n select\n size=\"small\"\n label=\"Target collection\"\n value={editorDefinition?.reference?.datasetId ?? ''}\n onChange={(event) =>\n setFieldEditor((prev) =>\n prev\n ? {\n ...prev,\n definition: {\n ...prev.definition,\n reference: {\n ...(prev.definition.reference ?? {\n datasetId: '',\n }),\n datasetId: event.target.value,\n },\n },\n }\n : prev,\n )\n }\n >\n {(() => {\n const targets = (datasets ?? [])\n .filter((target) => target.$id !== dataset?.$id)\n // Only targets this dataset's sites can actually resolve\n // (AGL-1044). A reference to a dataset a site cannot see\n // renders blank with nothing to say why, so an\n // unresolvable target is not offered. The currently\n // selected one always stays listed — otherwise changing\n // scope would silently blank an existing field.\n .filter(\n (target) =>\n target.$id ===\n editorDefinition?.reference?.datasetId ||\n sharingCovers(target as Record<string, unknown>, sharingPreview as Record<string, unknown>),\n )\n // Who a target is shared with only where two share a name (AGL-4047).\n const labels = datasetPickerLabelsOf(targets as DatasetRailEntry[], hostNames)\n return targets.map((target) => (\n <MenuItem key={target.$id} value={target.$id}>\n {labels[target.$id] || datasetDisplayName(target) || target.$id}\n </MenuItem>\n ))\n })()}\n </TextField>\n {(() => {\n // Flag an EXISTING reference that this dataset's scope has\n // outgrown — the field was valid when created and quietly\n // is not any more.\n const targetId = editorDefinition?.reference?.datasetId\n const target = (datasets ?? []).find((d) => d.$id === targetId)\n if (\n !target ||\n sharingCovers(target as Record<string, unknown>, sharingPreview as Record<string, unknown>)\n ) {\n return null\n }\n return (\n <Alert severity=\"warning\">\n {`\"${datasetDisplayName(target) || target.$id}\" is not shared with ` +\n 'every site this collection is. Those sites will show ' +\n 'this field blank. Widen its sharing, or narrow this ' +\n \"collection's.\"}\n </Alert>\n )\n })()}\n <TextField\n select\n size=\"small\"\n label=\"Display field\"\n value={editorDefinition?.reference?.displayFieldId ?? ''}\n onChange={(event) =>\n setFieldEditor((prev) =>\n prev?.definition.reference\n ? {\n ...prev,\n definition: {\n ...prev.definition,\n reference: {\n ...prev.definition.reference,\n displayFieldId: event.target.value,\n },\n },\n }\n : prev,\n )\n }\n helperText=\"Shown in pickers and grid cells\"\n >\n {effectiveDatasetModel(\n (datasets ?? []).find(\n (target) =>\n target.$id === editorDefinition?.reference?.datasetId,\n ) ?? {},\n ).order.map((targetFieldId) => (\n <MenuItem key={targetFieldId} value={targetFieldId}>\n {targetFieldId}\n </MenuItem>\n ))}\n </TextField>\n <TextField\n select\n size=\"small\"\n label=\"When a referenced document is deleted\"\n value={editorDefinition?.reference?.onDelete ?? 'setNull'}\n onChange={(event) =>\n setFieldEditor((prev) =>\n prev?.definition.reference\n ? {\n ...prev,\n definition: {\n ...prev.definition,\n reference: {\n ...prev.definition.reference,\n onDelete: event.target.value as\n | 'restrict'\n | 'setNull',\n },\n },\n }\n : prev,\n )\n }\n >\n <MenuItem value=\"setNull\">{'Clear the reference'}</MenuItem>\n <MenuItem value=\"restrict\">{'Block the delete'}</MenuItem>\n </TextField>\n <FormControlLabel\n control={\n <Checkbox\n size=\"small\"\n checked={Boolean(editorDefinition?.reference?.multiple)}\n onChange={(event) =>\n setFieldEditor((prev) =>\n prev?.definition.reference\n ? {\n ...prev,\n definition: {\n ...prev.definition,\n reference: {\n ...prev.definition.reference,\n multiple: event.target.checked,\n },\n },\n }\n : prev,\n )\n }\n />\n }\n label=\"Allow multiple (many-to-many)\"\n />\n </>\n ) : null}\n <FormControlLabel\n control={\n <Checkbox\n size=\"small\"\n checked={Boolean(editorDefinition?.required)}\n onChange={(event) =>\n setFieldEditor((prev) =>\n prev\n ? {\n ...prev,\n definition: {\n ...prev.definition,\n required: event.target.checked,\n },\n }\n : prev,\n )\n }\n />\n }\n label=\"Required\"\n />\n <TextField\n size=\"small\"\n label=\"Default value\"\n value={String(editorDefinition?.default ?? '')}\n onChange={(event) =>\n setFieldEditor((prev) =>\n prev\n ? {\n ...prev,\n definition: {\n ...prev.definition,\n ...(event.target.value\n ? { default: event.target.value }\n : { default: undefined }),\n },\n }\n : prev,\n )\n }\n helperText=\"Pre-filled when creating documents\"\n />\n {editorDefinition?.type === 'text' ? (\n <>\n <TextField\n size=\"small\"\n label=\"Pattern (regex)\"\n value={editorDefinition?.validation?.regex ?? ''}\n onChange={(event) =>\n setFieldEditor((prev) =>\n prev\n ? {\n ...prev,\n definition: {\n ...prev.definition,\n validation: {\n ...(prev.definition.validation ?? {}),\n ...(event.target.value\n ? { regex: event.target.value }\n : { regex: undefined }),\n },\n },\n }\n : prev,\n )\n }\n />\n <TextField\n size=\"small\"\n label=\"Options\"\n value={fieldEditor?.optionsText ?? ''}\n onChange={(event) =>\n setFieldEditor((prev) =>\n prev ? { ...prev, optionsText: event.target.value } : prev,\n )\n }\n helperText=\"Comma-separated enum, e.g. basic, plus\"\n />\n </>\n ) : null}\n {editorDefinition &&\n ['int32', 'int64', 'float', 'timestamp', 'text'].includes(\n editorDefinition.type,\n ) ? (\n <Stack direction=\"row\" spacing={1}>\n {(['min', 'max'] as const).map((bound) => (\n <TextField\n key={bound}\n size=\"small\"\n type=\"number\"\n label={\n editorDefinition.type === 'text'\n ? `${bound === 'min' ? 'Min' : 'Max'} length`\n : bound === 'min'\n ? 'Min'\n : 'Max'\n }\n value={editorDefinition.validation?.[bound] ?? ''}\n onChange={(event) =>\n setFieldEditor((prev) =>\n prev\n ? {\n ...prev,\n definition: {\n ...prev.definition,\n validation: {\n ...(prev.definition.validation ?? {}),\n ...(event.target.value === ''\n ? { [bound]: undefined }\n : { [bound]: Number(event.target.value) }),\n },\n },\n }\n : prev,\n )\n }\n />\n ))}\n </Stack>\n ) : null}\n </DialogContent>\n <DialogActions>\n <Button onClick={() => setFieldEditor(null)}>{'Cancel'}</Button>\n <Button\n variant=\"contained\"\n color=\"primary\"\n disabled={!editorDefinition?.name.trim() || Boolean(fieldIdError)}\n onClick={handleFieldSave}\n >\n {fieldEditor?.fieldId ? 'Save field' : 'Add field'}\n </Button>\n </DialogActions>\n </Dialog>\n </>\n )\n}\nDatasetSchemaDialog.displayName = 'DatasetSchemaDialog'\n\nexport default DatasetSchemaDialog\n"],"names":["getCustomFieldType","listCustomFieldTypes","describeSharing","narrowsScope","scopeSharingOf","sharingCovers","sharingFromChoice","storedScope","visibleToHost","useConfirmationContext","SiteSharingField","authorizedFetch","useSnackbar","Button","Checkbox","Alert","Box","Chip","Dialog","DialogActions","DialogContent","DialogTitle","FormControlLabel","IconButton","MenuItem","Stack","TextField","Typography","doc","updateDoc","useCallback","useEffect","useMemo","useState","useFirestore","useOrgDataScope","useScopeTokens","useUser","writeGuardedBySeed","DATASET_AUTHORABLE_FIELD_TYPES","DATASET_FIELD_TYPES","DATASET_FIELD_TYPE_LABELS","effectiveDatasetModel","datasetDisplayName","datasetNameLower","defaultDatasetFieldId","validateDatasetFieldId","RECORD_PAGE_ADDRESS_FIELD_TYPE","isRecordAddressField","useOrgSites","datasetPickerLabelsOf","AUTHORABLE_TYPES","SchemaControls","props","locked","component","disabled","sx","border","m","p","minWidth","children","sharingChoiceOf","dataset","sharing","mode","hostIds","exceptHostIds","sharingChoiceKey","choice","picked","sort","join","DatasetSchemaDialog","editorDefinition","hostId","datasets","recordCount","seedFromCache","seedUnreadable","seedListen","canChangeSharing","sharingOnlyReason","onClose","scope","dataScope","orgId","firestore","enqueueSnackbar","confirm","orgWide","viewerOrgWide","loaded","scopeLoaded","undefined","sites","orgHostList","ready","sitesReady","hostNames","data","user","sharingSites","map","host","id","$id","name","subdomain","setSharing","scopeUnset","sharingDraft","leftOut","sharingProblem","problem","sharingPreview","fields","visibleTo","model","setModel","order","names","setNames","singular","plural","effective","JSON","parse","stringify","fieldEditor","setFieldEditor","openFieldEditor","fieldId","definition","type","optionsText","validation","options","idDraft","idTouched","handleFieldSave","trim","description","split","option","filter","Boolean","length","Object","keys","idError","Set","existing","toLowerCase","variant","persist","confirmed","title","confirmationText","then","catch","prev","includes","handleFieldRemove","confirmationButtonProps","color","moveField","delta","index","indexOf","target","splice","handleSave","scopeChanged","sharingWrite","previousScope","nextScope","losing","proceed","sharingRefusal","subject","unreadable","fromCache","listen","displayName","nameLower","response","method","headers","body","action","datasetId","ok","payload","json","String","error","result","message","isNewField","fieldIdError","open","maxWidth","fullWidth","display","flexDirection","gap","severity","direction","spacing","mt","size","label","value","onChange","event","helperText","fromEntries","site","field","alignItems","px","py","borderColor","borderRadius","flex","noWrap","required","onClick","aria-label","alignSelf","autoFocus","next","multiline","minRows","select","customType","selected","startsWith","fieldType","slice","baseType","pluginId","slugFrom","reference","targets","labels","targetId","find","d","displayFieldId","targetFieldId","onDelete","control","checked","multiple","default","regex","bound","Number"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA,SACEA,kBAAkB,EAClBC,oBAAoB,EACpBC,eAAe,EACfC,YAAY,EACZC,cAAc,EACdC,aAAa,EACbC,iBAAiB,EACjBC,WAAW,EAC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KAAK,KAAK,KACvB;4DAAE,CAAC6C,MAAM,EAAEpK;wDAAU,IACrB;4DAAE,CAACoK,MAAM,EAAEC,OAAO5C,MAAM7C,MAAM,CAAC2C,KAAK;wDAAE;;qDAIhDpD;;uCA1BHiG;;iCAgCT;;;kCAEN,MAAChP;;0CACC,KAACN;gCAAOwN,SAAS,IAAMlG,eAAe;0CAAQ;;0CAC9C,KAACtH;gCACC8I,SAAQ;gCACRW,OAAM;gCACN9G,UAAU,EAACmB,oCAAAA,iBAAkBiC,IAAI,CAACkC,IAAI,OAAMK,QAAQsD;gCACpD4B,SAASxF;0CAERX,CAAAA,+BAAAA,YAAaG,OAAO,IAAG,eAAe;;;;;;;;AAMnD;AACA3D,oBAAoB+G,WAAW,GAAG;AAElC,eAAe/G,oBAAmB"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/data/src/lib/components/dataset-schema-dialog.component.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n'use client'\n\nimport {\n getCustomFieldType,\n listCustomFieldTypes,\n describeSharing,\n narrowsScope,\n scopeSharingOf,\n sharingCovers,\n sharingFromChoice,\n storedScope,\n visibleToHost,\n} from '@aglyn/aglyn'\nimport { useConfirmationContext } from '@aglyn/shared-ui-jsx'\nimport {\n SiteSharingField,\n type SiteSharingValue,\n} from '@aglyn/shared-ui-jsx/components/site-sharing-field.component'\nimport { authorizedFetch } from '@aglyn/shared-util-http/authorized-token'\nimport { useSnackbar } from '@aglyn/shared-ui-snackstack'\nimport {\n Button,\n Checkbox,\n Alert,\n Box,\n Chip,\n Dialog,\n DialogActions,\n DialogContent,\n DialogTitle,\n FormControlLabel,\n IconButton,\n MenuItem,\n Stack,\n TextField,\n Typography,\n} from '@mui/material'\nimport { doc, updateDoc } from 'firebase/firestore'\nimport { type ReactNode, useCallback, useEffect, useMemo, useState } from 'react'\nimport {\n useFirestore,\n useOrgDataScope,\n useScopeTokens,\n useUser,\n writeGuardedBySeed,\n type ListenHandle,\n} from '@aglyn/tenant-feature-instance'\nimport { DATASET_AUTHORABLE_FIELD_TYPES, DATASET_FIELD_TYPES, DATASET_FIELD_TYPE_LABELS, type DatasetFieldDefinition, type DatasetFieldType, type DatasetModel, effectiveDatasetModel } from '../model/dataset-models'\nimport { datasetDisplayName, datasetNameLower, defaultDatasetFieldId, validateDatasetFieldId } from '../model/datasets'\nimport { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from '../record-pages/record-pages'\nimport { useOrgSites } from './use-org-sites'\nimport { type DatasetRailEntry, datasetPickerLabelsOf } from '../model/dataset-rail'\n\n/** Types surfaced in the picker; the rest exist for compat, not authoring. */\nconst AUTHORABLE_TYPES = DATASET_AUTHORABLE_FIELD_TYPES\n\nexport interface DatasetSchemaDialogProps {\n /** Host context; resolves the owning org for the data scope. */\n hostId?: string\n /** Direct org scope (AGL-239): wins over `hostId` resolution when set. */\n orgId?: string\n dataset: {\n $id: string\n displayName?: string\n fields?: string[]\n model?: DatasetModel\n names?: { singular?: string; plural?: string }\n } | null\n /** All host collections, for reference-field target pickers (AGL-180). */\n datasets?: Array<{\n $id: string\n displayName?: string\n fields?: string[]\n model?: DatasetModel\n }>\n recordCount: number\n /**\n * The listener that produced `dataset` has NOT been confirmed by the\n * server (AGL-1358). Required rather than optional on purpose: the\n * listener lives in the parent card, so this dialog cannot compute the\n * verdict, and an optional prop a caller forgets is a guard that is off\n * while looking present — which is exactly how AGL-1356 stayed open.\n */\n seedFromCache: boolean\n /** That listener FAILED (`status === 'error'`). */\n seedUnreadable?: boolean\n /** That listener, so a save waits on that read alone (AGL-4135). */\n seedListen?: ListenHandle | null\n /**\n * Whether this member may change who the dataset is shared with: \"Manage\n * data\" with every site in reach. A site's verdict writes the dataset and never\n * moves it, so someone it admits reads the sharing instead (AGL-4047).\n */\n canChangeSharing?: boolean\n /**\n * Why this member may change who the dataset is shared with and nothing else\n * here, or absent where they may change it all (AGL-4047): a site that narrows\n * them takes the dataset's schema and records, and sharing is not among those.\n * The schema shows switched off, with this reason, and a save writes the\n * sharing alone.\n */\n sharingOnlyReason?: string\n onClose: () => void\n}\n\n/** The dialog's schema controls, switched off together where only the sharing is this member's. */\nfunction SchemaControls(props: { locked: boolean; children: ReactNode }) {\n return props.locked ? (\n <Box component=\"fieldset\" disabled sx={{ border: 0, m: 0, p: 0, minWidth: 0 }}>\n {props.children}\n </Box>\n ) : (\n <>{props.children}</>\n )\n}\n\n/**\n * How a dataset is shared, as the choice the sharing field edits, or null where\n * it stores no sharing (AGL-1484). The seed and the save both read it from here,\n * so a dialog nobody touched compares equal to its own document and writes none.\n */\nfunction sharingChoiceOf(dataset: unknown): SiteSharingValue | null {\n const sharing = scopeSharingOf(dataset as Record<string, unknown> | null)\n if (sharing.mode === 'all') return { mode: 'all' }\n if (sharing.mode === 'selected') return { mode: 'selected', hostIds: sharing.hostIds }\n if (sharing.mode === 'allExcept') return { mode: 'allExcept', exceptHostIds: sharing.exceptHostIds }\n return null\n}\n\n/** Two choices compare by what they pick, in any order. */\nfunction sharingChoiceKey(choice: SiteSharingValue | null): string {\n if (!choice) return 'unset'\n if (choice.mode === 'all') return 'all'\n const picked = choice.mode === 'selected' ? choice.hostIds : choice.exceptHostIds\n return `${choice.mode}:${[...picked].sort().join(',')}`\n}\n\n/**\n * Model builder (AGL-178): edits the AGL-177 typed model on a dataset —\n * singular/plural display names (dod.ts Schema.Name), add/edit/remove/\n * reorder fields, per-field type/required/default/description/validation.\n * Schema-change policies (documented per the issue): type changes never\n * rewrite documents — non-conforming values surface in the editor when it\n * validates (AGL-179); removed fields leave orphaned values that strip\n * lazily on next document save; fieldIds are stable keys — only display\n * names rename.\n */\nexport function DatasetSchemaDialog(props: DatasetSchemaDialogProps) {\n const {\n hostId,\n dataset,\n datasets,\n recordCount,\n seedFromCache,\n seedUnreadable,\n seedListen,\n canChangeSharing = true,\n sharingOnlyReason,\n onClose,\n } = props\n // Org-shared data root (AGL-237/239). Null until the async org lookup\n // settles (AGL-1061), and for a host with no owning org. Saving is held\n // on it rather than redirected: the host path this used to fall back to\n // is now denied by the rules outright (AGL-1050), so a save there would\n // fail loudly instead of quietly — but it should not be attempted at all.\n const { scope: dataScope, orgId } = useOrgDataScope({\n hostId,\n orgId: props.orgId,\n })\n const firestore = useFirestore()\n const { enqueueSnackbar } = useSnackbar()\n const { confirm } = useConfirmationContext()\n\n // Sharing scope (AGL-1044) — org datasets only; the legacy host path is\n // site-private by construction.\n // `orgWide` reads TRUE while the member doc loads (AGL-1047), which would\n // offer a scoped collaborator the sharing field for a beat before replacing\n // it with the read-only summary — and offering a control the AGL-1041\n // rules will reject is the thing the branch below exists to avoid. Hold\n // the whole block until `loaded` rather than flash the wrong one.\n const { orgWide: viewerOrgWide, loaded: scopeLoaded } = useScopeTokens(\n orgId ?? undefined,\n )\n // Sites in this org, for naming what a narrowing would cost: the Data\n // card's own query (`useOrgSites`), so the two share one listener.\n const { sites: orgHostList, ready: sitesReady, hostNames } = useOrgSites(orgId)\n const { data: user } = useUser()\n const sharingSites = useMemo(\n () => orgHostList.map((host) => ({ id: host.$id, name: host.name ?? host.subdomain ?? host.$id })),\n [orgHostList],\n )\n /**\n * Who this dataset is shared with, as edited here. Null while the dataset\n * stores NO scope (AGL-1484) — as opposed to storing `['org']`.\n *\n * The dialog used to render the two identically, which for a dataset is a\n * worse lie than it was for a media file: `orgs/{orgId}/datasets` is read\n * with `array-contains-any` in `resolve-dataset.ts` and in the console's\n * own `organizations.ts`, so an unstamped dataset is matched by no reader\n * in the product. It renders on no site and is missing from the reference\n * cards even for an org-wide member — while this control said \"All sites\".\n */\n const [sharing, setSharing] = useState<SiteSharingValue | null>(null)\n const scopeUnset = sharing === null\n /**\n * What the choice would write, or why it cannot be. The same answer the\n * `set-sharing` route gives from the workspace's sites, which it reads for\n * itself: the sites a choice leaves out stay known here even where this member\n * can't name them, so they aren't taken for sites that are gone.\n */\n const sharingDraft = useMemo(() => {\n if (!sharing) return null\n const leftOut = sharing.mode === 'allExcept' ? sharing.exceptHostIds : []\n return sharingFromChoice(sharing, [...orgHostList.map((host) => host.$id), ...leftOut])\n }, [sharing, orgHostList])\n // Nothing to say about leaving sites out until the sites have been read.\n const sharingProblem = sharing?.mode !== 'allExcept' || sitesReady ? (sharingDraft?.problem ?? null) : null\n /** The dataset as this choice would leave it, for what depends on where it is. */\n const sharingPreview = useMemo(() => sharingDraft?.fields ?? { visibleTo: [] as string[] }, [sharingDraft])\n\n const [model, setModel] = useState<DatasetModel>({ fields: {}, order: [] })\n const [names, setNames] = useState<{ singular: string; plural: string }>({\n singular: '',\n plural: '',\n })\n useEffect(() => {\n if (!dataset) return\n // The fourth copy of the AGL-1466 substitution (AGL-1484), and the seed\n // half of it. Persisting the default on open was the other option and\n // AGL-1466 ruled it out: opening a dialog would write, the AGL-1042\n // rules refuse that write from anyone who is not org-wide, and it\n // repairs only what somebody happens to look at — a repair mechanism\n // wearing a UI. `handleSave` reads the SAME helper; see the note there\n // for why the pair is the safety property. The sharing is seeded by the\n // effect below.\n const effective = effectiveDatasetModel(dataset)\n setModel({\n fields: JSON.parse(JSON.stringify(effective.fields)),\n order: [...effective.order],\n })\n setNames({\n singular: dataset.names?.singular ?? '',\n plural: dataset.names?.plural ?? datasetDisplayName(dataset),\n })\n }, [dataset])\n /*\n * The sharing, seeded for this dataset and again only when its STORED\n * sharing moves, not on every snapshot of it (AGL-4047). A save writes the\n * schema before the route answers for the sharing, so a refused sharing\n * change still brings a fresh dataset, and seeding from it put the choice\n * back on the stored one while the refusal was said: the choice being\n * refused is the one to keep.\n */\n const storedSharing = useMemo(() => (dataset ? sharingChoiceOf(dataset) : null), [dataset])\n const storedSharingKey = dataset ? `${dataset.$id}|${sharingChoiceKey(storedSharing)}` : null\n useEffect(() => {\n if (storedSharingKey === null) return\n setSharing(storedSharing)\n // eslint-disable-next-line react-hooks/exhaustive-deps -- `storedSharing` is read through its key\n }, [storedSharingKey])\n\n // Per-field editor (null fieldId = new field). `idDraft`/`idTouched` back\n // the editable Reference ID (AGL-578): for a new field the draft follows\n // the display name until the user edits it; existing fields keep the id\n // frozen (idTouched=true, input disabled).\n const [fieldEditor, setFieldEditor] = useState<{\n fieldId: string | null\n definition: DatasetFieldDefinition\n optionsText: string\n idDraft: string\n idTouched: boolean\n } | null>(null)\n\n const openFieldEditor = useCallback(\n (fieldId: string | null) => () => {\n const definition: DatasetFieldDefinition = fieldId\n ? JSON.parse(JSON.stringify(model.fields[fieldId]))\n : { name: '', type: 'text' }\n setFieldEditor({\n fieldId,\n definition,\n optionsText: (definition.validation?.options ?? []).join(', '),\n idDraft: fieldId ?? '',\n idTouched: fieldId != null,\n })\n },\n [model],\n )\n\n const handleFieldSave = useCallback(async () => {\n if (!fieldEditor) return\n const definition = { ...fieldEditor.definition }\n if (!definition.name.trim()) return\n definition.name = definition.name.trim()\n // Descriptions (AGL-560) surface as hints wherever the field appears;\n // blank ones are dropped so the model doesn't accrete empty strings.\n const description = definition.description?.trim()\n if (description) definition.description = description\n else delete definition.description\n const options = fieldEditor.optionsText\n .split(',')\n .map((option) => option.trim())\n .filter(Boolean)\n definition.validation = {\n ...(definition.validation ?? {}),\n ...(options.length ? { options } : {}),\n }\n if (!options.length) delete definition.validation.options\n if (!Object.keys(definition.validation).length) delete definition.validation\n\n let fieldId = fieldEditor.fieldId\n if (!fieldId) {\n // New field: the reference id comes from the (editable) draft, which\n // defaulted from the display name. Validate before it becomes a key.\n const id = fieldEditor.idDraft.trim()\n const idError = validateDatasetFieldId(\n id,\n new Set(model.order.map((existing) => existing.toLowerCase())),\n )\n if (idError) {\n return void enqueueSnackbar(idError, {\n variant: 'warning',\n persist: false,\n })\n }\n fieldId = id\n } else if (\n recordCount > 0 &&\n model.fields[fieldId] &&\n model.fields[fieldId].type !== definition.type\n ) {\n // Documented policy: changing a type never rewrites documents;\n // existing values that no longer conform get flagged when edited.\n const confirmed = await confirm({\n title: 'Change field type?',\n description:\n `${recordCount} document${recordCount === 1 ? '' : 's'} exist. ` +\n 'Stored values are not rewritten — ones that no longer match ' +\n `\"${DATASET_FIELD_TYPE_LABELS[definition.type]}\" will be flagged ` +\n 'when documents are next edited.',\n confirmationText: 'Change type',\n })\n .then(() => true)\n .catch(() => false)\n if (!confirmed) return\n }\n setModel((prev) => ({\n fields: { ...prev.fields, [fieldId as string]: definition },\n order: prev.order.includes(fieldId as string)\n ? prev.order\n : [...prev.order, fieldId as string],\n }))\n setFieldEditor(null)\n }, [fieldEditor, model, recordCount, confirm, enqueueSnackbar])\n\n const handleFieldRemove = useCallback(\n (fieldId: string) => async () => {\n const confirmed = await confirm({\n title: `Remove field \"${model.fields[fieldId]?.name ?? fieldId}\"?`,\n description:\n 'Existing documents keep their stored value until they are next ' +\n 'saved (it is stripped then). Bindings using this field stop ' +\n 'resolving.',\n confirmationText: 'Remove',\n confirmationButtonProps: { color: 'error' },\n })\n .then(() => true)\n .catch(() => false)\n if (!confirmed) return\n setModel((prev) => {\n const fields = { ...prev.fields }\n delete fields[fieldId]\n return { fields, order: prev.order.filter((id) => id !== fieldId) }\n })\n },\n [model, confirm],\n )\n\n const moveField = useCallback(\n (fieldId: string, delta: number) => () =>\n setModel((prev) => {\n const index = prev.order.indexOf(fieldId)\n const target = index + delta\n if (index < 0 || target < 0 || target >= prev.order.length) return prev\n const order = [...prev.order]\n order.splice(index, 1)\n order.splice(target, 0, fieldId)\n return { ...prev, order }\n }),\n [],\n )\n\n const handleSave = useCallback(async () => {\n if (!dataset || !dataScope) return\n /**\n * What the document actually carries, nothing when it carries nothing\n * (AGL-1484) — matching the seed above, through the same helper.\n *\n * The pairing is the whole safety property, not tidiness. Both sides\n * used to substitute `[ORG_SCOPE_TOKEN]`, so an unset dataset compared\n * equal to itself and merely OPENING the dialog wrote nothing; the\n * damage was confined to the screen. Correcting the seed alone would\n * make `scopeChanged` true for every unset dataset the moment its\n * dialog opened, turning a lie on screen into a write nobody asked for\n * — one the AGL-1041 rules then reject for any member who is not\n * org-wide, failing the WHOLE schema save with it.\n *\n * Nothing is also the honest previous value in the other direction: a\n * deliberate save of exactly `['org']` on an unset dataset used to\n * compare equal to the default and be dropped, and that is the one save\n * an unstamped dataset most needs to land.\n */\n const scopeChanged = sharingChoiceKey(sharingChoiceOf(dataset)) !== sharingChoiceKey(sharing)\n /**\n * The sharing this save writes, or null when it writes none.\n *\n * Only an org-wide member may change it — the route and the AGL-1041 rules\n * refuse anyone else, and it is written through the route because a marker\n * is the server's alone (AGL-4047).\n *\n * A choice that cannot be stored — \"Selected sites\" with no site picked, or\n * more sites than one query can match, or nothing left out, or everything —\n * refuses the save rather than substituting a scope: the org token would\n * share the collection with every site, and anything narrower would drop\n * sites somebody picked.\n */\n const sharingWrite = orgId && viewerOrgWide && canChangeSharing && scopeChanged ? sharing : null\n if (sharingWrite && sharingDraft?.problem) {\n return void enqueueSnackbar(sharingDraft.problem, {\n variant: 'warning',\n persist: false,\n })\n }\n const previousScope: string[] = storedScope((dataset as { visibleTo?: string[] }).visibleTo) ?? []\n const nextScope: readonly string[] = sharingPreview.visibleTo\n if (scopeChanged && narrowsScope(previousScope, nextScope)) {\n // Narrowing takes a dataset away from sites whose pages may bind it,\n // and a repeatable bound to a dataset it can no longer see renders\n // nothing (AGL-1039). Name the cost before paying it.\n const losing = orgHostList\n .filter((host) => visibleToHost(previousScope, host.$id))\n .filter((host) => !visibleToHost(nextScope, host.$id))\n .map((host) => host.name ?? host.subdomain ?? host.$id)\n const proceed = await confirm({\n title: 'Limit which sites can use this collection?',\n description: losing.length\n ? `${losing.join(', ')} will stop seeing this collection. Pages ` +\n 'that repeat over it will render nothing. No data is deleted.'\n : 'No site loses access, so nothing breaks today.',\n confirmationText: 'Limit access',\n })\n .then(() => true)\n .catch(() => false)\n if (!proceed) return\n }\n // Nothing of theirs to write when the sharing did not move.\n if (sharingOnlyReason && !sharingWrite) return void onClose()\n if (!model.order.length) {\n return void enqueueSnackbar('A collection needs at least one field', {\n variant: 'warning',\n persist: false,\n })\n }\n /**\n * Refuse the write when the seeding listener is unconfirmed (AGL-1358).\n *\n * Everything below is seeded from `dataset` and written back whole, so\n * `updateDoc` field-level merging protects nothing — the untouched\n * fields are all in the payload. Two of them make a stale seed worse\n * than an inconvenience:\n *\n * - `visibleTo` is the AGL-1041/1042 scoping PREDICATE. Rewriting it\n * from a cached seed re-exposes a collection that was narrowed, or\n * hides one that was widened, and the confirmation above is computed\n * against `previousScope` read from that same stale seed — so it does\n * not even warn about the sites it is really taking access from.\n * - `model` is the entire schema. A cached seed reinstates fields that\n * were deleted and drops fields that were added.\n *\n * The schema goes first, because who may write it depends on where the\n * dataset sits as it stands, the question the rule asks of this one save.\n */\n let sharingRefusal: string | null = null\n await writeGuardedBySeed(\n {\n subject: 'collection schema',\n unreadable: seedUnreadable,\n fromCache: seedFromCache,\n listen: seedListen,\n },\n async () => {\n if (!sharingOnlyReason) {\n await updateDoc(\n doc(firestore, dataScope[0], dataScope[1], 'datasets', dataset.$id),\n {\n model,\n names: {\n singular: names.singular.trim(),\n plural: names.plural.trim(),\n },\n // The name's search key moves with it (AGL-4047).\n ...(names.plural.trim()\n ? {\n displayName: names.plural.trim(),\n nameLower: datasetNameLower(names.plural),\n }\n : {}),\n // v1 compat: keep the flat column list mirroring the model order\n // so unmigrated consumers (AGL-103 bindings) keep working.\n fields: model.order,\n },\n )\n }\n if (sharingWrite) {\n const response = await authorizedFetch(user, '/api/orgs/datasets', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n orgId,\n action: 'set-sharing',\n datasetId: dataset.$id,\n choice: sharingWrite,\n }),\n })\n if (!response.ok) {\n const payload = await response.json().catch(() => ({}))\n sharingRefusal = String(payload?.error ?? 'The sharing could not be changed.')\n }\n }\n },\n )\n .then((result) => {\n // A refusal leaves the dialog open with the edited schema intact.\n if (!result.ok) {\n return void enqueueSnackbar(result.message, {\n variant: 'warning',\n persist: false,\n })\n }\n if (sharingRefusal) {\n return void enqueueSnackbar(\n sharingOnlyReason ? sharingRefusal : `Schema saved. Its sharing didn’t change: ${sharingRefusal}`,\n { variant: 'warning', persist: false },\n )\n }\n enqueueSnackbar(sharingOnlyReason ? 'Sharing saved' : 'Schema saved', { variant: 'success', persist: false })\n onClose()\n })\n .catch(() =>\n enqueueSnackbar('An error has occurred', { variant: 'error' }),\n )\n }, [\n dataset,\n model,\n names,\n sharing,\n sharingDraft,\n sharingPreview,\n user,\n viewerOrgWide,\n canChangeSharing,\n sharingOnlyReason,\n orgHostList,\n confirm,\n firestore,\n dataScope,\n orgId,\n seedFromCache,\n seedUnreadable,\n seedListen,\n enqueueSnackbar,\n onClose,\n ])\n\n const editorDefinition = fieldEditor?.definition\n // Reference ID editing (AGL-578): the id is editable only while creating a\n // field; live-validate the draft so the input and Save button can react.\n const isNewField = fieldEditor != null && fieldEditor.fieldId == null\n const fieldIdError =\n fieldEditor && isNewField\n ? validateDatasetFieldId(\n fieldEditor.idDraft,\n new Set(model.order.map((id) => id.toLowerCase())),\n )\n : null\n\n return (\n <>\n <Dialog\n open={Boolean(dataset)}\n onClose={onClose}\n maxWidth=\"sm\"\n fullWidth\n >\n <DialogTitle>{`Schema — ${datasetDisplayName(dataset)}`}</DialogTitle>\n <DialogContent\n sx={{ display: 'flex', flexDirection: 'column', gap: 2 }}\n >\n {sharingOnlyReason ? <Alert severity=\"info\">{sharingOnlyReason}</Alert> : null}\n <SchemaControls locked={Boolean(sharingOnlyReason)}>\n <Stack direction=\"row\" spacing={1} sx={{ mt: 1 }}>\n <TextField\n size=\"small\"\n label=\"Singular name\"\n value={names.singular}\n onChange={(event) =>\n setNames((prev) => ({ ...prev, singular: event.target.value }))\n }\n helperText=\"e.g. Product\"\n />\n <TextField\n size=\"small\"\n label=\"Plural name\"\n value={names.plural}\n onChange={(event) =>\n setNames((prev) => ({ ...prev, plural: event.target.value }))\n }\n helperText=\"e.g. Products (shown as the title)\"\n />\n </Stack>\n </SchemaControls>\n {/* Sharing scope (AGL-1044). Org datasets only; the legacy host\n path is site-private already. Read-only for scoped members —\n the rules deny them the write and it would fail the whole\n document, so a control that always errors is worse than the\n value. */}\n {orgId ? (\n <Stack spacing={0.5}>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {'Shared with'}\n </Typography>\n {!scopeLoaded ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'Checking your access…'}\n </Typography>\n ) : viewerOrgWide && canChangeSharing ? (\n <>\n {/*\n The state this dialog used to hide (AGL-1484), in the\n words the folder dialog and the media drawer already\n use. It costs a sentence, and it is the difference\n between reading \"All sites\" off a collection no site can\n see and being told to choose. No choice shows as picked\n until someone picks one.\n */}\n {scopeUnset ? (\n <Alert severity=\"warning\">\n {'This collection has never been shared. Nothing is ' +\n 'stored, so it is hidden from every site and any ' +\n 'page repeating over it renders nothing. Choose who ' +\n 'it is shared with to fix that.'}\n </Alert>\n ) : null}\n <SiteSharingField\n value={sharing}\n onChange={setSharing}\n sites={sharingSites}\n sitesReady={sitesReady}\n problem={sharingProblem}\n />\n {/* Says what sharing does NOT do, which is the part\n people get wrong (AGL-1046). It controls which sites\n may use the data; it is not a permission on the rows\n a published page already renders. */}\n <Typography variant=\"caption\" color=\"text.secondary\">\n {\n 'Sites you exclude cannot see or use this dataset — in the console or on their pages.'\n }\n </Typography>\n </>\n ) : (\n <Typography variant=\"body2\">\n {/*\n A scoped collaborator cannot fix this — the AGL-1041\n rules deny them the write — but they are the ones who\n notice a repeatable rendering nothing on their site, so\n they get the reason rather than `describeScope`'s \"No\n sites\", which reads like a setting somebody chose\n (AGL-1484).\n */}\n {scopeUnset\n ? 'Never shared — hidden from every site'\n : describeSharing(\n dataset as Record<string, unknown> | null,\n Object.fromEntries(\n sharingSites.map((site) => [site.id, site.name]),\n ),\n )}\n </Typography>\n )}\n </Stack>\n ) : null}\n <SchemaControls locked={Boolean(sharingOnlyReason)}>\n <Stack spacing={0.5}>\n {model.order.map((fieldId, index) => {\n const field = model.fields[fieldId]\n if (!field) return null\n return (\n <Stack\n key={fieldId}\n direction=\"row\"\n spacing={1}\n sx={{\n alignItems: 'center',\n px: 1,\n py: 0.5,\n border: '1px solid',\n borderColor: 'divider',\n borderRadius: 1,\n }}\n >\n <Stack sx={{ flex: 1, minWidth: 0 }}>\n <Typography variant=\"body2\" noWrap>\n {field.name}\n <Typography\n component=\"span\"\n variant=\"caption\"\n color=\"text.secondary\"\n >\n {` · ${fieldId}`}\n </Typography>\n </Typography>\n {field.description ? (\n <Typography\n variant=\"caption\"\n color=\"text.secondary\"\n noWrap\n >\n {field.description}\n </Typography>\n ) : null}\n </Stack>\n <Chip\n size=\"small\"\n label={DATASET_FIELD_TYPE_LABELS[field.type] ?? field.type}\n />\n {field.required || field.validation?.required ? (\n <Chip size=\"small\" color=\"primary\" label=\"required\" />\n ) : null}\n <IconButton\n size=\"small\"\n disabled={index === 0}\n onClick={moveField(fieldId, -1)}\n aria-label=\"Move up\"\n >\n {'▲'}\n </IconButton>\n <IconButton\n size=\"small\"\n disabled={index === model.order.length - 1}\n onClick={moveField(fieldId, 1)}\n aria-label=\"Move down\"\n >\n {'▼'}\n </IconButton>\n <Button size=\"small\" onClick={openFieldEditor(fieldId)}>\n {'Edit'}\n </Button>\n <Button\n size=\"small\"\n color=\"error\"\n onClick={handleFieldRemove(fieldId)}\n >\n {'Remove'}\n </Button>\n </Stack>\n )\n })}\n </Stack>\n <Button\n size=\"small\"\n variant=\"outlined\"\n color=\"primary\"\n onClick={openFieldEditor(null)}\n sx={{ alignSelf: 'flex-start' }}\n >\n {'Add field'}\n </Button>\n </SchemaControls>\n </DialogContent>\n <DialogActions>\n <Button onClick={onClose}>{'Cancel'}</Button>\n {/* Held until the data scope resolves (AGL-1061) — a save in that\n window writes the schema to the legacy host path. */}\n <Button\n variant=\"contained\"\n color=\"primary\"\n disabled={!dataScope}\n onClick={handleSave}\n >\n {sharingOnlyReason ? 'Save sharing' : 'Save schema'}\n </Button>\n </DialogActions>\n </Dialog>\n\n <Dialog\n open={Boolean(fieldEditor)}\n onClose={() => setFieldEditor(null)}\n maxWidth=\"xs\"\n fullWidth\n >\n <DialogTitle>\n {fieldEditor?.fieldId ? 'Edit field' : 'New field'}\n </DialogTitle>\n <DialogContent\n sx={{ display: 'flex', flexDirection: 'column', gap: 2 }}\n >\n <TextField\n size=\"small\"\n label=\"Display name\"\n value={editorDefinition?.name ?? ''}\n autoFocus\n onChange={(event) => {\n const name = event.target.value\n setFieldEditor((prev) => {\n if (!prev) return prev\n const next = {\n ...prev,\n definition: { ...prev.definition, name },\n }\n // The reference id follows the display name until the user\n // edits it (new fields only) — AGL-578.\n if (prev.fieldId == null && !prev.idTouched) {\n next.idDraft = defaultDatasetFieldId(\n name,\n new Set(model.order.map((id) => id.toLowerCase())),\n )\n }\n return next\n })\n }}\n sx={{ mt: 1 }}\n helperText=\"Shown to people editing records and wherever the field appears\"\n />\n <TextField\n size=\"small\"\n label=\"Reference ID\"\n value={\n isNewField\n ? (fieldEditor?.idDraft ?? '')\n : (fieldEditor?.fieldId ?? '')\n }\n disabled={!isNewField}\n onChange={(event) =>\n setFieldEditor((prev) =>\n prev\n ? { ...prev, idDraft: event.target.value, idTouched: true }\n : prev,\n )\n }\n error={Boolean(fieldIdError)}\n helperText={\n isNewField\n ? (fieldIdError ??\n 'Stable key used in bindings ({{item.id}}), forms, and imports. Auto-filled from the display name — edit to override. Fixed once the field is created.')\n : 'Reference IDs are stable keys and cannot change after creation'\n }\n />\n <TextField\n size=\"small\"\n label=\"Description\"\n multiline\n minRows={2}\n value={editorDefinition?.description ?? ''}\n onChange={(event) =>\n setFieldEditor((prev) =>\n prev\n ? {\n ...prev,\n definition: {\n ...prev.definition,\n description: event.target.value,\n },\n }\n : prev,\n )\n }\n helperText=\"What this field is for — shown as a hint wherever the field appears\"\n />\n <TextField\n select\n size=\"small\"\n label=\"Type\"\n value={\n editorDefinition?.customType\n ? `custom:${editorDefinition.customType}`\n : (editorDefinition?.type ?? 'text')\n }\n onChange={(event) =>\n setFieldEditor((prev) => {\n if (!prev) return prev\n const selected = event.target.value\n // Custom field types (AGL-434): ride a base storage type\n // and stamp customType so the record editor + validators\n // pick up the plugin behavior.\n if (selected.startsWith('custom:')) {\n const fieldType = getCustomFieldType(selected.slice(7))\n if (!fieldType) return prev\n return {\n ...prev,\n definition: {\n ...prev.definition,\n type: fieldType.baseType as DatasetFieldType,\n customType: fieldType.name,\n },\n }\n }\n const definition = {\n ...prev.definition,\n type: selected as DatasetFieldType,\n }\n delete definition.customType\n return { ...prev, definition }\n })\n }\n >\n {(fieldEditor?.fieldId &&\n editorDefinition &&\n !AUTHORABLE_TYPES.includes(editorDefinition.type)\n ? DATASET_FIELD_TYPES\n : AUTHORABLE_TYPES\n ).map((type) => (\n <MenuItem key={type} value={type}>\n {DATASET_FIELD_TYPE_LABELS[type]}\n </MenuItem>\n ))}\n {listCustomFieldTypes().map((fieldType) => (\n <MenuItem\n key={`custom:${fieldType.name}`}\n value={`custom:${fieldType.name}`}\n >\n {`${fieldType.label} (${fieldType.pluginId})`}\n </MenuItem>\n ))}\n </TextField>\n {editorDefinition?.customType === RECORD_PAGE_ADDRESS_FIELD_TYPE ? (\n <TextField\n select\n size=\"small\"\n label=\"Fill in from\"\n value={editorDefinition.slugFrom ?? ''}\n onChange={(event) =>\n setFieldEditor((prev) => {\n if (!prev) return prev\n const definition = { ...prev.definition }\n if (event.target.value) definition.slugFrom = event.target.value\n else delete definition.slugFrom\n return { ...prev, definition }\n })\n }\n helperText=\"An empty address fills in from this field once, and stays put when the record is renamed\"\n >\n <MenuItem value=\"\">Nothing — type each address</MenuItem>\n {model.order\n .filter(\n (fieldId) =>\n fieldId !== fieldEditor?.fieldId &&\n model.fields[fieldId]?.type === 'text' &&\n !isRecordAddressField(model.fields[fieldId]),\n )\n .map((fieldId) => (\n <MenuItem key={fieldId} value={fieldId}>\n {model.fields[fieldId]?.name ?? fieldId}\n </MenuItem>\n ))}\n </TextField>\n ) : null}\n {editorDefinition?.type === 'reference' ? (\n <>\n <TextField\n select\n size=\"small\"\n label=\"Target collection\"\n value={editorDefinition?.reference?.datasetId ?? ''}\n onChange={(event) =>\n setFieldEditor((prev) =>\n prev\n ? {\n ...prev,\n definition: {\n ...prev.definition,\n reference: {\n ...(prev.definition.reference ?? {\n datasetId: '',\n }),\n datasetId: event.target.value,\n },\n },\n }\n : prev,\n )\n }\n >\n {(() => {\n const targets = (datasets ?? [])\n .filter((target) => target.$id !== dataset?.$id)\n // Only targets this dataset's sites can actually resolve\n // (AGL-1044). A reference to a dataset a site cannot see\n // renders blank with nothing to say why, so an\n // unresolvable target is not offered. The currently\n // selected one always stays listed — otherwise changing\n // scope would silently blank an existing field.\n .filter(\n (target) =>\n target.$id ===\n editorDefinition?.reference?.datasetId ||\n sharingCovers(target as Record<string, unknown>, sharingPreview as Record<string, unknown>),\n )\n // Who a target is shared with only where two share a name (AGL-4047).\n const labels = datasetPickerLabelsOf(targets as DatasetRailEntry[], hostNames)\n return targets.map((target) => (\n <MenuItem key={target.$id} value={target.$id}>\n {labels[target.$id] || datasetDisplayName(target) || target.$id}\n </MenuItem>\n ))\n })()}\n </TextField>\n {(() => {\n // Flag an EXISTING reference that this dataset's scope has\n // outgrown — the field was valid when created and quietly\n // is not any more.\n const targetId = editorDefinition?.reference?.datasetId\n const target = (datasets ?? []).find((d) => d.$id === targetId)\n if (\n !target ||\n sharingCovers(target as Record<string, unknown>, sharingPreview as Record<string, unknown>)\n ) {\n return null\n }\n return (\n <Alert severity=\"warning\">\n {`\"${datasetDisplayName(target) || target.$id}\" is not shared with ` +\n 'every site this collection is. Those sites will show ' +\n 'this field blank. Widen its sharing, or narrow this ' +\n \"collection's.\"}\n </Alert>\n )\n })()}\n <TextField\n select\n size=\"small\"\n label=\"Display field\"\n value={editorDefinition?.reference?.displayFieldId ?? ''}\n onChange={(event) =>\n setFieldEditor((prev) =>\n prev?.definition.reference\n ? {\n ...prev,\n definition: {\n ...prev.definition,\n reference: {\n ...prev.definition.reference,\n displayFieldId: event.target.value,\n },\n },\n }\n : prev,\n )\n }\n helperText=\"Shown in pickers and grid cells\"\n >\n {effectiveDatasetModel(\n (datasets ?? []).find(\n (target) =>\n target.$id === editorDefinition?.reference?.datasetId,\n ) ?? {},\n ).order.map((targetFieldId) => (\n <MenuItem key={targetFieldId} value={targetFieldId}>\n {targetFieldId}\n </MenuItem>\n ))}\n </TextField>\n <TextField\n select\n size=\"small\"\n label=\"When a referenced document is deleted\"\n value={editorDefinition?.reference?.onDelete ?? 'setNull'}\n onChange={(event) =>\n setFieldEditor((prev) =>\n prev?.definition.reference\n ? {\n ...prev,\n definition: {\n ...prev.definition,\n reference: {\n ...prev.definition.reference,\n onDelete: event.target.value as\n | 'restrict'\n | 'setNull',\n },\n },\n }\n : prev,\n )\n }\n >\n <MenuItem value=\"setNull\">{'Clear the reference'}</MenuItem>\n <MenuItem value=\"restrict\">{'Block the delete'}</MenuItem>\n </TextField>\n <FormControlLabel\n control={\n <Checkbox\n size=\"small\"\n checked={Boolean(editorDefinition?.reference?.multiple)}\n onChange={(event) =>\n setFieldEditor((prev) =>\n prev?.definition.reference\n ? {\n ...prev,\n definition: {\n ...prev.definition,\n reference: {\n ...prev.definition.reference,\n multiple: event.target.checked,\n },\n },\n }\n : prev,\n )\n }\n />\n }\n label=\"Allow multiple (many-to-many)\"\n />\n </>\n ) : null}\n <FormControlLabel\n control={\n <Checkbox\n size=\"small\"\n checked={Boolean(editorDefinition?.required)}\n onChange={(event) =>\n setFieldEditor((prev) =>\n prev\n ? {\n ...prev,\n definition: {\n ...prev.definition,\n required: event.target.checked,\n },\n }\n : prev,\n )\n }\n />\n }\n label=\"Required\"\n />\n <TextField\n size=\"small\"\n label=\"Default value\"\n value={String(editorDefinition?.default ?? '')}\n onChange={(event) =>\n setFieldEditor((prev) =>\n prev\n ? {\n ...prev,\n definition: {\n ...prev.definition,\n ...(event.target.value\n ? { default: event.target.value }\n : { default: undefined }),\n },\n }\n : prev,\n )\n }\n helperText=\"Pre-filled when creating documents\"\n />\n {editorDefinition?.type === 'text' ? (\n <>\n <TextField\n size=\"small\"\n label=\"Pattern (regex)\"\n value={editorDefinition?.validation?.regex ?? ''}\n onChange={(event) =>\n setFieldEditor((prev) =>\n prev\n ? {\n ...prev,\n definition: {\n ...prev.definition,\n validation: {\n ...(prev.definition.validation ?? {}),\n ...(event.target.value\n ? { regex: event.target.value }\n : { regex: undefined }),\n },\n },\n }\n : prev,\n )\n }\n />\n <TextField\n size=\"small\"\n label=\"Options\"\n value={fieldEditor?.optionsText ?? ''}\n onChange={(event) =>\n setFieldEditor((prev) =>\n prev ? { ...prev, optionsText: event.target.value } : prev,\n )\n }\n helperText=\"Comma-separated enum, e.g. basic, plus\"\n />\n </>\n ) : null}\n {editorDefinition &&\n ['int32', 'int64', 'float', 'timestamp', 'text'].includes(\n editorDefinition.type,\n ) ? (\n <Stack direction=\"row\" spacing={1}>\n {(['min', 'max'] as const).map((bound) => (\n <TextField\n key={bound}\n size=\"small\"\n type=\"number\"\n label={\n editorDefinition.type === 'text'\n ? `${bound === 'min' ? 'Min' : 'Max'} length`\n : bound === 'min'\n ? 'Min'\n : 'Max'\n }\n value={editorDefinition.validation?.[bound] ?? ''}\n onChange={(event) =>\n setFieldEditor((prev) =>\n prev\n ? {\n ...prev,\n definition: {\n ...prev.definition,\n validation: {\n ...(prev.definition.validation ?? {}),\n ...(event.target.value === ''\n ? { [bound]: undefined }\n : { [bound]: Number(event.target.value) }),\n },\n },\n }\n : prev,\n )\n }\n />\n ))}\n </Stack>\n ) : null}\n </DialogContent>\n <DialogActions>\n <Button onClick={() => setFieldEditor(null)}>{'Cancel'}</Button>\n <Button\n variant=\"contained\"\n color=\"primary\"\n disabled={!editorDefinition?.name.trim() || Boolean(fieldIdError)}\n onClick={handleFieldSave}\n >\n {fieldEditor?.fieldId ? 'Save field' : 'Add field'}\n </Button>\n </DialogActions>\n </Dialog>\n </>\n )\n}\nDatasetSchemaDialog.displayName = 'DatasetSchemaDialog'\n\nexport default DatasetSchemaDialog\n"],"names":["getCustomFieldType","listCustomFieldTypes","describeSharing","narrowsScope","scopeSharingOf","sharingCovers","sharingFromChoice","storedScope","visibleToHost","useConfirmationContext","SiteSharingField","authorizedFetch","useSnackbar","Button","Checkbox","Alert","Box","Chip","Dialog","DialogActions","DialogContent","DialogTitle","FormControlLabel","IconButton","MenuItem","Stack","TextField","Typography","doc","updateDoc","useCallback","useEffect","useMemo","useState","useFirestore","useOrgDataScope","useScopeTokens","useUser","writeGuardedBySeed","DATASET_AUTHORABLE_FIELD_TYPES","DATASET_FIELD_TYPES","DATASET_FIELD_TYPE_LABELS","effectiveDatasetModel","datasetDisplayName","datasetNameLower","defaultDatasetFieldId","validateDatasetFieldId","RECORD_PAGE_ADDRESS_FIELD_TYPE","isRecordAddressField","useOrgSites","datasetPickerLabelsOf","AUTHORABLE_TYPES","SchemaControls","props","locked","component","disabled","sx","border","m","p","minWidth","children","sharingChoiceOf","dataset","sharing","mode","hostIds","exceptHostIds","sharingChoiceKey","choice","picked","sort","join","DatasetSchemaDialog","editorDefinition","hostId","datasets","recordCount","seedFromCache","seedUnreadable","seedListen","canChangeSharing","sharingOnlyReason","onClose","scope","dataScope","orgId","firestore","enqueueSnackbar","confirm","orgWide","viewerOrgWide","loaded","scopeLoaded","undefined","sites","orgHostList","ready","sitesReady","hostNames","data","user","sharingSites","map","host","id","$id","name","subdomain","setSharing","scopeUnset","sharingDraft","leftOut","sharingProblem","problem","sharingPreview","fields","visibleTo","model","setModel","order","names","setNames","singular","plural","effective","JSON","parse","stringify","storedSharing","storedSharingKey","fieldEditor","setFieldEditor","openFieldEditor","fieldId","definition","type","optionsText","validation","options","idDraft","idTouched","handleFieldSave","trim","description","split","option","filter","Boolean","length","Object","keys","idError","Set","existing","toLowerCase","variant","persist","confirmed","title","confirmationText","then","catch","prev","includes","handleFieldRemove","confirmationButtonProps","color","moveField","delta","index","indexOf","target","splice","handleSave","scopeChanged","sharingWrite","previousScope","nextScope","losing","proceed","sharingRefusal","subject","unreadable","fromCache","listen","displayName","nameLower","response","method","headers","body","action","datasetId","ok","payload","json","String","error","result","message","isNewField","fieldIdError","open","maxWidth","fullWidth","display","flexDirection","gap","severity","direction","spacing","mt","size","label","value","onChange","event","helperText","fromEntries","site","field","alignItems","px","py","borderColor","borderRadius","flex","noWrap","required","onClick","aria-label","alignSelf","autoFocus","next","multiline","minRows","select","customType","selected","startsWith","fieldType","slice","baseType","pluginId","slugFrom","reference","targets","labels","targetId","find","d","displayFieldId","targetFieldId","onDelete","control","checked","multiple","default","regex","bound","Number"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA,SACEA,kBAAkB,EAClBC,oBAAoB,EACpBC,eAAe,EACfC,YAAY,EACZC,cAAc,EACdC,aAAa,EACbC,iBAAiB,EACjBC,WAAW,EACXC,aAAa,QACR,eAAc;AACrB,SAASC,sBAAsB,QAAQ,uBAAsB;AAC7D,SACEC,gBAAgB,QAEX,+DAA8D;AACrE,SAASC,eAAe,QAAQ,2CAA0C;AAC1E,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SACEC,MAAM,EACNC,QAAQ,EACRC,KAAK,EACLC,GAAG,EACHC,IAAI,EACJC,MAAM,EACNC,aAAa,EACbC,aAAa,EACbC,WAAW,EACXC,gBAAgB,EAChBC,UAAU,EACVC,QAAQ,EACRC,KAAK,EACLC,SAAS,EACTC,UAAU,QACL,gBAAe;AACtB,SAASC,GAAG,EAAEC,SAAS,QAAQ,qBAAoB;AACnD,SAAyBC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAO;AACjF,SACEC,YAAY,EACZC,eAAe,EACfC,cAAc,EACdC,OAAO,EACPC,kBA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AACxH;gCACCgJ,SAAQ;gCACRW,OAAM;gCACNhH,UAAU,EAACmB,oCAAAA,iBAAkBiC,IAAI,CAACoC,IAAI,OAAMK,QAAQsD;gCACpD4B,SAASxF;0CAERX,CAAAA,+BAAAA,YAAaG,OAAO,IAAG,eAAe;;;;;;;;AAMnD;AACA7D,oBAAoBiH,WAAW,GAAG;AAElC,eAAejH,oBAAmB"}
|
|
@@ -31,7 +31,7 @@ import { listFilterGridColumns } from "@aglyn/shared-ui-jsx/const/list-grid-filt
|
|
|
31
31
|
import { useListGridFilter } from "@aglyn/shared-ui-jsx/hooks/use-list-grid-filter";
|
|
32
32
|
import { useSnackbar } from "@aglyn/shared-ui-snackstack";
|
|
33
33
|
import { Timestamp } from "@aglyn/shared-util-timestamp";
|
|
34
|
-
import { Alert, Box, Button, Chip, Dialog, DialogActions, DialogContent, DialogTitle, MenuItem, Stack, TextField, Tooltip, Typography } from "@mui/material";
|
|
34
|
+
import { Alert, Box, Button, Chip, CircularProgress, Dialog, DialogActions, DialogContent, DialogTitle, MenuItem, Stack, TextField, Tooltip, Typography } from "@mui/material";
|
|
35
35
|
import { collection, deleteDoc, deleteField, doc, endAt, getCountFromServer, getDoc, getDocs, limit, orderBy, query, startAt, where, setDoc, writeBatch } from "firebase/firestore";
|
|
36
36
|
import { useRouter } from "next/navigation";
|
|
37
37
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
@@ -296,7 +296,18 @@ export function newDatasetSharingNote(siteOnly) {
|
|
|
296
296
|
const [selectedId, setSelectedId] = useState(null);
|
|
297
297
|
const wantedId = (_ref1 = routeDatasetId != null ? routeDatasetId : selectedId) != null ? _ref1 : undefined;
|
|
298
298
|
const listed = wantedId ? datasets.find((item)=>item.$id === wantedId) : undefined;
|
|
299
|
-
|
|
299
|
+
/**
|
|
300
|
+
* The list has emitted, from the cache or the server: enough to look for
|
|
301
|
+
* the open dataset on its own when the window does not hold it.
|
|
302
|
+
*/ const listAnswered = datasetsStatus !== 'loading';
|
|
303
|
+
/**
|
|
304
|
+
* The SERVER has answered the list (AGL-4047). Only this may say there are
|
|
305
|
+
* no datasets. `useFirestoreCollection` hands back `[]` from its first
|
|
306
|
+
* render, before any snapshot, and a cold cache answers `[]` too, unconfirmed:
|
|
307
|
+
* reading either as "none" showed a site with five datasets the "Create a
|
|
308
|
+
* dataset" empty state for the 16 s its list took to reach the server.
|
|
309
|
+
*/ const listConfirmed = scopeReady && datasetsStatus === 'success' && !datasetsFromCache;
|
|
310
|
+
/** The list failed for good, so neither "none" nor "loading" is true. */ const listUnreadable = datasetsStatus === 'error';
|
|
300
311
|
/*
|
|
301
312
|
* A dataset the address names that the loaded window does not hold — past
|
|
302
313
|
* the window, outside the filter, or only just created — is read on its
|
|
@@ -1470,7 +1481,7 @@ export function newDatasetSharingNote(siteOnly) {
|
|
|
1470
1481
|
}) : null;
|
|
1471
1482
|
const railFooter = /*#__PURE__*/ _jsxs(_Fragment, {
|
|
1472
1483
|
children: [
|
|
1473
|
-
|
|
1484
|
+
listConfirmed && serverNameKey && datasets.length === 0 ? /*#__PURE__*/ _jsx(Typography, {
|
|
1474
1485
|
variant: "body2",
|
|
1475
1486
|
color: "text.secondary",
|
|
1476
1487
|
sx: {
|
|
@@ -1640,7 +1651,19 @@ export function newDatasetSharingNote(siteOnly) {
|
|
|
1640
1651
|
}) : notFound ? /*#__PURE__*/ _jsx(Alert, {
|
|
1641
1652
|
severity: "info",
|
|
1642
1653
|
children: 'This dataset doesn’t exist, or you can’t open it.'
|
|
1643
|
-
}) : recordPanel ? recordPanel : !selected ?
|
|
1654
|
+
}) : recordPanel ? recordPanel : !selected ? listUnreadable && !wantedId ? /*#__PURE__*/ _jsx(Alert, {
|
|
1655
|
+
severity: "error",
|
|
1656
|
+
children: 'We couldn’t load your datasets. This does not mean there are none.'
|
|
1657
|
+
}) : !listConfirmed || wantedId ? // Until the server answers, and while the dataset the address names is
|
|
1658
|
+
// read on its own: never the empty state, which is a verdict.
|
|
1659
|
+
/*#__PURE__*/ _jsx(CardDisplay, {
|
|
1660
|
+
contentGutterX: true,
|
|
1661
|
+
contentGutterY: true,
|
|
1662
|
+
children: /*#__PURE__*/ _jsx(CircularProgress, {
|
|
1663
|
+
size: 24,
|
|
1664
|
+
"aria-label": "Loading datasets"
|
|
1665
|
+
})
|
|
1666
|
+
}) : datasets.length === 0 && !sharedWith && !serverNameKey ? /*#__PURE__*/ _jsx(CardDisplay, {
|
|
1644
1667
|
contentGutterX: true,
|
|
1645
1668
|
contentGutterY: true,
|
|
1646
1669
|
children: /*#__PURE__*/ _jsx(Typography, {
|