Skip to content

Commit a37e0cc

Browse files
authored
Configurable API Version (#58)
* feat: configurable `apiVersion` * chore: bump deps * chore: add note to readme about other options
1 parent 4f67572 commit a37e0cc

13 files changed

+9324
-3475
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
Sanity Studio v3 Tool and Document Action for empowering content editors to migrate Documents and Assets between Sanity Datasets and Projects from inside the Studio.
44

5+
> [!IMPORTANT]
6+
> You might not need this plugin. It was developed long before Sanity had fully-featured [live preview, visual editing](https://www.sanity.io/docs/visual-editing/introduction-to-visual-editing), [perspectives](https://www.sanity.io/docs/content-lake/perspectives) and [content releases](https://www.sanity.io/docs/user-guides/content-releases) which are more seamless ways to stage and preview content before publishing into production. It is recommended you investigate these features first before using this plugin.
7+
58
## Installation
69

710
```
@@ -64,6 +67,7 @@ The plugin has some configuration options. These can be set by adding a config f
6467
// Required settings to show document action
6568
types: ['article', 'page'],
6669
// Optional settings
70+
apiVersion: '2025-02-19',
6771
tool: true,
6872
filter: '_type != "product"',
6973
follow: [],

package-lock.json

Lines changed: 9295 additions & 3444 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,16 @@
9090
"react-dom": "^18.2.0",
9191
"react-is": "^18.2.0",
9292
"rimraf": "^4.4.1",
93-
"sanity": "^3.8.1",
94-
"styled-components": "^5.3.3",
93+
"sanity": "^3.79.0",
94+
"styled-components": "^6.1.8",
9595
"typescript": "^5.0.3"
9696
},
9797
"peerDependencies": {
98-
"@sanity/ui": "^1.0 || ^2.0",
98+
"@sanity/ui": "^2.0.0",
9999
"react": "^18",
100100
"react-dom": "^18",
101-
"sanity": "^3.0.0",
102-
"styled-components": "^5.0 || ^6.0"
101+
"sanity": "^3.79.0",
102+
"styled-components": "^6.0.0"
103103
},
104104
"engines": {
105105
"node": ">=14.0.0"

src/components/CrossDatasetDuplicator.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export default function CrossDatasetDuplicator(props: CrossDatasetDuplicatorProp
6969
return (
7070
<>
7171
<DuplicatorQuery token={secrets?.bearerToken} pluginConfig={pluginConfig} />
72-
<ResetSecret />
72+
<ResetSecret apiVersion={pluginConfig.apiVersion} />
7373
</>
7474
)
7575
}

src/components/Duplicator.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,14 @@ import {getDocumentsInArray} from '../helpers/getDocumentsInArray'
3838
import SelectButtons from './SelectButtons'
3939
import StatusBadge, {MessageTypes} from './StatusBadge'
4040
import Feedback from './Feedback'
41-
import {clientConfig} from '../helpers/clientConfig'
4241
import {PluginConfig} from '../types'
4342

4443
export type DuplicatorProps = {
4544
docs: SanityDocument[]
4645
// TODO: Find out if this is even used?
4746
// draftIds: string[]
4847
token: string
49-
pluginConfig: PluginConfig
48+
pluginConfig: Required<PluginConfig>
5049
onDuplicated?: () => Promise<void>
5150
}
5251

@@ -71,7 +70,7 @@ export default function Duplicator(props: DuplicatorProps) {
7170
const isDarkMode = useTheme().sanity.color.dark
7271

7372
// Prepare origin (this Studio) client
74-
const originClient = useClient(clientConfig)
73+
const originClient = useClient({apiVersion: pluginConfig.apiVersion})
7574

7675
const schema = useSchema()
7776

@@ -139,7 +138,6 @@ export default function Duplicator(props: DuplicatorProps) {
139138

140139
const payloadIds = payloadActual.map(({doc}) => doc._id)
141140
const destinationClient = originClient.withConfig({
142-
...clientConfig,
143141
dataset: destination.dataset,
144142
projectId: destination.projectId,
145143
})
@@ -235,7 +233,7 @@ export default function Duplicator(props: DuplicatorProps) {
235233
setMessage({text: 'Duplicating...', tone: `transparent`})
236234

237235
const destinationClient = originClient.withConfig({
238-
...clientConfig,
236+
apiVersion: pluginConfig.apiVersion,
239237
dataset: destination.dataset,
240238
projectId: destination.projectId,
241239
})

src/components/DuplicatorQuery.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,22 @@ import {Button, Stack, Box, Label, Text, Card, Flex, Grid, Container, TextInput}
33
import {useSchema, useClient, SanityDocument} from 'sanity'
44

55
import Duplicator from './Duplicator'
6-
import {clientConfig} from '../helpers/clientConfig'
76
import {PluginConfig} from '../types'
87

98
type DuplicatorQueryProps = {
109
token: string
11-
pluginConfig: PluginConfig
10+
pluginConfig: Required<PluginConfig>
1211
}
1312

1413
type InitialData = {
1514
docs: SanityDocument[]
16-
// draftIds: string[]
1715
}
1816

1917
export default function DuplicatorQuery(props: DuplicatorQueryProps) {
2018
const {token, pluginConfig} = props
2119

22-
const {queries: preDefinedQueries} = pluginConfig
23-
const originClient = useClient(clientConfig)
20+
const {queries: preDefinedQueries, apiVersion} = pluginConfig
21+
const originClient = useClient({apiVersion})
2422

2523
const schema = useSchema()
2624
const schemaTypes = schema.getTypeNames()
@@ -29,7 +27,6 @@ export default function DuplicatorQuery(props: DuplicatorQueryProps) {
2927
const [fetched, setFetched] = useState(false)
3028
const [initialData, setInitialData] = useState<InitialData>({
3129
docs: [],
32-
// draftIds: []
3330
})
3431
function handleSubmit(e?: any) {
3532
if (e) e.preventDefault()
@@ -43,13 +40,9 @@ export default function DuplicatorQuery(props: DuplicatorQueryProps) {
4340
.filter((doc) => schemaTypes.includes(doc._type))
4441
.filter((doc) => !doc._id.startsWith(`drafts.`))
4542
: []
46-
// const initialDraftIds = res.length
47-
// ? res.filter((doc) => doc._id.startsWith(`drafts.`)).map((doc) => doc._id)
48-
// : []
4943

5044
setInitialData({
5145
docs: registeredAndPublishedDocs,
52-
// draftIds: initialDraftIds
5346
})
5447
setFetched(true)
5548
})

src/components/DuplicatorWrapper.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,17 @@ import {SanityDocument, useClient} from 'sanity'
44

55
import type {DuplicatorProps} from './Duplicator'
66
import Duplicator from './Duplicator'
7-
import {clientConfig} from '../helpers/clientConfig'
87

98
export default function DuplicatorWrapper(props: DuplicatorProps) {
109
const {docs, token, pluginConfig, onDuplicated} = props
1110
const [inbound, setInbound] = useState<SanityDocument[]>([])
12-
const {follow = []} = pluginConfig
11+
const {follow = [], apiVersion} = pluginConfig
1312

1413
// Make the first mode the default if there's only one
1514
const [mode, setMode] = useState<'inbound' | 'outbound'>(
1615
follow.length === 1 ? follow[0] : `outbound`
1716
)
18-
const client = useClient(clientConfig)
17+
const client = useClient({apiVersion})
1918

2019
// "Inbound" will start with all documents that reference the first one
2120
// And then you can gather "Outbound" references thereafter

src/components/ResetSecret.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ import {useCallback} from 'react'
22
import {useClient} from 'sanity'
33
import {Button, Flex} from '@sanity/ui'
44

5-
import {clientConfig} from '../helpers/clientConfig'
65
import {SECRET_NAMESPACE} from '../helpers/constants'
76

8-
export default function ResetSecret() {
9-
const client = useClient(clientConfig)
7+
type ResetSecretProps = {
8+
apiVersion: string
9+
}
10+
11+
export default function ResetSecret({apiVersion}: ResetSecretProps) {
12+
const client = useClient({apiVersion})
1013

1114
const handleClick = useCallback(() => {
1215
client.delete({query: `*[_id == "secrets.${SECRET_NAMESPACE}"]`})

src/context/ConfigProvider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {PluginConfig} from '../types'
77

88
const CrossDatasetDuplicatorContext = createContext(DEFAULT_CONFIG)
99

10-
type ConfigProviderProps = LayoutProps & {pluginConfig: PluginConfig}
10+
type ConfigProviderProps = LayoutProps & {pluginConfig: Required<PluginConfig>}
1111

1212
/**
1313
* Plugin config context hook from the Cross Dataset Duplicator plugin

src/helpers/clientConfig.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)