@sanity/cross-dataset-duplicator 0.3.5 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -2
- package/config.dist.json +2 -1
- package/lib/actions/DuplicateToAction.js +5 -20
- package/lib/actions/DuplicateToAction.js.map +1 -1
- package/lib/actions/index.js +2 -11
- package/lib/actions/index.js.map +1 -1
- package/lib/components/CrossDatasetDuplicator.js +11 -37
- package/lib/components/CrossDatasetDuplicator.js.map +1 -1
- package/lib/components/DuplicatorQuery.js +13 -35
- package/lib/components/DuplicatorQuery.js.map +1 -1
- package/lib/components/DuplicatorTool.js +131 -150
- package/lib/components/DuplicatorTool.js.map +1 -1
- package/lib/components/Feedback.js +2 -6
- package/lib/components/Feedback.js.map +1 -1
- package/lib/components/ResetSecret.js +0 -9
- package/lib/components/ResetSecret.js.map +1 -1
- package/lib/components/SelectButtons.js +5 -30
- package/lib/components/SelectButtons.js.map +1 -1
- package/lib/components/StatusBadge.js +1 -8
- package/lib/components/StatusBadge.js.map +1 -1
- package/lib/helpers/clientConfig.js.map +1 -1
- package/lib/helpers/constants.js.map +1 -1
- package/lib/helpers/getDocumentsInArray.js +13 -20
- package/lib/helpers/getDocumentsInArray.js.map +1 -1
- package/lib/helpers/index.js +0 -3
- package/lib/helpers/index.js.map +1 -1
- package/lib/index.js +0 -3
- package/lib/index.js.map +1 -1
- package/lib/tool/index.js +0 -6
- package/lib/tool/index.js.map +1 -1
- package/package.json +3 -3
- package/src/components/CrossDatasetDuplicator.tsx +2 -2
- package/src/components/DuplicatorTool.tsx +61 -2
- package/src/helpers/getDocumentsInArray.ts +8 -5
package/lib/helpers/index.js
CHANGED
|
@@ -6,20 +6,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.createInitialMessage = createInitialMessage;
|
|
7
7
|
exports.stickyStyles = void 0;
|
|
8
8
|
exports.typeIsAsset = typeIsAsset;
|
|
9
|
-
|
|
10
9
|
function typeIsAsset() {
|
|
11
10
|
var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
|
|
12
11
|
if (!type) return false;
|
|
13
12
|
return ['sanity.imageAsset', 'sanity.fileAsset'].includes(type);
|
|
14
13
|
}
|
|
15
|
-
|
|
16
14
|
function createInitialMessage() {
|
|
17
15
|
var docCount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
18
16
|
var refsCount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
19
17
|
var message = [docCount === 1 ? "This Document contains" : "These ".concat(docCount, " Documents contain"), refsCount === 1 ? "1 Reference." : "".concat(refsCount, " References."), refsCount === 1 ? "That Document" : "Those Documents", "may have References too. If referenced Documents do not exist at the target Destination, this transaction will fail."];
|
|
20
18
|
return message.join(" ");
|
|
21
19
|
}
|
|
22
|
-
|
|
23
20
|
var stickyStyles = {
|
|
24
21
|
position: 'sticky',
|
|
25
22
|
top: 0,
|
package/lib/helpers/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["typeIsAsset","type","includes","createInitialMessage","docCount","refsCount","message","join","stickyStyles","position","top","zIndex","backgroundColor"],"sources":["../../src/helpers/index.ts"],"sourcesContent":["export function typeIsAsset(type = ``) {\n if (!type) return false\n\n return ['sanity.imageAsset', 'sanity.fileAsset'].includes(type)\n}\n\nexport function createInitialMessage(docCount = 0, refsCount = 0) {\n const message = [\n docCount === 1 ? `This Document contains` : `These ${docCount} Documents contain`,\n refsCount === 1 ? `1 Reference.` : `${refsCount} References.`,\n refsCount === 1 ? `That Document` : `Those Documents`,\n `may have References too. If referenced Documents do not exist at the target Destination, this transaction will fail.`\n ]\n\n return message.join(` `)\n}\n\nexport const stickyStyles = {\n position: 'sticky',\n top: 0,\n zIndex: 100,\n backgroundColor: `rgba(255,255,255,0.95)`,\n}"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":["typeIsAsset","type","includes","createInitialMessage","docCount","refsCount","message","join","stickyStyles","position","top","zIndex","backgroundColor"],"sources":["../../src/helpers/index.ts"],"sourcesContent":["export function typeIsAsset(type = ``) {\n if (!type) return false\n\n return ['sanity.imageAsset', 'sanity.fileAsset'].includes(type)\n}\n\nexport function createInitialMessage(docCount = 0, refsCount = 0) {\n const message = [\n docCount === 1 ? `This Document contains` : `These ${docCount} Documents contain`,\n refsCount === 1 ? `1 Reference.` : `${refsCount} References.`,\n refsCount === 1 ? `That Document` : `Those Documents`,\n `may have References too. If referenced Documents do not exist at the target Destination, this transaction will fail.`\n ]\n\n return message.join(` `)\n}\n\nexport const stickyStyles = {\n position: 'sticky',\n top: 0,\n zIndex: 100,\n backgroundColor: `rgba(255,255,255,0.95)`,\n}"],"mappings":";;;;;;;;AAAO,SAASA,WAAW,GAAY;EAAA,IAAXC,IAAI;EAC9B,IAAI,CAACA,IAAI,EAAE,OAAO,KAAK;EAEvB,OAAO,CAAC,mBAAmB,EAAE,kBAAkB,CAAC,CAACC,QAAQ,CAACD,IAAI,CAAC;AACjE;AAEO,SAASE,oBAAoB,GAA8B;EAAA,IAA7BC,QAAQ,uEAAG,CAAC;EAAA,IAAEC,SAAS,uEAAG,CAAC;EAC9D,IAAMC,OAAO,GAAG,CACdF,QAAQ,KAAK,CAAC,8CAAuCA,QAAQ,uBAAoB,EACjFC,SAAS,KAAK,CAAC,8BAAuBA,SAAS,iBAAc,EAC7DA,SAAS,KAAK,CAAC,sCAAsC,yHAEtD;EAED,OAAOC,OAAO,CAACC,IAAI,KAAK;AAC1B;AAEO,IAAMC,YAAY,GAAG;EAC1BC,QAAQ,EAAE,QAAQ;EAClBC,GAAG,EAAE,CAAC;EACNC,MAAM,EAAE,GAAG;EACXC,eAAe;AACjB,CAAC;AAAA"}
|
package/lib/index.js
CHANGED
|
@@ -15,10 +15,7 @@ Object.defineProperty(exports, "DuplicateToAction", {
|
|
|
15
15
|
return _DuplicateToAction.default;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
|
-
|
|
19
18
|
var _DuplicateToAction = _interopRequireDefault(require("./actions/DuplicateToAction"));
|
|
20
|
-
|
|
21
19
|
var _CrossDatasetDuplicator = _interopRequireDefault(require("./components/CrossDatasetDuplicator"));
|
|
22
|
-
|
|
23
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
24
21
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/index.js"],"sourcesContent":["import DuplicateToAction from \"./actions/DuplicateToAction\";\nimport CrossDatasetDuplicator from \"./components/CrossDatasetDuplicator\";\n\nexport {\n DuplicateToAction,\n CrossDatasetDuplicator\n}"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.js"],"sourcesContent":["import DuplicateToAction from \"./actions/DuplicateToAction\";\nimport CrossDatasetDuplicator from \"./components/CrossDatasetDuplicator\";\n\nexport {\n DuplicateToAction,\n CrossDatasetDuplicator\n}"],"mappings":";;;;;;;;;;;;;;;;;AAAA;AACA;AAAyE"}
|
package/lib/tool/index.js
CHANGED
|
@@ -4,21 +4,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _icons = require("@sanity/icons");
|
|
9
|
-
|
|
10
8
|
var _crossDatasetDuplicator = _interopRequireDefault(require("config:@sanity/cross-dataset-duplicator"));
|
|
11
|
-
|
|
12
9
|
var _CrossDatasetDuplicator = _interopRequireDefault(require("../components/CrossDatasetDuplicator"));
|
|
13
|
-
|
|
14
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
16
11
|
var _default = _crossDatasetDuplicator.default !== null && _crossDatasetDuplicator.default !== void 0 && _crossDatasetDuplicator.default.tool ? {
|
|
17
12
|
title: 'Duplicator',
|
|
18
13
|
name: 'duplicator',
|
|
19
14
|
icon: _icons.LaunchIcon,
|
|
20
15
|
component: _CrossDatasetDuplicator.default
|
|
21
16
|
} : null;
|
|
22
|
-
|
|
23
17
|
exports.default = _default;
|
|
24
18
|
//# sourceMappingURL=index.js.map
|
package/lib/tool/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["config","tool","title","name","icon","LaunchIcon","component","CrossDatasetDuplicator"],"sources":["../../src/tool/index.ts"],"sourcesContent":["import {LaunchIcon} from '@sanity/icons'\nimport config from 'config:@sanity/cross-dataset-duplicator'\n\nimport CrossDatasetDuplicator from '../components/CrossDatasetDuplicator'\n\nexport default config?.tool\n ? {\n title: 'Duplicator',\n name: 'duplicator',\n icon: LaunchIcon,\n component: CrossDatasetDuplicator,\n }\n : null\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":["config","tool","title","name","icon","LaunchIcon","component","CrossDatasetDuplicator"],"sources":["../../src/tool/index.ts"],"sourcesContent":["import {LaunchIcon} from '@sanity/icons'\nimport config from 'config:@sanity/cross-dataset-duplicator'\n\nimport CrossDatasetDuplicator from '../components/CrossDatasetDuplicator'\n\nexport default config?.tool\n ? {\n title: 'Duplicator',\n name: 'duplicator',\n icon: LaunchIcon,\n component: CrossDatasetDuplicator,\n }\n : null\n"],"mappings":";;;;;;AAAA;AACA;AAEA;AAAyE;AAAA,eAE1DA,+BAAM,aAANA,+BAAM,eAANA,+BAAM,CAAEC,IAAI,GACvB;EACEC,KAAK,EAAE,YAAY;EACnBC,IAAI,EAAE,YAAY;EAClBC,IAAI,EAAEC,iBAAU;EAChBC,SAAS,EAAEC;AACb,CAAC,GACD,IAAI;AAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/cross-dataset-duplicator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Empower content editors to migrate Documents and Assets between Sanity Projects and Datasets from inside Sanity Studio",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"license": "MIT",
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@sanity/icons": "^1.2.5",
|
|
32
|
+
"@sanity/mutator": "^2.13.0",
|
|
32
33
|
"@sanity/ui": "^0.36.15",
|
|
33
34
|
"async": "^3.2.1",
|
|
34
35
|
"dset": "^3.1.0",
|
|
@@ -47,8 +48,7 @@
|
|
|
47
48
|
"sanipack": "^2.1.0"
|
|
48
49
|
},
|
|
49
50
|
"peerDependencies": {
|
|
50
|
-
"react": "^17.0.0"
|
|
51
|
-
"@sanity/mutator": "^2.13.0"
|
|
51
|
+
"react": "^17.0.0"
|
|
52
52
|
},
|
|
53
53
|
"bugs": {
|
|
54
54
|
"url": "https://github.com/sanity-io/cross-dataset-duplicator/issues"
|
|
@@ -3,7 +3,7 @@ import {useSecrets, SettingsView} from 'sanity-secrets'
|
|
|
3
3
|
import {ThemeProvider, Flex, Box, Spinner} from '@sanity/ui'
|
|
4
4
|
|
|
5
5
|
import DuplicatorQuery from './DuplicatorQuery'
|
|
6
|
-
import
|
|
6
|
+
import {DuplicatorToolWrapper} from './DuplicatorTool'
|
|
7
7
|
import ResetSecret from './ResetSecret'
|
|
8
8
|
import Feedback from './Feedback'
|
|
9
9
|
import {SanityDocument} from '../types'
|
|
@@ -94,7 +94,7 @@ export default function CrossDatasetDuplicator(props: CrossDatasetDuplicatorProp
|
|
|
94
94
|
|
|
95
95
|
return (
|
|
96
96
|
<ThemeProvider>
|
|
97
|
-
<
|
|
97
|
+
<DuplicatorToolWrapper docs={docs} token={secrets?.bearerToken} />
|
|
98
98
|
</ThemeProvider>
|
|
99
99
|
)
|
|
100
100
|
}
|
|
@@ -5,6 +5,7 @@ import asyncify from 'async/asyncify'
|
|
|
5
5
|
import {extract, extractWithPath} from '@sanity/mutator'
|
|
6
6
|
import {dset} from 'dset'
|
|
7
7
|
import {
|
|
8
|
+
Grid,
|
|
8
9
|
Card,
|
|
9
10
|
Container,
|
|
10
11
|
Text,
|
|
@@ -15,12 +16,14 @@ import {
|
|
|
15
16
|
Select,
|
|
16
17
|
Flex,
|
|
17
18
|
Checkbox,
|
|
19
|
+
Tab,
|
|
18
20
|
} from '@sanity/ui'
|
|
19
21
|
import {ArrowRightIcon, SearchIcon, LaunchIcon} from '@sanity/icons'
|
|
20
22
|
import sanityClient from 'part:@sanity/base/client'
|
|
21
23
|
import Preview from 'part:@sanity/base/preview'
|
|
22
24
|
import schema from 'part:@sanity/base/schema'
|
|
23
25
|
import config from 'config:sanity'
|
|
26
|
+
import duplicatorConfig from 'config:@sanity/cross-dataset-duplicator'
|
|
24
27
|
|
|
25
28
|
import {typeIsAsset, stickyStyles, createInitialMessage} from '../helpers'
|
|
26
29
|
import {getDocumentsInArray} from '../helpers/getDocumentsInArray'
|
|
@@ -36,6 +39,58 @@ type DuplicatorToolProps = {
|
|
|
36
39
|
token: string
|
|
37
40
|
}
|
|
38
41
|
|
|
42
|
+
export function DuplicatorToolWrapper(props: DuplicatorToolProps) {
|
|
43
|
+
const {docs, token} = props
|
|
44
|
+
const [mode, setMode] = useState('outbound')
|
|
45
|
+
const [inbound, setInbound] = useState([])
|
|
46
|
+
const {follow = []} = duplicatorConfig
|
|
47
|
+
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
;(async () => {
|
|
50
|
+
const inboundReferences = await sanityClient.fetch('*[references($id)]', {id: docs[0]._id})
|
|
51
|
+
setInbound([...props.docs, ...inboundReferences])
|
|
52
|
+
})()
|
|
53
|
+
}, [])
|
|
54
|
+
|
|
55
|
+
console.log(docs, inbound)
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<Container>
|
|
59
|
+
{follow.includes(`inbound`) || follow.includes(`outbound`) ? (
|
|
60
|
+
<Card paddingX={4} paddingBottom={4} marginBottom={4} borderBottom>
|
|
61
|
+
<Grid columns={2} gap={4}>
|
|
62
|
+
{follow.includes(`outbound`) ? (
|
|
63
|
+
<Button
|
|
64
|
+
mode="ghost"
|
|
65
|
+
tone="primary"
|
|
66
|
+
selected={mode === 'outbound'}
|
|
67
|
+
onClick={() => setMode('outbound')}
|
|
68
|
+
text={`Outbound`}
|
|
69
|
+
/>
|
|
70
|
+
) : null}
|
|
71
|
+
{follow.includes(`inbound`) ? (
|
|
72
|
+
<Button
|
|
73
|
+
mode="ghost"
|
|
74
|
+
tone="primary"
|
|
75
|
+
selected={mode === 'inbound'}
|
|
76
|
+
onClick={() => setMode('inbound')}
|
|
77
|
+
disabled={inbound.length === 0}
|
|
78
|
+
text={inbound.length > 0 ? `Inbound (${inbound.length})` : 'No inbound references'}
|
|
79
|
+
/>
|
|
80
|
+
) : null}
|
|
81
|
+
</Grid>
|
|
82
|
+
</Card>
|
|
83
|
+
) : null}
|
|
84
|
+
<DuplicatorTool
|
|
85
|
+
key={mode}
|
|
86
|
+
docs={mode === 'outbound' ? docs : inbound}
|
|
87
|
+
token={token}
|
|
88
|
+
draftIds={[]}
|
|
89
|
+
/>
|
|
90
|
+
</Container>
|
|
91
|
+
)
|
|
92
|
+
}
|
|
93
|
+
|
|
39
94
|
export default function DuplicatorTool(props: DuplicatorToolProps) {
|
|
40
95
|
const {docs, draftIds, token} = props
|
|
41
96
|
|
|
@@ -379,7 +434,9 @@ export default function DuplicatorTool(props: DuplicatorToolProps) {
|
|
|
379
434
|
.map((space) => (
|
|
380
435
|
<option key={space.name} value={space.name} disabled={space.disabled}>
|
|
381
436
|
{space.title ?? space.name}
|
|
382
|
-
{hasMultipleProjectIds || space.usingEnvForProjectId
|
|
437
|
+
{hasMultipleProjectIds || space.usingEnvForProjectId
|
|
438
|
+
? ` (${space.api.projectId})`
|
|
439
|
+
: ``}
|
|
383
440
|
</option>
|
|
384
441
|
))}
|
|
385
442
|
</Select>
|
|
@@ -395,7 +452,9 @@ export default function DuplicatorTool(props: DuplicatorToolProps) {
|
|
|
395
452
|
{spacesOptions.map((space) => (
|
|
396
453
|
<option key={space.name} value={space.name} disabled={space.disabled}>
|
|
397
454
|
{space.title ?? space.name}
|
|
398
|
-
{hasMultipleProjectIds || space.usingEnvForProjectId
|
|
455
|
+
{hasMultipleProjectIds || space.usingEnvForProjectId
|
|
456
|
+
? ` (${space.api.projectId})`
|
|
457
|
+
: ``}
|
|
399
458
|
{space.disabled ? ` (Current)` : ``}
|
|
400
459
|
</option>
|
|
401
460
|
))}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import {extract} from '@sanity/mutator'
|
|
2
|
-
import {SanityDocument} from '../types'
|
|
1
|
+
import { extract } from '@sanity/mutator'
|
|
2
|
+
import { SanityDocument } from '../types'
|
|
3
|
+
|
|
4
|
+
import config from 'config:@sanity/cross-dataset-duplicator'
|
|
3
5
|
|
|
4
6
|
// Recursively fetch Documents from an array of _id's and their references
|
|
5
7
|
// Heavy use of Set is to avoid recursively querying for id's already in the payload
|
|
@@ -12,7 +14,8 @@ export async function getDocumentsInArray(
|
|
|
12
14
|
const collection = []
|
|
13
15
|
|
|
14
16
|
// Find initial docs
|
|
15
|
-
const
|
|
17
|
+
const filter = ['_id in $fetchIds', config.filter].filter(Boolean).join(' && ')
|
|
18
|
+
const query = `*[${filter}]${projection ?? ``}`
|
|
16
19
|
const data: SanityDocument[] = await client.fetch(query, {
|
|
17
20
|
fetchIds: fetchIds ?? [],
|
|
18
21
|
})
|
|
@@ -22,7 +25,7 @@ export async function getDocumentsInArray(
|
|
|
22
25
|
}
|
|
23
26
|
|
|
24
27
|
const localCurrentIds = currentIds ?? new Set()
|
|
25
|
-
|
|
28
|
+
|
|
26
29
|
// Find new ids in the returned data
|
|
27
30
|
// Unless we started with an empty set, get the _ids from the data
|
|
28
31
|
const newDataIds: Set<string> = new Set(
|
|
@@ -70,7 +73,7 @@ export async function getDocumentsInArray(
|
|
|
70
73
|
}
|
|
71
74
|
|
|
72
75
|
return [...acc, cur]
|
|
73
|
-
}, [])
|
|
76
|
+
}, [])
|
|
74
77
|
|
|
75
78
|
return uniqueCollection
|
|
76
79
|
}
|