@sanity/cross-dataset-duplicator 1.4.0-beta.2 → 1.4.1
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 +10 -9
- package/dist/index.d.ts +4 -8
- package/dist/index.esm.js +58 -49
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +57 -48
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Duplicator.tsx +4 -2
- package/src/components/DuplicatorQuery.tsx +33 -11
- package/src/components/StatusBadge.tsx +5 -1
- package/src/helpers/constants.ts +1 -0
- package/src/helpers/getDocumentsInArray.ts +10 -57
- package/src/types/index.ts +4 -9
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -5,13 +5,13 @@ Sanity Studio v3 Tool and Document Action for empowering content editors to migr
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```
|
|
8
|
-
npm install --save @sanity/cross-dataset-duplicator
|
|
8
|
+
npm install --save @sanity/cross-dataset-duplicator
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
or
|
|
12
12
|
|
|
13
13
|
```
|
|
14
|
-
yarn add @sanity/cross-dataset-duplicator
|
|
14
|
+
yarn add @sanity/cross-dataset-duplicator
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
### Important Notes
|
|
@@ -67,10 +67,12 @@ The plugin has some configuration options. These can be set by adding a config f
|
|
|
67
67
|
tool: true,
|
|
68
68
|
filter: '_type != "product"',
|
|
69
69
|
follow: [],
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
70
|
+
queries:[
|
|
71
|
+
{
|
|
72
|
+
label: "All articles",
|
|
73
|
+
query: '_type == "article"'
|
|
74
|
+
}
|
|
75
|
+
]
|
|
74
76
|
})
|
|
75
77
|
]
|
|
76
78
|
})
|
|
@@ -81,9 +83,8 @@ The plugin has some configuration options. These can be set by adding a config f
|
|
|
81
83
|
- `tool` (boolean, default: true) – Set whether the Migration **Tool** is enabled.
|
|
82
84
|
- `types` (Array[String], default: []) – Set which Schema Types the Migration Action should be enabled in.
|
|
83
85
|
- `filter` (String, default: undefined) - Set a predicate for documents when gathering dependencies.
|
|
84
|
-
- `follow` (("inbound" | "outbound")[], default: []) – Add buttons to allow the user to begin with just the existing document or first fetch all inbound references.
|
|
85
|
-
- `
|
|
86
|
-
- `reference.assetsOnly`: (boolean) - If true, only gather image and file assets. The 'referenceMaxDepth' option must be set for this to work.
|
|
86
|
+
- `follow` (("inbound" | "outbound")[], default: ["outbound"]) – Add buttons to allow the user to begin with just the existing document or first fetch all inbound references.
|
|
87
|
+
- `queries`(Array[{label: string, query: string}], default: []) - Add button to allow the query to be populate with predefined useful queries.
|
|
87
88
|
|
|
88
89
|
#### Action Options
|
|
89
90
|
|
package/dist/index.d.ts
CHANGED
|
@@ -65,16 +65,12 @@ export declare interface PluginConfig {
|
|
|
65
65
|
types?: string[]
|
|
66
66
|
filter?: string
|
|
67
67
|
follow?: ('inbound' | 'outbound')[]
|
|
68
|
-
|
|
68
|
+
queries?: PreDefinedQuery[]
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
*/
|
|
75
|
-
export declare type reference = {
|
|
76
|
-
maxDepth: number
|
|
77
|
-
assetsOnly?: boolean
|
|
71
|
+
declare type PreDefinedQuery = {
|
|
72
|
+
label: string
|
|
73
|
+
query: string
|
|
78
74
|
}
|
|
79
75
|
|
|
80
76
|
/**
|
package/dist/index.esm.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useClient, useSchema, useWorkspaces, Preview, definePlugin } from 'sanity';
|
|
2
2
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
3
3
|
import React, { useState, useEffect, useCallback, createContext, useContext } from 'react';
|
|
4
|
-
import { ArrowRightIcon, SearchIcon, LaunchIcon } from '@sanity/icons';
|
|
4
|
+
import { InfoOutlineIcon, ArrowRightIcon, SearchIcon, LaunchIcon } from '@sanity/icons';
|
|
5
5
|
import { useSecrets, SettingsView } from '@sanity/studio-secrets';
|
|
6
6
|
import { Card, Flex, Button, Badge, Tooltip, Box, Text, useTheme, Container, Stack, Label, Select, Checkbox, Spinner, Grid, TextInput } from '@sanity/ui';
|
|
7
7
|
import mapLimit from 'async/mapLimit';
|
|
@@ -24,10 +24,7 @@ const stickyStyles = function () {
|
|
|
24
24
|
backgroundColor: isDarkMode ? "rgba(10,10,10,0.95)" : "rgba(255,255,255,0.95)"
|
|
25
25
|
};
|
|
26
26
|
};
|
|
27
|
-
const isAsset = doc => doc._type === "sanity.imageAsset" || doc._type === "sanity.fileAsset";
|
|
28
|
-
const returnOnlyAssets = references => references.filter(item => isAsset(item));
|
|
29
27
|
async function getDocumentsInArray(options) {
|
|
30
|
-
let recurrsionDepth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
31
28
|
const {
|
|
32
29
|
fetchIds,
|
|
33
30
|
client,
|
|
@@ -35,9 +32,6 @@ async function getDocumentsInArray(options) {
|
|
|
35
32
|
currentIds,
|
|
36
33
|
projection
|
|
37
34
|
} = options;
|
|
38
|
-
const {
|
|
39
|
-
reference
|
|
40
|
-
} = pluginConfig;
|
|
41
35
|
const collection = [];
|
|
42
36
|
const filter = ["_id in $fetchIds", pluginConfig.filter].filter(Boolean).join(" && ");
|
|
43
37
|
const query = "*[".concat(filter, "]").concat(projection != null ? projection : "");
|
|
@@ -58,35 +52,14 @@ async function getDocumentsInArray(options) {
|
|
|
58
52
|
if (references.length) {
|
|
59
53
|
const newReferenceIds = new Set(references.filter(ref => !localCurrentIds.has(ref)));
|
|
60
54
|
if (newReferenceIds.size) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
if (
|
|
70
|
-
// // If we are at the max depth and reference?.assetsOnly is falsy
|
|
71
|
-
(referenceDocs == null ? void 0 : referenceDocs.length) && recurrsionDepth === reference.maxDepth + 1 && !(reference == null ? void 0 : reference.assetsOnly)) {
|
|
72
|
-
collection.push(...referenceDocs);
|
|
73
|
-
} else if (
|
|
74
|
-
// // If we are at the max depth and reference?.assetsOnly is truthy
|
|
75
|
-
(referenceDocs == null ? void 0 : referenceDocs.length) && recurrsionDepth === reference.maxDepth + 1 && (reference == null ? void 0 : reference.assetsOnly)) {
|
|
76
|
-
collection.push(...returnOnlyAssets(referenceDocs));
|
|
77
|
-
} else if ((referenceDocs == null ? void 0 : referenceDocs.length) && recurrsionDepth < reference.maxDepth + 1) {
|
|
78
|
-
collection.push(...referenceDocs);
|
|
79
|
-
}
|
|
80
|
-
} else {
|
|
81
|
-
const referenceDocs = await getDocumentsInArray({
|
|
82
|
-
fetchIds: Array.from(newReferenceIds),
|
|
83
|
-
currentIds: localCurrentIds,
|
|
84
|
-
client,
|
|
85
|
-
pluginConfig
|
|
86
|
-
});
|
|
87
|
-
if (referenceDocs == null ? void 0 : referenceDocs.length) {
|
|
88
|
-
collection.push(...referenceDocs);
|
|
89
|
-
}
|
|
55
|
+
const referenceDocs = await getDocumentsInArray({
|
|
56
|
+
fetchIds: Array.from(newReferenceIds),
|
|
57
|
+
currentIds: localCurrentIds,
|
|
58
|
+
client,
|
|
59
|
+
pluginConfig
|
|
60
|
+
});
|
|
61
|
+
if (referenceDocs == null ? void 0 : referenceDocs.length) {
|
|
62
|
+
collection.push(...referenceDocs);
|
|
90
63
|
}
|
|
91
64
|
}
|
|
92
65
|
}
|
|
@@ -239,13 +212,18 @@ function StatusBadge(props) {
|
|
|
239
212
|
fallbackPlacements: ["right", "left"],
|
|
240
213
|
placement: "top",
|
|
241
214
|
portal: true,
|
|
242
|
-
children: /* @__PURE__ */
|
|
215
|
+
children: /* @__PURE__ */jsxs(Badge, {
|
|
243
216
|
muted: true,
|
|
244
|
-
padding:
|
|
217
|
+
padding: 3,
|
|
245
218
|
fontSize: 1,
|
|
246
219
|
tone: badgeTone,
|
|
247
220
|
mode: "outline",
|
|
248
|
-
children: badgeStatus
|
|
221
|
+
children: [badgeStatus, /* @__PURE__ */jsx(Box, {
|
|
222
|
+
marginLeft: 2,
|
|
223
|
+
display: "inline-block",
|
|
224
|
+
as: "span",
|
|
225
|
+
children: /* @__PURE__ */jsx(InfoOutlineIcon, {})
|
|
226
|
+
})]
|
|
249
227
|
})
|
|
250
228
|
});
|
|
251
229
|
}
|
|
@@ -282,7 +260,7 @@ function Duplicator(props) {
|
|
|
282
260
|
const workspaces = useWorkspaces();
|
|
283
261
|
const workspacesOptions = workspaces.map(workspace => ({
|
|
284
262
|
...workspace,
|
|
285
|
-
disabled: workspace.dataset === originClient.config().dataset
|
|
263
|
+
disabled: workspace.dataset === originClient.config().dataset && workspace.projectId === originClient.config().projectId
|
|
286
264
|
}));
|
|
287
265
|
const [destination, setDestination] = useState(workspaces.length ? (_a = workspacesOptions.find(space => !space.disabled)) != null ? _a : null : null);
|
|
288
266
|
const [message, setMessage] = useState(null);
|
|
@@ -303,7 +281,7 @@ function Duplicator(props) {
|
|
|
303
281
|
doc
|
|
304
282
|
});
|
|
305
283
|
});
|
|
306
|
-
|
|
284
|
+
updatePayloadStatuses(initialPayload);
|
|
307
285
|
const docCount = docs.length;
|
|
308
286
|
const refsCount = initialRefs.length;
|
|
309
287
|
if (initialRefs.length) {
|
|
@@ -745,15 +723,19 @@ function Duplicator(props) {
|
|
|
745
723
|
});
|
|
746
724
|
}
|
|
747
725
|
function DuplicatorQuery(props) {
|
|
748
|
-
var _a
|
|
726
|
+
var _a;
|
|
749
727
|
const {
|
|
750
728
|
token,
|
|
751
729
|
pluginConfig
|
|
752
730
|
} = props;
|
|
731
|
+
const {
|
|
732
|
+
queries: preDefinedQueries
|
|
733
|
+
} = pluginConfig;
|
|
753
734
|
const originClient = useClient(clientConfig);
|
|
754
735
|
const schema = useSchema();
|
|
755
736
|
const schemaTypes = schema.getTypeNames();
|
|
756
737
|
const [value, setValue] = useState("");
|
|
738
|
+
const [fetched, setFetched] = useState(false);
|
|
757
739
|
const [initialData, setInitialData] = useState({
|
|
758
740
|
docs: []
|
|
759
741
|
// draftIds: []
|
|
@@ -767,6 +749,8 @@ function DuplicatorQuery(props) {
|
|
|
767
749
|
docs: registeredAndPublishedDocs
|
|
768
750
|
// draftIds: initialDraftIds
|
|
769
751
|
});
|
|
752
|
+
|
|
753
|
+
setFetched(true);
|
|
770
754
|
}).catch(err => console.error(err));
|
|
771
755
|
}
|
|
772
756
|
useEffect(() => {
|
|
@@ -781,9 +765,9 @@ function DuplicatorQuery(props) {
|
|
|
781
765
|
children: /* @__PURE__ */jsxs(Grid, {
|
|
782
766
|
columns: [1, 1, 1, 2],
|
|
783
767
|
gap: [1, 1, 1, 4],
|
|
784
|
-
children: [/* @__PURE__ */
|
|
768
|
+
children: [/* @__PURE__ */jsxs(Box, {
|
|
785
769
|
padding: [2, 2, 2, 0],
|
|
786
|
-
children: /* @__PURE__ */jsx(Card, {
|
|
770
|
+
children: [/* @__PURE__ */jsx(Card, {
|
|
787
771
|
padding: 4,
|
|
788
772
|
radius: 3,
|
|
789
773
|
border: true,
|
|
@@ -824,14 +808,38 @@ function DuplicatorQuery(props) {
|
|
|
824
808
|
})
|
|
825
809
|
})]
|
|
826
810
|
})
|
|
827
|
-
})
|
|
828
|
-
|
|
811
|
+
}), preDefinedQueries && (preDefinedQueries == null ? void 0 : preDefinedQueries.length) > 0 && /* @__PURE__ */jsx(Card, {
|
|
812
|
+
marginTop: 2,
|
|
813
|
+
padding: 4,
|
|
814
|
+
radius: 3,
|
|
815
|
+
border: true,
|
|
816
|
+
children: /* @__PURE__ */jsx(Box, {
|
|
817
|
+
children: /* @__PURE__ */jsxs(Stack, {
|
|
818
|
+
space: 4,
|
|
819
|
+
children: [/* @__PURE__ */jsx(Box, {
|
|
820
|
+
children: /* @__PURE__ */jsx(Label, {
|
|
821
|
+
children: "Predefined Queries"
|
|
822
|
+
})
|
|
823
|
+
}), /* @__PURE__ */jsx(Stack, {
|
|
824
|
+
space: 2,
|
|
825
|
+
children: preDefinedQueries.map(query => /* @__PURE__ */jsx(Button, {
|
|
826
|
+
padding: 2,
|
|
827
|
+
paddingX: 4,
|
|
828
|
+
tone: "primary",
|
|
829
|
+
onClick: () => setValue("*[".concat(query.query, "]")),
|
|
830
|
+
text: query.label
|
|
831
|
+
}, query.label.replace(/\s+/g, "-")))
|
|
832
|
+
})]
|
|
833
|
+
})
|
|
834
|
+
})
|
|
835
|
+
})]
|
|
836
|
+
}), fetched && initialData.docs.length < 1 && /* @__PURE__ */jsx(Container, {
|
|
829
837
|
width: 1,
|
|
830
838
|
children: /* @__PURE__ */jsx(Card, {
|
|
831
839
|
padding: 5,
|
|
832
|
-
children: value ? "No
|
|
840
|
+
children: value ? "No documents match this query" : "Start with a valid GROQ query"
|
|
833
841
|
})
|
|
834
|
-
}), ((
|
|
842
|
+
}), ((_a = initialData.docs) == null ? void 0 : _a.length) > 0 && /* @__PURE__ */jsx(Duplicator, {
|
|
835
843
|
docs: initialData.docs,
|
|
836
844
|
token,
|
|
837
845
|
pluginConfig
|
|
@@ -900,7 +908,8 @@ const DEFAULT_CONFIG = {
|
|
|
900
908
|
tool: true,
|
|
901
909
|
types: [],
|
|
902
910
|
filter: "",
|
|
903
|
-
follow: ["outbound"]
|
|
911
|
+
follow: ["outbound"],
|
|
912
|
+
queries: []
|
|
904
913
|
};
|
|
905
914
|
function ResetSecret() {
|
|
906
915
|
const client = useClient(clientConfig);
|