@aglyn/plugins-data 1.13.0 → 1.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +12 -10
- package/src/lib/artifact/dataset-schema-artifact.server.js +10 -4
- package/src/lib/artifact/dataset-schema-artifact.server.js.map +1 -1
- package/src/lib/components/data-console-page.js +4 -2
- package/src/lib/components/data-console-page.js.map +1 -1
- package/src/lib/components/dataset-record-dialog.component.d.ts +22 -0
- package/src/lib/components/dataset-record-dialog.component.js +77 -54
- package/src/lib/components/dataset-record-dialog.component.js.map +1 -1
- package/src/lib/components/dataset-schema-dialog.component.js +195 -168
- package/src/lib/components/dataset-schema-dialog.component.js.map +1 -1
- package/src/lib/components/host-datasets-card.component.d.ts +12 -0
- package/src/lib/components/host-datasets-card.component.js +652 -221
- package/src/lib/components/host-datasets-card.component.js.map +1 -1
- package/src/lib/components/use-dataset-writes-blocked.d.ts +5 -4
- package/src/lib/components/use-dataset-writes-blocked.js +11 -12
- package/src/lib/components/use-dataset-writes-blocked.js.map +1 -1
- package/src/lib/components/use-org-sites.d.ts +27 -0
- package/src/lib/components/use-org-sites.js +68 -0
- package/src/lib/components/use-org-sites.js.map +1 -0
- package/src/lib/model/data-record-routes.js +6 -3
- package/src/lib/model/data-record-routes.js.map +1 -1
- package/src/lib/model/dataset-model-core.d.ts +22 -0
- package/src/lib/model/dataset-model-core.js +34 -0
- package/src/lib/model/dataset-model-core.js.map +1 -1
- package/src/lib/model/dataset-rail.d.ts +88 -0
- package/src/lib/model/dataset-rail.js +123 -0
- package/src/lib/model/dataset-rail.js.map +1 -0
- package/src/lib/model/dataset-record-list.js +17 -2
- package/src/lib/model/dataset-record-list.js.map +1 -1
- package/src/lib/model/dataset-record.js +8 -3
- package/src/lib/model/dataset-record.js.map +1 -1
- package/src/lib/model/datasets.d.ts +14 -0
- package/src/lib/model/datasets.js +10 -0
- package/src/lib/model/datasets.js.map +1 -1
- package/src/lib/plugin.d.ts +5 -1
- package/src/lib/plugin.js +8 -3
- package/src/lib/plugin.js.map +1 -1
- package/src/lib/record-pages/record-template-section.component.js +12 -1
- package/src/lib/record-pages/record-template-section.component.js.map +1 -1
- package/src/lib/server/api-v1/datasets.js +6 -1
- package/src/lib/server/api-v1/datasets.js.map +1 -1
- package/src/lib/server/dataset-access.server.d.ts +4 -3
- package/src/lib/server/dataset-access.server.js +7 -5
- package/src/lib/server/dataset-access.server.js.map +1 -1
- package/src/lib/server/dataset-drafts.js +2 -0
- package/src/lib/server/dataset-drafts.js.map +1 -1
- package/src/lib/server/dataset-site-erasure.d.ts +2 -2
- package/src/lib/server/dataset-site-erasure.js +4 -26
- package/src/lib/server/dataset-site-erasure.js.map +1 -1
- package/src/lib/server/datasets-route.d.ts +2 -0
- package/src/lib/server/datasets-route.js +125 -19
- package/src/lib/server/datasets-route.js.map +1 -1
- package/src/lib/site-bundle/datasets-site-bundle.server.d.ts +4 -2
- package/src/lib/site-bundle/datasets-site-bundle.server.js +16 -5
- package/src/lib/site-bundle/datasets-site-bundle.server.js.map +1 -1
- package/src/lib/transfer/dataset-transfer-access.server.js +3 -3
- package/src/lib/transfer/dataset-transfer-access.server.js.map +1 -1
|
@@ -16,16 +16,20 @@
|
|
|
16
16
|
*/ 'use client';
|
|
17
17
|
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
18
18
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
19
|
-
import { getCustomFieldType, listCustomFieldTypes,
|
|
19
|
+
import { getCustomFieldType, listCustomFieldTypes, describeSharing, narrowsScope, scopeSharingOf, sharingCovers, sharingFromChoice, storedScope, visibleToHost } from "@aglyn/aglyn";
|
|
20
20
|
import { useConfirmationContext } from "@aglyn/shared-ui-jsx";
|
|
21
|
+
import { SiteSharingField } from "@aglyn/shared-ui-jsx/components/site-sharing-field.component";
|
|
22
|
+
import { authorizedFetch } from "@aglyn/shared-util-http/authorized-token";
|
|
21
23
|
import { useSnackbar } from "@aglyn/shared-ui-snackstack";
|
|
22
|
-
import { Button, Checkbox, Alert, Box, Chip, Dialog, DialogActions, DialogContent, DialogTitle, FormControlLabel, IconButton, MenuItem,
|
|
23
|
-
import {
|
|
24
|
-
import { useCallback, useEffect, useState } from "react";
|
|
25
|
-
import { useFirestore,
|
|
24
|
+
import { Button, Checkbox, Alert, Box, Chip, Dialog, DialogActions, DialogContent, DialogTitle, FormControlLabel, IconButton, MenuItem, Stack, TextField, Typography } from "@mui/material";
|
|
25
|
+
import { doc, updateDoc } from "firebase/firestore";
|
|
26
|
+
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
27
|
+
import { useFirestore, useOrgDataScope, useScopeTokens, useUser, writeGuardedBySeed } from "@aglyn/tenant-feature-instance";
|
|
26
28
|
import { DATASET_AUTHORABLE_FIELD_TYPES, DATASET_FIELD_TYPES, DATASET_FIELD_TYPE_LABELS, effectiveDatasetModel } from "../model/dataset-models.js";
|
|
27
|
-
import { datasetDisplayName, defaultDatasetFieldId, validateDatasetFieldId } from "../model/datasets.js";
|
|
29
|
+
import { datasetDisplayName, datasetNameLower, defaultDatasetFieldId, validateDatasetFieldId } from "../model/datasets.js";
|
|
28
30
|
import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-pages/record-pages.js";
|
|
31
|
+
import { useOrgSites } from "./use-org-sites.js";
|
|
32
|
+
import { datasetPickerLabelsOf } from "../model/dataset-rail.js";
|
|
29
33
|
/** Types surfaced in the picker; the rest exist for compat, not authoring. */ const AUTHORABLE_TYPES = DATASET_AUTHORABLE_FIELD_TYPES;
|
|
30
34
|
/** The dialog's schema controls, switched off together where only the sharing is this member's. */ function SchemaControls(props) {
|
|
31
35
|
return props.locked ? /*#__PURE__*/ _jsx(Box, {
|
|
@@ -42,6 +46,33 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
|
|
|
42
46
|
children: props.children
|
|
43
47
|
});
|
|
44
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* How a dataset is shared, as the choice the sharing field edits, or null where
|
|
51
|
+
* it stores no sharing (AGL-1484). The seed and the save both read it from here,
|
|
52
|
+
* so a dialog nobody touched compares equal to its own document and writes none.
|
|
53
|
+
*/ function sharingChoiceOf(dataset) {
|
|
54
|
+
const sharing = scopeSharingOf(dataset);
|
|
55
|
+
if (sharing.mode === 'all') return {
|
|
56
|
+
mode: 'all'
|
|
57
|
+
};
|
|
58
|
+
if (sharing.mode === 'selected') return {
|
|
59
|
+
mode: 'selected',
|
|
60
|
+
hostIds: sharing.hostIds
|
|
61
|
+
};
|
|
62
|
+
if (sharing.mode === 'allExcept') return {
|
|
63
|
+
mode: 'allExcept',
|
|
64
|
+
exceptHostIds: sharing.exceptHostIds
|
|
65
|
+
};
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
/** Two choices compare by what they pick, in any order. */ function sharingChoiceKey(choice) {
|
|
69
|
+
if (!choice) return 'unset';
|
|
70
|
+
if (choice.mode === 'all') return 'all';
|
|
71
|
+
const picked = choice.mode === 'selected' ? choice.hostIds : choice.exceptHostIds;
|
|
72
|
+
return `${choice.mode}:${[
|
|
73
|
+
...picked
|
|
74
|
+
].sort().join(',')}`;
|
|
75
|
+
}
|
|
45
76
|
/**
|
|
46
77
|
* Model builder (AGL-178): edits the AGL-177 typed model on a dataset —
|
|
47
78
|
* singular/plural display names (dod.ts Schema.Name), add/edit/remove/
|
|
@@ -52,7 +83,7 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
|
|
|
52
83
|
* lazily on next document save; fieldIds are stable keys — only display
|
|
53
84
|
* names rename.
|
|
54
85
|
*/ export function DatasetSchemaDialog(props) {
|
|
55
|
-
var _ref, _ref1, _ref2, _ref3, _ref4,
|
|
86
|
+
var _ref, _ref1, _ref2, _ref3, _ref4, _ref5, _editorDefinition_slugFrom, _ref6, _ref7, _find, _ref8, _ref9, _ref10, _ref11;
|
|
56
87
|
var _editorDefinition_reference, _editorDefinition_reference1, _editorDefinition_reference2, _editorDefinition_reference3, _editorDefinition_validation;
|
|
57
88
|
const { hostId, dataset, datasets, recordCount, seedFromCache, seedUnreadable, seedListen, canChangeSharing = true, sharingOnlyReason, onClose } = props;
|
|
58
89
|
// Org-shared data root (AGL-237/239). Null until the async org lookup
|
|
@@ -70,41 +101,27 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
|
|
|
70
101
|
// Sharing scope (AGL-1044) — org datasets only; the legacy host path is
|
|
71
102
|
// site-private by construction.
|
|
72
103
|
// `orgWide` reads TRUE while the member doc loads (AGL-1047), which would
|
|
73
|
-
// offer a scoped collaborator the
|
|
104
|
+
// offer a scoped collaborator the sharing field for a beat before replacing
|
|
74
105
|
// it with the read-only summary — and offering a control the AGL-1041
|
|
75
106
|
// rules will reject is the thing the branch below exists to avoid. Hold
|
|
76
107
|
// the whole block until `loaded` rather than flash the wrong one.
|
|
77
108
|
const { orgWide: viewerOrgWide, loaded: scopeLoaded } = useScopeTokens(orgId != null ? orgId : undefined);
|
|
78
|
-
// Sites in this org, for naming what a narrowing would cost
|
|
79
|
-
//
|
|
80
|
-
|
|
81
|
-
// membership filter, which is the part this was missing (AGL-1145).
|
|
82
|
-
//
|
|
83
|
-
// `/hosts/{hostId}` is gated per document on `memberRoles.{uid}`, and
|
|
84
|
-
// Firestore evaluates a LIST against the QUERY rather than its results: it
|
|
85
|
-
// refuses to run one that COULD return a denied document, whatever today's
|
|
86
|
-
// data happens to hold. So filtering on `orgId` alone was not a partial
|
|
87
|
-
// result, it was a flat denial for every non-staff caller — including one
|
|
88
|
-
// who is a member of every site in the org. Proved in the emulator
|
|
89
|
-
// (cloud/hosts-list-constraint.spec.mjs); the reason nobody hit it is that
|
|
90
|
-
// staff match the rule's other branch, and staff are who tested it.
|
|
109
|
+
// Sites in this org, for naming what a narrowing would cost: the Data
|
|
110
|
+
// card's own query (`useOrgSites`), so the two share one listener.
|
|
111
|
+
const { sites: orgHostList, ready: sitesReady, hostNames } = useOrgSites(orgId);
|
|
91
112
|
const { data: user } = useUser();
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
], {
|
|
102
|
-
idField: '$id'
|
|
103
|
-
});
|
|
104
|
-
const orgHostList = orgHostDocs != null ? orgHostDocs : [];
|
|
105
|
-
const [visibleTo, setVisibleTo] = useState([]);
|
|
113
|
+
const sharingSites = useMemo(()=>orgHostList.map((host)=>{
|
|
114
|
+
var _ref, _host_name;
|
|
115
|
+
return {
|
|
116
|
+
id: host.$id,
|
|
117
|
+
name: (_ref = (_host_name = host.name) != null ? _host_name : host.subdomain) != null ? _ref : host.$id
|
|
118
|
+
};
|
|
119
|
+
}), [
|
|
120
|
+
orgHostList
|
|
121
|
+
]);
|
|
106
122
|
/**
|
|
107
|
-
*
|
|
123
|
+
* Who this dataset is shared with, as edited here. Null while the dataset
|
|
124
|
+
* stores NO scope (AGL-1484) — as opposed to storing `['org']`.
|
|
108
125
|
*
|
|
109
126
|
* The dialog used to render the two identically, which for a dataset is a
|
|
110
127
|
* worse lie than it was for a media file: `orgs/{orgId}/datasets` is read
|
|
@@ -112,7 +129,34 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
|
|
|
112
129
|
* own `organizations.ts`, so an unstamped dataset is matched by no reader
|
|
113
130
|
* in the product. It renders on no site and is missing from the reference
|
|
114
131
|
* cards even for an org-wide member — while this control said "All sites".
|
|
115
|
-
*/ const [
|
|
132
|
+
*/ const [sharing, setSharing] = useState(null);
|
|
133
|
+
const scopeUnset = sharing === null;
|
|
134
|
+
/**
|
|
135
|
+
* What the choice would write, or why it cannot be. The same answer the
|
|
136
|
+
* `set-sharing` route gives from the workspace's sites, which it reads for
|
|
137
|
+
* itself: the sites a choice leaves out stay known here even where this member
|
|
138
|
+
* can't name them, so they aren't taken for sites that are gone.
|
|
139
|
+
*/ const sharingDraft = useMemo(()=>{
|
|
140
|
+
if (!sharing) return null;
|
|
141
|
+
const leftOut = sharing.mode === 'allExcept' ? sharing.exceptHostIds : [];
|
|
142
|
+
return sharingFromChoice(sharing, [
|
|
143
|
+
...orgHostList.map((host)=>host.$id),
|
|
144
|
+
...leftOut
|
|
145
|
+
]);
|
|
146
|
+
}, [
|
|
147
|
+
sharing,
|
|
148
|
+
orgHostList
|
|
149
|
+
]);
|
|
150
|
+
// Nothing to say about leaving sites out until the sites have been read.
|
|
151
|
+
const sharingProblem = (sharing == null ? void 0 : sharing.mode) !== 'allExcept' || sitesReady ? (_ref = sharingDraft == null ? void 0 : sharingDraft.problem) != null ? _ref : null : null;
|
|
152
|
+
/** The dataset as this choice would leave it, for what depends on where it is. */ const sharingPreview = useMemo(()=>{
|
|
153
|
+
var _ref;
|
|
154
|
+
return (_ref = sharingDraft == null ? void 0 : sharingDraft.fields) != null ? _ref : {
|
|
155
|
+
visibleTo: []
|
|
156
|
+
};
|
|
157
|
+
}, [
|
|
158
|
+
sharingDraft
|
|
159
|
+
]);
|
|
116
160
|
const [model, setModel] = useState({
|
|
117
161
|
fields: {},
|
|
118
162
|
order: []
|
|
@@ -130,11 +174,9 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
|
|
|
130
174
|
// AGL-1466 ruled it out: opening a dialog would write, the AGL-1042
|
|
131
175
|
// rules refuse that write from anyone who is not org-wide, and it
|
|
132
176
|
// repairs only what somebody happens to look at — a repair mechanism
|
|
133
|
-
// wearing a UI. `
|
|
134
|
-
//
|
|
135
|
-
|
|
136
|
-
setVisibleTo(storedDatasetScope != null ? storedDatasetScope : []);
|
|
137
|
-
setScopeUnset(!storedDatasetScope);
|
|
177
|
+
// wearing a UI. `handleSave` reads the SAME helper; see the note there
|
|
178
|
+
// for why the pair is the safety property.
|
|
179
|
+
setSharing(sharingChoiceOf(dataset));
|
|
138
180
|
const effective = effectiveDatasetModel(dataset);
|
|
139
181
|
setModel({
|
|
140
182
|
fields: JSON.parse(JSON.stringify(effective.fields)),
|
|
@@ -270,7 +312,7 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
|
|
|
270
312
|
var _storedScope;
|
|
271
313
|
if (!dataset || !dataScope) return;
|
|
272
314
|
/**
|
|
273
|
-
* What the document actually carries,
|
|
315
|
+
* What the document actually carries, nothing when it carries nothing
|
|
274
316
|
* (AGL-1484) — matching the seed above, through the same helper.
|
|
275
317
|
*
|
|
276
318
|
* The pairing is the whole safety property, not tidiness. Both sides
|
|
@@ -282,38 +324,37 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
|
|
|
282
324
|
* — one the AGL-1041 rules then reject for any member who is not
|
|
283
325
|
* org-wide, failing the WHOLE schema save with it.
|
|
284
326
|
*
|
|
285
|
-
*
|
|
327
|
+
* Nothing is also the honest previous value in the other direction: a
|
|
286
328
|
* deliberate save of exactly `['org']` on an unset dataset used to
|
|
287
329
|
* compare equal to the default and be dropped, and that is the one save
|
|
288
330
|
* an unstamped dataset most needs to land.
|
|
289
|
-
*/ const
|
|
290
|
-
const scopeChanged = JSON.stringify([
|
|
291
|
-
...previousScope
|
|
292
|
-
].sort()) !== JSON.stringify([
|
|
293
|
-
...visibleTo
|
|
294
|
-
].sort());
|
|
331
|
+
*/ const scopeChanged = sharingChoiceKey(sharingChoiceOf(dataset)) !== sharingChoiceKey(sharing);
|
|
295
332
|
/**
|
|
296
|
-
* The
|
|
333
|
+
* The sharing this save writes, or null when it writes none.
|
|
297
334
|
*
|
|
298
|
-
* Only an org-wide member may change the
|
|
299
|
-
* anyone else, and
|
|
335
|
+
* Only an org-wide member may change it — the route and the AGL-1041 rules
|
|
336
|
+
* refuse anyone else, and it is written through the route because a marker
|
|
337
|
+
* is the server's alone (AGL-4047).
|
|
300
338
|
*
|
|
301
|
-
* A
|
|
302
|
-
*
|
|
303
|
-
* than substituting a scope: the org token would
|
|
304
|
-
* every site, and anything narrower would drop
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
339
|
+
* A choice that cannot be stored — "Selected sites" with no site picked, or
|
|
340
|
+
* more sites than one query can match, or nothing left out, or everything —
|
|
341
|
+
* refuses the save rather than substituting a scope: the org token would
|
|
342
|
+
* share the collection with every site, and anything narrower would drop
|
|
343
|
+
* sites somebody picked.
|
|
344
|
+
*/ const sharingWrite = orgId && viewerOrgWide && canChangeSharing && scopeChanged ? sharing : null;
|
|
345
|
+
if (sharingWrite && (sharingDraft == null ? void 0 : sharingDraft.problem)) {
|
|
346
|
+
return void enqueueSnackbar(sharingDraft.problem, {
|
|
308
347
|
variant: 'warning',
|
|
309
348
|
persist: false
|
|
310
349
|
});
|
|
311
350
|
}
|
|
312
|
-
|
|
351
|
+
const previousScope = (_storedScope = storedScope(dataset.visibleTo)) != null ? _storedScope : [];
|
|
352
|
+
const nextScope = sharingPreview.visibleTo;
|
|
353
|
+
if (scopeChanged && narrowsScope(previousScope, nextScope)) {
|
|
313
354
|
// Narrowing takes a dataset away from sites whose pages may bind it,
|
|
314
355
|
// and a repeatable bound to a dataset it can no longer see renders
|
|
315
356
|
// nothing (AGL-1039). Name the cost before paying it.
|
|
316
|
-
const losing = orgHostList.filter((host)=>visibleToHost(previousScope, host.$id)).filter((host)=>!visibleToHost(
|
|
357
|
+
const losing = orgHostList.filter((host)=>visibleToHost(previousScope, host.$id)).filter((host)=>!visibleToHost(nextScope, host.$id)).map((host)=>{
|
|
317
358
|
var _ref, _host_name;
|
|
318
359
|
return (_ref = (_host_name = host.name) != null ? _host_name : host.subdomain) != null ? _ref : host.$id;
|
|
319
360
|
});
|
|
@@ -325,7 +366,7 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
|
|
|
325
366
|
if (!proceed) return;
|
|
326
367
|
}
|
|
327
368
|
// Nothing of theirs to write when the sharing did not move.
|
|
328
|
-
if (sharingOnlyReason && !
|
|
369
|
+
if (sharingOnlyReason && !sharingWrite) return void onClose();
|
|
329
370
|
if (!model.order.length) {
|
|
330
371
|
return void enqueueSnackbar('A collection needs at least one field', {
|
|
331
372
|
variant: 'warning',
|
|
@@ -347,28 +388,52 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
|
|
|
347
388
|
* not even warn about the sites it is really taking access from.
|
|
348
389
|
* - `model` is the entire schema. A cached seed reinstates fields that
|
|
349
390
|
* were deleted and drops fields that were added.
|
|
350
|
-
|
|
391
|
+
*
|
|
392
|
+
* The schema goes first, because who may write it depends on where the
|
|
393
|
+
* dataset sits as it stands, the question the rule asks of this one save.
|
|
394
|
+
*/ let sharingRefusal = null;
|
|
395
|
+
await writeGuardedBySeed({
|
|
351
396
|
subject: 'collection schema',
|
|
352
397
|
unreadable: seedUnreadable,
|
|
353
398
|
fromCache: seedFromCache,
|
|
354
399
|
listen: seedListen
|
|
355
|
-
}, async ()=>
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
400
|
+
}, async ()=>{
|
|
401
|
+
if (!sharingOnlyReason) {
|
|
402
|
+
await updateDoc(doc(firestore, dataScope[0], dataScope[1], 'datasets', dataset.$id), _extends({
|
|
403
|
+
model,
|
|
404
|
+
names: {
|
|
405
|
+
singular: names.singular.trim(),
|
|
406
|
+
plural: names.plural.trim()
|
|
407
|
+
}
|
|
408
|
+
}, names.plural.trim() ? {
|
|
409
|
+
displayName: names.plural.trim(),
|
|
410
|
+
nameLower: datasetNameLower(names.plural)
|
|
411
|
+
} : {}, {
|
|
412
|
+
// v1 compat: keep the flat column list mirroring the model order
|
|
413
|
+
// so unmigrated consumers (AGL-103 bindings) keep working.
|
|
414
|
+
fields: model.order
|
|
415
|
+
}));
|
|
416
|
+
}
|
|
417
|
+
if (sharingWrite) {
|
|
418
|
+
const response = await authorizedFetch(user, '/api/orgs/datasets', {
|
|
419
|
+
method: 'POST',
|
|
420
|
+
headers: {
|
|
421
|
+
'Content-Type': 'application/json'
|
|
422
|
+
},
|
|
423
|
+
body: JSON.stringify({
|
|
424
|
+
orgId,
|
|
425
|
+
action: 'set-sharing',
|
|
426
|
+
datasetId: dataset.$id,
|
|
427
|
+
choice: sharingWrite
|
|
428
|
+
})
|
|
429
|
+
});
|
|
430
|
+
if (!response.ok) {
|
|
431
|
+
var _ref;
|
|
432
|
+
const payload = await response.json().catch(()=>({}));
|
|
433
|
+
sharingRefusal = String((_ref = payload == null ? void 0 : payload.error) != null ? _ref : 'The sharing could not be changed.');
|
|
362
434
|
}
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
} : {}, {
|
|
366
|
-
// v1 compat: keep the flat column list mirroring the model order
|
|
367
|
-
// so unmigrated consumers (AGL-103 bindings) keep working.
|
|
368
|
-
fields: model.order
|
|
369
|
-
}, (scopeWrite == null ? void 0 : scopeWrite.scope) ? {
|
|
370
|
-
visibleTo: scopeWrite.scope
|
|
371
|
-
} : {}))).then((result)=>{
|
|
435
|
+
}
|
|
436
|
+
}).then((result)=>{
|
|
372
437
|
// A refusal leaves the dialog open with the edited schema intact.
|
|
373
438
|
if (!result.ok) {
|
|
374
439
|
return void enqueueSnackbar(result.message, {
|
|
@@ -376,6 +441,12 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
|
|
|
376
441
|
persist: false
|
|
377
442
|
});
|
|
378
443
|
}
|
|
444
|
+
if (sharingRefusal) {
|
|
445
|
+
return void enqueueSnackbar(sharingOnlyReason ? sharingRefusal : `Schema saved. Its sharing didn’t change: ${sharingRefusal}`, {
|
|
446
|
+
variant: 'warning',
|
|
447
|
+
persist: false
|
|
448
|
+
});
|
|
449
|
+
}
|
|
379
450
|
enqueueSnackbar(sharingOnlyReason ? 'Sharing saved' : 'Schema saved', {
|
|
380
451
|
variant: 'success',
|
|
381
452
|
persist: false
|
|
@@ -388,7 +459,10 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
|
|
|
388
459
|
dataset,
|
|
389
460
|
model,
|
|
390
461
|
names,
|
|
391
|
-
|
|
462
|
+
sharing,
|
|
463
|
+
sharingDraft,
|
|
464
|
+
sharingPreview,
|
|
465
|
+
user,
|
|
392
466
|
viewerOrgWide,
|
|
393
467
|
canChangeSharing,
|
|
394
468
|
sharingOnlyReason,
|
|
@@ -478,77 +552,25 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
|
|
|
478
552
|
severity: "warning",
|
|
479
553
|
children: 'This collection has never been shared. Nothing is ' + 'stored, so it is hidden from every site and any ' + 'page repeating over it renders nothing. Choose who ' + 'it is shared with to fix that.'
|
|
480
554
|
}) : null,
|
|
481
|
-
/*#__PURE__*/
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
// stored.
|
|
488
|
-
setScopeUnset(false);
|
|
489
|
-
setVisibleTo(event.target.value === 'org' ? [
|
|
490
|
-
ORG_SCOPE_TOKEN
|
|
491
|
-
] : []);
|
|
492
|
-
},
|
|
493
|
-
children: [
|
|
494
|
-
scopeUnset ? /*#__PURE__*/ _jsx(MenuItem, {
|
|
495
|
-
value: "unset",
|
|
496
|
-
disabled: true,
|
|
497
|
-
children: 'Not shared with any site'
|
|
498
|
-
}) : null,
|
|
499
|
-
/*#__PURE__*/ _jsx(MenuItem, {
|
|
500
|
-
value: "org",
|
|
501
|
-
children: 'All sites'
|
|
502
|
-
}),
|
|
503
|
-
/*#__PURE__*/ _jsx(MenuItem, {
|
|
504
|
-
value: "hosts",
|
|
505
|
-
children: 'Selected sites…'
|
|
506
|
-
})
|
|
507
|
-
]
|
|
555
|
+
/*#__PURE__*/ _jsx(SiteSharingField, {
|
|
556
|
+
value: sharing,
|
|
557
|
+
onChange: setSharing,
|
|
558
|
+
sites: sharingSites,
|
|
559
|
+
sitesReady: sitesReady,
|
|
560
|
+
problem: sharingProblem
|
|
508
561
|
}),
|
|
509
562
|
/*#__PURE__*/ _jsx(Typography, {
|
|
510
563
|
variant: "caption",
|
|
511
564
|
color: "text.secondary",
|
|
512
565
|
children: 'Sites you exclude cannot see or use this dataset — in the console or on their pages.'
|
|
513
|
-
})
|
|
514
|
-
!scopeUnset && !visibleTo.includes(ORG_SCOPE_TOKEN) ? /*#__PURE__*/ _jsx(Stack, {
|
|
515
|
-
direction: "row",
|
|
516
|
-
spacing: 0.5,
|
|
517
|
-
useFlexGap: true,
|
|
518
|
-
sx: {
|
|
519
|
-
flexWrap: 'wrap'
|
|
520
|
-
},
|
|
521
|
-
children: orgHostList.map((host)=>{
|
|
522
|
-
var _ref, _host_name;
|
|
523
|
-
const token = hostScopeToken(host.$id);
|
|
524
|
-
const on = visibleTo.includes(token);
|
|
525
|
-
return /*#__PURE__*/ _jsx(Chip, {
|
|
526
|
-
size: "small",
|
|
527
|
-
label: (_ref = (_host_name = host.name) != null ? _host_name : host.subdomain) != null ? _ref : host.$id,
|
|
528
|
-
color: on ? 'primary' : 'default',
|
|
529
|
-
variant: on ? 'filled' : 'outlined',
|
|
530
|
-
onClick: ()=>setVisibleTo((prev)=>on ? prev.filter((t)=>t !== token) : [
|
|
531
|
-
...prev,
|
|
532
|
-
token
|
|
533
|
-
])
|
|
534
|
-
}, host.$id);
|
|
535
|
-
})
|
|
536
|
-
}) : null,
|
|
537
|
-
!scopeUnset && scopeToStore(visibleTo).problem ? /*#__PURE__*/ _jsx(Typography, {
|
|
538
|
-
variant: "caption",
|
|
539
|
-
color: "error",
|
|
540
|
-
children: scopeToStore(visibleTo).problem
|
|
541
|
-
}) : null
|
|
566
|
+
})
|
|
542
567
|
]
|
|
543
568
|
}) : /*#__PURE__*/ _jsx(Typography, {
|
|
544
569
|
variant: "body2",
|
|
545
|
-
children: scopeUnset ? 'Never shared — hidden from every site' :
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
(_ref = (_host_name = host.name) != null ? _host_name : host.subdomain) != null ? _ref : host.$id
|
|
550
|
-
];
|
|
551
|
-
})))
|
|
570
|
+
children: scopeUnset ? 'Never shared — hidden from every site' : describeSharing(dataset, Object.fromEntries(sharingSites.map((site)=>[
|
|
571
|
+
site.id,
|
|
572
|
+
site.name
|
|
573
|
+
])))
|
|
552
574
|
})
|
|
553
575
|
]
|
|
554
576
|
}) : null,
|
|
@@ -689,7 +711,7 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
|
|
|
689
711
|
/*#__PURE__*/ _jsx(TextField, {
|
|
690
712
|
size: "small",
|
|
691
713
|
label: "Display name",
|
|
692
|
-
value: (
|
|
714
|
+
value: (_ref1 = editorDefinition == null ? void 0 : editorDefinition.name) != null ? _ref1 : '',
|
|
693
715
|
autoFocus: true,
|
|
694
716
|
onChange: (event)=>{
|
|
695
717
|
const name = event.target.value;
|
|
@@ -716,7 +738,7 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
|
|
|
716
738
|
/*#__PURE__*/ _jsx(TextField, {
|
|
717
739
|
size: "small",
|
|
718
740
|
label: "Reference ID",
|
|
719
|
-
value: isNewField ? (
|
|
741
|
+
value: isNewField ? (_ref2 = fieldEditor == null ? void 0 : fieldEditor.idDraft) != null ? _ref2 : '' : (_ref3 = fieldEditor == null ? void 0 : fieldEditor.fieldId) != null ? _ref3 : '',
|
|
720
742
|
disabled: !isNewField,
|
|
721
743
|
onChange: (event)=>setFieldEditor((prev)=>prev ? _extends({}, prev, {
|
|
722
744
|
idDraft: event.target.value,
|
|
@@ -730,7 +752,7 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
|
|
|
730
752
|
label: "Description",
|
|
731
753
|
multiline: true,
|
|
732
754
|
minRows: 2,
|
|
733
|
-
value: (
|
|
755
|
+
value: (_ref4 = editorDefinition == null ? void 0 : editorDefinition.description) != null ? _ref4 : '',
|
|
734
756
|
onChange: (event)=>setFieldEditor((prev)=>prev ? _extends({}, prev, {
|
|
735
757
|
definition: _extends({}, prev.definition, {
|
|
736
758
|
description: event.target.value
|
|
@@ -742,7 +764,7 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
|
|
|
742
764
|
select: true,
|
|
743
765
|
size: "small",
|
|
744
766
|
label: "Type",
|
|
745
|
-
value: (editorDefinition == null ? void 0 : editorDefinition.customType) ? `custom:${editorDefinition.customType}` : (
|
|
767
|
+
value: (editorDefinition == null ? void 0 : editorDefinition.customType) ? `custom:${editorDefinition.customType}` : (_ref5 = editorDefinition == null ? void 0 : editorDefinition.type) != null ? _ref5 : 'text',
|
|
746
768
|
onChange: (event)=>setFieldEditor((prev)=>{
|
|
747
769
|
if (!prev) return prev;
|
|
748
770
|
const selected = event.target.value;
|
|
@@ -817,7 +839,7 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
|
|
|
817
839
|
select: true,
|
|
818
840
|
size: "small",
|
|
819
841
|
label: "Target collection",
|
|
820
|
-
value: (
|
|
842
|
+
value: (_ref6 = editorDefinition == null ? void 0 : (_editorDefinition_reference = editorDefinition.reference) == null ? void 0 : _editorDefinition_reference.datasetId) != null ? _ref6 : '',
|
|
821
843
|
onChange: (event)=>setFieldEditor((prev)=>{
|
|
822
844
|
var _prev_definition_reference;
|
|
823
845
|
return prev ? _extends({}, prev, {
|
|
@@ -830,19 +852,24 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
|
|
|
830
852
|
})
|
|
831
853
|
}) : prev;
|
|
832
854
|
}),
|
|
833
|
-
children: (
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
855
|
+
children: (()=>{
|
|
856
|
+
const targets = (datasets != null ? datasets : []).filter((target)=>target.$id !== (dataset == null ? void 0 : dataset.$id))// Only targets this dataset's sites can actually resolve
|
|
857
|
+
// (AGL-1044). A reference to a dataset a site cannot see
|
|
858
|
+
// renders blank with nothing to say why, so an
|
|
859
|
+
// unresolvable target is not offered. The currently
|
|
860
|
+
// selected one always stays listed — otherwise changing
|
|
861
|
+
// scope would silently blank an existing field.
|
|
862
|
+
.filter((target)=>{
|
|
863
|
+
var _editorDefinition_reference;
|
|
864
|
+
return target.$id === (editorDefinition == null ? void 0 : (_editorDefinition_reference = editorDefinition.reference) == null ? void 0 : _editorDefinition_reference.datasetId) || sharingCovers(target, sharingPreview);
|
|
865
|
+
});
|
|
866
|
+
// Who a target is shared with only where two share a name (AGL-4047).
|
|
867
|
+
const labels = datasetPickerLabelsOf(targets, hostNames);
|
|
868
|
+
return targets.map((target)=>/*#__PURE__*/ _jsx(MenuItem, {
|
|
869
|
+
value: target.$id,
|
|
870
|
+
children: labels[target.$id] || datasetDisplayName(target) || target.$id
|
|
871
|
+
}, target.$id));
|
|
872
|
+
})()
|
|
846
873
|
}),
|
|
847
874
|
(()=>{
|
|
848
875
|
var _editorDefinition_reference;
|
|
@@ -851,7 +878,7 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
|
|
|
851
878
|
// is not any more.
|
|
852
879
|
const targetId = editorDefinition == null ? void 0 : (_editorDefinition_reference = editorDefinition.reference) == null ? void 0 : _editorDefinition_reference.datasetId;
|
|
853
880
|
const target = (datasets != null ? datasets : []).find((d)=>d.$id === targetId);
|
|
854
|
-
if (!target ||
|
|
881
|
+
if (!target || sharingCovers(target, sharingPreview)) {
|
|
855
882
|
return null;
|
|
856
883
|
}
|
|
857
884
|
return /*#__PURE__*/ _jsx(Alert, {
|
|
@@ -863,7 +890,7 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
|
|
|
863
890
|
select: true,
|
|
864
891
|
size: "small",
|
|
865
892
|
label: "Display field",
|
|
866
|
-
value: (
|
|
893
|
+
value: (_ref7 = editorDefinition == null ? void 0 : (_editorDefinition_reference1 = editorDefinition.reference) == null ? void 0 : _editorDefinition_reference1.displayFieldId) != null ? _ref7 : '',
|
|
867
894
|
onChange: (event)=>setFieldEditor((prev)=>(prev == null ? void 0 : prev.definition.reference) ? _extends({}, prev, {
|
|
868
895
|
definition: _extends({}, prev.definition, {
|
|
869
896
|
reference: _extends({}, prev.definition.reference, {
|
|
@@ -884,7 +911,7 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
|
|
|
884
911
|
select: true,
|
|
885
912
|
size: "small",
|
|
886
913
|
label: "When a referenced document is deleted",
|
|
887
|
-
value: (
|
|
914
|
+
value: (_ref8 = editorDefinition == null ? void 0 : (_editorDefinition_reference2 = editorDefinition.reference) == null ? void 0 : _editorDefinition_reference2.onDelete) != null ? _ref8 : 'setNull',
|
|
888
915
|
onChange: (event)=>setFieldEditor((prev)=>(prev == null ? void 0 : prev.definition.reference) ? _extends({}, prev, {
|
|
889
916
|
definition: _extends({}, prev.definition, {
|
|
890
917
|
reference: _extends({}, prev.definition.reference, {
|
|
@@ -934,7 +961,7 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
|
|
|
934
961
|
/*#__PURE__*/ _jsx(TextField, {
|
|
935
962
|
size: "small",
|
|
936
963
|
label: "Default value",
|
|
937
|
-
value: String((
|
|
964
|
+
value: String((_ref9 = editorDefinition == null ? void 0 : editorDefinition.default) != null ? _ref9 : ''),
|
|
938
965
|
onChange: (event)=>setFieldEditor((prev)=>prev ? _extends({}, prev, {
|
|
939
966
|
definition: _extends({}, prev.definition, event.target.value ? {
|
|
940
967
|
default: event.target.value
|
|
@@ -949,7 +976,7 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
|
|
|
949
976
|
/*#__PURE__*/ _jsx(TextField, {
|
|
950
977
|
size: "small",
|
|
951
978
|
label: "Pattern (regex)",
|
|
952
|
-
value: (
|
|
979
|
+
value: (_ref10 = editorDefinition == null ? void 0 : (_editorDefinition_validation = editorDefinition.validation) == null ? void 0 : _editorDefinition_validation.regex) != null ? _ref10 : '',
|
|
953
980
|
onChange: (event)=>setFieldEditor((prev)=>{
|
|
954
981
|
var _prev_definition_validation;
|
|
955
982
|
return prev ? _extends({}, prev, {
|
|
@@ -966,7 +993,7 @@ import { RECORD_PAGE_ADDRESS_FIELD_TYPE, isRecordAddressField } from "../record-
|
|
|
966
993
|
/*#__PURE__*/ _jsx(TextField, {
|
|
967
994
|
size: "small",
|
|
968
995
|
label: "Options",
|
|
969
|
-
value: (
|
|
996
|
+
value: (_ref11 = fieldEditor == null ? void 0 : fieldEditor.optionsText) != null ? _ref11 : '',
|
|
970
997
|
onChange: (event)=>setFieldEditor((prev)=>prev ? _extends({}, prev, {
|
|
971
998
|
optionsText: event.target.value
|
|
972
999
|
}) : prev),
|