@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/dist/index.js
CHANGED
|
@@ -37,10 +37,7 @@ const stickyStyles = function () {
|
|
|
37
37
|
backgroundColor: isDarkMode ? "rgba(10,10,10,0.95)" : "rgba(255,255,255,0.95)"
|
|
38
38
|
};
|
|
39
39
|
};
|
|
40
|
-
const isAsset = doc => doc._type === "sanity.imageAsset" || doc._type === "sanity.fileAsset";
|
|
41
|
-
const returnOnlyAssets = references => references.filter(item => isAsset(item));
|
|
42
40
|
async function getDocumentsInArray(options) {
|
|
43
|
-
let recurrsionDepth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
44
41
|
const {
|
|
45
42
|
fetchIds,
|
|
46
43
|
client,
|
|
@@ -48,9 +45,6 @@ async function getDocumentsInArray(options) {
|
|
|
48
45
|
currentIds,
|
|
49
46
|
projection
|
|
50
47
|
} = options;
|
|
51
|
-
const {
|
|
52
|
-
reference
|
|
53
|
-
} = pluginConfig;
|
|
54
48
|
const collection = [];
|
|
55
49
|
const filter = ["_id in $fetchIds", pluginConfig.filter].filter(Boolean).join(" && ");
|
|
56
50
|
const query = "*[".concat(filter, "]").concat(projection != null ? projection : "");
|
|
@@ -71,35 +65,14 @@ async function getDocumentsInArray(options) {
|
|
|
71
65
|
if (references.length) {
|
|
72
66
|
const newReferenceIds = new Set(references.filter(ref => !localCurrentIds.has(ref)));
|
|
73
67
|
if (newReferenceIds.size) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
if (
|
|
83
|
-
// // If we are at the max depth and reference?.assetsOnly is falsy
|
|
84
|
-
(referenceDocs == null ? void 0 : referenceDocs.length) && recurrsionDepth === reference.maxDepth + 1 && !(reference == null ? void 0 : reference.assetsOnly)) {
|
|
85
|
-
collection.push(...referenceDocs);
|
|
86
|
-
} else if (
|
|
87
|
-
// // If we are at the max depth and reference?.assetsOnly is truthy
|
|
88
|
-
(referenceDocs == null ? void 0 : referenceDocs.length) && recurrsionDepth === reference.maxDepth + 1 && (reference == null ? void 0 : reference.assetsOnly)) {
|
|
89
|
-
collection.push(...returnOnlyAssets(referenceDocs));
|
|
90
|
-
} else if ((referenceDocs == null ? void 0 : referenceDocs.length) && recurrsionDepth < reference.maxDepth + 1) {
|
|
91
|
-
collection.push(...referenceDocs);
|
|
92
|
-
}
|
|
93
|
-
} else {
|
|
94
|
-
const referenceDocs = await getDocumentsInArray({
|
|
95
|
-
fetchIds: Array.from(newReferenceIds),
|
|
96
|
-
currentIds: localCurrentIds,
|
|
97
|
-
client,
|
|
98
|
-
pluginConfig
|
|
99
|
-
});
|
|
100
|
-
if (referenceDocs == null ? void 0 : referenceDocs.length) {
|
|
101
|
-
collection.push(...referenceDocs);
|
|
102
|
-
}
|
|
68
|
+
const referenceDocs = await getDocumentsInArray({
|
|
69
|
+
fetchIds: Array.from(newReferenceIds),
|
|
70
|
+
currentIds: localCurrentIds,
|
|
71
|
+
client,
|
|
72
|
+
pluginConfig
|
|
73
|
+
});
|
|
74
|
+
if (referenceDocs == null ? void 0 : referenceDocs.length) {
|
|
75
|
+
collection.push(...referenceDocs);
|
|
103
76
|
}
|
|
104
77
|
}
|
|
105
78
|
}
|
|
@@ -252,13 +225,18 @@ function StatusBadge(props) {
|
|
|
252
225
|
fallbackPlacements: ["right", "left"],
|
|
253
226
|
placement: "top",
|
|
254
227
|
portal: true,
|
|
255
|
-
children: /* @__PURE__ */jsxRuntime.
|
|
228
|
+
children: /* @__PURE__ */jsxRuntime.jsxs(ui.Badge, {
|
|
256
229
|
muted: true,
|
|
257
|
-
padding:
|
|
230
|
+
padding: 3,
|
|
258
231
|
fontSize: 1,
|
|
259
232
|
tone: badgeTone,
|
|
260
233
|
mode: "outline",
|
|
261
|
-
children: badgeStatus
|
|
234
|
+
children: [badgeStatus, /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
|
|
235
|
+
marginLeft: 2,
|
|
236
|
+
display: "inline-block",
|
|
237
|
+
as: "span",
|
|
238
|
+
children: /* @__PURE__ */jsxRuntime.jsx(icons.InfoOutlineIcon, {})
|
|
239
|
+
})]
|
|
262
240
|
})
|
|
263
241
|
});
|
|
264
242
|
}
|
|
@@ -295,7 +273,7 @@ function Duplicator(props) {
|
|
|
295
273
|
const workspaces = sanity.useWorkspaces();
|
|
296
274
|
const workspacesOptions = workspaces.map(workspace => ({
|
|
297
275
|
...workspace,
|
|
298
|
-
disabled: workspace.dataset === originClient.config().dataset
|
|
276
|
+
disabled: workspace.dataset === originClient.config().dataset && workspace.projectId === originClient.config().projectId
|
|
299
277
|
}));
|
|
300
278
|
const [destination, setDestination] = React.useState(workspaces.length ? (_a = workspacesOptions.find(space => !space.disabled)) != null ? _a : null : null);
|
|
301
279
|
const [message, setMessage] = React.useState(null);
|
|
@@ -316,7 +294,7 @@ function Duplicator(props) {
|
|
|
316
294
|
doc
|
|
317
295
|
});
|
|
318
296
|
});
|
|
319
|
-
|
|
297
|
+
updatePayloadStatuses(initialPayload);
|
|
320
298
|
const docCount = docs.length;
|
|
321
299
|
const refsCount = initialRefs.length;
|
|
322
300
|
if (initialRefs.length) {
|
|
@@ -758,15 +736,19 @@ function Duplicator(props) {
|
|
|
758
736
|
});
|
|
759
737
|
}
|
|
760
738
|
function DuplicatorQuery(props) {
|
|
761
|
-
var _a
|
|
739
|
+
var _a;
|
|
762
740
|
const {
|
|
763
741
|
token,
|
|
764
742
|
pluginConfig
|
|
765
743
|
} = props;
|
|
744
|
+
const {
|
|
745
|
+
queries: preDefinedQueries
|
|
746
|
+
} = pluginConfig;
|
|
766
747
|
const originClient = sanity.useClient(clientConfig);
|
|
767
748
|
const schema = sanity.useSchema();
|
|
768
749
|
const schemaTypes = schema.getTypeNames();
|
|
769
750
|
const [value, setValue] = React.useState("");
|
|
751
|
+
const [fetched, setFetched] = React.useState(false);
|
|
770
752
|
const [initialData, setInitialData] = React.useState({
|
|
771
753
|
docs: []
|
|
772
754
|
// draftIds: []
|
|
@@ -780,6 +762,8 @@ function DuplicatorQuery(props) {
|
|
|
780
762
|
docs: registeredAndPublishedDocs
|
|
781
763
|
// draftIds: initialDraftIds
|
|
782
764
|
});
|
|
765
|
+
|
|
766
|
+
setFetched(true);
|
|
783
767
|
}).catch(err => console.error(err));
|
|
784
768
|
}
|
|
785
769
|
React.useEffect(() => {
|
|
@@ -794,9 +778,9 @@ function DuplicatorQuery(props) {
|
|
|
794
778
|
children: /* @__PURE__ */jsxRuntime.jsxs(ui.Grid, {
|
|
795
779
|
columns: [1, 1, 1, 2],
|
|
796
780
|
gap: [1, 1, 1, 4],
|
|
797
|
-
children: [/* @__PURE__ */jsxRuntime.
|
|
781
|
+
children: [/* @__PURE__ */jsxRuntime.jsxs(ui.Box, {
|
|
798
782
|
padding: [2, 2, 2, 0],
|
|
799
|
-
children: /* @__PURE__ */jsxRuntime.jsx(ui.Card, {
|
|
783
|
+
children: [/* @__PURE__ */jsxRuntime.jsx(ui.Card, {
|
|
800
784
|
padding: 4,
|
|
801
785
|
radius: 3,
|
|
802
786
|
border: true,
|
|
@@ -837,14 +821,38 @@ function DuplicatorQuery(props) {
|
|
|
837
821
|
})
|
|
838
822
|
})]
|
|
839
823
|
})
|
|
840
|
-
})
|
|
841
|
-
|
|
824
|
+
}), preDefinedQueries && (preDefinedQueries == null ? void 0 : preDefinedQueries.length) > 0 && /* @__PURE__ */jsxRuntime.jsx(ui.Card, {
|
|
825
|
+
marginTop: 2,
|
|
826
|
+
padding: 4,
|
|
827
|
+
radius: 3,
|
|
828
|
+
border: true,
|
|
829
|
+
children: /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
|
|
830
|
+
children: /* @__PURE__ */jsxRuntime.jsxs(ui.Stack, {
|
|
831
|
+
space: 4,
|
|
832
|
+
children: [/* @__PURE__ */jsxRuntime.jsx(ui.Box, {
|
|
833
|
+
children: /* @__PURE__ */jsxRuntime.jsx(ui.Label, {
|
|
834
|
+
children: "Predefined Queries"
|
|
835
|
+
})
|
|
836
|
+
}), /* @__PURE__ */jsxRuntime.jsx(ui.Stack, {
|
|
837
|
+
space: 2,
|
|
838
|
+
children: preDefinedQueries.map(query => /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
|
|
839
|
+
padding: 2,
|
|
840
|
+
paddingX: 4,
|
|
841
|
+
tone: "primary",
|
|
842
|
+
onClick: () => setValue("*[".concat(query.query, "]")),
|
|
843
|
+
text: query.label
|
|
844
|
+
}, query.label.replace(/\s+/g, "-")))
|
|
845
|
+
})]
|
|
846
|
+
})
|
|
847
|
+
})
|
|
848
|
+
})]
|
|
849
|
+
}), fetched && initialData.docs.length < 1 && /* @__PURE__ */jsxRuntime.jsx(ui.Container, {
|
|
842
850
|
width: 1,
|
|
843
851
|
children: /* @__PURE__ */jsxRuntime.jsx(ui.Card, {
|
|
844
852
|
padding: 5,
|
|
845
|
-
children: value ? "No
|
|
853
|
+
children: value ? "No documents match this query" : "Start with a valid GROQ query"
|
|
846
854
|
})
|
|
847
|
-
}), ((
|
|
855
|
+
}), ((_a = initialData.docs) == null ? void 0 : _a.length) > 0 && /* @__PURE__ */jsxRuntime.jsx(Duplicator, {
|
|
848
856
|
docs: initialData.docs,
|
|
849
857
|
token,
|
|
850
858
|
pluginConfig
|
|
@@ -913,7 +921,8 @@ const DEFAULT_CONFIG = {
|
|
|
913
921
|
tool: true,
|
|
914
922
|
types: [],
|
|
915
923
|
filter: "",
|
|
916
|
-
follow: ["outbound"]
|
|
924
|
+
follow: ["outbound"],
|
|
925
|
+
queries: []
|
|
917
926
|
};
|
|
918
927
|
function ResetSecret() {
|
|
919
928
|
const client = sanity.useClient(clientConfig);
|