@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.
Files changed (64) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +53 -57
  3. package/lib/index.esm.js +1 -0
  4. package/lib/index.esm.js.map +1 -0
  5. package/lib/index.js +1 -21
  6. package/lib/index.js.map +1 -1
  7. package/lib/src/index.d.ts +548 -0
  8. package/package.json +64 -38
  9. package/sanity.json +2 -10
  10. package/src/actions/DuplicateToAction.tsx +20 -8
  11. package/src/components/CrossDatasetDuplicator.tsx +34 -49
  12. package/src/components/CrossDatasetDuplicatorAction.tsx +14 -0
  13. package/src/components/CrossDatasetDuplicatorTool.tsx +18 -0
  14. package/src/components/{DuplicatorTool.tsx → Duplicator.tsx} +179 -181
  15. package/src/components/DuplicatorQuery.tsx +36 -13
  16. package/src/components/DuplicatorWrapper.tsx +66 -0
  17. package/src/components/ResetSecret.tsx +9 -9
  18. package/src/components/SelectButtons.tsx +13 -9
  19. package/src/components/StatusBadge.tsx +13 -9
  20. package/src/context/ConfigProvider.tsx +30 -0
  21. package/src/helpers/clientConfig.ts +1 -1
  22. package/src/helpers/constants.ts +10 -1
  23. package/src/helpers/getDocumentsInArray.ts +28 -21
  24. package/src/helpers/index.ts +6 -10
  25. package/src/index.ts +5 -0
  26. package/src/plugin.tsx +31 -0
  27. package/src/tool/index.ts +11 -10
  28. package/src/types/index.ts +17 -7
  29. package/v2-incompatible.js +11 -0
  30. package/.babelrc +0 -3
  31. package/.eslintignore +0 -1
  32. package/config.dist.json +0 -5
  33. package/lib/actions/DuplicateToAction.js +0 -44
  34. package/lib/actions/DuplicateToAction.js.map +0 -1
  35. package/lib/actions/index.js +0 -29
  36. package/lib/actions/index.js.map +0 -1
  37. package/lib/components/CrossDatasetDuplicator.js +0 -81
  38. package/lib/components/CrossDatasetDuplicator.js.map +0 -1
  39. package/lib/components/DuplicatorQuery.js +0 -105
  40. package/lib/components/DuplicatorQuery.js.map +0 -1
  41. package/lib/components/DuplicatorTool.js +0 -556
  42. package/lib/components/DuplicatorTool.js.map +0 -1
  43. package/lib/components/Feedback.js +0 -23
  44. package/lib/components/Feedback.js.map +0 -1
  45. package/lib/components/ResetSecret.js +0 -34
  46. package/lib/components/ResetSecret.js.map +0 -1
  47. package/lib/components/SelectButtons.js +0 -84
  48. package/lib/components/SelectButtons.js.map +0 -1
  49. package/lib/components/StatusBadge.js +0 -85
  50. package/lib/components/StatusBadge.js.map +0 -1
  51. package/lib/helpers/clientConfig.js +0 -11
  52. package/lib/helpers/clientConfig.js.map +0 -1
  53. package/lib/helpers/constants.js +0 -9
  54. package/lib/helpers/constants.js.map +0 -1
  55. package/lib/helpers/getDocumentsInArray.js +0 -74
  56. package/lib/helpers/getDocumentsInArray.js.map +0 -1
  57. package/lib/helpers/index.js +0 -27
  58. package/lib/helpers/index.js.map +0 -1
  59. package/lib/tool/index.js +0 -18
  60. package/lib/tool/index.js.map +0 -1
  61. package/lib/types/index.js +0 -2
  62. package/lib/types/index.js.map +0 -1
  63. package/src/actions/index.ts +0 -22
  64. 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 CrossDatasetDuplicator from '../components/CrossDatasetDuplicator'
5
+ import {CrossDatasetDuplicatorAction} from '../components/CrossDatasetDuplicatorAction'
5
6
 
6
- export default function DuplicateToAction({draft, published, onComplete}) {
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 && published && {
14
- type: 'modal',
15
- title: 'Cross Dataset Duplicator',
16
- content: <CrossDatasetDuplicator docs={[published]} mode="action" />,
17
- onClose: () => onComplete(),
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 {ThemeProvider, Flex, Box, Spinner} from '@sanity/ui'
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 {DuplicatorToolWrapper} from './DuplicatorTool'
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 secretsData = useSecrets(SECRET_NAMESPACE)
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
- <ThemeProvider>
55
- <Flex justify="center" align="center">
56
- <Box padding={5}>
57
- <Spinner />
58
- </Box>
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
- <ThemeProvider>
67
- <SettingsView
68
- title="Token Required"
69
- namespace={SECRET_NAMESPACE}
70
- keys={secretConfigKeys}
71
- // eslint-disable-next-line react/jsx-no-bind
72
- onClose={() => setShowSecretsPrompt(false)}
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
- <ThemeProvider>
81
- <DuplicatorQuery token={secrets?.bearerToken} />
69
+ <>
70
+ <DuplicatorQuery token={secrets?.bearerToken} pluginConfig={pluginConfig} />
82
71
  <ResetSecret />
83
- </ThemeProvider>
72
+ </>
84
73
  )
85
74
  }
86
75
 
87
76
  if (!docs?.length) {
88
- return (
89
- <ThemeProvider>
90
- <Feedback>No docs passed into Duplicator Tool</Feedback>
91
- </ThemeProvider>
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
+ }