@sanity/cross-dataset-duplicator 1.2.3 → 1.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/dist/index.esm.js +160 -157
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +159 -156
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Duplicator.tsx +126 -116
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
Checkbox,
|
|
28
28
|
CardTone,
|
|
29
29
|
useTheme,
|
|
30
|
+
Spinner,
|
|
30
31
|
} from '@sanity/ui'
|
|
31
32
|
import {ArrowRightIcon, SearchIcon, LaunchIcon} from '@sanity/icons'
|
|
32
33
|
import {SanityAssetDocument} from '@sanity/client'
|
|
@@ -229,7 +230,7 @@ export default function Duplicator(props: DuplicatorProps) {
|
|
|
229
230
|
let currentProgress = 0
|
|
230
231
|
setProgress([currentProgress, assetsCount])
|
|
231
232
|
|
|
232
|
-
setMessage({text: 'Duplicating...', tone: `
|
|
233
|
+
setMessage({text: 'Duplicating...', tone: `transparent`})
|
|
233
234
|
|
|
234
235
|
const destinationClient = originClient.withConfig({
|
|
235
236
|
...clientConfig,
|
|
@@ -264,7 +265,15 @@ export default function Duplicator(props: DuplicatorProps) {
|
|
|
264
265
|
svgMaps.push({old: doc._id, new: assetDoc._id})
|
|
265
266
|
}
|
|
266
267
|
|
|
268
|
+
// This adds the newly created asset document to the transaction but ...
|
|
269
|
+
// it doesn't have some of the original asset's metadata like `altText` or `title`
|
|
267
270
|
transactionDocs.push(assetDoc)
|
|
271
|
+
|
|
272
|
+
// So the original `doc` is added to the transaction as well below
|
|
273
|
+
// However, we don't want to retain `url` or `path` keys
|
|
274
|
+
// because these strings contain the origin's dataset name
|
|
275
|
+
doc.url = assetDoc.url
|
|
276
|
+
doc.path = assetDoc.path
|
|
268
277
|
})
|
|
269
278
|
|
|
270
279
|
currentProgress += 1
|
|
@@ -420,137 +429,138 @@ export default function Duplicator(props: DuplicatorProps) {
|
|
|
420
429
|
<Container width={1}>
|
|
421
430
|
<Card border>
|
|
422
431
|
<Stack>
|
|
423
|
-
|
|
424
|
-
<
|
|
425
|
-
<
|
|
426
|
-
<
|
|
427
|
-
<
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
>
|
|
433
|
-
{workspacesOptions
|
|
434
|
-
.filter((space) => space.disabled)
|
|
435
|
-
.map((space) => (
|
|
436
|
-
<option key={space.name} value={space.name} disabled={space.disabled}>
|
|
437
|
-
{space.title ?? space.name}
|
|
438
|
-
{hasMultipleProjectIds ? ` (${space.projectId})` : ``}
|
|
439
|
-
</option>
|
|
440
|
-
))}
|
|
441
|
-
</Select>
|
|
442
|
-
</Stack>
|
|
443
|
-
<Box padding={4} paddingTop={5} paddingBottom={0}>
|
|
444
|
-
<Text size={3}>
|
|
445
|
-
<ArrowRightIcon />
|
|
446
|
-
</Text>
|
|
447
|
-
</Box>
|
|
448
|
-
<Stack style={{flex: 1}} space={3}>
|
|
449
|
-
<Label>To Destination</Label>
|
|
450
|
-
<Select onChange={handleChange}>
|
|
451
|
-
{workspacesOptions.map((space) => (
|
|
432
|
+
<Card padding={4} style={stickyStyles(isDarkMode)}>
|
|
433
|
+
<Stack space={4}>
|
|
434
|
+
<Flex gap={3}>
|
|
435
|
+
<Stack style={{flex: 1}} space={3}>
|
|
436
|
+
<Label>Duplicate from</Label>
|
|
437
|
+
<Select readOnly value={workspacesOptions.find((space) => space.disabled)?.name}>
|
|
438
|
+
{workspacesOptions
|
|
439
|
+
.filter((space) => space.disabled)
|
|
440
|
+
.map((space) => (
|
|
452
441
|
<option key={space.name} value={space.name} disabled={space.disabled}>
|
|
453
442
|
{space.title ?? space.name}
|
|
454
443
|
{hasMultipleProjectIds ? ` (${space.projectId})` : ``}
|
|
455
|
-
{space.disabled ? ` (Current)` : ``}
|
|
456
444
|
</option>
|
|
457
445
|
))}
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
</
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
446
|
+
</Select>
|
|
447
|
+
</Stack>
|
|
448
|
+
<Box padding={4} paddingTop={5} paddingBottom={0}>
|
|
449
|
+
<Text size={3}>
|
|
450
|
+
<ArrowRightIcon />
|
|
451
|
+
</Text>
|
|
452
|
+
</Box>
|
|
453
|
+
<Stack style={{flex: 1}} space={3}>
|
|
454
|
+
<Label>To Destination</Label>
|
|
455
|
+
<Select onChange={handleChange}>
|
|
456
|
+
{workspacesOptions.map((space) => (
|
|
457
|
+
<option key={space.name} value={space.name} disabled={space.disabled}>
|
|
458
|
+
{space.title ?? space.name}
|
|
459
|
+
{hasMultipleProjectIds ? ` (${space.projectId})` : ``}
|
|
460
|
+
{space.disabled ? ` (Current)` : ``}
|
|
461
|
+
</option>
|
|
462
|
+
))}
|
|
463
|
+
</Select>
|
|
464
|
+
</Stack>
|
|
465
|
+
</Flex>
|
|
466
|
+
|
|
467
|
+
{isDuplicating && (
|
|
468
|
+
<Card border radius={2}>
|
|
469
|
+
<Card
|
|
470
|
+
style={{
|
|
471
|
+
width: '100%',
|
|
472
|
+
transform: `scaleX(${progress[0] / progress[1]})`,
|
|
473
|
+
transformOrigin: 'left',
|
|
474
|
+
transition: 'transform .2s ease',
|
|
475
|
+
boxSizing: 'border-box',
|
|
476
|
+
}}
|
|
477
|
+
padding={1}
|
|
478
|
+
tone="positive"
|
|
479
|
+
/>
|
|
480
|
+
</Card>
|
|
481
|
+
)}
|
|
482
|
+
{payload.length > 0 && (
|
|
483
|
+
<>
|
|
484
|
+
<Label>{headingText}</Label>
|
|
485
|
+
<SelectButtons payload={payload} setPayload={setPayload} />
|
|
486
|
+
</>
|
|
487
|
+
)}
|
|
488
|
+
</Stack>
|
|
489
|
+
</Card>
|
|
490
|
+
<Card borderTop padding={4}>
|
|
491
|
+
<Stack space={3}>
|
|
492
|
+
{message && (
|
|
487
493
|
<Card padding={3} radius={2} shadow={1} tone={message.tone}>
|
|
488
494
|
<Text size={1}>{message.text}</Text>
|
|
489
495
|
</Card>
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
496
|
+
)}
|
|
497
|
+
{payload.length > 0 ? (
|
|
498
|
+
<Stack>
|
|
499
|
+
{payload.map(({doc, include, status, hasDraft}, index) => {
|
|
500
|
+
const schemaType = schema.get(doc._type)
|
|
501
|
+
|
|
502
|
+
return (
|
|
503
|
+
<React.Fragment key={doc._id}>
|
|
504
|
+
<Flex align="center">
|
|
505
|
+
<Checkbox checked={include} onChange={() => handleCheckbox(doc._id)} />
|
|
506
|
+
<Box flex={1} paddingX={3}>
|
|
507
|
+
{schemaType ? (
|
|
508
|
+
<Preview value={doc} schemaType={schemaType} />
|
|
509
|
+
) : (
|
|
510
|
+
<Card tone="caution">Invalid schema type</Card>
|
|
511
|
+
)}
|
|
512
|
+
</Box>
|
|
513
|
+
<Flex align="center" gap={2}>
|
|
514
|
+
{hasDraft ? <StatusBadge status="UNPUBLISHED" isAsset={false} /> : null}
|
|
515
|
+
<StatusBadge status={status} isAsset={isAssetId(doc._id)} />
|
|
516
|
+
</Flex>
|
|
511
517
|
</Flex>
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
</
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
)
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
518
|
+
{doc?.extension === 'svg' && index === firstSvgIndex && (
|
|
519
|
+
<Card padding={3} radius={2} shadow={1} tone="caution">
|
|
520
|
+
<Text size={1}>
|
|
521
|
+
Due to how SVGs are sanitized after first uploaded, duplicated SVG
|
|
522
|
+
assets may have new <code>_id</code>'s at the destination. The newly
|
|
523
|
+
generated <code>_id</code> will be the same in each duplication, but
|
|
524
|
+
it will never be the same <code>_id</code> as the first time this
|
|
525
|
+
Asset was uploaded. References to the asset will be updated to use the
|
|
526
|
+
new <code>_id</code>.
|
|
527
|
+
</Text>
|
|
528
|
+
</Card>
|
|
529
|
+
)}
|
|
530
|
+
</React.Fragment>
|
|
531
|
+
)
|
|
532
|
+
})}
|
|
533
|
+
</Stack>
|
|
534
|
+
) : (
|
|
535
|
+
<Flex padding={4} align="center" justify="center">
|
|
536
|
+
<Spinner />
|
|
537
|
+
</Flex>
|
|
538
|
+
)}
|
|
539
|
+
<Stack space={2}>
|
|
540
|
+
{hasReferences && (
|
|
541
|
+
<Button
|
|
542
|
+
fontSize={2}
|
|
543
|
+
padding={4}
|
|
544
|
+
tone="positive"
|
|
545
|
+
mode="ghost"
|
|
546
|
+
icon={SearchIcon}
|
|
547
|
+
onClick={handleReferences}
|
|
548
|
+
text="Gather References"
|
|
549
|
+
disabled={isDuplicating || !selectedTotal || isGathering}
|
|
550
|
+
/>
|
|
551
|
+
)}
|
|
532
552
|
<Button
|
|
533
553
|
fontSize={2}
|
|
534
554
|
padding={4}
|
|
535
555
|
tone="positive"
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
text="Gather References"
|
|
556
|
+
icon={LaunchIcon}
|
|
557
|
+
onClick={handleDuplicate}
|
|
558
|
+
text={buttonText}
|
|
540
559
|
disabled={isDuplicating || !selectedTotal || isGathering}
|
|
541
560
|
/>
|
|
542
|
-
|
|
543
|
-
<Button
|
|
544
|
-
fontSize={2}
|
|
545
|
-
padding={4}
|
|
546
|
-
tone="positive"
|
|
547
|
-
icon={LaunchIcon}
|
|
548
|
-
onClick={handleDuplicate}
|
|
549
|
-
text={buttonText}
|
|
550
|
-
disabled={isDuplicating || !selectedTotal || isGathering}
|
|
551
|
-
/>
|
|
561
|
+
</Stack>
|
|
552
562
|
</Stack>
|
|
553
|
-
|
|
563
|
+
</Card>
|
|
554
564
|
</Stack>
|
|
555
565
|
</Card>
|
|
556
566
|
</Container>
|