@sanity/cross-dataset-duplicator 0.3.4 → 0.3.6

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.
@@ -4,126 +4,91 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = DuplicatorTool;
7
-
8
7
  var _react = _interopRequireWildcard(require("react"));
9
-
10
8
  var _mapLimit = _interopRequireDefault(require("async/mapLimit"));
11
-
12
9
  var _asyncify = _interopRequireDefault(require("async/asyncify"));
13
-
14
10
  var _mutator = require("@sanity/mutator");
15
-
16
11
  var _dset = require("dset");
17
-
18
12
  var _ui = require("@sanity/ui");
19
-
20
13
  var _icons = require("@sanity/icons");
21
-
22
14
  var _client = _interopRequireDefault(require("part:@sanity/base/client"));
23
-
24
15
  var _preview = _interopRequireDefault(require("part:@sanity/base/preview"));
25
-
26
16
  var _schema = _interopRequireDefault(require("part:@sanity/base/schema"));
27
-
28
17
  var _configSanity = _interopRequireDefault(require("config:sanity"));
29
-
30
18
  var _helpers = require("../helpers");
31
-
32
19
  var _getDocumentsInArray = require("../helpers/getDocumentsInArray");
33
-
34
20
  var _SelectButtons = _interopRequireDefault(require("./SelectButtons"));
35
-
36
21
  var _StatusBadge = _interopRequireDefault(require("./StatusBadge"));
37
-
38
22
  var _Feedback = _interopRequireDefault(require("./Feedback"));
39
-
40
23
  var _clientConfig = require("../helpers/clientConfig");
41
-
42
24
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
43
-
44
25
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
45
-
46
26
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
47
-
48
27
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
49
-
50
28
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
51
-
52
29
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
53
-
54
30
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
55
-
56
31
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
57
-
58
32
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
59
-
60
33
  function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
61
-
62
34
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
63
-
64
35
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
65
-
66
36
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
67
-
68
37
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
69
-
70
38
  function DuplicatorTool(props) {
71
39
  var _config$__experimenta, _destination$title, _spacesOptions$find, _message$tone;
72
-
73
40
  var docs = props.docs,
74
- draftIds = props.draftIds,
75
- token = props.token; // Prepare origin (this Studio) client
41
+ draftIds = props.draftIds,
42
+ token = props.token;
43
+
44
+ // Prepare origin (this Studio) client
76
45
  // In function-scope so it is up to date on every render
46
+ var originClient = _client.default.withConfig(_clientConfig.clientConfig);
77
47
 
78
- var originClient = _client.default.withConfig(_clientConfig.clientConfig); // Create list of dataset options
48
+ // Create list of dataset options
79
49
  // and set initial value of dropdown
80
-
81
-
82
50
  var spacesOptions = _configSanity.default !== null && _configSanity.default !== void 0 && (_config$__experimenta = _configSanity.default.__experimental_spaces) !== null && _config$__experimenta !== void 0 && _config$__experimenta.length ? _configSanity.default.__experimental_spaces.map(space => _objectSpread(_objectSpread({}, space), {}, {
51
+ api: _objectSpread(_objectSpread({}, space.api), {}, {
52
+ projectId: space.api.projectId || process.env.SANITY_STUDIO_API_PROJECT_ID
53
+ }),
54
+ usingEnvForProjectId: !space.api.projectId && process.env.SANITY_STUDIO_API_PROJECT_ID,
83
55
  disabled: space.api.dataset === originClient.config().dataset && space.api.projectId === originClient.config().projectId
84
56
  })) : [];
85
-
86
57
  var _useState = (0, _react.useState)(spacesOptions.length ? spacesOptions.find(space => !space.disabled) : {}),
87
- _useState2 = _slicedToArray(_useState, 2),
88
- destination = _useState2[0],
89
- setDestination = _useState2[1];
90
-
58
+ _useState2 = _slicedToArray(_useState, 2),
59
+ destination = _useState2[0],
60
+ setDestination = _useState2[1];
91
61
  var _useState3 = (0, _react.useState)({}),
92
- _useState4 = _slicedToArray(_useState3, 2),
93
- message = _useState4[0],
94
- setMessage = _useState4[1];
95
-
62
+ _useState4 = _slicedToArray(_useState3, 2),
63
+ message = _useState4[0],
64
+ setMessage = _useState4[1];
96
65
  var _useState5 = (0, _react.useState)(docs.length ? docs.map(item => ({
97
- doc: item,
98
- include: true,
99
- status: null,
100
- hasDraft: draftIds !== null && draftIds !== void 0 && draftIds.length ? draftIds.includes("drafts.".concat(item._id)) : false
101
- })) : []),
102
- _useState6 = _slicedToArray(_useState5, 2),
103
- payload = _useState6[0],
104
- setPayload = _useState6[1];
105
-
66
+ doc: item,
67
+ include: true,
68
+ status: null,
69
+ hasDraft: draftIds !== null && draftIds !== void 0 && draftIds.length ? draftIds.includes("drafts.".concat(item._id)) : false
70
+ })) : []),
71
+ _useState6 = _slicedToArray(_useState5, 2),
72
+ payload = _useState6[0],
73
+ setPayload = _useState6[1];
106
74
  var _useState7 = (0, _react.useState)(false),
107
- _useState8 = _slicedToArray(_useState7, 2),
108
- hasReferences = _useState8[0],
109
- setHasReferences = _useState8[1];
110
-
75
+ _useState8 = _slicedToArray(_useState7, 2),
76
+ hasReferences = _useState8[0],
77
+ setHasReferences = _useState8[1];
111
78
  var _useState9 = (0, _react.useState)(false),
112
- _useState10 = _slicedToArray(_useState9, 2),
113
- isDuplicating = _useState10[0],
114
- setIsDuplicating = _useState10[1];
115
-
79
+ _useState10 = _slicedToArray(_useState9, 2),
80
+ isDuplicating = _useState10[0],
81
+ setIsDuplicating = _useState10[1];
116
82
  var _useState11 = (0, _react.useState)(false),
117
- _useState12 = _slicedToArray(_useState11, 2),
118
- isGathering = _useState12[0],
119
- setIsGathering = _useState12[1];
120
-
83
+ _useState12 = _slicedToArray(_useState11, 2),
84
+ isGathering = _useState12[0],
85
+ setIsGathering = _useState12[1];
121
86
  var _useState13 = (0, _react.useState)([0, 0]),
122
- _useState14 = _slicedToArray(_useState13, 2),
123
- progress = _useState14[0],
124
- setProgress = _useState14[1]; // Check for References and update message
125
-
87
+ _useState14 = _slicedToArray(_useState13, 2),
88
+ progress = _useState14[0],
89
+ setProgress = _useState14[1];
126
90
 
91
+ // Check for References and update message
127
92
  (0, _react.useEffect)(() => {
128
93
  var expr = ".._ref";
129
94
  var initialRefs = [];
@@ -138,7 +103,6 @@ function DuplicatorTool(props) {
138
103
  setPayload(initialPayload);
139
104
  var docCount = docs.length;
140
105
  var refsCount = initialRefs.length;
141
-
142
106
  if (initialRefs.length) {
143
107
  setHasReferences(true);
144
108
  setMessage({
@@ -146,44 +110,39 @@ function DuplicatorTool(props) {
146
110
  text: (0, _helpers.createInitialMessage)(docCount, refsCount)
147
111
  });
148
112
  }
149
- }, [docs]); // Re-check payload on destination when value changes
150
- // (On initial render + select change)
113
+ }, [docs]);
151
114
 
115
+ // Re-check payload on destination when value changes
116
+ // (On initial render + select change)
152
117
  (0, _react.useEffect)(() => {
153
118
  updatePayloadStatuses();
154
- }, [destination, docs]); // Check if payload documents exist at destination
119
+ }, [destination, docs]);
155
120
 
121
+ // Check if payload documents exist at destination
156
122
  function updatePayloadStatuses() {
157
123
  return _updatePayloadStatuses.apply(this, arguments);
158
124
  }
159
-
160
125
  function _updatePayloadStatuses() {
161
126
  _updatePayloadStatuses = _asyncToGenerator(function* () {
162
127
  var newPayload = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
163
128
  var payloadActual = newPayload.length ? newPayload : payload;
164
-
165
129
  if (!payloadActual.length || !(destination !== null && destination !== void 0 && destination.name)) {
166
130
  return;
167
131
  }
168
-
169
132
  var payloadIds = payloadActual.map(_ref3 => {
170
133
  var doc = _ref3.doc;
171
134
  return doc._id;
172
135
  });
173
-
174
136
  var destinationClient = _client.default.withConfig(_objectSpread(_objectSpread({}, _clientConfig.clientConfig), {}, {
175
137
  dataset: destination.api.dataset,
176
138
  projectId: destination.api.projectId
177
139
  }));
178
-
179
140
  var destinationData = yield destinationClient.fetch("*[_id in $payloadIds]{ _id, _updatedAt }", {
180
141
  payloadIds
181
142
  });
182
143
  var updatedPayload = payloadActual.map(item => {
183
144
  var _item$doc;
184
-
185
145
  var existingDoc = destinationData.find(doc => doc._id === item.doc._id);
186
-
187
146
  if (existingDoc !== null && existingDoc !== void 0 && existingDoc._updatedAt && item !== null && item !== void 0 && (_item$doc = item.doc) !== null && _item$doc !== void 0 && _item$doc._updatedAt) {
188
147
  if (existingDoc._updatedAt === item.doc._updatedAt) {
189
148
  // Exact same document exists at destination
@@ -197,31 +156,26 @@ function DuplicatorTool(props) {
197
156
  } else {
198
157
  item.status = 'CREATE';
199
158
  }
200
-
201
159
  return item;
202
160
  });
203
161
  setPayload(updatedPayload);
204
162
  });
205
163
  return _updatePayloadStatuses.apply(this, arguments);
206
164
  }
207
-
208
165
  function handleCheckbox(_id) {
209
166
  var updatedPayload = payload.map(item => {
210
167
  if (item.doc._id === _id) {
211
168
  item.include = !item.include;
212
169
  }
213
-
214
170
  return item;
215
171
  });
216
172
  setPayload(updatedPayload);
217
- } // Find and recursively follow references beginning with this document
218
-
173
+ }
219
174
 
175
+ // Find and recursively follow references beginning with this document
220
176
  function handleReferences() {
221
177
  return _handleReferences.apply(this, arguments);
222
178
  } // Duplicate payload to destination dataset
223
-
224
-
225
179
  function _handleReferences() {
226
180
  _handleReferences = _asyncToGenerator(function* () {
227
181
  setIsGathering(true);
@@ -231,8 +185,9 @@ function DuplicatorTool(props) {
231
185
  var draftDocsIds = new Set(draftDocs.map(_ref4 => {
232
186
  var _id = _ref4._id;
233
187
  return _id;
234
- })); // Shape it up
188
+ }));
235
189
 
190
+ // Shape it up
236
191
  var payloadShaped = payloadDocs.map(doc => ({
237
192
  doc,
238
193
  // Include this in the transaction?
@@ -248,17 +203,15 @@ function DuplicatorTool(props) {
248
203
  });
249
204
  return _handleReferences.apply(this, arguments);
250
205
  }
251
-
252
206
  function handleDuplicate() {
253
207
  return _handleDuplicate.apply(this, arguments);
254
208
  }
255
-
256
209
  function _handleDuplicate() {
257
210
  _handleDuplicate = _asyncToGenerator(function* () {
258
211
  setIsDuplicating(true);
259
212
  var assetsCount = payload.filter(_ref5 => {
260
213
  var doc = _ref5.doc,
261
- include = _ref5.include;
214
+ include = _ref5.include;
262
215
  return include && (0, _helpers.typeIsAsset)(doc._type);
263
216
  }).length;
264
217
  var currentProgress = 0;
@@ -266,27 +219,23 @@ function DuplicatorTool(props) {
266
219
  setMessage({
267
220
  text: 'Duplicating...'
268
221
  });
269
-
270
222
  var destinationClient = _client.default.withConfig(_objectSpread(_objectSpread({}, _clientConfig.clientConfig), {}, {
271
223
  dataset: destination.api.dataset,
272
224
  projectId: destination.api.projectId
273
225
  }));
274
-
275
226
  var transactionDocs = [];
276
- var svgMaps = []; // Upload assets and then add to transaction
227
+ var svgMaps = [];
277
228
 
229
+ // Upload assets and then add to transaction
278
230
  function fetchDoc(_x) {
279
231
  return _fetchDoc.apply(this, arguments);
280
232
  } // Promises are limited to three at once
281
-
282
-
283
233
  function _fetchDoc() {
284
234
  _fetchDoc = _asyncToGenerator(function* (doc) {
285
235
  if ((0, _helpers.typeIsAsset)(doc._type)) {
286
236
  // Download and upload asset
287
237
  // Get the *original* image with this dlRaw param to create the same determenistic _id
288
238
  var uploadType = doc._type.split('.').pop().replace('Asset', '');
289
-
290
239
  var downloadUrl = uploadType === 'image' ? "".concat(doc.url, "?dlRaw=true") : doc.url;
291
240
  var downloadConfig = uploadType === 'image' ? {
292
241
  headers: {
@@ -299,18 +248,17 @@ function DuplicatorTool(props) {
299
248
  var options = {
300
249
  filename: doc.originalFilename
301
250
  };
302
- var assetDoc = yield destinationClient.assets.upload(uploadType, assetData, options); // SVG _id's need remapping before transaction
251
+ var assetDoc = yield destinationClient.assets.upload(uploadType, assetData, options);
303
252
 
253
+ // SVG _id's need remapping before transaction
304
254
  if ((doc === null || doc === void 0 ? void 0 : doc.extension) === 'svg') {
305
255
  svgMaps.push({
306
256
  old: doc._id,
307
257
  new: assetDoc._id
308
258
  });
309
259
  }
310
-
311
260
  transactionDocs.push(assetDoc);
312
261
  });
313
-
314
262
  return function (_x2) {
315
263
  return _ref6.apply(this, arguments);
316
264
  };
@@ -321,12 +269,10 @@ function DuplicatorTool(props) {
321
269
  });
322
270
  return setProgress([currentProgress, assetsCount]);
323
271
  }
324
-
325
272
  return transactionDocs.push(doc);
326
273
  });
327
274
  return _fetchDoc.apply(this, arguments);
328
275
  }
329
-
330
276
  var result = new Promise((resolve, reject) => {
331
277
  var payloadIncludedDocs = payload.filter(item => item.include).map(item => item.doc);
332
278
  (0, _mapLimit.default)(payloadIncludedDocs, 3, (0, _asyncify.default)(fetchDoc), err => {
@@ -339,34 +285,32 @@ function DuplicatorTool(props) {
339
285
  console.error(err);
340
286
  reject(new Error('Duplication Failed'));
341
287
  }
342
-
343
288
  resolve();
344
289
  });
345
290
  });
346
- yield result; // Remap SVG references to new _id's
291
+ yield result;
347
292
 
293
+ // Remap SVG references to new _id's
348
294
  var transactionDocsMapped = transactionDocs.map(doc => {
349
295
  var expr = ".._ref";
350
296
  var references = (0, _mutator.extractWithPath)(expr, doc);
351
-
352
297
  if (!references.length) {
353
298
  return doc;
354
- } // For every found _ref, search for an SVG asset _id and update
355
-
299
+ }
356
300
 
301
+ // For every found _ref, search for an SVG asset _id and update
357
302
  references.forEach(ref => {
358
303
  var _svgMaps$find;
359
-
360
304
  var newRefValue = (_svgMaps$find = svgMaps.find(asset => asset.old === ref.value)) === null || _svgMaps$find === void 0 ? void 0 : _svgMaps$find.new;
361
-
362
305
  if (newRefValue) {
363
306
  var refPath = ref.path.join('.');
364
307
  (0, _dset.dset)(doc, refPath, newRefValue);
365
308
  }
366
309
  });
367
310
  return doc;
368
- }); // Create transaction
311
+ });
369
312
 
313
+ // Create transaction
370
314
  var transaction = destinationClient.transaction();
371
315
  transactionDocsMapped.forEach(doc => {
372
316
  transaction.createOrReplace(doc);
@@ -388,17 +332,14 @@ function DuplicatorTool(props) {
388
332
  });
389
333
  return _handleDuplicate.apply(this, arguments);
390
334
  }
391
-
392
335
  function handleChange(e) {
393
336
  setDestination(spacesOptions.find(space => space.name === e.currentTarget.value));
394
337
  }
395
-
396
338
  if (!spacesOptions.length) {
397
339
  return /*#__PURE__*/_react.default.createElement(_Feedback.default, {
398
340
  tone: "critical"
399
341
  }, /*#__PURE__*/_react.default.createElement("code", null, "__experimental_spaces"), " not found in ", /*#__PURE__*/_react.default.createElement("code", null, "sanity.json"));
400
342
  }
401
-
402
343
  var payloadCount = payload.length;
403
344
  var firstSvgIndex = payload.findIndex(_ref => {
404
345
  var doc = _ref.doc;
@@ -410,30 +351,23 @@ function DuplicatorTool(props) {
410
351
  var destinationTitle = (_destination$title = destination === null || destination === void 0 ? void 0 : destination.title) !== null && _destination$title !== void 0 ? _destination$title : destination === null || destination === void 0 ? void 0 : destination.name;
411
352
  var hasMultipleProjectIds = new Set(spacesOptions.map(space => {
412
353
  var _space$api;
413
-
414
354
  return space === null || space === void 0 ? void 0 : (_space$api = space.api) === null || _space$api === void 0 ? void 0 : _space$api.projectId;
415
355
  }).filter(Boolean)).size > 1;
416
356
  var headingText = [selectedTotal, "/", payloadCount, "Documents and Assets selected"].join(" ");
417
-
418
357
  var buttonText = _react.default.useMemo(() => {
419
358
  var text = ["Duplicate"];
420
-
421
359
  if (selectedDocumentsCount > 1) {
422
360
  text.push(selectedDocumentsCount, selectedDocumentsCount === 1 ? "Document" : "Documents");
423
361
  }
424
-
425
362
  if (selectedAssetsCount > 1) {
426
363
  text.push("and", selectedAssetsCount, selectedAssetsCount === 1 ? "Asset" : "Assets");
427
364
  }
428
-
429
365
  if (originClient.config().projectId !== destination.api.projectId) {
430
366
  text.push("between Projects");
431
367
  }
432
-
433
368
  text.push("to", destinationTitle);
434
369
  return text.join(" ");
435
370
  }, [selectedDocumentsCount, selectedAssetsCount, destinationTitle]);
436
-
437
371
  return /*#__PURE__*/_react.default.createElement(_ui.Container, {
438
372
  width: 1
439
373
  }, /*#__PURE__*/_react.default.createElement(_ui.Card, null, /*#__PURE__*/_react.default.createElement(_ui.Stack, null, /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_ui.Card, {
@@ -454,12 +388,11 @@ function DuplicatorTool(props) {
454
388
  value: (_spacesOptions$find = spacesOptions.find(space => space.disabled)) === null || _spacesOptions$find === void 0 ? void 0 : _spacesOptions$find.name
455
389
  }, spacesOptions.filter(space => space.disabled).map(space => {
456
390
  var _space$title;
457
-
458
391
  return /*#__PURE__*/_react.default.createElement("option", {
459
392
  key: space.name,
460
393
  value: space.name,
461
394
  disabled: space.disabled
462
- }, (_space$title = space.title) !== null && _space$title !== void 0 ? _space$title : space.name, hasMultipleProjectIds ? " (".concat(space.api.projectId, ")") : "");
395
+ }, (_space$title = space.title) !== null && _space$title !== void 0 ? _space$title : space.name, hasMultipleProjectIds || space.usingEnvForProjectId ? " (".concat(space.api.projectId, ")") : "");
463
396
  }))), /*#__PURE__*/_react.default.createElement(_ui.Box, {
464
397
  padding: 4,
465
398
  paddingTop: 5,
@@ -475,12 +408,11 @@ function DuplicatorTool(props) {
475
408
  onChange: handleChange
476
409
  }, spacesOptions.map(space => {
477
410
  var _space$title2;
478
-
479
411
  return /*#__PURE__*/_react.default.createElement("option", {
480
412
  key: space.name,
481
413
  value: space.name,
482
414
  disabled: space.disabled
483
- }, (_space$title2 = space.title) !== null && _space$title2 !== void 0 ? _space$title2 : space.name, hasMultipleProjectIds ? " (".concat(space.api.projectId, ")") : "", space.disabled ? " (Current)" : "");
415
+ }, (_space$title2 = space.title) !== null && _space$title2 !== void 0 ? _space$title2 : space.name, hasMultipleProjectIds || space.usingEnvForProjectId ? " (".concat(space.api.projectId, ")") : "", space.disabled ? " (Current)" : "");
484
416
  })))), isDuplicating && /*#__PURE__*/_react.default.createElement(_ui.Card, {
485
417
  border: true,
486
418
  radius: 2
@@ -512,9 +444,9 @@ function DuplicatorTool(props) {
512
444
  space: 3
513
445
  }, payload.map((_ref2, index) => {
514
446
  var doc = _ref2.doc,
515
- include = _ref2.include,
516
- status = _ref2.status,
517
- hasDraft = _ref2.hasDraft;
447
+ include = _ref2.include,
448
+ status = _ref2.status,
449
+ hasDraft = _ref2.hasDraft;
518
450
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, {
519
451
  key: doc._id
520
452
  }, /*#__PURE__*/_react.default.createElement(_ui.Flex, {
@@ -1 +1 @@
1
- {"version":3,"file":"DuplicatorTool.js","names":["DuplicatorTool","props","docs","draftIds","token","originClient","sanityClient","withConfig","clientConfig","spacesOptions","config","__experimental_spaces","length","map","space","disabled","api","dataset","projectId","useState","find","destination","setDestination","message","setMessage","item","doc","include","status","hasDraft","includes","_id","payload","setPayload","hasReferences","setHasReferences","isDuplicating","setIsDuplicating","isGathering","setIsGathering","progress","setProgress","useEffect","expr","initialRefs","initialPayload","forEach","push","extract","docCount","refsCount","tone","text","createInitialMessage","updatePayloadStatuses","newPayload","payloadActual","name","payloadIds","destinationClient","destinationData","fetch","updatedPayload","existingDoc","_updatedAt","Date","handleCheckbox","handleReferences","docIds","payloadDocs","getDocumentsInArray","draftDocs","id","draftDocsIds","Set","payloadShaped","has","handleDuplicate","assetsCount","filter","typeIsAsset","_type","currentProgress","transactionDocs","svgMaps","fetchDoc","uploadType","split","pop","replace","downloadUrl","url","downloadConfig","headers","Authorization","then","res","assetData","blob","options","filename","originalFilename","assetDoc","assets","upload","extension","old","new","result","Promise","resolve","reject","payloadIncludedDocs","mapLimit","asyncify","err","console","error","Error","transactionDocsMapped","references","extractWithPath","ref","newRefValue","asset","value","refPath","path","join","dset","transaction","createOrReplace","commit","catch","details","description","handleChange","e","currentTarget","payloadCount","firstSvgIndex","findIndex","selectedDocumentsCount","selectedAssetsCount","selectedTotal","destinationTitle","title","hasMultipleProjectIds","Boolean","size","headingText","buttonText","React","useMemo","stickyStyles","flex","width","transform","transformOrigin","transition","boxSizing","index","schema","get","SearchIcon","LaunchIcon"],"sources":["../../src/components/DuplicatorTool.tsx"],"sourcesContent":["/* eslint-disable react/jsx-no-bind */\nimport React, {useState, useEffect} from 'react'\nimport mapLimit from 'async/mapLimit'\nimport asyncify from 'async/asyncify'\nimport {extract, extractWithPath} from '@sanity/mutator'\nimport {dset} from 'dset'\nimport {\n Card,\n Container,\n Text,\n Box,\n Button,\n Label,\n Stack,\n Select,\n Flex,\n Checkbox,\n} from '@sanity/ui'\nimport {ArrowRightIcon, SearchIcon, LaunchIcon} from '@sanity/icons'\nimport sanityClient from 'part:@sanity/base/client'\nimport Preview from 'part:@sanity/base/preview'\nimport schema from 'part:@sanity/base/schema'\nimport config from 'config:sanity'\n\nimport {typeIsAsset, stickyStyles, createInitialMessage} from '../helpers'\nimport {getDocumentsInArray} from '../helpers/getDocumentsInArray'\nimport SelectButtons from './SelectButtons'\nimport StatusBadge from './StatusBadge'\nimport Feedback from './Feedback'\nimport {SanityDocument} from '../types'\nimport {clientConfig} from '../helpers/clientConfig'\n\ntype DuplicatorToolProps = {\n docs: SanityDocument[]\n draftIds: string[]\n token: string\n}\n\nexport default function DuplicatorTool(props: DuplicatorToolProps) {\n const {docs, draftIds, token} = props\n\n // Prepare origin (this Studio) client\n // In function-scope so it is up to date on every render\n const originClient = sanityClient.withConfig(clientConfig)\n\n // Create list of dataset options\n // and set initial value of dropdown\n const spacesOptions = config?.__experimental_spaces?.length\n ? config.__experimental_spaces.map((space) => ({\n ...space,\n disabled:\n space.api.dataset === originClient.config().dataset &&\n space.api.projectId === originClient.config().projectId,\n }))\n : []\n\n const [destination, setDestination] = useState(\n spacesOptions.length ? spacesOptions.find((space) => !space.disabled) : {}\n )\n const [message, setMessage] = useState({})\n const [payload, setPayload] = useState(\n docs.length\n ? docs.map((item) => ({\n doc: item,\n include: true,\n status: null,\n hasDraft: draftIds?.length ? draftIds.includes(`drafts.${item._id}`) : false,\n }))\n : []\n )\n const [hasReferences, setHasReferences] = useState(false)\n const [isDuplicating, setIsDuplicating] = useState(false)\n const [isGathering, setIsGathering] = useState(false)\n const [progress, setProgress] = useState([0, 0])\n\n // Check for References and update message\n useEffect(() => {\n const expr = `.._ref`\n const initialRefs = []\n const initialPayload = []\n\n docs.forEach((doc) => {\n initialRefs.push(...extract(expr, doc))\n initialPayload.push({include: true, doc})\n })\n\n setPayload(initialPayload)\n\n const docCount = docs.length\n const refsCount = initialRefs.length\n\n if (initialRefs.length) {\n setHasReferences(true)\n\n setMessage({\n tone: `caution`,\n text: createInitialMessage(docCount, refsCount),\n })\n }\n }, [docs])\n\n // Re-check payload on destination when value changes\n // (On initial render + select change)\n useEffect(() => {\n updatePayloadStatuses()\n }, [destination, docs])\n\n // Check if payload documents exist at destination\n async function updatePayloadStatuses(newPayload = []) {\n const payloadActual = newPayload.length ? newPayload : payload\n\n if (!payloadActual.length || !destination?.name) {\n return\n }\n\n const payloadIds = payloadActual.map(({doc}) => doc._id)\n const destinationClient = sanityClient.withConfig({\n ...clientConfig,\n dataset: destination.api.dataset,\n projectId: destination.api.projectId,\n })\n const destinationData = await destinationClient.fetch(\n `*[_id in $payloadIds]{ _id, _updatedAt }`,\n {payloadIds}\n )\n\n const updatedPayload = payloadActual.map((item) => {\n const existingDoc = destinationData.find((doc) => doc._id === item.doc._id)\n\n if (existingDoc?._updatedAt && item?.doc?._updatedAt) {\n if (existingDoc._updatedAt === item.doc._updatedAt) {\n // Exact same document exists at destination\n // We don't compare by _rev because that is updated in a transaction\n item.status = `EXISTS`\n } else if (existingDoc._updatedAt && item.doc._updatedAt) {\n item.status =\n new Date(existingDoc._updatedAt) > new Date(item.doc._updatedAt)\n ? // Document at destination is newer\n `OVERWRITE`\n : // Document at destination is older\n `UPDATE`\n }\n } else {\n item.status = 'CREATE'\n }\n\n return item\n })\n\n setPayload(updatedPayload)\n }\n\n function handleCheckbox(_id) {\n const updatedPayload = payload.map((item) => {\n if (item.doc._id === _id) {\n item.include = !item.include\n }\n\n return item\n })\n\n setPayload(updatedPayload)\n }\n\n // Find and recursively follow references beginning with this document\n async function handleReferences() {\n setIsGathering(true)\n const docIds = docs.map((doc) => doc._id)\n\n const payloadDocs = await getDocumentsInArray(docIds, originClient, null)\n const draftDocs = await getDocumentsInArray(\n docIds.map((id) => `drafts.${id}`),\n originClient,\n null,\n `{_id}`\n )\n const draftDocsIds = new Set(draftDocs.map(({_id}) => _id))\n\n // Shape it up\n const payloadShaped = payloadDocs.map((doc) => ({\n doc,\n // Include this in the transaction?\n include: true,\n // Does it exist at the destination?\n status: '',\n // Does it have any drafts?\n hasDraft: draftDocsIds.has(`drafts.${doc._id}`),\n }))\n\n setPayload(payloadShaped)\n updatePayloadStatuses(payloadShaped)\n setIsGathering(false)\n }\n\n // Duplicate payload to destination dataset\n async function handleDuplicate() {\n setIsDuplicating(true)\n\n const assetsCount = payload.filter(({doc, include}) => include && typeIsAsset(doc._type)).length\n let currentProgress = 0\n setProgress([currentProgress, assetsCount])\n\n setMessage({text: 'Duplicating...'})\n\n const destinationClient = sanityClient.withConfig({\n ...clientConfig,\n dataset: destination.api.dataset,\n projectId: destination.api.projectId,\n })\n\n const transactionDocs = []\n const svgMaps = []\n\n // Upload assets and then add to transaction\n async function fetchDoc(doc) {\n if (typeIsAsset(doc._type)) {\n // Download and upload asset\n // Get the *original* image with this dlRaw param to create the same determenistic _id\n const uploadType = doc._type.split('.').pop().replace('Asset', '')\n const downloadUrl = uploadType === 'image' ? `${doc.url}?dlRaw=true` : doc.url\n const downloadConfig =\n uploadType === 'image' ? {headers: {Authorization: `Bearer ${token}`}} : {}\n\n await fetch(downloadUrl, downloadConfig).then(async (res) => {\n const assetData = await res.blob()\n\n const options = {filename: doc.originalFilename}\n const assetDoc = await destinationClient.assets.upload(uploadType, assetData, options)\n\n // SVG _id's need remapping before transaction\n if (doc?.extension === 'svg') {\n svgMaps.push({old: doc._id, new: assetDoc._id})\n }\n\n transactionDocs.push(assetDoc)\n })\n\n currentProgress += 1\n setMessage({\n text: `Duplicating ${currentProgress}/${assetsCount} ${\n assetsCount === 1 ? `Assets` : `Assets`\n }`,\n })\n\n return setProgress([currentProgress, assetsCount])\n }\n\n return transactionDocs.push(doc)\n }\n\n // Promises are limited to three at once\n const result = new Promise((resolve, reject) => {\n const payloadIncludedDocs = payload.filter((item) => item.include).map((item) => item.doc)\n\n mapLimit(payloadIncludedDocs, 3, asyncify(fetchDoc), (err) => {\n if (err) {\n setIsDuplicating(false)\n setMessage({tone: 'critical', text: `Duplication Failed`})\n console.error(err)\n reject(new Error('Duplication Failed'))\n }\n\n resolve()\n })\n })\n\n await result\n\n // Remap SVG references to new _id's\n const transactionDocsMapped = transactionDocs.map((doc) => {\n const expr = `.._ref`\n const references = extractWithPath(expr, doc)\n\n if (!references.length) {\n return doc\n }\n\n // For every found _ref, search for an SVG asset _id and update\n references.forEach((ref) => {\n const newRefValue = svgMaps.find((asset) => asset.old === ref.value)?.new\n\n if (newRefValue) {\n const refPath = ref.path.join('.')\n\n dset(doc, refPath, newRefValue)\n }\n })\n\n return doc\n })\n\n // Create transaction\n const transaction = destinationClient.transaction()\n\n transactionDocsMapped.forEach((doc) => {\n transaction.createOrReplace(doc)\n })\n\n await transaction\n .commit()\n .then((res) => {\n setMessage({tone: 'positive', text: 'Duplication complete!'})\n\n updatePayloadStatuses()\n })\n .catch((err) => {\n setMessage({tone: 'critical', text: err.details.description})\n })\n\n setIsDuplicating(false)\n setProgress(0)\n }\n\n function handleChange(e) {\n setDestination(spacesOptions.find((space) => space.name === e.currentTarget.value))\n }\n\n if (!spacesOptions.length) {\n return (\n <Feedback tone=\"critical\">\n <code>__experimental_spaces</code> not found in <code>sanity.json</code>\n </Feedback>\n )\n }\n\n const payloadCount = payload.length\n const firstSvgIndex = payload.findIndex(({doc}) => doc.extension === 'svg')\n const selectedDocumentsCount = payload.filter(\n (item) => item.include && !typeIsAsset(item.doc._type)\n ).length\n const selectedAssetsCount = payload.filter(\n (item) => item.include && typeIsAsset(item.doc._type)\n ).length\n const selectedTotal = selectedDocumentsCount + selectedAssetsCount\n const destinationTitle = destination?.title ?? destination?.name\n const hasMultipleProjectIds =\n new Set(spacesOptions.map((space) => space?.api?.projectId).filter(Boolean)).size > 1\n\n const headingText = [selectedTotal, `/`, payloadCount, `Documents and Assets selected`].join(` `)\n\n const buttonText = React.useMemo(() => {\n const text = [`Duplicate`]\n\n if (selectedDocumentsCount > 1) {\n text.push(selectedDocumentsCount, selectedDocumentsCount === 1 ? `Document` : `Documents`)\n }\n\n if (selectedAssetsCount > 1) {\n text.push(`and`, selectedAssetsCount, selectedAssetsCount === 1 ? `Asset` : `Assets`)\n }\n\n if (originClient.config().projectId !== destination.api.projectId) {\n text.push(`between Projects`)\n }\n\n text.push(`to`, destinationTitle)\n\n return text.join(` `)\n }, [selectedDocumentsCount, selectedAssetsCount, destinationTitle])\n\n return (\n <Container width={1}>\n <Card>\n <Stack>\n <>\n <Card borderBottom padding={4} style={stickyStyles}>\n <Stack space={4}>\n <Flex space={3}>\n <Stack style={{flex: 1}} space={3}>\n <Label>Duplicate from</Label>\n <Select readOnly value={spacesOptions.find((space) => space.disabled)?.name}>\n {spacesOptions\n .filter((space) => space.disabled)\n .map((space) => (\n <option key={space.name} value={space.name} disabled={space.disabled}>\n {space.title ?? space.name}\n {hasMultipleProjectIds ? ` (${space.api.projectId})` : ``}\n </option>\n ))}\n </Select>\n </Stack>\n <Box padding={4} paddingTop={5} paddingBottom={0}>\n <Text size={3}>\n <ArrowRightIcon />\n </Text>\n </Box>\n <Stack style={{flex: 1}} space={3}>\n <Label>To Destination</Label>\n <Select onChange={handleChange}>\n {spacesOptions.map((space) => (\n <option key={space.name} value={space.name} disabled={space.disabled}>\n {space.title ?? space.name}\n {hasMultipleProjectIds ? ` (${space.api.projectId})` : ``}\n {space.disabled ? ` (Current)` : ``}\n </option>\n ))}\n </Select>\n </Stack>\n </Flex>\n\n {isDuplicating && (\n <Card border radius={2}>\n <Card\n style={{\n width: '100%',\n transform: `scaleX(${progress[0] / progress[1]})`,\n transformOrigin: 'left',\n transition: 'transform .2s ease',\n boxSizing: 'border-box',\n }}\n padding={1}\n tone=\"positive\"\n />\n </Card>\n )}\n {payload.length > 0 && (\n <>\n <Label>{headingText}</Label>\n <SelectButtons payload={payload} setPayload={setPayload} />\n </>\n )}\n </Stack>\n </Card>\n {message?.text && (\n <Box paddingX={4} paddingTop={4}>\n <Card padding={3} radius={2} shadow={1} tone={message?.tone ?? 'transparent'}>\n <Text size={1}>{message.text}</Text>\n </Card>\n </Box>\n )}\n {payload.length > 0 && (\n <Stack padding={4} space={3}>\n {payload.map(({doc, include, status, hasDraft}, index) => (\n <React.Fragment key={doc._id}>\n <Flex align=\"center\">\n <Checkbox checked={include} onChange={() => handleCheckbox(doc._id)} />\n <Box flex={1} paddingX={3}>\n <Preview value={doc} type={schema.get(doc._type)} />\n </Box>\n <Flex items=\"center\" gap={2}>\n {hasDraft ? <StatusBadge status=\"UNPUBLISHED\" isAsset={false} /> : null}\n <StatusBadge status={status} isAsset={typeIsAsset(doc._type)} />\n </Flex>\n </Flex>\n {doc?.extension === 'svg' && index === firstSvgIndex && (\n <Card padding={3} radius={2} shadow={1} tone=\"caution\">\n <Text size={1}>\n Due to how SVGs are sanitized after first uploaded, duplicated SVG assets\n may have new <code>_id</code>'s at the destination. The newly generated{' '}\n <code>_id</code> will be the same in each duplication, but it will never\n be the same <code>_id</code> as the first time this Asset was uploaded.\n References to the asset will be updated to use the new <code>_id</code>.\n </Text>\n </Card>\n )}\n </React.Fragment>\n ))}\n </Stack>\n )}\n <Stack space={2} padding={4} paddingTop={0}>\n {hasReferences && (\n <Button\n fontSize={2}\n padding={4}\n tone=\"positive\"\n mode=\"ghost\"\n icon={SearchIcon}\n onClick={handleReferences}\n text=\"Gather References\"\n disabled={isDuplicating || !selectedTotal || isGathering}\n />\n )}\n <Button\n fontSize={2}\n padding={4}\n tone=\"positive\"\n icon={LaunchIcon}\n onClick={handleDuplicate}\n text={buttonText}\n disabled={isDuplicating || !selectedTotal || isGathering}\n />\n </Stack>\n </>\n </Stack>\n </Card>\n </Container>\n )\n}\n"],"mappings":";;;;;;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAYA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQe,SAASA,cAAT,CAAwBC,KAAxB,EAAoD;EAAA;;EACjE,IAAOC,IAAP,GAAgCD,KAAhC,CAAOC,IAAP;EAAA,IAAaC,QAAb,GAAgCF,KAAhC,CAAaE,QAAb;EAAA,IAAuBC,KAAvB,GAAgCH,KAAhC,CAAuBG,KAAvB,CADiE,CAGjE;EACA;;EACA,IAAMC,YAAY,GAAGC,eAAA,CAAaC,UAAb,CAAwBC,0BAAxB,CAArB,CALiE,CAOjE;EACA;;;EACA,IAAMC,aAAa,GAAGC,qBAAA,aAAAA,qBAAA,wCAAAA,qBAAA,CAAQC,qBAAR,wEAA+BC,MAA/B,GAClBF,qBAAA,CAAOC,qBAAP,C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aAAlB,IAAmC1G;EAR/C,EAFJ,eAaE,6BAAC,UAAD;IACE,QAAQ,EAAE,CADZ;IAEE,OAAO,EAAE,CAFX;IAGE,IAAI,EAAC,UAHP;IAIE,IAAI,EAAE+H,iBAJR;IAKE,OAAO,EAAExF,eALX;IAME,IAAI,EAAE0E,UANR;IAOE,QAAQ,EAAEnH,aAAa,IAAI,CAAC4G,aAAlB,IAAmC1G;EAP/C,EAbF,CA/FF,CADF,CADF,CADF,CADF;AA+HD"}
1
+ {"version":3,"file":"DuplicatorTool.js","names":["DuplicatorTool","props","docs","draftIds","token","originClient","sanityClient","withConfig","clientConfig","spacesOptions","config","__experimental_spaces","length","map","space","api","projectId","process","env","SANITY_STUDIO_API_PROJECT_ID","usingEnvForProjectId","disabled","dataset","useState","find","destination","setDestination","message","setMessage","item","doc","include","status","hasDraft","includes","_id","payload","setPayload","hasReferences","setHasReferences","isDuplicating","setIsDuplicating","isGathering","setIsGathering","progress","setProgress","useEffect","expr","initialRefs","initialPayload","forEach","push","extract","docCount","refsCount","tone","text","createInitialMessage","updatePayloadStatuses","newPayload","payloadActual","name","payloadIds","destinationClient","destinationData","fetch","updatedPayload","existingDoc","_updatedAt","Date","handleCheckbox","handleReferences","docIds","payloadDocs","getDocumentsInArray","draftDocs","id","draftDocsIds","Set","payloadShaped","has","handleDuplicate","assetsCount","filter","typeIsAsset","_type","currentProgress","transactionDocs","svgMaps","fetchDoc","uploadType","split","pop","replace","downloadUrl","url","downloadConfig","headers","Authorization","then","res","assetData","blob","options","filename","originalFilename","assetDoc","assets","upload","extension","old","new","result","Promise","resolve","reject","payloadIncludedDocs","mapLimit","asyncify","err","console","error","Error","transactionDocsMapped","references","extractWithPath","ref","newRefValue","asset","value","refPath","path","join","dset","transaction","createOrReplace","commit","catch","details","description","handleChange","e","currentTarget","payloadCount","firstSvgIndex","findIndex","selectedDocumentsCount","selectedAssetsCount","selectedTotal","destinationTitle","title","hasMultipleProjectIds","Boolean","size","headingText","buttonText","React","useMemo","stickyStyles","flex","width","transform","transformOrigin","transition","boxSizing","index","schema","get","SearchIcon","LaunchIcon"],"sources":["../../src/components/DuplicatorTool.tsx"],"sourcesContent":["/* eslint-disable react/jsx-no-bind */\nimport React, {useState, useEffect} from 'react'\nimport mapLimit from 'async/mapLimit'\nimport asyncify from 'async/asyncify'\nimport {extract, extractWithPath} from '@sanity/mutator'\nimport {dset} from 'dset'\nimport {\n Card,\n Container,\n Text,\n Box,\n Button,\n Label,\n Stack,\n Select,\n Flex,\n Checkbox,\n} from '@sanity/ui'\nimport {ArrowRightIcon, SearchIcon, LaunchIcon} from '@sanity/icons'\nimport sanityClient from 'part:@sanity/base/client'\nimport Preview from 'part:@sanity/base/preview'\nimport schema from 'part:@sanity/base/schema'\nimport config from 'config:sanity'\n\nimport {typeIsAsset, stickyStyles, createInitialMessage} from '../helpers'\nimport {getDocumentsInArray} from '../helpers/getDocumentsInArray'\nimport SelectButtons from './SelectButtons'\nimport StatusBadge from './StatusBadge'\nimport Feedback from './Feedback'\nimport {SanityDocument} from '../types'\nimport {clientConfig} from '../helpers/clientConfig'\n\ntype DuplicatorToolProps = {\n docs: SanityDocument[]\n draftIds: string[]\n token: string\n}\n\nexport default function DuplicatorTool(props: DuplicatorToolProps) {\n const {docs, draftIds, token} = props\n\n // Prepare origin (this Studio) client\n // In function-scope so it is up to date on every render\n const originClient = sanityClient.withConfig(clientConfig)\n\n // Create list of dataset options\n // and set initial value of dropdown\n const spacesOptions = config?.__experimental_spaces?.length\n ? config.__experimental_spaces.map((space) => ({\n ...space,\n api: {\n ...space.api,\n projectId: space.api.projectId || process.env.SANITY_STUDIO_API_PROJECT_ID,\n },\n usingEnvForProjectId: !space.api.projectId && process.env.SANITY_STUDIO_API_PROJECT_ID,\n disabled:\n space.api.dataset === originClient.config().dataset &&\n space.api.projectId === originClient.config().projectId,\n }))\n : []\n\n const [destination, setDestination] = useState(\n spacesOptions.length ? spacesOptions.find((space) => !space.disabled) : {}\n )\n const [message, setMessage] = useState({})\n const [payload, setPayload] = useState(\n docs.length\n ? docs.map((item) => ({\n doc: item,\n include: true,\n status: null,\n hasDraft: draftIds?.length ? draftIds.includes(`drafts.${item._id}`) : false,\n }))\n : []\n )\n const [hasReferences, setHasReferences] = useState(false)\n const [isDuplicating, setIsDuplicating] = useState(false)\n const [isGathering, setIsGathering] = useState(false)\n const [progress, setProgress] = useState([0, 0])\n\n // Check for References and update message\n useEffect(() => {\n const expr = `.._ref`\n const initialRefs = []\n const initialPayload = []\n\n docs.forEach((doc) => {\n initialRefs.push(...extract(expr, doc))\n initialPayload.push({include: true, doc})\n })\n\n setPayload(initialPayload)\n\n const docCount = docs.length\n const refsCount = initialRefs.length\n\n if (initialRefs.length) {\n setHasReferences(true)\n\n setMessage({\n tone: `caution`,\n text: createInitialMessage(docCount, refsCount),\n })\n }\n }, [docs])\n\n // Re-check payload on destination when value changes\n // (On initial render + select change)\n useEffect(() => {\n updatePayloadStatuses()\n }, [destination, docs])\n\n // Check if payload documents exist at destination\n async function updatePayloadStatuses(newPayload = []) {\n const payloadActual = newPayload.length ? newPayload : payload\n\n if (!payloadActual.length || !destination?.name) {\n return\n }\n\n const payloadIds = payloadActual.map(({doc}) => doc._id)\n const destinationClient = sanityClient.withConfig({\n ...clientConfig,\n dataset: destination.api.dataset,\n projectId: destination.api.projectId,\n })\n const destinationData = await destinationClient.fetch(\n `*[_id in $payloadIds]{ _id, _updatedAt }`,\n {payloadIds}\n )\n\n const updatedPayload = payloadActual.map((item) => {\n const existingDoc = destinationData.find((doc) => doc._id === item.doc._id)\n\n if (existingDoc?._updatedAt && item?.doc?._updatedAt) {\n if (existingDoc._updatedAt === item.doc._updatedAt) {\n // Exact same document exists at destination\n // We don't compare by _rev because that is updated in a transaction\n item.status = `EXISTS`\n } else if (existingDoc._updatedAt && item.doc._updatedAt) {\n item.status =\n new Date(existingDoc._updatedAt) > new Date(item.doc._updatedAt)\n ? // Document at destination is newer\n `OVERWRITE`\n : // Document at destination is older\n `UPDATE`\n }\n } else {\n item.status = 'CREATE'\n }\n\n return item\n })\n\n setPayload(updatedPayload)\n }\n\n function handleCheckbox(_id) {\n const updatedPayload = payload.map((item) => {\n if (item.doc._id === _id) {\n item.include = !item.include\n }\n\n return item\n })\n\n setPayload(updatedPayload)\n }\n\n // Find and recursively follow references beginning with this document\n async function handleReferences() {\n setIsGathering(true)\n const docIds = docs.map((doc) => doc._id)\n\n const payloadDocs = await getDocumentsInArray(docIds, originClient, null)\n const draftDocs = await getDocumentsInArray(\n docIds.map((id) => `drafts.${id}`),\n originClient,\n null,\n `{_id}`\n )\n const draftDocsIds = new Set(draftDocs.map(({_id}) => _id))\n\n // Shape it up\n const payloadShaped = payloadDocs.map((doc) => ({\n doc,\n // Include this in the transaction?\n include: true,\n // Does it exist at the destination?\n status: '',\n // Does it have any drafts?\n hasDraft: draftDocsIds.has(`drafts.${doc._id}`),\n }))\n\n setPayload(payloadShaped)\n updatePayloadStatuses(payloadShaped)\n setIsGathering(false)\n }\n\n // Duplicate payload to destination dataset\n async function handleDuplicate() {\n setIsDuplicating(true)\n\n const assetsCount = payload.filter(({doc, include}) => include && typeIsAsset(doc._type)).length\n let currentProgress = 0\n setProgress([currentProgress, assetsCount])\n\n setMessage({text: 'Duplicating...'})\n\n const destinationClient = sanityClient.withConfig({\n ...clientConfig,\n dataset: destination.api.dataset,\n projectId: destination.api.projectId,\n })\n\n const transactionDocs = []\n const svgMaps = []\n\n // Upload assets and then add to transaction\n async function fetchDoc(doc) {\n if (typeIsAsset(doc._type)) {\n // Download and upload asset\n // Get the *original* image with this dlRaw param to create the same determenistic _id\n const uploadType = doc._type.split('.').pop().replace('Asset', '')\n const downloadUrl = uploadType === 'image' ? `${doc.url}?dlRaw=true` : doc.url\n const downloadConfig =\n uploadType === 'image' ? {headers: {Authorization: `Bearer ${token}`}} : {}\n\n await fetch(downloadUrl, downloadConfig).then(async (res) => {\n const assetData = await res.blob()\n\n const options = {filename: doc.originalFilename}\n const assetDoc = await destinationClient.assets.upload(uploadType, assetData, options)\n\n // SVG _id's need remapping before transaction\n if (doc?.extension === 'svg') {\n svgMaps.push({old: doc._id, new: assetDoc._id})\n }\n\n transactionDocs.push(assetDoc)\n })\n\n currentProgress += 1\n setMessage({\n text: `Duplicating ${currentProgress}/${assetsCount} ${\n assetsCount === 1 ? `Assets` : `Assets`\n }`,\n })\n\n return setProgress([currentProgress, assetsCount])\n }\n\n return transactionDocs.push(doc)\n }\n\n // Promises are limited to three at once\n const result = new Promise((resolve, reject) => {\n const payloadIncludedDocs = payload.filter((item) => item.include).map((item) => item.doc)\n\n mapLimit(payloadIncludedDocs, 3, asyncify(fetchDoc), (err) => {\n if (err) {\n setIsDuplicating(false)\n setMessage({tone: 'critical', text: `Duplication Failed`})\n console.error(err)\n reject(new Error('Duplication Failed'))\n }\n\n resolve()\n })\n })\n\n await result\n\n // Remap SVG references to new _id's\n const transactionDocsMapped = transactionDocs.map((doc) => {\n const expr = `.._ref`\n const references = extractWithPath(expr, doc)\n\n if (!references.length) {\n return doc\n }\n\n // For every found _ref, search for an SVG asset _id and update\n references.forEach((ref) => {\n const newRefValue = svgMaps.find((asset) => asset.old === ref.value)?.new\n\n if (newRefValue) {\n const refPath = ref.path.join('.')\n\n dset(doc, refPath, newRefValue)\n }\n })\n\n return doc\n })\n\n // Create transaction\n const transaction = destinationClient.transaction()\n\n transactionDocsMapped.forEach((doc) => {\n transaction.createOrReplace(doc)\n })\n\n await transaction\n .commit()\n .then((res) => {\n setMessage({tone: 'positive', text: 'Duplication complete!'})\n\n updatePayloadStatuses()\n })\n .catch((err) => {\n setMessage({tone: 'critical', text: err.details.description})\n })\n\n setIsDuplicating(false)\n setProgress(0)\n }\n\n function handleChange(e) {\n setDestination(spacesOptions.find((space) => space.name === e.currentTarget.value))\n }\n\n if (!spacesOptions.length) {\n return (\n <Feedback tone=\"critical\">\n <code>__experimental_spaces</code> not found in <code>sanity.json</code>\n </Feedback>\n )\n }\n\n const payloadCount = payload.length\n const firstSvgIndex = payload.findIndex(({doc}) => doc.extension === 'svg')\n const selectedDocumentsCount = payload.filter(\n (item) => item.include && !typeIsAsset(item.doc._type)\n ).length\n const selectedAssetsCount = payload.filter(\n (item) => item.include && typeIsAsset(item.doc._type)\n ).length\n const selectedTotal = selectedDocumentsCount + selectedAssetsCount\n const destinationTitle = destination?.title ?? destination?.name\n const hasMultipleProjectIds =\n new Set(spacesOptions.map((space) => space?.api?.projectId).filter(Boolean)).size > 1\n\n const headingText = [selectedTotal, `/`, payloadCount, `Documents and Assets selected`].join(` `)\n\n const buttonText = React.useMemo(() => {\n const text = [`Duplicate`]\n\n if (selectedDocumentsCount > 1) {\n text.push(selectedDocumentsCount, selectedDocumentsCount === 1 ? `Document` : `Documents`)\n }\n\n if (selectedAssetsCount > 1) {\n text.push(`and`, selectedAssetsCount, selectedAssetsCount === 1 ? `Asset` : `Assets`)\n }\n\n if (originClient.config().projectId !== destination.api.projectId) {\n text.push(`between Projects`)\n }\n\n text.push(`to`, destinationTitle)\n\n return text.join(` `)\n }, [selectedDocumentsCount, selectedAssetsCount, destinationTitle])\n\n return (\n <Container width={1}>\n <Card>\n <Stack>\n <>\n <Card borderBottom padding={4} style={stickyStyles}>\n <Stack space={4}>\n <Flex space={3}>\n <Stack style={{flex: 1}} space={3}>\n <Label>Duplicate from</Label>\n <Select readOnly value={spacesOptions.find((space) => space.disabled)?.name}>\n {spacesOptions\n .filter((space) => space.disabled)\n .map((space) => (\n <option key={space.name} value={space.name} disabled={space.disabled}>\n {space.title ?? space.name}\n {hasMultipleProjectIds || space.usingEnvForProjectId ? ` (${space.api.projectId})` : ``}\n </option>\n ))}\n </Select>\n </Stack>\n <Box padding={4} paddingTop={5} paddingBottom={0}>\n <Text size={3}>\n <ArrowRightIcon />\n </Text>\n </Box>\n <Stack style={{flex: 1}} space={3}>\n <Label>To Destination</Label>\n <Select onChange={handleChange}>\n {spacesOptions.map((space) => (\n <option key={space.name} value={space.name} disabled={space.disabled}>\n {space.title ?? space.name}\n {hasMultipleProjectIds || space.usingEnvForProjectId ? ` (${space.api.projectId})` : ``}\n {space.disabled ? ` (Current)` : ``}\n </option>\n ))}\n </Select>\n </Stack>\n </Flex>\n\n {isDuplicating && (\n <Card border radius={2}>\n <Card\n style={{\n width: '100%',\n transform: `scaleX(${progress[0] / progress[1]})`,\n transformOrigin: 'left',\n transition: 'transform .2s ease',\n boxSizing: 'border-box',\n }}\n padding={1}\n tone=\"positive\"\n />\n </Card>\n )}\n {payload.length > 0 && (\n <>\n <Label>{headingText}</Label>\n <SelectButtons payload={payload} setPayload={setPayload} />\n </>\n )}\n </Stack>\n </Card>\n {message?.text && (\n <Box paddingX={4} paddingTop={4}>\n <Card padding={3} radius={2} shadow={1} tone={message?.tone ?? 'transparent'}>\n <Text size={1}>{message.text}</Text>\n </Card>\n </Box>\n )}\n {payload.length > 0 && (\n <Stack padding={4} space={3}>\n {payload.map(({doc, include, status, hasDraft}, index) => (\n <React.Fragment key={doc._id}>\n <Flex align=\"center\">\n <Checkbox checked={include} onChange={() => handleCheckbox(doc._id)} />\n <Box flex={1} paddingX={3}>\n <Preview value={doc} type={schema.get(doc._type)} />\n </Box>\n <Flex items=\"center\" gap={2}>\n {hasDraft ? <StatusBadge status=\"UNPUBLISHED\" isAsset={false} /> : null}\n <StatusBadge status={status} isAsset={typeIsAsset(doc._type)} />\n </Flex>\n </Flex>\n {doc?.extension === 'svg' && index === firstSvgIndex && (\n <Card padding={3} radius={2} shadow={1} tone=\"caution\">\n <Text size={1}>\n Due to how SVGs are sanitized after first uploaded, duplicated SVG assets\n may have new <code>_id</code>'s at the destination. The newly generated{' '}\n <code>_id</code> will be the same in each duplication, but it will never\n be the same <code>_id</code> as the first time this Asset was uploaded.\n References to the asset will be updated to use the new <code>_id</code>.\n </Text>\n </Card>\n )}\n </React.Fragment>\n ))}\n </Stack>\n )}\n <Stack space={2} padding={4} paddingTop={0}>\n {hasReferences && (\n <Button\n fontSize={2}\n padding={4}\n tone=\"positive\"\n mode=\"ghost\"\n icon={SearchIcon}\n onClick={handleReferences}\n text=\"Gather References\"\n disabled={isDuplicating || !selectedTotal || isGathering}\n />\n )}\n <Button\n fontSize={2}\n padding={4}\n tone=\"positive\"\n icon={LaunchIcon}\n onClick={handleDuplicate}\n text={buttonText}\n disabled={isDuplicating || !selectedTotal || isGathering}\n />\n </Stack>\n </>\n </Stack>\n </Card>\n </Container>\n )\n}\n"],"mappings":";;;;;;AACA;AACA;AACA;AACA;AACA;AACA;AAYA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AAEA;AAAoD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQrC,SAASA,cAAc,CAACC,KAA0B,EAAE;EAAA;EACjE,IAAOC,IAAI,GAAqBD,KAAK,CAA9BC,IAAI;IAAEC,QAAQ,GAAWF,KAAK,CAAxBE,QAAQ;IAAEC,KAAK,GAAIH,KAAK,CAAdG,KAAK;;EAE5B;EACA;EACA,IAAMC,YAAY,GAAGC,eAAY,CAACC,UAAU,CAACC,0BAAY,CAAC;;EAE1D;EACA;EACA,IAAMC,aAAa,GAAGC,qBAAM,aAANA,qBAAM,wCAANA,qBAAM,CAAEC,qBAAqB,kDAA7B,sBAA+BC,MAAM,GACvDF,qBAAM,CAACC,qBAAqB,CAACE,GAAG,CAAEC,KAAK,oCAClCA,KAAK;IACRC,GAAG,kCACED,KAAK,CAACC,GAAG;MACZC,SAAS,EAAEF,KAAK,CAACC,GAAG,CAACC,SAAS,IAAIC,OAAO,CAACC,GAAG,CAACC;IAA4B,EAC3E;IACDC,oBAAoB,EAAE,CAACN,KAAK,CAACC,GAAG,CAACC,SAAS,IAAIC,OAAO,CAACC,GAAG,CAACC,4BAA4B;IACtFE,QAAQ,EACNP,KAAK,CAACC,GAAG,CAACO,OAAO,KAAKjB,YAAY,CAACK,MAAM,EAAE,CAACY,OAAO,IACnDR,KAAK,CAACC,GAAG,CAACC,SAAS,KAAKX,YAAY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