@sanity/cross-dataset-duplicator 0.4.0 → 1.1.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/LICENSE +1 -1
- package/README.md +53 -57
- package/lib/index.esm.js +1 -0
- package/lib/index.esm.js.map +1 -0
- package/lib/index.js +1 -21
- package/lib/index.js.map +1 -1
- package/lib/src/index.d.ts +548 -0
- package/package.json +64 -38
- package/sanity.json +2 -10
- package/src/actions/DuplicateToAction.tsx +20 -8
- package/src/components/CrossDatasetDuplicator.tsx +34 -49
- package/src/components/CrossDatasetDuplicatorAction.tsx +14 -0
- package/src/components/CrossDatasetDuplicatorTool.tsx +18 -0
- package/src/components/{DuplicatorTool.tsx → Duplicator.tsx} +179 -181
- package/src/components/DuplicatorQuery.tsx +36 -13
- package/src/components/DuplicatorWrapper.tsx +66 -0
- package/src/components/ResetSecret.tsx +9 -9
- package/src/components/SelectButtons.tsx +13 -9
- package/src/components/StatusBadge.tsx +13 -9
- package/src/context/ConfigProvider.tsx +30 -0
- package/src/helpers/clientConfig.ts +1 -1
- package/src/helpers/constants.ts +10 -1
- package/src/helpers/getDocumentsInArray.ts +28 -21
- package/src/helpers/index.ts +6 -10
- package/src/index.ts +5 -0
- package/src/plugin.tsx +31 -0
- package/src/tool/index.ts +11 -10
- package/src/types/index.ts +17 -7
- package/v2-incompatible.js +11 -0
- package/.babelrc +0 -3
- package/.eslintignore +0 -1
- package/config.dist.json +0 -5
- package/lib/actions/DuplicateToAction.js +0 -44
- package/lib/actions/DuplicateToAction.js.map +0 -1
- package/lib/actions/index.js +0 -29
- package/lib/actions/index.js.map +0 -1
- package/lib/components/CrossDatasetDuplicator.js +0 -81
- package/lib/components/CrossDatasetDuplicator.js.map +0 -1
- package/lib/components/DuplicatorQuery.js +0 -105
- package/lib/components/DuplicatorQuery.js.map +0 -1
- package/lib/components/DuplicatorTool.js +0 -556
- package/lib/components/DuplicatorTool.js.map +0 -1
- package/lib/components/Feedback.js +0 -23
- package/lib/components/Feedback.js.map +0 -1
- package/lib/components/ResetSecret.js +0 -34
- package/lib/components/ResetSecret.js.map +0 -1
- package/lib/components/SelectButtons.js +0 -84
- package/lib/components/SelectButtons.js.map +0 -1
- package/lib/components/StatusBadge.js +0 -85
- package/lib/components/StatusBadge.js.map +0 -1
- package/lib/helpers/clientConfig.js +0 -11
- package/lib/helpers/clientConfig.js.map +0 -1
- package/lib/helpers/constants.js +0 -9
- package/lib/helpers/constants.js.map +0 -1
- package/lib/helpers/getDocumentsInArray.js +0 -74
- package/lib/helpers/getDocumentsInArray.js.map +0 -1
- package/lib/helpers/index.js +0 -27
- package/lib/helpers/index.js.map +0 -1
- package/lib/tool/index.js +0 -18
- package/lib/tool/index.js.map +0 -1
- package/lib/types/index.js +0 -2
- package/lib/types/index.js.map +0 -1
- package/src/actions/index.ts +0 -22
- package/src/index.js +0 -7
|
@@ -1,22 +1,34 @@
|
|
|
1
1
|
import React, {useState} from 'react'
|
|
2
2
|
import {LaunchIcon} from '@sanity/icons'
|
|
3
|
+
import {DocumentActionProps} from 'sanity'
|
|
3
4
|
|
|
4
|
-
import
|
|
5
|
+
import {CrossDatasetDuplicatorAction} from '../components/CrossDatasetDuplicatorAction'
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Document action from the Cross Dataset Duplicator plugin
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export const DuplicateToAction = (props: DocumentActionProps) => {
|
|
12
|
+
const {draft, published, onComplete} = props
|
|
7
13
|
const [dialogOpen, setDialogOpen] = useState(false)
|
|
8
14
|
|
|
9
15
|
return {
|
|
10
16
|
disabled: draft,
|
|
11
17
|
title: draft ? `Document must be Published to begin` : null,
|
|
12
18
|
label: 'Duplicate to...',
|
|
13
|
-
dialog: dialogOpen &&
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
dialog: dialogOpen &&
|
|
20
|
+
published && {
|
|
21
|
+
type: 'modal',
|
|
22
|
+
title: 'Cross Dataset Duplicator',
|
|
23
|
+
content: <CrossDatasetDuplicatorAction docs={[published]} />,
|
|
24
|
+
onClose: () => {
|
|
25
|
+
onComplete()
|
|
26
|
+
setDialogOpen(false)
|
|
27
|
+
},
|
|
28
|
+
},
|
|
19
29
|
onHandle: () => setDialogOpen(true),
|
|
20
30
|
icon: LaunchIcon,
|
|
21
31
|
}
|
|
22
32
|
}
|
|
33
|
+
|
|
34
|
+
DuplicateToAction.action = 'duplicateTo'
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import React, {useEffect, useState} from 'react'
|
|
2
|
-
import {useSecrets, SettingsView} from 'sanity-secrets'
|
|
3
|
-
import {
|
|
2
|
+
import {useSecrets, SettingsView} from '@sanity/studio-secrets'
|
|
3
|
+
import {Flex, Box, Spinner} from '@sanity/ui'
|
|
4
|
+
import {SanityDocument} from 'sanity'
|
|
4
5
|
|
|
5
6
|
import DuplicatorQuery from './DuplicatorQuery'
|
|
6
|
-
import
|
|
7
|
+
import DuplicatorWrapper from './DuplicatorWrapper'
|
|
7
8
|
import ResetSecret from './ResetSecret'
|
|
8
9
|
import Feedback from './Feedback'
|
|
9
|
-
import {SanityDocument} from '../types'
|
|
10
10
|
import {SECRET_NAMESPACE} from '../helpers/constants'
|
|
11
|
+
import {useCrossDatasetDuplicatorConfig} from '../context/ConfigProvider'
|
|
11
12
|
|
|
12
13
|
// Check for auth secret (required for asset uploads)
|
|
13
14
|
const secretConfigKeys = [
|
|
@@ -19,20 +20,20 @@ const secretConfigKeys = [
|
|
|
19
20
|
},
|
|
20
21
|
]
|
|
21
22
|
|
|
23
|
+
type Secrets = {
|
|
24
|
+
bearerToken?: string
|
|
25
|
+
}
|
|
26
|
+
|
|
22
27
|
type CrossDatasetDuplicatorProps = {
|
|
23
28
|
mode: 'tool' | 'action'
|
|
24
29
|
docs: SanityDocument[]
|
|
25
30
|
}
|
|
26
31
|
|
|
27
|
-
type Secrets = {
|
|
28
|
-
bearerToken?: string
|
|
29
|
-
}
|
|
30
|
-
|
|
31
32
|
export default function CrossDatasetDuplicator(props: CrossDatasetDuplicatorProps) {
|
|
32
|
-
const {mode = `tool`, docs = []} = props
|
|
33
|
+
const {mode = `tool`, docs = []} = props ?? {}
|
|
34
|
+
const pluginConfig = useCrossDatasetDuplicatorConfig()
|
|
33
35
|
|
|
34
|
-
const
|
|
35
|
-
const {loading, secrets}: {loading: boolean; secrets: Secrets} = secretsData
|
|
36
|
+
const {loading, secrets} = useSecrets<Secrets>(SECRET_NAMESPACE)
|
|
36
37
|
const [showSecretsPrompt, setShowSecretsPrompt] = useState(false)
|
|
37
38
|
|
|
38
39
|
useEffect(() => {
|
|
@@ -41,60 +42,44 @@ export default function CrossDatasetDuplicator(props: CrossDatasetDuplicatorProp
|
|
|
41
42
|
}
|
|
42
43
|
}, [secrets])
|
|
43
44
|
|
|
44
|
-
if (!secretsData) {
|
|
45
|
-
return (
|
|
46
|
-
<Feedback>
|
|
47
|
-
Could not query for Secrets. You may have insufficient permissions on your account.
|
|
48
|
-
</Feedback>
|
|
49
|
-
)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
45
|
if (loading) {
|
|
53
46
|
return (
|
|
54
|
-
<
|
|
55
|
-
<
|
|
56
|
-
<
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
</Flex>
|
|
60
|
-
</ThemeProvider>
|
|
47
|
+
<Flex justify="center" align="center">
|
|
48
|
+
<Box padding={5}>
|
|
49
|
+
<Spinner />
|
|
50
|
+
</Box>
|
|
51
|
+
</Flex>
|
|
61
52
|
)
|
|
62
53
|
}
|
|
63
54
|
|
|
64
55
|
if ((!loading && showSecretsPrompt) || !secrets?.bearerToken) {
|
|
65
56
|
return (
|
|
66
|
-
<
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
/>
|
|
74
|
-
</ThemeProvider>
|
|
57
|
+
<SettingsView
|
|
58
|
+
title="Token Required"
|
|
59
|
+
namespace={SECRET_NAMESPACE}
|
|
60
|
+
keys={secretConfigKeys}
|
|
61
|
+
// eslint-disable-next-line react/jsx-no-bind
|
|
62
|
+
onClose={() => setShowSecretsPrompt(false)}
|
|
63
|
+
/>
|
|
75
64
|
)
|
|
76
65
|
}
|
|
77
66
|
|
|
78
|
-
if (mode === 'tool') {
|
|
67
|
+
if (mode === 'tool' && pluginConfig) {
|
|
79
68
|
return (
|
|
80
|
-
|
|
81
|
-
<DuplicatorQuery token={secrets?.bearerToken} />
|
|
69
|
+
<>
|
|
70
|
+
<DuplicatorQuery token={secrets?.bearerToken} pluginConfig={pluginConfig} />
|
|
82
71
|
<ResetSecret />
|
|
83
|
-
|
|
72
|
+
</>
|
|
84
73
|
)
|
|
85
74
|
}
|
|
86
75
|
|
|
87
76
|
if (!docs?.length) {
|
|
88
|
-
return
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
77
|
+
return <Feedback>No docs passed into Duplicator Tool</Feedback>
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (!pluginConfig) {
|
|
81
|
+
return <Feedback>No plugin config</Feedback>
|
|
93
82
|
}
|
|
94
83
|
|
|
95
|
-
return
|
|
96
|
-
<ThemeProvider>
|
|
97
|
-
<DuplicatorToolWrapper docs={docs} token={secrets?.bearerToken} />
|
|
98
|
-
</ThemeProvider>
|
|
99
|
-
)
|
|
84
|
+
return <DuplicatorWrapper docs={docs} token={secrets?.bearerToken} pluginConfig={pluginConfig} />
|
|
100
85
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import {CrossDatasetDuplicatorActionProps} from '../types'
|
|
3
|
+
|
|
4
|
+
import CrossDatasetDuplicator from './CrossDatasetDuplicator'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Component to perform a migration from the Cross Dataset Duplicator plugin
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export function CrossDatasetDuplicatorAction(props: CrossDatasetDuplicatorActionProps) {
|
|
11
|
+
const {docs = []} = props
|
|
12
|
+
|
|
13
|
+
return <CrossDatasetDuplicator mode="action" docs={docs} />
|
|
14
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import {SanityDocument, Tool} from 'sanity'
|
|
3
|
+
|
|
4
|
+
import CrossDatasetDuplicator from './CrossDatasetDuplicator'
|
|
5
|
+
|
|
6
|
+
export type MultiToolConfig = {
|
|
7
|
+
docs: SanityDocument[]
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
type CrossDatasetDuplicatorProps = {
|
|
11
|
+
tool: Tool<MultiToolConfig>
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function CrossDatasetDuplicatorTool(props: CrossDatasetDuplicatorProps) {
|
|
15
|
+
const {docs = []} = props.tool.options ?? {}
|
|
16
|
+
|
|
17
|
+
return <CrossDatasetDuplicator mode="tool" docs={docs} />
|
|
18
|
+
}
|