@sanity/cross-dataset-duplicator 0.3.5 → 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,81 +4,49 @@ 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), {}, {
83
51
  api: _objectSpread(_objectSpread({}, space.api), {}, {
84
52
  projectId: space.api.projectId || process.env.SANITY_STUDIO_API_PROJECT_ID
@@ -86,48 +54,41 @@ function DuplicatorTool(props) {
86
54
  usingEnvForProjectId: !space.api.projectId && process.env.SANITY_STUDIO_API_PROJECT_ID,
87
55
  disabled: space.api.dataset === originClient.config().dataset && space.api.projectId === originClient.config().projectId
88
56
  })) : [];
89
-
90
57
  var _useState = (0, _react.useState)(spacesOptions.length ? spacesOptions.find(space => !space.disabled) : {}),
91
- _useState2 = _slicedToArray(_useState, 2),
92
- destination = _useState2[0],
93
- setDestination = _useState2[1];
94
-
58
+ _useState2 = _slicedToArray(_useState, 2),
59
+ destination = _useState2[0],
60
+ setDestination = _useState2[1];
95
61
  var _useState3 = (0, _react.useState)({}),
96
- _useState4 = _slicedToArray(_useState3, 2),
97
- message = _useState4[0],
98
- setMessage = _useState4[1];
99
-
62
+ _useState4 = _slicedToArray(_useState3, 2),
63
+ message = _useState4[0],
64
+ setMessage = _useState4[1];
100
65
  var _useState5 = (0, _react.useState)(docs.length ? docs.map(item => ({
101
- doc: item,
102
- include: true,
103
- status: null,
104
- hasDraft: draftIds !== null && draftIds !== void 0 && draftIds.length ? draftIds.includes("drafts.".concat(item._id)) : false
105
- })) : []),
106
- _useState6 = _slicedToArray(_useState5, 2),
107
- payload = _useState6[0],
108
- setPayload = _useState6[1];
109
-
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];
110
74
  var _useState7 = (0, _react.useState)(false),
111
- _useState8 = _slicedToArray(_useState7, 2),
112
- hasReferences = _useState8[0],
113
- setHasReferences = _useState8[1];
114
-
75
+ _useState8 = _slicedToArray(_useState7, 2),
76
+ hasReferences = _useState8[0],
77
+ setHasReferences = _useState8[1];
115
78
  var _useState9 = (0, _react.useState)(false),
116
- _useState10 = _slicedToArray(_useState9, 2),
117
- isDuplicating = _useState10[0],
118
- setIsDuplicating = _useState10[1];
119
-
79
+ _useState10 = _slicedToArray(_useState9, 2),
80
+ isDuplicating = _useState10[0],
81
+ setIsDuplicating = _useState10[1];
120
82
  var _useState11 = (0, _react.useState)(false),
121
- _useState12 = _slicedToArray(_useState11, 2),
122
- isGathering = _useState12[0],
123
- setIsGathering = _useState12[1];
124
-
83
+ _useState12 = _slicedToArray(_useState11, 2),
84
+ isGathering = _useState12[0],
85
+ setIsGathering = _useState12[1];
125
86
  var _useState13 = (0, _react.useState)([0, 0]),
126
- _useState14 = _slicedToArray(_useState13, 2),
127
- progress = _useState14[0],
128
- setProgress = _useState14[1]; // Check for References and update message
129
-
87
+ _useState14 = _slicedToArray(_useState13, 2),
88
+ progress = _useState14[0],
89
+ setProgress = _useState14[1];
130
90
 
91
+ // Check for References and update message
131
92
  (0, _react.useEffect)(() => {
132
93
  var expr = ".._ref";
133
94
  var initialRefs = [];
@@ -142,7 +103,6 @@ function DuplicatorTool(props) {
142
103
  setPayload(initialPayload);
143
104
  var docCount = docs.length;
144
105
  var refsCount = initialRefs.length;
145
-
146
106
  if (initialRefs.length) {
147
107
  setHasReferences(true);
148
108
  setMessage({
@@ -150,44 +110,39 @@ function DuplicatorTool(props) {
150
110
  text: (0, _helpers.createInitialMessage)(docCount, refsCount)
151
111
  });
152
112
  }
153
- }, [docs]); // Re-check payload on destination when value changes
154
- // (On initial render + select change)
113
+ }, [docs]);
155
114
 
115
+ // Re-check payload on destination when value changes
116
+ // (On initial render + select change)
156
117
  (0, _react.useEffect)(() => {
157
118
  updatePayloadStatuses();
158
- }, [destination, docs]); // Check if payload documents exist at destination
119
+ }, [destination, docs]);
159
120
 
121
+ // Check if payload documents exist at destination
160
122
  function updatePayloadStatuses() {
161
123
  return _updatePayloadStatuses.apply(this, arguments);
162
124
  }
163
-
164
125
  function _updatePayloadStatuses() {
165
126
  _updatePayloadStatuses = _asyncToGenerator(function* () {
166
127
  var newPayload = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
167
128
  var payloadActual = newPayload.length ? newPayload : payload;
168
-
169
129
  if (!payloadActual.length || !(destination !== null && destination !== void 0 && destination.name)) {
170
130
  return;
171
131
  }
172
-
173
132
  var payloadIds = payloadActual.map(_ref3 => {
174
133
  var doc = _ref3.doc;
175
134
  return doc._id;
176
135
  });
177
-
178
136
  var destinationClient = _client.default.withConfig(_objectSpread(_objectSpread({}, _clientConfig.clientConfig), {}, {
179
137
  dataset: destination.api.dataset,
180
138
  projectId: destination.api.projectId
181
139
  }));
182
-
183
140
  var destinationData = yield destinationClient.fetch("*[_id in $payloadIds]{ _id, _updatedAt }", {
184
141
  payloadIds
185
142
  });
186
143
  var updatedPayload = payloadActual.map(item => {
187
144
  var _item$doc;
188
-
189
145
  var existingDoc = destinationData.find(doc => doc._id === item.doc._id);
190
-
191
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) {
192
147
  if (existingDoc._updatedAt === item.doc._updatedAt) {
193
148
  // Exact same document exists at destination
@@ -201,31 +156,26 @@ function DuplicatorTool(props) {
201
156
  } else {
202
157
  item.status = 'CREATE';
203
158
  }
204
-
205
159
  return item;
206
160
  });
207
161
  setPayload(updatedPayload);
208
162
  });
209
163
  return _updatePayloadStatuses.apply(this, arguments);
210
164
  }
211
-
212
165
  function handleCheckbox(_id) {
213
166
  var updatedPayload = payload.map(item => {
214
167
  if (item.doc._id === _id) {
215
168
  item.include = !item.include;
216
169
  }
217
-
218
170
  return item;
219
171
  });
220
172
  setPayload(updatedPayload);
221
- } // Find and recursively follow references beginning with this document
222
-
173
+ }
223
174
 
175
+ // Find and recursively follow references beginning with this document
224
176
  function handleReferences() {
225
177
  return _handleReferences.apply(this, arguments);
226
178
  } // Duplicate payload to destination dataset
227
-
228
-
229
179
  function _handleReferences() {
230
180
  _handleReferences = _asyncToGenerator(function* () {
231
181
  setIsGathering(true);
@@ -235,8 +185,9 @@ function DuplicatorTool(props) {
235
185
  var draftDocsIds = new Set(draftDocs.map(_ref4 => {
236
186
  var _id = _ref4._id;
237
187
  return _id;
238
- })); // Shape it up
188
+ }));
239
189
 
190
+ // Shape it up
240
191
  var payloadShaped = payloadDocs.map(doc => ({
241
192
  doc,
242
193
  // Include this in the transaction?
@@ -252,17 +203,15 @@ function DuplicatorTool(props) {
252
203
  });
253
204
  return _handleReferences.apply(this, arguments);
254
205
  }
255
-
256
206
  function handleDuplicate() {
257
207
  return _handleDuplicate.apply(this, arguments);
258
208
  }
259
-
260
209
  function _handleDuplicate() {
261
210
  _handleDuplicate = _asyncToGenerator(function* () {
262
211
  setIsDuplicating(true);
263
212
  var assetsCount = payload.filter(_ref5 => {
264
213
  var doc = _ref5.doc,
265
- include = _ref5.include;
214
+ include = _ref5.include;
266
215
  return include && (0, _helpers.typeIsAsset)(doc._type);
267
216
  }).length;
268
217
  var currentProgress = 0;
@@ -270,27 +219,23 @@ function DuplicatorTool(props) {
270
219
  setMessage({
271
220
  text: 'Duplicating...'
272
221
  });
273
-
274
222
  var destinationClient = _client.default.withConfig(_objectSpread(_objectSpread({}, _clientConfig.clientConfig), {}, {
275
223
  dataset: destination.api.dataset,
276
224
  projectId: destination.api.projectId
277
225
  }));
278
-
279
226
  var transactionDocs = [];
280
- var svgMaps = []; // Upload assets and then add to transaction
227
+ var svgMaps = [];
281
228
 
229
+ // Upload assets and then add to transaction
282
230
  function fetchDoc(_x) {
283
231
  return _fetchDoc.apply(this, arguments);
284
232
  } // Promises are limited to three at once
285
-
286
-
287
233
  function _fetchDoc() {
288
234
  _fetchDoc = _asyncToGenerator(function* (doc) {
289
235
  if ((0, _helpers.typeIsAsset)(doc._type)) {
290
236
  // Download and upload asset
291
237
  // Get the *original* image with this dlRaw param to create the same determenistic _id
292
238
  var uploadType = doc._type.split('.').pop().replace('Asset', '');
293
-
294
239
  var downloadUrl = uploadType === 'image' ? "".concat(doc.url, "?dlRaw=true") : doc.url;
295
240
  var downloadConfig = uploadType === 'image' ? {
296
241
  headers: {
@@ -303,18 +248,17 @@ function DuplicatorTool(props) {
303
248
  var options = {
304
249
  filename: doc.originalFilename
305
250
  };
306
- 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);
307
252
 
253
+ // SVG _id's need remapping before transaction
308
254
  if ((doc === null || doc === void 0 ? void 0 : doc.extension) === 'svg') {
309
255
  svgMaps.push({
310
256
  old: doc._id,
311
257
  new: assetDoc._id
312
258
  });
313
259
  }
314
-
315
260
  transactionDocs.push(assetDoc);
316
261
  });
317
-
318
262
  return function (_x2) {
319
263
  return _ref6.apply(this, arguments);
320
264
  };
@@ -325,12 +269,10 @@ function DuplicatorTool(props) {
325
269
  });
326
270
  return setProgress([currentProgress, assetsCount]);
327
271
  }
328
-
329
272
  return transactionDocs.push(doc);
330
273
  });
331
274
  return _fetchDoc.apply(this, arguments);
332
275
  }
333
-
334
276
  var result = new Promise((resolve, reject) => {
335
277
  var payloadIncludedDocs = payload.filter(item => item.include).map(item => item.doc);
336
278
  (0, _mapLimit.default)(payloadIncludedDocs, 3, (0, _asyncify.default)(fetchDoc), err => {
@@ -343,34 +285,32 @@ function DuplicatorTool(props) {
343
285
  console.error(err);
344
286
  reject(new Error('Duplication Failed'));
345
287
  }
346
-
347
288
  resolve();
348
289
  });
349
290
  });
350
- yield result; // Remap SVG references to new _id's
291
+ yield result;
351
292
 
293
+ // Remap SVG references to new _id's
352
294
  var transactionDocsMapped = transactionDocs.map(doc => {
353
295
  var expr = ".._ref";
354
296
  var references = (0, _mutator.extractWithPath)(expr, doc);
355
-
356
297
  if (!references.length) {
357
298
  return doc;
358
- } // For every found _ref, search for an SVG asset _id and update
359
-
299
+ }
360
300
 
301
+ // For every found _ref, search for an SVG asset _id and update
361
302
  references.forEach(ref => {
362
303
  var _svgMaps$find;
363
-
364
304
  var newRefValue = (_svgMaps$find = svgMaps.find(asset => asset.old === ref.value)) === null || _svgMaps$find === void 0 ? void 0 : _svgMaps$find.new;
365
-
366
305
  if (newRefValue) {
367
306
  var refPath = ref.path.join('.');
368
307
  (0, _dset.dset)(doc, refPath, newRefValue);
369
308
  }
370
309
  });
371
310
  return doc;
372
- }); // Create transaction
311
+ });
373
312
 
313
+ // Create transaction
374
314
  var transaction = destinationClient.transaction();
375
315
  transactionDocsMapped.forEach(doc => {
376
316
  transaction.createOrReplace(doc);
@@ -392,17 +332,14 @@ function DuplicatorTool(props) {
392
332
  });
393
333
  return _handleDuplicate.apply(this, arguments);
394
334
  }
395
-
396
335
  function handleChange(e) {
397
336
  setDestination(spacesOptions.find(space => space.name === e.currentTarget.value));
398
337
  }
399
-
400
338
  if (!spacesOptions.length) {
401
339
  return /*#__PURE__*/_react.default.createElement(_Feedback.default, {
402
340
  tone: "critical"
403
341
  }, /*#__PURE__*/_react.default.createElement("code", null, "__experimental_spaces"), " not found in ", /*#__PURE__*/_react.default.createElement("code", null, "sanity.json"));
404
342
  }
405
-
406
343
  var payloadCount = payload.length;
407
344
  var firstSvgIndex = payload.findIndex(_ref => {
408
345
  var doc = _ref.doc;
@@ -414,30 +351,23 @@ function DuplicatorTool(props) {
414
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;
415
352
  var hasMultipleProjectIds = new Set(spacesOptions.map(space => {
416
353
  var _space$api;
417
-
418
354
  return space === null || space === void 0 ? void 0 : (_space$api = space.api) === null || _space$api === void 0 ? void 0 : _space$api.projectId;
419
355
  }).filter(Boolean)).size > 1;
420
356
  var headingText = [selectedTotal, "/", payloadCount, "Documents and Assets selected"].join(" ");
421
-
422
357
  var buttonText = _react.default.useMemo(() => {
423
358
  var text = ["Duplicate"];
424
-
425
359
  if (selectedDocumentsCount > 1) {
426
360
  text.push(selectedDocumentsCount, selectedDocumentsCount === 1 ? "Document" : "Documents");
427
361
  }
428
-
429
362
  if (selectedAssetsCount > 1) {
430
363
  text.push("and", selectedAssetsCount, selectedAssetsCount === 1 ? "Asset" : "Assets");
431
364
  }
432
-
433
365
  if (originClient.config().projectId !== destination.api.projectId) {
434
366
  text.push("between Projects");
435
367
  }
436
-
437
368
  text.push("to", destinationTitle);
438
369
  return text.join(" ");
439
370
  }, [selectedDocumentsCount, selectedAssetsCount, destinationTitle]);
440
-
441
371
  return /*#__PURE__*/_react.default.createElement(_ui.Container, {
442
372
  width: 1
443
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, {
@@ -458,7 +388,6 @@ function DuplicatorTool(props) {
458
388
  value: (_spacesOptions$find = spacesOptions.find(space => space.disabled)) === null || _spacesOptions$find === void 0 ? void 0 : _spacesOptions$find.name
459
389
  }, spacesOptions.filter(space => space.disabled).map(space => {
460
390
  var _space$title;
461
-
462
391
  return /*#__PURE__*/_react.default.createElement("option", {
463
392
  key: space.name,
464
393
  value: space.name,
@@ -479,7 +408,6 @@ function DuplicatorTool(props) {
479
408
  onChange: handleChange
480
409
  }, spacesOptions.map(space => {
481
410
  var _space$title2;
482
-
483
411
  return /*#__PURE__*/_react.default.createElement("option", {
484
412
  key: space.name,
485
413
  value: space.name,
@@ -516,9 +444,9 @@ function DuplicatorTool(props) {
516
444
  space: 3
517
445
  }, payload.map((_ref2, index) => {
518
446
  var doc = _ref2.doc,
519
- include = _ref2.include,
520
- status = _ref2.status,
521
- hasDraft = _ref2.hasDraft;
447
+ include = _ref2.include,
448
+ status = _ref2.status,
449
+ hasDraft = _ref2.hasDraft;
522
450
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, {
523
451
  key: doc._id
524
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","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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,CAA6BE,GAA7B,CAAkCC,KAAD,oCAC5BA,KAD4B;IAE/BC,GAAG,kCACED,KAAK,CAACC,GADR;MAEDC,SAAS,EAAEF,KAAK,CAACC,GAAN,CAAUC,SAAV,IAAuBC,OAAO,CAACC,GAAR,CAAYC;IAF7C,EAF4B;IAM/BC,oBAAoB,EAAE,CAACN,KAAK,CAACC,GAAN,CAAUC,SAAX,IAAwBC,OAAO,CAACC,GAAR,CAAYC,4BAN3B;IAO/BE,QAAQ,EACNP,KAAK,CAACC,GAAN,CAAUO,OAAV,KAAsBjB,YAAY,CAACK,MAAb,GAAsBY,OAA5C,IACAR,KAAK,CAACC,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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,CAACK,MAAM,EAAE,CAACM;EAAS,EACzD,CAAC,GACH,EAAE;EAEN,gBAAsC,IAAAO,eAAQ,EAC5Cd,aAAa,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