@sanity/cross-dataset-duplicator 1.0.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 +4 -6
- package/lib/index.esm.js +1 -2
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +1 -2
- package/lib/index.js.map +1 -1
- package/lib/src/index.d.ts +529 -1
- package/package.json +1 -1
- package/src/actions/DuplicateToAction.tsx +10 -24
- package/src/components/CrossDatasetDuplicator.tsx +6 -17
- package/src/components/CrossDatasetDuplicatorAction.tsx +14 -0
- package/src/components/CrossDatasetDuplicatorTool.tsx +18 -0
- package/src/context/ConfigProvider.tsx +30 -0
- package/src/helpers/constants.ts +9 -0
- package/src/index.ts +4 -35
- package/src/plugin.tsx +31 -0
- package/src/tool/index.ts +3 -6
- package/src/types/index.ts +10 -0
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -19,9 +19,9 @@ This plugin is designed as a convenience for Authors to make small, infrequent c
|
|
|
19
19
|
|
|
20
20
|
- This plugin should be used in conjunction with a reliable backup strategy.
|
|
21
21
|
- Proceed with caution as this plugin can instantly write changes to Datasets.
|
|
22
|
-
- Larger migrations may take more time, especially with Assets.
|
|
22
|
+
- Larger migrations may take more time, especially with Assets. Trying to upload them all at once could result in a rate-limiting issue, so the plugin mitigates this by limiting simultaneous asset uploads to 3.
|
|
23
23
|
- If an Asset is already present at the destination, there's no need to duplicate it again.
|
|
24
|
-
- Before starting a Duplication you can select which Documents and Assets to include. Migrations will fail if every Referenced Document or Asset is not included in the transaction or already present at the destination Dataset.
|
|
24
|
+
- Before starting a Duplication you can select which Documents and Assets to include. Migrations will fail if every Referenced Document or Asset is not included in the transaction or is already present at the destination Dataset.
|
|
25
25
|
|
|
26
26
|
## Tool
|
|
27
27
|
|
|
@@ -35,17 +35,15 @@ The **Duplicate to...** Document Action allows you to migrate an individual Docu
|
|
|
35
35
|
|
|
36
36
|

|
|
37
37
|
|
|
38
|
-
**Note:** If your Studio registered its own Document Actions, the plugin config will be overruled. See "Importing the Document Action" below.
|
|
39
|
-
|
|
40
38
|
## Required Setup
|
|
41
39
|
|
|
42
40
|
### 1. Workspaces
|
|
43
41
|
|
|
44
42
|
You must have more than one [Workspace configured](https://www.sanity.io/docs/config-api-reference#37c85e3072b2) to use this plugin.
|
|
45
43
|
|
|
46
|
-
All Datasets and Project
|
|
44
|
+
All Datasets and Project IDs set up as Workspaces will become selectable "destinations" for Migrations.
|
|
47
45
|
|
|
48
|
-
Once
|
|
46
|
+
Once set up, you will see a dropdown menu next to the Search bar in the Studio with the Datasets you have configured.
|
|
49
47
|
|
|
50
48
|
### 2. Configuration
|
|
51
49
|
|
package/lib/index.esm.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
function e(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,i)}return n}function t(t){for(var i=1;i<arguments.length;i++){var o=null!=arguments[i]?arguments[i]:{};i%2?e(Object(o),!0).forEach((function(e){n(t,e,o[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(o)):e(Object(o)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(o,e))}))}return t}function n(e,t,n){return(t=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var i=n.call(e,t||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}import{useClient as i,useSchema as o,useWorkspaces as a,Preview as d,definePlugin as l}from"sanity";import{jsx as r,jsxs as c,Fragment as s}from"react/jsx-runtime";import u,{useState as h,useEffect as p}from"react";import{ArrowRightIcon as f,SearchIcon as g,LaunchIcon as m}from"@sanity/icons";import{useSecrets as b,SettingsView as y}from"@sanity/studio-secrets";import{Card as v,Flex as w,Button as D,Badge as E,Tooltip as T,Box as S,Text as A,useTheme as I,Container as C,Stack as _,Label as O,Select as x,Checkbox as k,Grid as R,TextInput as j,Spinner as P}from"@sanity/ui";import U from"async/mapLimit";import z from"async/asyncify";import{extractWithPath as B}from"@sanity/mutator";import{dset as N}from"dset";import{isAssetId as L,isSanityFileAsset as X}from"@sanity/asset-utils";function V(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;const n=[1===e?"This Document contains":"These ".concat(e," Documents contain"),1===t?"1 Reference.":"".concat(t," References."),1===t?"That Document":"Those Documents","may have References too. If referenced Documents do not exist at the target Destination, this transaction will fail."];return n.join(" ")}const W=function(){let e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];return{position:"sticky",top:0,zIndex:100,backgroundColor:e?"rgba(10,10,10,0.95)":"rgba(255,255,255,0.95)"}};async function q(e){const{fetchIds:t,client:n,pluginConfig:i,currentIds:o,projection:a}=e,d=[],l=["_id in $fetchIds",i.filter].filter(Boolean).join(" && "),r="*[".concat(l,"]").concat(null!=a?a:""),c=await n.fetch(r,{fetchIds:null!=t?t:[]});if(!(null==c?void 0:c.length))return[];const s=null!=o?o:new Set,u=new Set(c.map((e=>e._id)).filter((e=>(null==o?void 0:o.size)?!s.has(e):Boolean(e))));u.size&&(d.push(...c),s.add(...u),await Promise.all(c.map((async e=>{const t=B(".._ref",e).map((e=>e.value));if(t.length){const e=new Set(t.filter((e=>!s.has(e))));if(e.size){const t=await q({fetchIds:Array.from(e),currentIds:s,client:n,pluginConfig:i});(null==t?void 0:t.length)&&d.push(...t)}}}))));return d.filter(Boolean).reduce(((e,t)=>e.some((e=>e._id===t._id))?e:[...e,t]),[])}const H=["All","None",null,"New","Existing","Older",null,"Documents","Assets"];function G(e){const{payload:t,setPayload:n}=e,[i,o]=h([]);return p((()=>{!(null==i?void 0:i.length)&&t.every((e=>e.include))&&o(["ALL"])}),[null==i?void 0:i.length,t]),r(v,{padding:1,radius:3,shadow:1,children:r(w,{gap:2,children:H.map(((e,a)=>e?r(D,{fontSize:1,mode:"bleed",padding:2,text:e,disabled:i.includes(e.toUpperCase()),onClick:()=>function(e){if(!e||!t.length)return;const i=[...t];switch(e){case"ALL":i.map((e=>e.include=!0));break;case"NONE":i.map((e=>e.include=!1));break;case"NEW":i.map((e=>e.include=Boolean("CREATE"===e.status)));break;case"EXISTING":i.map((e=>e.include=Boolean("EXISTS"===e.status)));break;case"OLDER":i.map((e=>e.include=Boolean("OVERWRITE"===e.status)));break;case"ASSETS":i.map((e=>e.include=L(e.doc._id)));break;case"DOCUMENTS":i.map((e=>e.include=!L(e.doc._id)))}o([e]),n(i)}(e.toUpperCase())},e):r(v,{borderLeft:!0},"divider-".concat(a))))})})}const F={EXISTS:"primary",OVERWRITE:"critical",UPDATE:"caution",CREATE:"positive",UNPUBLISHED:"caution"},Q={EXISTS:"critical",OVERWRITE:"critical",UPDATE:"critical",CREATE:"positive",UNPUBLISHED:"default"},$={EXISTS:"This document already exists at the Destination with the same ID with the same Updated time.",OVERWRITE:"A newer version of this document exists at the Destination, and it will be overwritten with this version.",UPDATE:"An older version of this document exists at the Destination, and it will be overwritten with this version.",CREATE:"This document will be created at the destination.",UNPUBLISHED:"A Draft version of this Document exists in this Dataset, but only the Published version will be duplicated to the destination."},M={EXISTS:"This Asset already exists at the Destination",OVERWRITE:"This Asset already exists at the Destination",UPDATE:"This Asset already exists at the Destination",CREATE:"This Asset does not yet exist at the Destination",UNPUBLISHED:""},Y={EXISTS:"RE-UPLOAD",OVERWRITE:"RE-UPLOAD",UPDATE:"RE-UPLOAD",CREATE:"UPLOAD",UNPUBLISHED:""};function J(e){const{status:t,isAsset:n}=e;if(!t)return null;const i=n?Q[t]:F[t];if(!i)return r(E,{muted:!0,padding:2,fontSize:1,mode:"outline",children:"Checking..."});const o=n?Y[t]:t;return r(T,{content:r(S,{padding:3,style:{maxWidth:200},children:r(A,{size:1,children:n?M[t]:$[t]})}),fallbackPlacements:["right","left"],placement:"top",portal:!0,children:r(E,{muted:!0,padding:2,fontSize:1,tone:i,mode:"outline",children:o})})}function K(e){const{children:t,tone:n="caution"}=e;return r(v,{padding:3,radius:2,shadow:1,tone:n,children:r(A,{size:1,children:t})})}const Z={apiVersion:"2021-05-19"};function ee(e){var n,l,b;const{docs:y,token:E,pluginConfig:T}=e,R=I().sanity.color.dark,j=i(Z),P=o(),H=a(),F=H.map((e=>t(t({},e),{},{disabled:e.dataset===j.config().dataset}))),[Q,$]=h(H.length&&null!=(n=F.find((e=>!e.disabled)))?n:null),[M,Y]=h(null),[ee,te]=h([]),[ne,ie]=h(!1),[oe,ae]=h(!1),[de,le]=h(!1),[re,ce]=h([0,0]);async function se(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];const n=e.length?e:ee;if(!n.length||!(null==Q?void 0:Q.name))return;const i=n.map((e=>{let{doc:t}=e;return t._id})),o=j.withConfig(t(t({},Z),{},{dataset:Q.dataset,projectId:Q.projectId})),a=await o.fetch("*[_id in $payloadIds]{ _id, _updatedAt }",{payloadIds:i}),d=n.map((e=>{var t;const n=a.find((t=>t._id===e.doc._id));return(null==n?void 0:n._updatedAt)&&(null==(t=null==e?void 0:e.doc)?void 0:t._updatedAt)?n._updatedAt===e.doc._updatedAt?e.status="EXISTS":n._updatedAt&&e.doc._updatedAt&&(e.status=new Date(n._updatedAt)>new Date(e.doc._updatedAt)?"OVERWRITE":"UPDATE"):e.status="CREATE",e}));te(d)}p((()=>{const e=[],t=[];y.forEach((n=>{const i=B(".._ref",n).map((e=>e.value));e.push(...i),t.push({include:!0,doc:n})})),te(t);const n=y.length,i=e.length;e.length&&(ie(!0),Y({tone:"caution",text:V(n,i)}))}),[y]),p((()=>{se()}),[Q]);const ue=ee.length,he=ee.findIndex((e=>{let{doc:t}=e;return"svg"===t.extension})),pe=ee.filter((e=>e.include&&!L(e.doc._id))).length,fe=ee.filter((e=>e.include&&L(e.doc._id))).length,ge=pe+fe,me=null!=(l=null==Q?void 0:Q.title)?l:null==Q?void 0:Q.name,be=new Set(F.map((e=>null==e?void 0:e.projectId)).filter(Boolean)).size>1,ye=[ge,"/",ue,"Documents and Assets selected"].join(" "),ve=u.useMemo((()=>{const e=["Duplicate"];return pe>1&&e.push(String(pe),1===pe?"Document":"Documents"),fe>1&&e.push("and",String(fe),1===fe?"Asset":"Assets"),j.config().projectId!==(null==Q?void 0:Q.projectId)&&e.push("between Projects"),e.push("to",String(me)),e.join(" ")}),[pe,fe,j,null==Q?void 0:Q.projectId,me]);return F.length<2?c(K,{tone:"critical",children:[r("code",{children:"sanity.config.ts"})," must contain at least two Workspaces to use this plugin."]}):r(C,{width:1,children:r(v,{border:!0,children:r(_,{children:c(s,{children:[r(v,{borderBottom:!0,padding:4,style:W(R),children:c(_,{space:4,children:[c(w,{gap:3,children:[c(_,{style:{flex:1},space:3,children:[r(O,{children:"Duplicate from"}),r(x,{readOnly:!0,value:null==(b=F.find((e=>e.disabled)))?void 0:b.name,children:F.filter((e=>e.disabled)).map((e=>{var t;return c("option",{value:e.name,disabled:e.disabled,children:[null!=(t=e.title)?t:e.name,be?" (".concat(e.projectId,")"):""]},e.name)}))})]}),r(S,{padding:4,paddingTop:5,paddingBottom:0,children:r(A,{size:3,children:r(f,{})})}),c(_,{style:{flex:1},space:3,children:[r(O,{children:"To Destination"}),r(x,{onChange:function(e){if(!F.length)return;const t=F.find((t=>t.name===e.currentTarget.value));t&&$(t)},children:F.map((e=>{var t;return c("option",{value:e.name,disabled:e.disabled,children:[null!=(t=e.title)?t:e.name,be?" (".concat(e.projectId,")"):"",e.disabled?" (Current)":""]},e.name)}))})]})]}),oe&&r(v,{border:!0,radius:2,children:r(v,{style:{width:"100%",transform:"scaleX(".concat(re[0]/re[1],")"),transformOrigin:"left",transition:"transform .2s ease",boxSizing:"border-box"},padding:1,tone:"positive"})}),ee.length>0&&c(s,{children:[r(O,{children:ye}),r(G,{payload:ee,setPayload:te})]})]})}),M&&r(S,{paddingX:4,paddingTop:4,children:r(v,{padding:3,radius:2,shadow:1,tone:M.tone,children:r(A,{size:1,children:M.text})})}),ee.length>0&&r(_,{padding:4,space:3,children:ee.map(((e,t)=>{let{doc:n,include:i,status:o,hasDraft:a}=e;const l=P.get(n._type);return c(u.Fragment,{children:[c(w,{align:"center",children:[r(k,{checked:i,onChange:()=>function(e){const t=ee.map((t=>(t.doc._id===e&&(t.include=!t.include),t)));te(t)}(n._id)}),r(S,{flex:1,paddingX:3,children:l?r(d,{value:n,schemaType:l}):r(v,{tone:"caution",children:"Invalid schema type"})}),c(w,{align:"center",gap:2,children:[a?r(J,{status:"UNPUBLISHED",isAsset:!1}):null,r(J,{status:o,isAsset:L(n._id)})]})]}),"svg"===(null==n?void 0:n.extension)&&t===he&&r(v,{padding:3,radius:2,shadow:1,tone:"caution",children:c(A,{size:1,children:["Due to how SVGs are sanitized after first uploaded, duplicated SVG assets may have new ",r("code",{children:"_id"}),"'s at the destination. The newly generated ",r("code",{children:"_id"})," will be the same in each duplication, but it will never be the same ",r("code",{children:"_id"})," as the first time this Asset was uploaded. References to the asset will be updated to use the new"," ",r("code",{children:"_id"}),"."]})})]},n._id)}))}),c(_,{space:2,padding:4,paddingTop:0,children:[ne&&r(D,{fontSize:2,padding:4,tone:"positive",mode:"ghost",icon:g,onClick:async function(){le(!0);const e=y.map((e=>e._id)),t=await q({fetchIds:e,client:j,pluginConfig:T}),n=await q({fetchIds:e.map((e=>"drafts.".concat(e))),client:j,projection:"{_id}",pluginConfig:T}),i=new Set(n.map((e=>{let{_id:t}=e;return t}))),o=t.map((e=>({doc:e,include:!0,status:void 0,hasDraft:i.has("drafts.".concat(e._id))})));te(o),se(o),le(!1)},text:"Gather References",disabled:oe||!ge||de}),r(D,{fontSize:2,padding:4,tone:"positive",icon:m,onClick:async function(){if(!Q)return;ae(!0);const e=ee.filter((e=>{let{doc:t,include:n}=e;return n&&L(t._id)})).length;let n=0;ce([n,e]),Y({text:"Duplicating...",tone:"default"});const i=j.withConfig(t(t({},Z),{},{dataset:Q.dataset,projectId:Q.projectId})),o=[],a=[];async function d(t){if(L(t._id)){const d=X(t),l=d?t.url:"".concat(t.url,"?dlRaw=true"),r=d?{}:{headers:{Authorization:"Bearer ".concat(E)}};return await fetch(l,r).then((async e=>{const n=await e.blob(),l={filename:t.originalFilename},r=await i.assets.upload(d?"file":"image",n,l);"svg"===(null==t?void 0:t.extension)&&a.push({old:t._id,new:r._id}),o.push(r)})),n+=1,Y({text:"Duplicating ".concat(n,"/").concat(e," ").concat("Assets"),tone:"default"}),ce([n,e])}return o.push(t)}const l=new Promise(((e,t)=>{const n=ee.filter((e=>e.include)).map((e=>e.doc));U(n,3,z(d),(n=>{n&&(ae(!1),Y({tone:"critical",text:"Duplication Failed"}),console.error(n),t(new Error("Duplication Failed"))),e()}))}));await l;const r=o.map((e=>{const t=B(".._ref",e);return t.length?(t.forEach((t=>{var n;const i=null==(n=a.find((e=>e.old===t.value)))?void 0:n.new;if(i){const n=t.path.join(".");N(e,n,i)}})),e):e})),c=i.transaction();r.forEach((e=>{c.createOrReplace(e)})),await c.commit().then((e=>{Y({tone:"positive",text:"Duplication complete!"}),se()})).catch((e=>{Y({tone:"critical",text:e.details.description})})),ae(!1),ce([0,0])},text:ve,disabled:oe||!ge||de})]})]})})})})}function te(e){var t,n;const{token:a,pluginConfig:d}=e,l=i(Z),s=o().getTypeNames(),[u,f]=h(""),[g,m]=h({docs:[]});function b(e){e&&e.preventDefault(),l.fetch(u).then((e=>{const t=e.length?e.filter((e=>s.includes(e._type))).filter((e=>!e._id.startsWith("drafts."))):[];m({docs:t})})).catch((e=>console.error(e)))}return p((()=>{var e;!(null==(e=g.docs)?void 0:e.length)&&u&&b()}),[]),r(C,{width:[1,1,1,3],padding:[0,0,0,5],children:c(R,{columns:[1,1,1,2],gap:[1,1,1,4],children:[r(S,{padding:[2,2,2,0],children:r(v,{padding:4,radius:3,border:!0,children:c(_,{space:4,children:[r(S,{children:r(O,{children:"Initial Documents Query"})}),r(S,{children:r(A,{children:"Start with a valid GROQ query to load initial documents. The query will need to return an Array of Objects. Drafts will be removed from the results."})}),r("form",{onSubmit:b,children:c(w,{children:[r(S,{flex:1,paddingRight:2,children:r(j,{style:{fontFamily:"monospace"},fontSize:2,onChange:e=>f(e.currentTarget.value),padding:4,placeholder:'*[_type == "article"]',value:null!=u?u:""})}),r(D,{padding:2,paddingX:4,tone:"primary",onClick:b,text:"Query",disabled:!u})]})})]})})}),!(null==(t=g.docs)?void 0:t.length)||g.docs.length<1&&r(C,{width:1,children:r(v,{padding:5,children:u?"No Documents registered to the Schema match this query":"Start with a valid GROQ query"})}),(null==(n=g.docs)?void 0:n.length)>0&&r(ee,{docs:g.docs,token:a,pluginConfig:d})]})})}function ne(e){const{docs:t,token:n,pluginConfig:o}=e,[a,d]=h([]),{follow:l=[]}=o,[s,u]=h(1===l.length?l[0]:"outbound"),f=i();return p((()=>{(async()=>{if(l.includes("inbound")){const n=await f.fetch("*[references($id)]",{id:t[0]._id});d([...e.docs,...n])}})()}),[]),c(C,{children:[l.length>1&&(l.includes("inbound")||l.includes("outbound"))?r(v,{paddingX:4,paddingBottom:4,marginBottom:4,borderBottom:!0,children:c(R,{columns:2,gap:4,children:[l.includes("outbound")?r(D,{mode:"ghost",tone:"primary",selected:"outbound"===s,onClick:()=>u("outbound"),text:"Outbound"}):null,l.includes("inbound")?r(D,{mode:"ghost",tone:"primary",selected:"inbound"===s,onClick:()=>u("inbound"),disabled:0===a.length,text:a.length>0?"Inbound (".concat(a.length,")"):"No inbound references"}):null]})}):null,r(ee,{docs:"outbound"===s?t:a,token:n,pluginConfig:o})]})}const ie="CrossDatasetDuplicator";function oe(){const e=i(Z),t=u.useCallback((()=>{e.delete({query:'*[_id == "secrets.'.concat(ie,'"]')})}),[e]);return r(w,{align:"center",justify:"flex-end",paddingX:[2,2,2,5],paddingY:5,children:r(D,{text:"Reset Secret",onClick:t,mode:"ghost",tone:"critical",fontSize:1,padding:2})})}const ae=[{key:"bearerToken",title:"An API token with Viewer permissions is required to duplicate the original files of assets, and will be used for all Duplications. Create one at sanity.io/manage",description:""}];function de(e){var t;const{mode:n="tool",docs:i=[],pluginConfig:o}=null!=(t=e.tool.options)?t:{},{loading:a,secrets:d}=b(ie),[l,u]=h(!1);return p((()=>{d&&u(!(null==d?void 0:d.bearerToken))}),[d]),a?r(w,{justify:"center",align:"center",children:r(S,{padding:5,children:r(P,{})})}):!a&&l||!(null==d?void 0:d.bearerToken)?r(y,{title:"Token Required",namespace:ie,keys:ae,onClose:()=>u(!1)}):"tool"===n&&o?c(s,{children:[r(te,{token:null==d?void 0:d.bearerToken,pluginConfig:o}),r(oe,{})]}):(null==i?void 0:i.length)?o?r(ne,{docs:i,token:null==d?void 0:d.bearerToken,pluginConfig:o}):r(K,{children:"No plugin config"}):r(K,{children:"No docs passed into Duplicator Tool"})}function le(e){let{draft:t,published:n,onComplete:i,pluginConfig:o}=e;const[a,d]=h(!1);return{disabled:t,title:t?"Document must be Published to begin":null,label:"Duplicate to...",dialog:a&&n&&{type:"modal",title:"Cross Dataset Duplicator",content:r(de,{tool:{options:{mode:"action",docs:[n],pluginConfig:o}}}),onClose:()=>{i(),d(!1)}},onHandle:()=>d(!0),icon:m}}const re=e=>({title:"Duplicator",name:"duplicator",icon:m,component:de,options:{mode:"tool",docs:[],pluginConfig:e}}),ce={tool:!0,types:[],filter:"",follow:["outbound"]},se=l((function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const n=t(t({},ce),e),{types:i}=n;return{name:"@sanity/cross-dataset-duplicator",tools:e=>n.tool?[...e,re(n)]:e,document:{actions:(e,o)=>{let{schemaType:a}=o;return i&&i.includes(a)?[...e,e=>le(t(t({},e),{},{pluginConfig:n}))]:e}}}}));export{se as crossDatasetDuplicator};
|
|
2
|
-
//# sourceMappingURL=index.esm.js.map
|
|
1
|
+
const e=["pluginConfig"];function t(e,t){if(null==e)return{};var n,i,o=function(e,t){if(null==e)return{};var n,i,o={},r=Object.keys(e);for(i=0;i<r.length;i++)n=r[i],t.indexOf(n)>=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);for(i=0;i<r.length;i++)n=r[i],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}function n(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,i)}return n}function i(e){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{};t%2?n(Object(i),!0).forEach((function(t){o(e,t,i[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):n(Object(i)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))}))}return e}function o(e,t,n){return(t=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var i=n.call(e,t||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}import{useClient as r,useSchema as a,useWorkspaces as l,Preview as d,definePlugin as c}from"sanity";import{jsx as s,jsxs as u,Fragment as h}from"react/jsx-runtime";import p,{useState as f,useEffect as g,createContext as m,useContext as b}from"react";import{ArrowRightIcon as y,SearchIcon as v,LaunchIcon as w}from"@sanity/icons";import{useSecrets as D,SettingsView as E}from"@sanity/studio-secrets";import{Card as T,Flex as S,Button as A,Badge as I,Tooltip as O,Box as _,Text as C,useTheme as x,Container as j,Stack as k,Label as P,Select as R,Checkbox as U,Grid as z,TextInput as B,Spinner as N}from"@sanity/ui";import L from"async/mapLimit";import X from"async/asyncify";import{extractWithPath as V}from"@sanity/mutator";import{dset as W}from"dset";import{isAssetId as q,isSanityFileAsset as H}from"@sanity/asset-utils";function G(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return[1===e?"This Document contains":"These ".concat(e," Documents contain"),1===t?"1 Reference.":"".concat(t," References."),1===t?"That Document":"Those Documents","may have References too. If referenced Documents do not exist at the target Destination, this transaction will fail."].join(" ")}const F=function(){return{position:"sticky",top:0,zIndex:100,backgroundColor:!(arguments.length>0&&void 0!==arguments[0])||arguments[0]?"rgba(10,10,10,0.95)":"rgba(255,255,255,0.95)"}};async function Q(e){const{fetchIds:t,client:n,pluginConfig:i,currentIds:o,projection:r}=e,a=[],l=["_id in $fetchIds",i.filter].filter(Boolean).join(" && "),d="*[".concat(l,"]").concat(null!=r?r:""),c=await n.fetch(d,{fetchIds:null!=t?t:[]});if(!(null==c?void 0:c.length))return[];const s=null!=o?o:new Set,u=new Set(c.map((e=>e._id)).filter((e=>(null==o?void 0:o.size)?!s.has(e):Boolean(e))));u.size&&(a.push(...c),s.add(...u),await Promise.all(c.map((async e=>{const t=V(".._ref",e).map((e=>e.value));if(t.length){const e=new Set(t.filter((e=>!s.has(e))));if(e.size){const t=await Q({fetchIds:Array.from(e),currentIds:s,client:n,pluginConfig:i});(null==t?void 0:t.length)&&a.push(...t)}}}))));return a.filter(Boolean).reduce(((e,t)=>e.some((e=>e._id===t._id))?e:[...e,t]),[])}const $=["All","None",null,"New","Existing","Older",null,"Documents","Assets"];function M(e){const{payload:t,setPayload:n}=e,[i,o]=f([]);return g((()=>{!(null==i?void 0:i.length)&&t.every((e=>e.include))&&o(["ALL"])}),[null==i?void 0:i.length,t]),s(T,{padding:1,radius:3,shadow:1,children:s(S,{gap:2,children:$.map(((e,r)=>e?s(A,{fontSize:1,mode:"bleed",padding:2,text:e,disabled:i.includes(e.toUpperCase()),onClick:()=>function(e){if(!e||!t.length)return;const i=[...t];switch(e){case"ALL":i.map((e=>e.include=!0));break;case"NONE":i.map((e=>e.include=!1));break;case"NEW":i.map((e=>e.include=Boolean("CREATE"===e.status)));break;case"EXISTING":i.map((e=>e.include=Boolean("EXISTS"===e.status)));break;case"OLDER":i.map((e=>e.include=Boolean("OVERWRITE"===e.status)));break;case"ASSETS":i.map((e=>e.include=q(e.doc._id)));break;case"DOCUMENTS":i.map((e=>e.include=!q(e.doc._id)))}o([e]),n(i)}(e.toUpperCase())},e):s(T,{borderLeft:!0},"divider-".concat(r))))})})}const Y={EXISTS:"primary",OVERWRITE:"critical",UPDATE:"caution",CREATE:"positive",UNPUBLISHED:"caution"},J={EXISTS:"critical",OVERWRITE:"critical",UPDATE:"critical",CREATE:"positive",UNPUBLISHED:"default"},K={EXISTS:"This document already exists at the Destination with the same ID with the same Updated time.",OVERWRITE:"A newer version of this document exists at the Destination, and it will be overwritten with this version.",UPDATE:"An older version of this document exists at the Destination, and it will be overwritten with this version.",CREATE:"This document will be created at the destination.",UNPUBLISHED:"A Draft version of this Document exists in this Dataset, but only the Published version will be duplicated to the destination."},Z={EXISTS:"This Asset already exists at the Destination",OVERWRITE:"This Asset already exists at the Destination",UPDATE:"This Asset already exists at the Destination",CREATE:"This Asset does not yet exist at the Destination",UNPUBLISHED:""},ee={EXISTS:"RE-UPLOAD",OVERWRITE:"RE-UPLOAD",UPDATE:"RE-UPLOAD",CREATE:"UPLOAD",UNPUBLISHED:""};function te(e){const{status:t,isAsset:n}=e;if(!t)return null;const i=n?J[t]:Y[t];if(!i)return s(I,{muted:!0,padding:2,fontSize:1,mode:"outline",children:"Checking..."});const o=n?Z[t]:K[t],r=n?ee[t]:t;return s(O,{content:s(_,{padding:3,style:{maxWidth:200},children:s(C,{size:1,children:o})}),fallbackPlacements:["right","left"],placement:"top",portal:!0,children:s(I,{muted:!0,padding:2,fontSize:1,tone:i,mode:"outline",children:r})})}function ne(e){const{children:t,tone:n="caution"}=e;return s(T,{padding:3,radius:2,shadow:1,tone:n,children:s(C,{size:1,children:t})})}const ie={apiVersion:"2021-05-19"};function oe(e){var t,n,o;const{docs:c,token:m,pluginConfig:b}=e,D=x().sanity.color.dark,E=r(ie),I=a(),O=l(),z=O.map((e=>i(i({},e),{},{disabled:e.dataset===E.config().dataset}))),[B,N]=f(O.length&&null!=(t=z.find((e=>!e.disabled)))?t:null),[$,Y]=f(null),[J,K]=f([]),[Z,ee]=f(!1),[oe,re]=f(!1),[ae,le]=f(!1),[de,ce]=f([0,0]);async function se(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];const t=e.length?e:J;if(!t.length||!(null==B?void 0:B.name))return;const n=t.map((e=>{let{doc:t}=e;return t._id})),o=E.withConfig(i(i({},ie),{},{dataset:B.dataset,projectId:B.projectId})),r=await o.fetch("*[_id in $payloadIds]{ _id, _updatedAt }",{payloadIds:n}),a=t.map((e=>{var t;const n=r.find((t=>t._id===e.doc._id));return(null==n?void 0:n._updatedAt)&&(null==(t=null==e?void 0:e.doc)?void 0:t._updatedAt)?n._updatedAt===e.doc._updatedAt?e.status="EXISTS":n._updatedAt&&e.doc._updatedAt&&(e.status=new Date(n._updatedAt)>new Date(e.doc._updatedAt)?"OVERWRITE":"UPDATE"):e.status="CREATE",e}));K(a)}g((()=>{const e=[],t=[];c.forEach((n=>{const i=V(".._ref",n).map((e=>e.value));e.push(...i),t.push({include:!0,doc:n})})),K(t);const n=c.length,i=e.length;e.length&&(ee(!0),Y({tone:"caution",text:G(n,i)}))}),[c]),g((()=>{se()}),[B]);const ue=J.length,he=J.findIndex((e=>{let{doc:t}=e;return"svg"===t.extension})),pe=J.filter((e=>e.include&&!q(e.doc._id))).length,fe=J.filter((e=>e.include&&q(e.doc._id))).length,ge=pe+fe,me=null!=(n=null==B?void 0:B.title)?n:null==B?void 0:B.name,be=new Set(z.map((e=>null==e?void 0:e.projectId)).filter(Boolean)).size>1,ye=[ge,"/",ue,"Documents and Assets selected"].join(" "),ve=p.useMemo((()=>{const e=["Duplicate"];return pe>1&&e.push(String(pe),1===pe?"Document":"Documents"),fe>1&&e.push("and",String(fe),1===fe?"Asset":"Assets"),E.config().projectId!==(null==B?void 0:B.projectId)&&e.push("between Projects"),e.push("to",String(me)),e.join(" ")}),[pe,fe,E,null==B?void 0:B.projectId,me]);return z.length<2?u(ne,{tone:"critical",children:[s("code",{children:"sanity.config.ts"})," must contain at least two Workspaces to use this plugin."]}):s(j,{width:1,children:s(T,{border:!0,children:s(k,{children:u(h,{children:[s(T,{borderBottom:!0,padding:4,style:F(D),children:u(k,{space:4,children:[u(S,{gap:3,children:[u(k,{style:{flex:1},space:3,children:[s(P,{children:"Duplicate from"}),s(R,{readOnly:!0,value:null==(o=z.find((e=>e.disabled)))?void 0:o.name,children:z.filter((e=>e.disabled)).map((e=>{var t;return u("option",{value:e.name,disabled:e.disabled,children:[null!=(t=e.title)?t:e.name,be?" (".concat(e.projectId,")"):""]},e.name)}))})]}),s(_,{padding:4,paddingTop:5,paddingBottom:0,children:s(C,{size:3,children:s(y,{})})}),u(k,{style:{flex:1},space:3,children:[s(P,{children:"To Destination"}),s(R,{onChange:function(e){if(!z.length)return;const t=z.find((t=>t.name===e.currentTarget.value));t&&N(t)},children:z.map((e=>{var t;return u("option",{value:e.name,disabled:e.disabled,children:[null!=(t=e.title)?t:e.name,be?" (".concat(e.projectId,")"):"",e.disabled?" (Current)":""]},e.name)}))})]})]}),oe&&s(T,{border:!0,radius:2,children:s(T,{style:{width:"100%",transform:"scaleX(".concat(de[0]/de[1],")"),transformOrigin:"left",transition:"transform .2s ease",boxSizing:"border-box"},padding:1,tone:"positive"})}),J.length>0&&u(h,{children:[s(P,{children:ye}),s(M,{payload:J,setPayload:K})]})]})}),$&&s(_,{paddingX:4,paddingTop:4,children:s(T,{padding:3,radius:2,shadow:1,tone:$.tone,children:s(C,{size:1,children:$.text})})}),J.length>0&&s(k,{padding:4,space:3,children:J.map(((e,t)=>{let{doc:n,include:i,status:o,hasDraft:r}=e;const a=I.get(n._type);return u(p.Fragment,{children:[u(S,{align:"center",children:[s(U,{checked:i,onChange:()=>function(e){const t=J.map((t=>(t.doc._id===e&&(t.include=!t.include),t)));K(t)}(n._id)}),s(_,{flex:1,paddingX:3,children:a?s(d,{value:n,schemaType:a}):s(T,{tone:"caution",children:"Invalid schema type"})}),u(S,{align:"center",gap:2,children:[r?s(te,{status:"UNPUBLISHED",isAsset:!1}):null,s(te,{status:o,isAsset:q(n._id)})]})]}),"svg"===(null==n?void 0:n.extension)&&t===he&&s(T,{padding:3,radius:2,shadow:1,tone:"caution",children:u(C,{size:1,children:["Due to how SVGs are sanitized after first uploaded, duplicated SVG assets may have new ",s("code",{children:"_id"}),"'s at the destination. The newly generated ",s("code",{children:"_id"})," will be the same in each duplication, but it will never be the same ",s("code",{children:"_id"})," as the first time this Asset was uploaded. References to the asset will be updated to use the new"," ",s("code",{children:"_id"}),"."]})})]},n._id)}))}),u(k,{space:2,padding:4,paddingTop:0,children:[Z&&s(A,{fontSize:2,padding:4,tone:"positive",mode:"ghost",icon:v,onClick:async function(){le(!0);const e=c.map((e=>e._id)),t=await Q({fetchIds:e,client:E,pluginConfig:b}),n=await Q({fetchIds:e.map((e=>"drafts.".concat(e))),client:E,projection:"{_id}",pluginConfig:b}),i=new Set(n.map((e=>{let{_id:t}=e;return t}))),o=t.map((e=>({doc:e,include:!0,status:void 0,hasDraft:i.has("drafts.".concat(e._id))})));K(o),se(o),le(!1)},text:"Gather References",disabled:oe||!ge||ae}),s(A,{fontSize:2,padding:4,tone:"positive",icon:w,onClick:async function(){if(!B)return;re(!0);const e=J.filter((e=>{let{doc:t,include:n}=e;return n&&q(t._id)})).length;let t=0;ce([t,e]),Y({text:"Duplicating...",tone:"default"});const n=E.withConfig(i(i({},ie),{},{dataset:B.dataset,projectId:B.projectId})),o=[],r=[];async function a(i){if(q(i._id)){const a=H(i),l=a?i.url:"".concat(i.url,"?dlRaw=true"),d=a?{}:{headers:{Authorization:"Bearer ".concat(m)}};return await fetch(l,d).then((async e=>{const t=await e.blob(),l={filename:i.originalFilename},d=await n.assets.upload(a?"file":"image",t,l);"svg"===(null==i?void 0:i.extension)&&r.push({old:i._id,new:d._id}),o.push(d)})),t+=1,Y({text:"Duplicating ".concat(t,"/").concat(e," ").concat("Assets"),tone:"default"}),ce([t,e])}return o.push(i)}const l=new Promise(((e,t)=>{const n=J.filter((e=>e.include)).map((e=>e.doc));L(n,3,X(a),(n=>{n&&(re(!1),Y({tone:"critical",text:"Duplication Failed"}),console.error(n),t(new Error("Duplication Failed"))),e()}))}));await l;const d=o.map((e=>{const t=V(".._ref",e);return t.length?(t.forEach((t=>{var n;const i=null==(n=r.find((e=>e.old===t.value)))?void 0:n.new;if(i){const n=t.path.join(".");W(e,n,i)}})),e):e})),c=n.transaction();d.forEach((e=>{c.createOrReplace(e)})),await c.commit().then((e=>{Y({tone:"positive",text:"Duplication complete!"}),se()})).catch((e=>{Y({tone:"critical",text:e.details.description})})),re(!1),ce([0,0])},text:ve,disabled:oe||!ge||ae})]})]})})})})}function re(e){var t,n;const{token:i,pluginConfig:o}=e,l=r(ie),d=a().getTypeNames(),[c,h]=f(""),[p,m]=f({docs:[]});function b(e){e&&e.preventDefault(),l.fetch(c).then((e=>{const t=e.length?e.filter((e=>d.includes(e._type))).filter((e=>!e._id.startsWith("drafts."))):[];m({docs:t})})).catch((e=>console.error(e)))}return g((()=>{var e;!(null==(e=p.docs)?void 0:e.length)&&c&&b()}),[]),s(j,{width:[1,1,1,3],padding:[0,0,0,5],children:u(z,{columns:[1,1,1,2],gap:[1,1,1,4],children:[s(_,{padding:[2,2,2,0],children:s(T,{padding:4,radius:3,border:!0,children:u(k,{space:4,children:[s(_,{children:s(P,{children:"Initial Documents Query"})}),s(_,{children:s(C,{children:"Start with a valid GROQ query to load initial documents. The query will need to return an Array of Objects. Drafts will be removed from the results."})}),s("form",{onSubmit:b,children:u(S,{children:[s(_,{flex:1,paddingRight:2,children:s(B,{style:{fontFamily:"monospace"},fontSize:2,onChange:e=>h(e.currentTarget.value),padding:4,placeholder:'*[_type == "article"]',value:null!=c?c:""})}),s(A,{padding:2,paddingX:4,tone:"primary",onClick:b,text:"Query",disabled:!c})]})})]})})}),!(null==(t=p.docs)?void 0:t.length)||p.docs.length<1&&s(j,{width:1,children:s(T,{padding:5,children:c?"No Documents registered to the Schema match this query":"Start with a valid GROQ query"})}),(null==(n=p.docs)?void 0:n.length)>0&&s(oe,{docs:p.docs,token:i,pluginConfig:o})]})})}function ae(e){const{docs:t,token:n,pluginConfig:i}=e,[o,a]=f([]),{follow:l=[]}=i,[d,c]=f(1===l.length?l[0]:"outbound"),h=r();return g((()=>{(async()=>{if(l.includes("inbound")){const n=await h.fetch("*[references($id)]",{id:t[0]._id});a([...e.docs,...n])}})()}),[]),u(j,{children:[l.length>1&&(l.includes("inbound")||l.includes("outbound"))?s(T,{paddingX:4,paddingBottom:4,marginBottom:4,borderBottom:!0,children:u(z,{columns:2,gap:4,children:[l.includes("outbound")?s(A,{mode:"ghost",tone:"primary",selected:"outbound"===d,onClick:()=>c("outbound"),text:"Outbound"}):null,l.includes("inbound")?s(A,{mode:"ghost",tone:"primary",selected:"inbound"===d,onClick:()=>c("inbound"),disabled:0===o.length,text:o.length>0?"Inbound (".concat(o.length,")"):"No inbound references"}):null]})}):null,s(oe,{docs:"outbound"===d?t:o,token:n,pluginConfig:i})]})}const le="CrossDatasetDuplicator",de={tool:!0,types:[],filter:"",follow:["outbound"]};function ce(){const e=r(ie),t=p.useCallback((()=>{e.delete({query:'*[_id == "secrets.'.concat(le,'"]')})}),[e]);return s(S,{align:"center",justify:"flex-end",paddingX:[2,2,2,5],paddingY:5,children:s(A,{text:"Reset Secret",onClick:t,mode:"ghost",tone:"critical",fontSize:1,padding:2})})}const se=m(de);function ue(){return b(se)}const he=[{key:"bearerToken",title:"An API token with Viewer permissions is required to duplicate the original files of assets, and will be used for all Duplications. Create one at sanity.io/manage",description:""}];function pe(e){const{mode:t="tool",docs:n=[]}=null!=e?e:{},i=ue(),{loading:o,secrets:r}=D(le),[a,l]=f(!1);return g((()=>{r&&l(!(null==r?void 0:r.bearerToken))}),[r]),o?s(S,{justify:"center",align:"center",children:s(_,{padding:5,children:s(N,{})})}):!o&&a||!(null==r?void 0:r.bearerToken)?s(E,{title:"Token Required",namespace:le,keys:he,onClose:()=>l(!1)}):"tool"===t&&i?u(h,{children:[s(re,{token:null==r?void 0:r.bearerToken,pluginConfig:i}),s(ce,{})]}):(null==n?void 0:n.length)?i?s(ae,{docs:n,token:null==r?void 0:r.bearerToken,pluginConfig:i}):s(ne,{children:"No plugin config"}):s(ne,{children:"No docs passed into Duplicator Tool"})}function fe(e){const{docs:t=[]}=e;return s(pe,{mode:"action",docs:t})}const ge=e=>{const{draft:t,published:n,onComplete:i}=e,[o,r]=f(!1);return{disabled:t,title:t?"Document must be Published to begin":null,label:"Duplicate to...",dialog:o&&n&&{type:"modal",title:"Cross Dataset Duplicator",content:s(fe,{docs:[n]}),onClose:()=>{i(),r(!1)}},onHandle:()=>r(!0),icon:w}};function me(e){var t;const{docs:n=[]}=null!=(t=e.tool.options)?t:{};return s(pe,{mode:"tool",docs:n})}ge.action="duplicateTo";const be=c((function(){let n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const o=i(i({},de),n),{types:r}=o;return{name:"@sanity/cross-dataset-duplicator",tools:e=>o.tool?[...e,{title:"Duplicator",name:"duplicator",icon:w,component:me,options:{docs:[]}}]:e,studio:{components:{layout:n=>function(n){const{pluginConfig:i}=n,o=t(n,e);return s(se.Provider,{value:i,children:n.renderDefault(o)})}(i(i({},n),{},{pluginConfig:o}))}},document:{actions:(e,t)=>{let{schemaType:n}=t;return r&&r.includes(n)?[...e,ge]:e}}}}));export{fe as CrossDatasetDuplicatorAction,ge as DuplicateToAction,be as crossDatasetDuplicator,ue as useCrossDatasetDuplicatorConfig};//# sourceMappingURL=index.esm.js.map
|
package/lib/index.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":["../src/helpers/index.ts","../src/helpers/getDocumentsInArray.ts","../src/components/SelectButtons.tsx","../src/components/StatusBadge.tsx","../src/components/Feedback.tsx","../src/helpers/clientConfig.ts","../src/components/Duplicator.tsx","../src/components/DuplicatorQuery.tsx","../src/components/DuplicatorWrapper.tsx","../src/helpers/constants.ts","../src/components/ResetSecret.tsx","../src/components/CrossDatasetDuplicator.tsx","../src/actions/DuplicateToAction.tsx","../src/tool/index.ts","../src/index.ts"],"sourcesContent":["import {CSSProperties} from 'react'\n\nexport function createInitialMessage(docCount = 0, refsCount = 0): string {\n const message = [\n docCount === 1 ? `This Document contains` : `These ${docCount} Documents contain`,\n refsCount === 1 ? `1 Reference.` : `${refsCount} References.`,\n refsCount === 1 ? `That Document` : `Those Documents`,\n `may have References too. If referenced Documents do not exist at the target Destination, this transaction will fail.`,\n ]\n\n return message.join(` `)\n}\n\nexport const stickyStyles = (isDarkMode = true): CSSProperties => ({\n position: 'sticky',\n top: 0,\n zIndex: 100,\n backgroundColor: isDarkMode ? `rgba(10,10,10,0.95)` : `rgba(255,255,255,0.95)`,\n})\n","import {extractWithPath} from '@sanity/mutator'\nimport {SanityClient, SanityDocument} from 'sanity'\nimport {PluginConfig} from '../types'\n\ntype OptionsBag = {\n fetchIds: string[]\n client: SanityClient\n pluginConfig: PluginConfig\n currentIds?: Set<string> | null\n projection?: string\n}\n\n// Recursively fetch Documents from an array of _id's and their references\n// Heavy use of Set is to avoid recursively querying for id's already in the payload\nexport async function getDocumentsInArray(options: OptionsBag): Promise<SanityDocument[]> {\n const {fetchIds, client, pluginConfig, currentIds, projection} = options\n const collection: SanityDocument[] = []\n\n // Find initial docs\n const filter = ['_id in $fetchIds', pluginConfig.filter].filter(Boolean).join(' && ')\n const query = `*[${filter}]${projection ?? ``}`\n const data: SanityDocument[] = await client.fetch(query, {\n fetchIds: fetchIds ?? [],\n })\n\n if (!data?.length) {\n return []\n }\n\n const localCurrentIds = currentIds ?? new Set<string>()\n\n // Find new ids in the returned data\n // Unless we started with an empty set, get the _ids from the data\n const newDataIds = new Set<string>(\n data\n .map((dataDoc) => dataDoc._id)\n .filter((id) => (currentIds?.size ? !localCurrentIds.has(id) : Boolean(id)))\n )\n\n if (newDataIds.size) {\n collection.push(...data)\n // @ts-ignore\n localCurrentIds.add(...newDataIds)\n\n // Check new data for more references\n await Promise.all(\n data.map(async (doc) => {\n const expr = `.._ref`\n const references: string[] = extractWithPath(expr, doc).map((ref) => ref.value as string)\n\n if (references.length) {\n // Find references not already in the Collection\n const newReferenceIds = new Set<string>(\n references.filter((ref) => !localCurrentIds.has(ref))\n )\n\n if (newReferenceIds.size) {\n // Recursive query for new documents\n const referenceDocs = await getDocumentsInArray({\n fetchIds: Array.from(newReferenceIds),\n currentIds: localCurrentIds,\n client,\n pluginConfig,\n })\n\n if (referenceDocs?.length) {\n collection.push(...referenceDocs)\n }\n }\n }\n })\n )\n }\n\n // Create a unique array of objects from collection\n // Set() wasn't working for unique id's ¯\\_(ツ)_/¯\n const uniqueCollection = collection.filter(Boolean).reduce((acc: SanityDocument[], cur) => {\n if (acc.some((doc) => doc._id === cur._id)) {\n return acc\n }\n\n return [...acc, cur]\n }, [])\n\n return uniqueCollection\n}\n","import React, {useState, useEffect} from 'react'\nimport {Button, Card, Flex} from '@sanity/ui'\n\nimport {PayloadItem} from './Duplicator'\nimport {isAssetId} from '@sanity/asset-utils'\n\nconst buttons = [`All`, `None`, null, `New`, `Existing`, `Older`, null, `Documents`, `Assets`]\n\ntype Action = 'ALL' | 'NONE' | 'NEW' | 'EXISTING' | 'OLDER' | 'ASSETS' | 'DOCUMENTS'\n\ntype SelectButtonsProps = {\n payload: PayloadItem[]\n setPayload: Function\n}\n\nexport default function SelectButtons(props: SelectButtonsProps) {\n const {payload, setPayload} = props\n const [disabledActions, setDisabledActions] = useState<Action[]>([])\n\n // Set intiial disabled button\n useEffect(() => {\n if (!disabledActions?.length && payload.every((item) => item.include)) {\n setDisabledActions([`ALL`])\n }\n }, [disabledActions?.length, payload])\n\n function handleSelectButton(action?: Action) {\n if (!action || !payload.length) return\n\n const newPayload = [...payload]\n\n switch (action) {\n case 'ALL':\n newPayload.map((item) => (item.include = true))\n break\n case 'NONE':\n newPayload.map((item) => (item.include = false))\n break\n case 'NEW':\n newPayload.map((item) => (item.include = Boolean(item.status === 'CREATE')))\n break\n case 'EXISTING':\n newPayload.map((item) => (item.include = Boolean(item.status === 'EXISTS')))\n break\n case 'OLDER':\n newPayload.map((item) => (item.include = Boolean(item.status === 'OVERWRITE')))\n break\n case 'ASSETS':\n newPayload.map((item) => (item.include = isAssetId(item.doc._id)))\n break\n case 'DOCUMENTS':\n newPayload.map((item) => (item.include = !isAssetId(item.doc._id)))\n break\n default:\n break\n }\n\n setDisabledActions([action])\n setPayload(newPayload)\n }\n\n return (\n <Card padding={1} radius={3} shadow={1}>\n <Flex gap={2}>\n {buttons.map((action, actionIndex) =>\n action ? (\n <Button\n key={action}\n fontSize={1}\n mode=\"bleed\"\n padding={2}\n text={action}\n disabled={disabledActions.includes(action.toUpperCase() as Action)}\n onClick={() => handleSelectButton(action.toUpperCase() as Action)}\n />\n ) : (\n // eslint-disable-next-line react/no-array-index-key\n <Card key={`divider-${actionIndex}`} borderLeft />\n )\n )}\n </Flex>\n </Card>\n )\n}\n","import React from 'react'\nimport {Box, Text, Badge, Tooltip} from '@sanity/ui'\nimport type {BadgeTone} from '@sanity/ui'\n\ntype StatusTones = {\n EXISTS: BadgeTone\n OVERWRITE: BadgeTone\n UPDATE: BadgeTone\n CREATE: BadgeTone\n UNPUBLISHED: BadgeTone\n}\n\nconst documentTones: StatusTones = {\n EXISTS: `primary`,\n OVERWRITE: `critical`,\n UPDATE: `caution`,\n CREATE: `positive`,\n UNPUBLISHED: `caution`,\n}\n\nconst assetTones: StatusTones = {\n EXISTS: `critical`,\n OVERWRITE: `critical`,\n UPDATE: `critical`,\n CREATE: `positive`,\n UNPUBLISHED: `default`,\n}\n\nexport type MessageTypes = {\n EXISTS: string\n OVERWRITE: string\n UPDATE: string\n CREATE: string\n UNPUBLISHED: string\n}\n\nconst documentMessages: MessageTypes = {\n // Only happens once document is copied the first time, and _updatedAt is the same\n EXISTS: `This document already exists at the Destination with the same ID with the same Updated time.`,\n // Is true immediately after transaction as _updatedAt is updated by API after mutation\n // Is also true if the document at the destination has been manually modified\n // Presently, the plugin doesn't actually compare the two documents\n OVERWRITE: `A newer version of this document exists at the Destination, and it will be overwritten with this version.`,\n // Document at destination is older\n UPDATE: `An older version of this document exists at the Destination, and it will be overwritten with this version.`,\n // Document at destination doesn't exist\n CREATE: `This document will be created at the destination.`,\n UNPUBLISHED: `A Draft version of this Document exists in this Dataset, but only the Published version will be duplicated to the destination.`,\n}\n\nconst assetMessages: MessageTypes = {\n EXISTS: `This Asset already exists at the Destination`,\n OVERWRITE: `This Asset already exists at the Destination`,\n UPDATE: `This Asset already exists at the Destination`,\n CREATE: `This Asset does not yet exist at the Destination`,\n UNPUBLISHED: ``,\n}\n\nconst assetStatus: MessageTypes = {\n EXISTS: `RE-UPLOAD`,\n OVERWRITE: `RE-UPLOAD`,\n UPDATE: `RE-UPLOAD`,\n CREATE: `UPLOAD`,\n UNPUBLISHED: ``,\n}\n\ntype StatusBadgeProps = {\n isAsset: boolean\n status?: keyof MessageTypes\n}\n\nexport default function StatusBadge(props: StatusBadgeProps) {\n const {status, isAsset} = props\n\n if (!status) {\n return null\n }\n\n const badgeTone = isAsset ? assetTones[status] : documentTones[status]\n\n if (!badgeTone) {\n return (\n <Badge muted padding={2} fontSize={1} mode=\"outline\">\n Checking...\n </Badge>\n )\n }\n\n const badgeText = isAsset ? assetMessages[status] : documentMessages[status]\n const badgeStatus = isAsset ? assetStatus[status] : status\n\n return (\n <Tooltip\n content={\n <Box padding={3} style={{maxWidth: 200}}>\n <Text size={1}>{badgeText}</Text>\n </Box>\n }\n fallbackPlacements={['right', 'left']}\n placement=\"top\"\n portal\n >\n <Badge muted padding={2} fontSize={1} tone={badgeTone} mode=\"outline\">\n {badgeStatus}\n </Badge>\n </Tooltip>\n )\n}\n","import React from 'react'\nimport {Card, Text} from '@sanity/ui'\nimport type {BadgeTone} from '@sanity/ui'\n\ntype FeedbackProps = {\n children?: React.ReactNode\n tone?: BadgeTone\n}\n\nexport default function Feedback(props: FeedbackProps) {\n const {children, tone = `caution`} = props\n\n return (\n <Card padding={3} radius={2} shadow={1} tone={tone}>\n <Text size={1}>{children}</Text>\n </Card>\n )\n}\n","export const clientConfig = {apiVersion: `2021-05-19`}\n","/* eslint-disable react/jsx-no-bind */\nimport React, {useState, useEffect} from 'react'\nimport {\n useClient,\n Preview,\n useSchema,\n useWorkspaces,\n WorkspaceSummary,\n SanityDocument,\n} from 'sanity'\n// @ts-ignore\nimport mapLimit from 'async/mapLimit'\n// @ts-ignore\nimport asyncify from 'async/asyncify'\nimport {extractWithPath} from '@sanity/mutator'\nimport {dset} from 'dset'\nimport {\n Card,\n Container,\n Text,\n Box,\n Button,\n Label,\n Stack,\n Select,\n Flex,\n Checkbox,\n CardTone,\n useTheme,\n} from '@sanity/ui'\nimport {ArrowRightIcon, SearchIcon, LaunchIcon} from '@sanity/icons'\nimport {SanityAssetDocument} from '@sanity/client'\nimport {isAssetId, isSanityFileAsset} from '@sanity/asset-utils'\n\nimport {stickyStyles, createInitialMessage} from '../helpers'\nimport {getDocumentsInArray} from '../helpers/getDocumentsInArray'\nimport SelectButtons from './SelectButtons'\nimport StatusBadge, {MessageTypes} from './StatusBadge'\nimport Feedback from './Feedback'\nimport {clientConfig} from '../helpers/clientConfig'\nimport {PluginConfig} from '../types'\n\nexport type DuplicatorProps = {\n docs: SanityDocument[]\n // TODO: Find out if this is even used?\n // draftIds: string[]\n token: string\n pluginConfig: PluginConfig\n}\n\nexport type PayloadItem = {\n doc: SanityDocument\n include: boolean\n status?: keyof MessageTypes\n hasDraft?: boolean\n}\n\ntype WorkspaceOption = WorkspaceSummary & {\n disabled: boolean\n}\n\ntype Message = {\n text: string\n tone: CardTone\n}\n\nexport default function Duplicator(props: DuplicatorProps) {\n const {docs, token, pluginConfig} = props\n const isDarkMode = useTheme().sanity.color.dark\n\n // Prepare origin (this Studio) client\n const originClient = useClient(clientConfig)\n\n const schema = useSchema()\n\n // Create list of dataset options\n // and set initial value of dropdown\n const workspaces = useWorkspaces()\n const workspacesOptions: WorkspaceOption[] = workspaces.map((workspace) => ({\n ...workspace,\n disabled: workspace.dataset === originClient.config().dataset,\n }))\n\n const [destination, setDestination] = useState<WorkspaceOption | null>(\n workspaces.length ? workspacesOptions.find((space) => !space.disabled) ?? null : null\n )\n const [message, setMessage] = useState<Message | null>(null)\n const [payload, setPayload] = useState<PayloadItem[]>([])\n\n const [hasReferences, setHasReferences] = useState(false)\n const [isDuplicating, setIsDuplicating] = useState(false)\n const [isGathering, setIsGathering] = useState(false)\n const [progress, setProgress] = useState<number[]>([0, 0])\n\n // Check for References and update message\n useEffect(() => {\n const expr = `.._ref`\n const initialRefs = []\n const initialPayload: PayloadItem[] = []\n\n docs.forEach((doc) => {\n const refs = extractWithPath(expr, doc).map((ref) => ref.value)\n initialRefs.push(...refs)\n initialPayload.push({include: true, doc})\n })\n\n setPayload(initialPayload)\n\n const docCount = docs.length\n const refsCount = initialRefs.length\n\n if (initialRefs.length) {\n setHasReferences(true)\n\n setMessage({\n tone: `caution`,\n text: createInitialMessage(docCount, refsCount),\n })\n }\n }, [docs])\n\n // Re-check payload on destination when value changes\n // (On initial render + select change)\n useEffect(() => {\n updatePayloadStatuses()\n }, [destination])\n\n // Check if payload documents exist at destination\n async function updatePayloadStatuses(newPayload: PayloadItem[] = []) {\n const payloadActual = newPayload.length ? newPayload : payload\n\n if (!payloadActual.length || !destination?.name) {\n return\n }\n\n const payloadIds = payloadActual.map(({doc}) => doc._id)\n const destinationClient = originClient.withConfig({\n ...clientConfig,\n dataset: destination.dataset,\n projectId: destination.projectId,\n })\n const destinationData: SanityDocument[] = await destinationClient.fetch(\n `*[_id in $payloadIds]{ _id, _updatedAt }`,\n {payloadIds}\n )\n\n const updatedPayload = payloadActual.map((item) => {\n const existingDoc = destinationData.find((doc) => doc._id === item.doc._id)\n\n if (existingDoc?._updatedAt && item?.doc?._updatedAt) {\n if (existingDoc._updatedAt === item.doc._updatedAt) {\n // Exact same document exists at destination\n // We don't compare by _rev because that is updated in a transaction\n item.status = `EXISTS`\n } else if (existingDoc._updatedAt && item.doc._updatedAt) {\n item.status =\n new Date(existingDoc._updatedAt) > new Date(item.doc._updatedAt)\n ? // Document at destination is newer\n `OVERWRITE`\n : // Document at destination is older\n `UPDATE`\n }\n } else {\n item.status = 'CREATE'\n }\n\n return item\n })\n\n setPayload(updatedPayload)\n }\n\n function handleCheckbox(_id: string) {\n const updatedPayload = payload.map((item) => {\n if (item.doc._id === _id) {\n item.include = !item.include\n }\n\n return item\n })\n\n setPayload(updatedPayload)\n }\n\n // Find and recursively follow references beginning with this document\n async function handleReferences() {\n setIsGathering(true)\n const docIds = docs.map((doc) => doc._id)\n\n const payloadDocs = await getDocumentsInArray({\n fetchIds: docIds,\n client: originClient,\n pluginConfig,\n })\n const draftDocs = await getDocumentsInArray({\n fetchIds: docIds.map((id) => `drafts.${id}`),\n client: originClient,\n projection: `{_id}`,\n pluginConfig,\n })\n const draftDocsIds = new Set(draftDocs.map(({_id}) => _id))\n\n // Shape it up\n const payloadShaped = payloadDocs.map((doc) => ({\n doc,\n // Include this in the transaction?\n include: true,\n // Does it exist at the destination?\n status: undefined,\n // Does it have any drafts?\n hasDraft: draftDocsIds.has(`drafts.${doc._id}`),\n }))\n\n setPayload(payloadShaped)\n updatePayloadStatuses(payloadShaped)\n setIsGathering(false)\n }\n\n // Duplicate payload to destination dataset\n async function handleDuplicate() {\n if (!destination) {\n return\n }\n\n setIsDuplicating(true)\n\n const assetsCount = payload.filter(({doc, include}) => include && isAssetId(doc._id)).length\n let currentProgress = 0\n setProgress([currentProgress, assetsCount])\n\n setMessage({text: 'Duplicating...', tone: `default`})\n\n const destinationClient = originClient.withConfig({\n ...clientConfig,\n dataset: destination.dataset,\n projectId: destination.projectId,\n })\n\n const transactionDocs: SanityDocument[] = []\n const svgMaps: {old: string; new: string}[] = []\n\n // Upload assets and then add to transaction\n async function fetchDoc(doc: SanityAssetDocument) {\n if (isAssetId(doc._id)) {\n // Download and upload asset\n // Get the *original* image with this dlRaw param to create the same determenistic _id\n const typeIsFile = isSanityFileAsset(doc)\n const downloadUrl = typeIsFile ? doc.url : `${doc.url}?dlRaw=true`\n const downloadConfig = typeIsFile ? {} : {headers: {Authorization: `Bearer ${token}`}}\n\n await fetch(downloadUrl, downloadConfig).then(async (res) => {\n const assetData = await res.blob()\n\n const options = {filename: doc.originalFilename}\n const assetDoc = await destinationClient.assets.upload(\n typeIsFile ? `file` : `image`,\n assetData,\n options\n )\n\n // SVG _id's need remapping before transaction\n if (doc?.extension === 'svg') {\n svgMaps.push({old: doc._id, new: assetDoc._id})\n }\n\n transactionDocs.push(assetDoc)\n })\n\n currentProgress += 1\n setMessage({\n text: `Duplicating ${currentProgress}/${assetsCount} ${\n assetsCount === 1 ? `Assets` : `Assets`\n }`,\n tone: 'default',\n })\n\n return setProgress([currentProgress, assetsCount])\n }\n\n return transactionDocs.push(doc)\n }\n\n // Promises are limited to three at once\n const result = new Promise((resolve, reject) => {\n const payloadIncludedDocs = payload.filter((item) => item.include).map((item) => item.doc)\n\n mapLimit(payloadIncludedDocs, 3, asyncify(fetchDoc), (err: Error) => {\n if (err) {\n setIsDuplicating(false)\n setMessage({tone: 'critical', text: `Duplication Failed`})\n console.error(err)\n reject(new Error('Duplication Failed'))\n }\n\n // @ts-ignore\n resolve()\n })\n })\n\n await result\n\n // Remap SVG references to new _id's\n const transactionDocsMapped = transactionDocs.map((doc) => {\n const expr = `.._ref`\n const references = extractWithPath(expr, doc)\n\n if (!references.length) {\n return doc\n }\n\n // For every found _ref, search for an SVG asset _id and update\n references.forEach((ref) => {\n const newRefValue = svgMaps.find((asset) => asset.old === ref.value)?.new\n\n if (newRefValue) {\n const refPath = ref.path.join('.')\n\n dset(doc, refPath, newRefValue)\n }\n })\n\n return doc\n })\n\n // Create transaction\n const transaction = destinationClient.transaction()\n\n transactionDocsMapped.forEach((doc) => {\n transaction.createOrReplace(doc)\n })\n\n await transaction\n .commit()\n .then((res) => {\n setMessage({tone: 'positive', text: 'Duplication complete!'})\n\n updatePayloadStatuses()\n })\n .catch((err) => {\n setMessage({tone: 'critical', text: err.details.description})\n })\n\n setIsDuplicating(false)\n setProgress([0, 0])\n }\n\n function handleChange(e: React.ChangeEvent<HTMLSelectElement>) {\n if (!workspacesOptions.length) {\n return\n }\n\n const targeted = workspacesOptions.find((space) => space.name === e.currentTarget.value)\n\n if (targeted) {\n setDestination(targeted)\n }\n }\n\n const payloadCount = payload.length\n const firstSvgIndex = payload.findIndex(({doc}) => doc.extension === 'svg')\n const selectedDocumentsCount = payload.filter(\n (item) => item.include && !isAssetId(item.doc._id)\n ).length\n const selectedAssetsCount = payload.filter(\n (item) => item.include && isAssetId(item.doc._id)\n ).length\n const selectedTotal = selectedDocumentsCount + selectedAssetsCount\n const destinationTitle = destination?.title ?? destination?.name\n const hasMultipleProjectIds =\n new Set(workspacesOptions.map((space) => space?.projectId).filter(Boolean)).size > 1\n\n const headingText = [selectedTotal, `/`, payloadCount, `Documents and Assets selected`].join(` `)\n\n const buttonText = React.useMemo(() => {\n const text = [`Duplicate`]\n\n if (selectedDocumentsCount > 1) {\n text.push(\n String(selectedDocumentsCount),\n selectedDocumentsCount === 1 ? `Document` : `Documents`\n )\n }\n\n if (selectedAssetsCount > 1) {\n text.push(`and`, String(selectedAssetsCount), selectedAssetsCount === 1 ? `Asset` : `Assets`)\n }\n\n if (originClient.config().projectId !== destination?.projectId) {\n text.push(`between Projects`)\n }\n\n text.push(`to`, String(destinationTitle))\n\n return text.join(` `)\n }, [\n selectedDocumentsCount,\n selectedAssetsCount,\n originClient,\n destination?.projectId,\n destinationTitle,\n ])\n\n if (workspacesOptions.length < 2) {\n return (\n <Feedback tone=\"critical\">\n <code>sanity.config.ts</code> must contain at least two Workspaces to use this plugin.\n </Feedback>\n )\n }\n\n return (\n <Container width={1}>\n <Card border>\n <Stack>\n <>\n <Card borderBottom padding={4} style={stickyStyles(isDarkMode)}>\n <Stack space={4}>\n <Flex gap={3}>\n <Stack style={{flex: 1}} space={3}>\n <Label>Duplicate from</Label>\n <Select\n readOnly\n value={workspacesOptions.find((space) => space.disabled)?.name}\n >\n {workspacesOptions\n .filter((space) => space.disabled)\n .map((space) => (\n <option key={space.name} value={space.name} disabled={space.disabled}>\n {space.title ?? space.name}\n {hasMultipleProjectIds ? ` (${space.projectId})` : ``}\n </option>\n ))}\n </Select>\n </Stack>\n <Box padding={4} paddingTop={5} paddingBottom={0}>\n <Text size={3}>\n <ArrowRightIcon />\n </Text>\n </Box>\n <Stack style={{flex: 1}} space={3}>\n <Label>To Destination</Label>\n <Select onChange={handleChange}>\n {workspacesOptions.map((space) => (\n <option key={space.name} value={space.name} disabled={space.disabled}>\n {space.title ?? space.name}\n {hasMultipleProjectIds ? ` (${space.projectId})` : ``}\n {space.disabled ? ` (Current)` : ``}\n </option>\n ))}\n </Select>\n </Stack>\n </Flex>\n\n {isDuplicating && (\n <Card border radius={2}>\n <Card\n style={{\n width: '100%',\n transform: `scaleX(${progress[0] / progress[1]})`,\n transformOrigin: 'left',\n transition: 'transform .2s ease',\n boxSizing: 'border-box',\n }}\n padding={1}\n tone=\"positive\"\n />\n </Card>\n )}\n {payload.length > 0 && (\n <>\n <Label>{headingText}</Label>\n <SelectButtons payload={payload} setPayload={setPayload} />\n </>\n )}\n </Stack>\n </Card>\n {message && (\n <Box paddingX={4} paddingTop={4}>\n <Card padding={3} radius={2} shadow={1} tone={message.tone}>\n <Text size={1}>{message.text}</Text>\n </Card>\n </Box>\n )}\n {payload.length > 0 && (\n <Stack padding={4} space={3}>\n {payload.map(({doc, include, status, hasDraft}, index) => {\n const schemaType = schema.get(doc._type)\n\n return (\n <React.Fragment key={doc._id}>\n <Flex align=\"center\">\n <Checkbox checked={include} onChange={() => handleCheckbox(doc._id)} />\n <Box flex={1} paddingX={3}>\n {schemaType ? (\n <Preview value={doc} schemaType={schemaType} />\n ) : (\n <Card tone=\"caution\">Invalid schema type</Card>\n )}\n </Box>\n <Flex align=\"center\" gap={2}>\n {hasDraft ? <StatusBadge status=\"UNPUBLISHED\" isAsset={false} /> : null}\n <StatusBadge status={status} isAsset={isAssetId(doc._id)} />\n </Flex>\n </Flex>\n {doc?.extension === 'svg' && index === firstSvgIndex && (\n <Card padding={3} radius={2} shadow={1} tone=\"caution\">\n <Text size={1}>\n Due to how SVGs are sanitized after first uploaded, duplicated SVG\n assets may have new <code>_id</code>'s at the destination. The newly\n generated <code>_id</code> will be the same in each duplication, but it\n will never be the same <code>_id</code> as the first time this Asset was\n uploaded. References to the asset will be updated to use the new{' '}\n <code>_id</code>.\n </Text>\n </Card>\n )}\n </React.Fragment>\n )\n })}\n </Stack>\n )}\n <Stack space={2} padding={4} paddingTop={0}>\n {hasReferences && (\n <Button\n fontSize={2}\n padding={4}\n tone=\"positive\"\n mode=\"ghost\"\n icon={SearchIcon}\n onClick={handleReferences}\n text=\"Gather References\"\n disabled={isDuplicating || !selectedTotal || isGathering}\n />\n )}\n <Button\n fontSize={2}\n padding={4}\n tone=\"positive\"\n icon={LaunchIcon}\n onClick={handleDuplicate}\n text={buttonText}\n disabled={isDuplicating || !selectedTotal || isGathering}\n />\n </Stack>\n </>\n </Stack>\n </Card>\n </Container>\n )\n}\n","import React, {useEffect, useState} from 'react'\nimport {Button, Stack, Box, Label, Text, Card, Flex, Grid, Container, TextInput} from '@sanity/ui'\nimport {useSchema, useClient, SanityDocument} from 'sanity'\n\nimport Duplicator from './Duplicator'\nimport {clientConfig} from '../helpers/clientConfig'\nimport {PluginConfig} from '../types'\n\ntype DuplicatorQueryProps = {\n token: string\n pluginConfig: PluginConfig\n}\n\ntype InitialData = {\n docs: SanityDocument[]\n // draftIds: string[]\n}\n\nexport default function DuplicatorQuery(props: DuplicatorQueryProps) {\n const {token, pluginConfig} = props\n\n const originClient = useClient(clientConfig)\n\n const schema = useSchema()\n const schemaTypes = schema.getTypeNames()\n\n const [value, setValue] = useState(``)\n const [initialData, setInitialData] = useState<InitialData>({\n docs: [],\n // draftIds: []\n })\n\n function handleSubmit(e?: any) {\n if (e) e.preventDefault()\n\n originClient\n .fetch(value)\n .then((res: SanityDocument[]) => {\n // Ensure queried docs are registered to the schema\n const registeredAndPublishedDocs = res.length\n ? res\n .filter((doc) => schemaTypes.includes(doc._type))\n .filter((doc) => !doc._id.startsWith(`drafts.`))\n : []\n // const initialDraftIds = res.length\n // ? res.filter((doc) => doc._id.startsWith(`drafts.`)).map((doc) => doc._id)\n // : []\n\n setInitialData({\n docs: registeredAndPublishedDocs,\n // draftIds: initialDraftIds\n })\n })\n .catch((err) => console.error(err))\n }\n\n // Auto-load initial textinput value\n useEffect(() => {\n if (!initialData.docs?.length && value) {\n handleSubmit()\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [])\n\n return (\n <Container width={[1, 1, 1, 3]} padding={[0, 0, 0, 5]}>\n <Grid columns={[1, 1, 1, 2]} gap={[1, 1, 1, 4]}>\n <Box padding={[2, 2, 2, 0]}>\n <Card padding={4} radius={3} border>\n <Stack space={4}>\n <Box>\n <Label>Initial Documents Query</Label>\n </Box>\n <Box>\n <Text>\n Start with a valid GROQ query to load initial documents. The query will need to\n return an Array of Objects. Drafts will be removed from the results.\n </Text>\n </Box>\n <form onSubmit={handleSubmit}>\n <Flex>\n <Box flex={1} paddingRight={2}>\n <TextInput\n style={{fontFamily: 'monospace'}}\n fontSize={2}\n // eslint-disable-next-line react/jsx-no-bind\n onChange={(event) => setValue(event.currentTarget.value)}\n padding={4}\n placeholder={`*[_type == \"article\"]`}\n value={value ?? ``}\n />\n </Box>\n <Button\n padding={2}\n paddingX={4}\n tone=\"primary\"\n onClick={handleSubmit}\n text=\"Query\"\n disabled={!value}\n />\n </Flex>\n </form>\n </Stack>\n </Card>\n </Box>\n {!initialData.docs?.length ||\n (initialData.docs.length < 1 && (\n <Container width={1}>\n <Card padding={5}>\n {value\n ? `No Documents registered to the Schema match this query`\n : `Start with a valid GROQ query`}\n </Card>\n </Container>\n ))}\n {initialData.docs?.length > 0 && (\n <Duplicator\n docs={initialData.docs}\n // draftIds={initialData.draftIds}\n token={token}\n pluginConfig={pluginConfig}\n />\n )}\n </Grid>\n </Container>\n )\n}\n","import React, {useState, useEffect} from 'react'\nimport {Grid, Card, Container, Button} from '@sanity/ui'\nimport {SanityDocument, useClient} from 'sanity'\n\nimport type {DuplicatorProps} from './Duplicator'\nimport Duplicator from './Duplicator'\n\nexport default function DuplicatorWrapper(props: DuplicatorProps) {\n const {docs, token, pluginConfig} = props\n const [inbound, setInbound] = useState<SanityDocument[]>([])\n const {follow = []} = pluginConfig\n\n // Make the first mode the default if there's only one\n const [mode, setMode] = useState<'inbound' | 'outbound'>(\n follow.length === 1 ? follow[0] : `outbound`\n )\n const client = useClient()\n\n // \"Inbound\" will start with all documents that reference the first one\n // And then you can gather \"Outbound\" references thereafter\n useEffect(() => {\n ;(async () => {\n if (follow.includes(`inbound`)) {\n const inboundReferences = await client.fetch(`*[references($id)]`, {id: docs[0]._id})\n setInbound([...props.docs, ...inboundReferences])\n }\n })()\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [])\n\n return (\n <Container>\n {follow.length > 1 && (follow.includes(`inbound`) || follow.includes(`outbound`)) ? (\n <Card paddingX={4} paddingBottom={4} marginBottom={4} borderBottom>\n <Grid columns={2} gap={4}>\n {follow.includes(`outbound`) ? (\n <Button\n mode=\"ghost\"\n tone=\"primary\"\n selected={mode === 'outbound'}\n onClick={() => setMode('outbound')}\n text=\"Outbound\"\n />\n ) : null}\n {follow.includes(`inbound`) ? (\n <Button\n mode=\"ghost\"\n tone=\"primary\"\n selected={mode === 'inbound'}\n onClick={() => setMode('inbound')}\n disabled={inbound.length === 0}\n text={inbound.length > 0 ? `Inbound (${inbound.length})` : 'No inbound references'}\n />\n ) : null}\n </Grid>\n </Card>\n ) : null}\n <Duplicator\n docs={mode === 'outbound' ? docs : inbound}\n token={token}\n // draftIds={[]}\n pluginConfig={pluginConfig}\n />\n </Container>\n )\n}\n","export const SECRET_NAMESPACE = `CrossDatasetDuplicator`\n","import React from 'react'\nimport {useClient} from 'sanity'\nimport {Button, Flex} from '@sanity/ui'\n\nimport {clientConfig} from '../helpers/clientConfig'\nimport {SECRET_NAMESPACE} from '../helpers/constants'\n\nexport default function ResetSecret() {\n const client = useClient(clientConfig)\n\n const handleClick = React.useCallback(() => {\n client.delete({query: `*[_id == \"secrets.${SECRET_NAMESPACE}\"]`})\n }, [client])\n\n return (\n <Flex align=\"center\" justify=\"flex-end\" paddingX={[2, 2, 2, 5]} paddingY={5}>\n <Button\n text=\"Reset Secret\"\n onClick={handleClick}\n mode=\"ghost\"\n tone=\"critical\"\n fontSize={1}\n padding={2}\n />\n </Flex>\n )\n}\n","import React, {useEffect, useState} from 'react'\nimport {useSecrets, SettingsView} from '@sanity/studio-secrets'\nimport {Flex, Box, Spinner} from '@sanity/ui'\nimport {SanityDocument, Tool} from 'sanity'\n\nimport DuplicatorQuery from './DuplicatorQuery'\nimport DuplicatorWrapper from './DuplicatorWrapper'\nimport ResetSecret from './ResetSecret'\nimport Feedback from './Feedback'\nimport {SECRET_NAMESPACE} from '../helpers/constants'\nimport {PluginConfig} from '../types'\n\n// Check for auth secret (required for asset uploads)\nconst secretConfigKeys = [\n {\n key: 'bearerToken',\n title:\n 'An API token with Viewer permissions is required to duplicate the original files of assets, and will be used for all Duplications. Create one at sanity.io/manage',\n description: '',\n },\n]\n\ntype Secrets = {\n bearerToken?: string\n}\n\nexport type MultiToolConfig = {\n mode: 'tool' | 'action'\n docs: SanityDocument[]\n pluginConfig: PluginConfig\n}\n\ntype CrossDatasetDuplicatorProps = {\n tool: Tool<MultiToolConfig>\n}\n\nexport default function CrossDatasetDuplicator(props: CrossDatasetDuplicatorProps) {\n const {mode = `tool`, docs = [], pluginConfig} = props.tool.options ?? {}\n\n const {loading, secrets} = useSecrets<Secrets>(SECRET_NAMESPACE)\n const [showSecretsPrompt, setShowSecretsPrompt] = useState(false)\n\n useEffect(() => {\n if (secrets) {\n setShowSecretsPrompt(!secrets?.bearerToken)\n }\n }, [secrets])\n\n if (loading) {\n return (\n <Flex justify=\"center\" align=\"center\">\n <Box padding={5}>\n <Spinner />\n </Box>\n </Flex>\n )\n }\n\n if ((!loading && showSecretsPrompt) || !secrets?.bearerToken) {\n return (\n <SettingsView\n title=\"Token Required\"\n namespace={SECRET_NAMESPACE}\n keys={secretConfigKeys}\n // eslint-disable-next-line react/jsx-no-bind\n onClose={() => setShowSecretsPrompt(false)}\n />\n )\n }\n\n if (mode === 'tool' && pluginConfig) {\n return (\n <>\n <DuplicatorQuery token={secrets?.bearerToken} pluginConfig={pluginConfig} />\n <ResetSecret />\n </>\n )\n }\n\n if (!docs?.length) {\n return <Feedback>No docs passed into Duplicator Tool</Feedback>\n }\n\n if (!pluginConfig) {\n return <Feedback>No plugin config</Feedback>\n }\n\n return (\n <DuplicatorWrapper\n docs={docs}\n token={secrets?.bearerToken}\n pluginConfig={pluginConfig}\n // draftIds={[]}\n />\n )\n}\n","import React, {useState} from 'react'\nimport {LaunchIcon} from '@sanity/icons'\nimport {DocumentActionProps} from 'sanity'\nimport {PluginConfig} from '../types'\n\nimport CrossDatasetDuplicator from '../components/CrossDatasetDuplicator'\n\ntype DuplicateToActionProps = DocumentActionProps & {pluginConfig: PluginConfig}\n\nexport default function DuplicateToAction({\n draft,\n published,\n onComplete,\n pluginConfig,\n}: DuplicateToActionProps) {\n const [dialogOpen, setDialogOpen] = useState(false)\n\n return {\n disabled: draft,\n title: draft ? `Document must be Published to begin` : null,\n label: 'Duplicate to...',\n dialog: dialogOpen &&\n published && {\n type: 'modal',\n title: 'Cross Dataset Duplicator',\n content: (\n <CrossDatasetDuplicator\n // TODO: Re-using the tool component was not clever\n // Undo that decision\n // @ts-ignore\n tool={{\n options: {\n mode: 'action',\n docs: [published],\n pluginConfig,\n },\n }}\n />\n ),\n onClose: () => {\n onComplete()\n setDialogOpen(false)\n },\n },\n onHandle: () => setDialogOpen(true),\n icon: LaunchIcon,\n }\n}\n","import type {Tool} from 'sanity'\nimport {LaunchIcon} from '@sanity/icons'\n\nimport CrossDatasetDuplicator, {MultiToolConfig} from '../components/CrossDatasetDuplicator'\nimport {PluginConfig} from '../types'\n\nexport const crossDatasetDuplicatorTool = (pluginConfig: PluginConfig): Tool<MultiToolConfig> => ({\n title: 'Duplicator',\n name: 'duplicator',\n icon: LaunchIcon,\n component: CrossDatasetDuplicator,\n options: {\n mode: 'tool',\n docs: [],\n pluginConfig,\n },\n})\n","import {definePlugin, DocumentActionProps} from 'sanity'\n\nimport DuplicateToAction from './actions/DuplicateToAction'\nimport {crossDatasetDuplicatorTool} from './tool'\nimport {PluginConfig} from './types'\n\nexport * from './types'\n\nconst DEFAULT_CONFIG: PluginConfig = {\n tool: true,\n types: [],\n filter: '',\n follow: ['outbound'],\n}\n\n/**\n * @sanity/cross-dataset-duplicator\n * @public\n */\nexport const crossDatasetDuplicator = definePlugin<PluginConfig | void>((config = {}) => {\n const pluginConfig = {...DEFAULT_CONFIG, ...config}\n const {types} = pluginConfig\n\n return {\n name: '@sanity/cross-dataset-duplicator',\n tools: (prev) =>\n pluginConfig.tool ? [...prev, crossDatasetDuplicatorTool(pluginConfig)] : prev,\n document: {\n actions: (prev, {schemaType}) => {\n return types && types.includes(schemaType)\n ? [...prev, (props: DocumentActionProps) => DuplicateToAction({...props, pluginConfig})]\n : prev\n },\n },\n }\n})\n"],"names":["createInitialMessage","docCount","refsCount","message","concat","join","stickyStyles","isDarkMode","position","top","zIndex","backgroundColor","async","getDocumentsInArray","options","fetchIds","client","pluginConfig","currentIds","projection","collection","filter","Boolean","query","data","fetch","length","localCurrentIds","Set","newDataIds","map","dataDoc","_id","id","size","has","push","add","Promise","all","references","extractWithPath","doc","ref","value","newReferenceIds","referenceDocs","Array","from","reduce","acc","cur","some","buttons","SelectButtons","props","payload","setPayload","disabledActions","setDisabledActions","useState","useEffect","every","item","include","jsx","Card","padding","radius","shadow","children","Flex","gap","action","actionIndex","Button","fontSize","mode","text","disabled","includes","toUpperCase","onClick","newPayload","status","isAssetId","handleSelectButton","borderLeft","documentTones","EXISTS","OVERWRITE","UPDATE","CREATE","UNPUBLISHED","assetTones","documentMessages","assetMessages","assetStatus","StatusBadge","isAsset","badgeTone","Badge","muted","badgeStatus","Tooltip","content","Box","style","maxWidth","Text","fallbackPlacements","placement","portal","tone","Feedback","clientConfig","apiVersion","Duplicator","_a","_b","_c","docs","token","useTheme","sanity","color","dark","originClient","useClient","schema","useSchema","workspaces","useWorkspaces","workspacesOptions","workspace","dataset","config","destination","setDestination","find","space","setMessage","hasReferences","setHasReferences","isDuplicating","setIsDuplicating","isGathering","setIsGathering","progress","setProgress","updatePayloadStatuses","payloadActual","name","payloadIds","_ref","destinationClient","withConfig","projectId","destinationData","updatedPayload","existingDoc","_updatedAt","Date","initialRefs","initialPayload","forEach","refs","payloadCount","firstSvgIndex","findIndex","_ref4","extension","selectedDocumentsCount","selectedAssetsCount","selectedTotal","destinationTitle","title","hasMultipleProjectIds","headingText","buttonText","React","useMemo","String","jsxs","Container","width","border","Stack","Fragment","borderBottom","flex","Label","Select","readOnly","paddingTop","paddingBottom","ArrowRightIcon","onChange","e","targeted","currentTarget","transform","transformOrigin","transition","boxSizing","paddingX","_ref5","index","hasDraft","schemaType","get","_type","align","Checkbox","checked","handleCheckbox","Preview","icon","SearchIcon","docIds","payloadDocs","draftDocs","draftDocsIds","_ref2","payloadShaped","LaunchIcon","assetsCount","_ref3","currentProgress","transactionDocs","svgMaps","fetchDoc","typeIsFile","isSanityFileAsset","downloadUrl","url","downloadConfig","headers","Authorization","then","assetData","res","blob","filename","originalFilename","assetDoc","assets","upload","old","new","result","resolve","reject","payloadIncludedDocs","mapLimit","asyncify","err","console","error","Error","transactionDocsMapped","newRefValue","asset","refPath","path","dset","transaction","createOrReplace","commit","catch","details","description","DuplicatorQuery","schemaTypes","getTypeNames","setValue","initialData","setInitialData","handleSubmit","preventDefault","registeredAndPublishedDocs","startsWith","Grid","columns","onSubmit","paddingRight","TextInput","fontFamily","event","placeholder","DuplicatorWrapper","inbound","setInbound","follow","setMode","inboundReferences","marginBottom","selected","SECRET_NAMESPACE","ResetSecret","handleClick","useCallback","delete","justify","paddingY","secretConfigKeys","key","CrossDatasetDuplicator","tool","loading","secrets","useSecrets","showSecretsPrompt","setShowSecretsPrompt","bearerToken","Spinner","SettingsView","namespace","keys","onClose","DuplicateToAction","_ref6","draft","published","onComplete","dialogOpen","setDialogOpen","label","dialog","type","onHandle","crossDatasetDuplicatorTool","component","DEFAULT_CONFIG","types","crossDatasetDuplicator","definePlugin","arguments","undefined","_objectSpread","tools","prev","document","actions","_ref7"],"mappings":"0xDAEO,SAASA,IAA0D,IAArCC,yDAAW,EAAGC,yDAAY,EAC7D,MAAMC,EAAU,CACD,IAAbF,EAAiB,yBAAA,SAAAG,OAAoCH,EAAA,sBACvC,IAAdC,2BAAsCA,EAAA,gBACxB,IAAdA,oCAEF,wHAEO,OAAAC,EAAQE,KAAQ,IACzB,CAEa,MAAAC,EAAe,WAAA,IAACC,6DAAsC,MAAA,CACjEC,SAAU,SACVC,IAAK,EACLC,OAAQ,IACRC,gBAAiBJ,iDACnB,ECJAK,eAAsBC,EAAoBC,GACxC,MAAMC,SAACA,EAAUC,OAAAA,EAAAC,aAAQA,EAAcC,WAAAA,EAAAC,WAAYA,GAAcL,EAC3DM,EAA+B,GAG/BC,EAAS,CAAC,mBAAoBJ,EAAaI,QAAQA,OAAOC,SAASjB,KAAK,QACxEkB,EAAaF,KAAAA,OAAAA,EAAUF,KAAAA,OAAc,MAAdA,EAAcA,EAAA,IACrCK,QAA+BR,EAAOS,MAAMF,EAAO,CACvDR,eAAUA,IAAY,KAGpB,WAACS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AA,IAAjBvI,WAACA,GAAgBuI,EAC/B,OAAOV,GAASA,EAAM9P,SAASiI,GAC3B,IAAIoI,EAAO9R,GAA+ByQ,UAAsBzQ,OAAOtC,mBACvEoU,CAAA,GAIZ"}
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/lib/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
"use strict";function e(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,i)}return n}function t(t){for(var i=1;i<arguments.length;i++){var s=null!=arguments[i]?arguments[i]:{};i%2?e(Object(s),!0).forEach((function(e){n(t,e,s[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(s)):e(Object(s)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(s,e))}))}return t}function n(e,t,n){return(t=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var i=n.call(e,t||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}Object.defineProperty(exports,"__esModule",{value:!0});var i=require("sanity"),s=require("react/jsx-runtime"),o=require("react"),a=require("@sanity/icons"),d=require("@sanity/studio-secrets"),l=require("@sanity/ui"),r=require("async/mapLimit"),c=require("async/asyncify"),u=require("@sanity/mutator"),h=require("dset"),p=require("@sanity/asset-utils");function f(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var g=f(o),x=f(r),m=f(c);function j(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;const n=[1===e?"This Document contains":"These ".concat(e," Documents contain"),1===t?"1 Reference.":"".concat(t," References."),1===t?"That Document":"Those Documents","may have References too. If referenced Documents do not exist at the target Destination, this transaction will fail."];return n.join(" ")}const b=function(){let e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];return{position:"sticky",top:0,zIndex:100,backgroundColor:e?"rgba(10,10,10,0.95)":"rgba(255,255,255,0.95)"}};async function y(e){const{fetchIds:t,client:n,pluginConfig:i,currentIds:s,projection:o}=e,a=[],d=["_id in $fetchIds",i.filter].filter(Boolean).join(" && "),l="*[".concat(d,"]").concat(null!=o?o:""),r=await n.fetch(l,{fetchIds:null!=t?t:[]});if(!(null==r?void 0:r.length))return[];const c=null!=s?s:new Set,h=new Set(r.map((e=>e._id)).filter((e=>(null==s?void 0:s.size)?!c.has(e):Boolean(e))));h.size&&(a.push(...r),c.add(...h),await Promise.all(r.map((async e=>{const t=u.extractWithPath(".._ref",e).map((e=>e.value));if(t.length){const e=new Set(t.filter((e=>!c.has(e))));if(e.size){const t=await y({fetchIds:Array.from(e),currentIds:c,client:n,pluginConfig:i});(null==t?void 0:t.length)&&a.push(...t)}}}))));return a.filter(Boolean).reduce(((e,t)=>e.some((e=>e._id===t._id))?e:[...e,t]),[])}const v=["All","None",null,"New","Existing","Older",null,"Documents","Assets"];function S(e){const{payload:t,setPayload:n}=e,[i,a]=o.useState([]);return o.useEffect((()=>{!(null==i?void 0:i.length)&&t.every((e=>e.include))&&a(["ALL"])}),[null==i?void 0:i.length,t]),s.jsx(l.Card,{padding:1,radius:3,shadow:1,children:s.jsx(l.Flex,{gap:2,children:v.map(((e,o)=>e?s.jsx(l.Button,{fontSize:1,mode:"bleed",padding:2,text:e,disabled:i.includes(e.toUpperCase()),onClick:()=>function(e){if(!e||!t.length)return;const i=[...t];switch(e){case"ALL":i.map((e=>e.include=!0));break;case"NONE":i.map((e=>e.include=!1));break;case"NEW":i.map((e=>e.include=Boolean("CREATE"===e.status)));break;case"EXISTING":i.map((e=>e.include=Boolean("EXISTS"===e.status)));break;case"OLDER":i.map((e=>e.include=Boolean("OVERWRITE"===e.status)));break;case"ASSETS":i.map((e=>e.include=p.isAssetId(e.doc._id)));break;case"DOCUMENTS":i.map((e=>e.include=!p.isAssetId(e.doc._id)))}a([e]),n(i)}(e.toUpperCase())},e):s.jsx(l.Card,{borderLeft:!0},"divider-".concat(o))))})})}const w={EXISTS:"primary",OVERWRITE:"critical",UPDATE:"caution",CREATE:"positive",UNPUBLISHED:"caution"},D={EXISTS:"critical",OVERWRITE:"critical",UPDATE:"critical",CREATE:"positive",UNPUBLISHED:"default"},C={EXISTS:"This document already exists at the Destination with the same ID with the same Updated time.",OVERWRITE:"A newer version of this document exists at the Destination, and it will be overwritten with this version.",UPDATE:"An older version of this document exists at the Destination, and it will be overwritten with this version.",CREATE:"This document will be created at the destination.",UNPUBLISHED:"A Draft version of this Document exists in this Dataset, but only the Published version will be duplicated to the destination."},E={EXISTS:"This Asset already exists at the Destination",OVERWRITE:"This Asset already exists at the Destination",UPDATE:"This Asset already exists at the Destination",CREATE:"This Asset does not yet exist at the Destination",UNPUBLISHED:""},T={EXISTS:"RE-UPLOAD",OVERWRITE:"RE-UPLOAD",UPDATE:"RE-UPLOAD",CREATE:"UPLOAD",UNPUBLISHED:""};function I(e){const{status:t,isAsset:n}=e;if(!t)return null;const i=n?D[t]:w[t];if(!i)return s.jsx(l.Badge,{muted:!0,padding:2,fontSize:1,mode:"outline",children:"Checking..."});const o=n?E[t]:C[t],a=n?T[t]:t;return s.jsx(l.Tooltip,{content:s.jsx(l.Box,{padding:3,style:{maxWidth:200},children:s.jsx(l.Text,{size:1,children:o})}),fallbackPlacements:["right","left"],placement:"top",portal:!0,children:s.jsx(l.Badge,{muted:!0,padding:2,fontSize:1,tone:i,mode:"outline",children:a})})}function A(e){const{children:t,tone:n="caution"}=e;return s.jsx(l.Card,{padding:3,radius:2,shadow:1,tone:n,children:s.jsx(l.Text,{size:1,children:t})})}const _={apiVersion:"2021-05-19"};function k(e){var n,d,r;const{docs:c,token:f,pluginConfig:v}=e,w=l.useTheme().sanity.color.dark,D=i.useClient(_),C=i.useSchema(),E=i.useWorkspaces(),T=E.map((e=>t(t({},e),{},{disabled:e.dataset===D.config().dataset}))),[k,P]=o.useState(E.length&&null!=(n=T.find((e=>!e.disabled)))?n:null),[O,R]=o.useState(null),[B,U]=o.useState([]),[L,z]=o.useState(!1),[N,q]=o.useState(!1),[F,W]=o.useState(!1),[X,V]=o.useState([0,0]);async function G(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];const n=e.length?e:B;if(!n.length||!(null==k?void 0:k.name))return;const i=n.map((e=>{let{doc:t}=e;return t._id})),s=D.withConfig(t(t({},_),{},{dataset:k.dataset,projectId:k.projectId})),o=await s.fetch("*[_id in $payloadIds]{ _id, _updatedAt }",{payloadIds:i}),a=n.map((e=>{var t;const n=o.find((t=>t._id===e.doc._id));return(null==n?void 0:n._updatedAt)&&(null==(t=null==e?void 0:e.doc)?void 0:t._updatedAt)?n._updatedAt===e.doc._updatedAt?e.status="EXISTS":n._updatedAt&&e.doc._updatedAt&&(e.status=new Date(n._updatedAt)>new Date(e.doc._updatedAt)?"OVERWRITE":"UPDATE"):e.status="CREATE",e}));U(a)}o.useEffect((()=>{const e=[],t=[];c.forEach((n=>{const i=u.extractWithPath(".._ref",n).map((e=>e.value));e.push(...i),t.push({include:!0,doc:n})})),U(t);const n=c.length,i=e.length;e.length&&(z(!0),R({tone:"caution",text:j(n,i)}))}),[c]),o.useEffect((()=>{G()}),[k]);const H=B.length,Q=B.findIndex((e=>{let{doc:t}=e;return"svg"===t.extension})),M=B.filter((e=>e.include&&!p.isAssetId(e.doc._id))).length,$=B.filter((e=>e.include&&p.isAssetId(e.doc._id))).length,Y=M+$,J=null!=(d=null==k?void 0:k.title)?d:null==k?void 0:k.name,K=new Set(T.map((e=>null==e?void 0:e.projectId)).filter(Boolean)).size>1,Z=[Y,"/",H,"Documents and Assets selected"].join(" "),ee=g.default.useMemo((()=>{const e=["Duplicate"];return M>1&&e.push(String(M),1===M?"Document":"Documents"),$>1&&e.push("and",String($),1===$?"Asset":"Assets"),D.config().projectId!==(null==k?void 0:k.projectId)&&e.push("between Projects"),e.push("to",String(J)),e.join(" ")}),[M,$,D,null==k?void 0:k.projectId,J]);return T.length<2?s.jsxs(A,{tone:"critical",children:[s.jsx("code",{children:"sanity.config.ts"})," must contain at least two Workspaces to use this plugin."]}):s.jsx(l.Container,{width:1,children:s.jsx(l.Card,{border:!0,children:s.jsx(l.Stack,{children:s.jsxs(s.Fragment,{children:[s.jsx(l.Card,{borderBottom:!0,padding:4,style:b(w),children:s.jsxs(l.Stack,{space:4,children:[s.jsxs(l.Flex,{gap:3,children:[s.jsxs(l.Stack,{style:{flex:1},space:3,children:[s.jsx(l.Label,{children:"Duplicate from"}),s.jsx(l.Select,{readOnly:!0,value:null==(r=T.find((e=>e.disabled)))?void 0:r.name,children:T.filter((e=>e.disabled)).map((e=>{var t;return s.jsxs("option",{value:e.name,disabled:e.disabled,children:[null!=(t=e.title)?t:e.name,K?" (".concat(e.projectId,")"):""]},e.name)}))})]}),s.jsx(l.Box,{padding:4,paddingTop:5,paddingBottom:0,children:s.jsx(l.Text,{size:3,children:s.jsx(a.ArrowRightIcon,{})})}),s.jsxs(l.Stack,{style:{flex:1},space:3,children:[s.jsx(l.Label,{children:"To Destination"}),s.jsx(l.Select,{onChange:function(e){if(!T.length)return;const t=T.find((t=>t.name===e.currentTarget.value));t&&P(t)},children:T.map((e=>{var t;return s.jsxs("option",{value:e.name,disabled:e.disabled,children:[null!=(t=e.title)?t:e.name,K?" (".concat(e.projectId,")"):"",e.disabled?" (Current)":""]},e.name)}))})]})]}),N&&s.jsx(l.Card,{border:!0,radius:2,children:s.jsx(l.Card,{style:{width:"100%",transform:"scaleX(".concat(X[0]/X[1],")"),transformOrigin:"left",transition:"transform .2s ease",boxSizing:"border-box"},padding:1,tone:"positive"})}),B.length>0&&s.jsxs(s.Fragment,{children:[s.jsx(l.Label,{children:Z}),s.jsx(S,{payload:B,setPayload:U})]})]})}),O&&s.jsx(l.Box,{paddingX:4,paddingTop:4,children:s.jsx(l.Card,{padding:3,radius:2,shadow:1,tone:O.tone,children:s.jsx(l.Text,{size:1,children:O.text})})}),B.length>0&&s.jsx(l.Stack,{padding:4,space:3,children:B.map(((e,t)=>{let{doc:n,include:o,status:a,hasDraft:d}=e;const r=C.get(n._type);return s.jsxs(g.default.Fragment,{children:[s.jsxs(l.Flex,{align:"center",children:[s.jsx(l.Checkbox,{checked:o,onChange:()=>function(e){const t=B.map((t=>(t.doc._id===e&&(t.include=!t.include),t)));U(t)}(n._id)}),s.jsx(l.Box,{flex:1,paddingX:3,children:r?s.jsx(i.Preview,{value:n,schemaType:r}):s.jsx(l.Card,{tone:"caution",children:"Invalid schema type"})}),s.jsxs(l.Flex,{align:"center",gap:2,children:[d?s.jsx(I,{status:"UNPUBLISHED",isAsset:!1}):null,s.jsx(I,{status:a,isAsset:p.isAssetId(n._id)})]})]}),"svg"===(null==n?void 0:n.extension)&&t===Q&&s.jsx(l.Card,{padding:3,radius:2,shadow:1,tone:"caution",children:s.jsxs(l.Text,{size:1,children:["Due to how SVGs are sanitized after first uploaded, duplicated SVG assets may have new ",s.jsx("code",{children:"_id"}),"'s at the destination. The newly generated ",s.jsx("code",{children:"_id"})," will be the same in each duplication, but it will never be the same ",s.jsx("code",{children:"_id"})," as the first time this Asset was uploaded. References to the asset will be updated to use the new"," ",s.jsx("code",{children:"_id"}),"."]})})]},n._id)}))}),s.jsxs(l.Stack,{space:2,padding:4,paddingTop:0,children:[L&&s.jsx(l.Button,{fontSize:2,padding:4,tone:"positive",mode:"ghost",icon:a.SearchIcon,onClick:async function(){W(!0);const e=c.map((e=>e._id)),t=await y({fetchIds:e,client:D,pluginConfig:v}),n=await y({fetchIds:e.map((e=>"drafts.".concat(e))),client:D,projection:"{_id}",pluginConfig:v}),i=new Set(n.map((e=>{let{_id:t}=e;return t}))),s=t.map((e=>({doc:e,include:!0,status:void 0,hasDraft:i.has("drafts.".concat(e._id))})));U(s),G(s),W(!1)},text:"Gather References",disabled:N||!Y||F}),s.jsx(l.Button,{fontSize:2,padding:4,tone:"positive",icon:a.LaunchIcon,onClick:async function(){if(!k)return;q(!0);const e=B.filter((e=>{let{doc:t,include:n}=e;return n&&p.isAssetId(t._id)})).length;let n=0;V([n,e]),R({text:"Duplicating...",tone:"default"});const i=D.withConfig(t(t({},_),{},{dataset:k.dataset,projectId:k.projectId})),s=[],o=[];async function a(t){if(p.isAssetId(t._id)){const a=p.isSanityFileAsset(t),d=a?t.url:"".concat(t.url,"?dlRaw=true"),l=a?{}:{headers:{Authorization:"Bearer ".concat(f)}};return await fetch(d,l).then((async e=>{const n=await e.blob(),d={filename:t.originalFilename},l=await i.assets.upload(a?"file":"image",n,d);"svg"===(null==t?void 0:t.extension)&&o.push({old:t._id,new:l._id}),s.push(l)})),n+=1,R({text:"Duplicating ".concat(n,"/").concat(e," ").concat("Assets"),tone:"default"}),V([n,e])}return s.push(t)}const d=new Promise(((e,t)=>{const n=B.filter((e=>e.include)).map((e=>e.doc));x.default(n,3,m.default(a),(n=>{n&&(q(!1),R({tone:"critical",text:"Duplication Failed"}),console.error(n),t(new Error("Duplication Failed"))),e()}))}));await d;const l=s.map((e=>{const t=u.extractWithPath(".._ref",e);return t.length?(t.forEach((t=>{var n;const i=null==(n=o.find((e=>e.old===t.value)))?void 0:n.new;if(i){const n=t.path.join(".");h.dset(e,n,i)}})),e):e})),r=i.transaction();l.forEach((e=>{r.createOrReplace(e)})),await r.commit().then((e=>{R({tone:"positive",text:"Duplication complete!"}),G()})).catch((e=>{R({tone:"critical",text:e.details.description})})),q(!1),V([0,0])},text:ee,disabled:N||!Y||F})]})]})})})})}function P(e){var t,n;const{token:a,pluginConfig:d}=e,r=i.useClient(_),c=i.useSchema().getTypeNames(),[u,h]=o.useState(""),[p,f]=o.useState({docs:[]});function g(e){e&&e.preventDefault(),r.fetch(u).then((e=>{const t=e.length?e.filter((e=>c.includes(e._type))).filter((e=>!e._id.startsWith("drafts."))):[];f({docs:t})})).catch((e=>console.error(e)))}return o.useEffect((()=>{var e;!(null==(e=p.docs)?void 0:e.length)&&u&&g()}),[]),s.jsx(l.Container,{width:[1,1,1,3],padding:[0,0,0,5],children:s.jsxs(l.Grid,{columns:[1,1,1,2],gap:[1,1,1,4],children:[s.jsx(l.Box,{padding:[2,2,2,0],children:s.jsx(l.Card,{padding:4,radius:3,border:!0,children:s.jsxs(l.Stack,{space:4,children:[s.jsx(l.Box,{children:s.jsx(l.Label,{children:"Initial Documents Query"})}),s.jsx(l.Box,{children:s.jsx(l.Text,{children:"Start with a valid GROQ query to load initial documents. The query will need to return an Array of Objects. Drafts will be removed from the results."})}),s.jsx("form",{onSubmit:g,children:s.jsxs(l.Flex,{children:[s.jsx(l.Box,{flex:1,paddingRight:2,children:s.jsx(l.TextInput,{style:{fontFamily:"monospace"},fontSize:2,onChange:e=>h(e.currentTarget.value),padding:4,placeholder:'*[_type == "article"]',value:null!=u?u:""})}),s.jsx(l.Button,{padding:2,paddingX:4,tone:"primary",onClick:g,text:"Query",disabled:!u})]})})]})})}),!(null==(t=p.docs)?void 0:t.length)||p.docs.length<1&&s.jsx(l.Container,{width:1,children:s.jsx(l.Card,{padding:5,children:u?"No Documents registered to the Schema match this query":"Start with a valid GROQ query"})}),(null==(n=p.docs)?void 0:n.length)>0&&s.jsx(k,{docs:p.docs,token:a,pluginConfig:d})]})})}function O(e){const{docs:t,token:n,pluginConfig:a}=e,[d,r]=o.useState([]),{follow:c=[]}=a,[u,h]=o.useState(1===c.length?c[0]:"outbound"),p=i.useClient();return o.useEffect((()=>{(async()=>{if(c.includes("inbound")){const n=await p.fetch("*[references($id)]",{id:t[0]._id});r([...e.docs,...n])}})()}),[]),s.jsxs(l.Container,{children:[c.length>1&&(c.includes("inbound")||c.includes("outbound"))?s.jsx(l.Card,{paddingX:4,paddingBottom:4,marginBottom:4,borderBottom:!0,children:s.jsxs(l.Grid,{columns:2,gap:4,children:[c.includes("outbound")?s.jsx(l.Button,{mode:"ghost",tone:"primary",selected:"outbound"===u,onClick:()=>h("outbound"),text:"Outbound"}):null,c.includes("inbound")?s.jsx(l.Button,{mode:"ghost",tone:"primary",selected:"inbound"===u,onClick:()=>h("inbound"),disabled:0===d.length,text:d.length>0?"Inbound (".concat(d.length,")"):"No inbound references"}):null]})}):null,s.jsx(k,{docs:"outbound"===u?t:d,token:n,pluginConfig:a})]})}const R="CrossDatasetDuplicator";function B(){const e=i.useClient(_),t=g.default.useCallback((()=>{e.delete({query:'*[_id == "secrets.'.concat(R,'"]')})}),[e]);return s.jsx(l.Flex,{align:"center",justify:"flex-end",paddingX:[2,2,2,5],paddingY:5,children:s.jsx(l.Button,{text:"Reset Secret",onClick:t,mode:"ghost",tone:"critical",fontSize:1,padding:2})})}const U=[{key:"bearerToken",title:"An API token with Viewer permissions is required to duplicate the original files of assets, and will be used for all Duplications. Create one at sanity.io/manage",description:""}];function L(e){var t;const{mode:n="tool",docs:i=[],pluginConfig:a}=null!=(t=e.tool.options)?t:{},{loading:r,secrets:c}=d.useSecrets(R),[u,h]=o.useState(!1);return o.useEffect((()=>{c&&h(!(null==c?void 0:c.bearerToken))}),[c]),r?s.jsx(l.Flex,{justify:"center",align:"center",children:s.jsx(l.Box,{padding:5,children:s.jsx(l.Spinner,{})})}):!r&&u||!(null==c?void 0:c.bearerToken)?s.jsx(d.SettingsView,{title:"Token Required",namespace:R,keys:U,onClose:()=>h(!1)}):"tool"===n&&a?s.jsxs(s.Fragment,{children:[s.jsx(P,{token:null==c?void 0:c.bearerToken,pluginConfig:a}),s.jsx(B,{})]}):(null==i?void 0:i.length)?a?s.jsx(O,{docs:i,token:null==c?void 0:c.bearerToken,pluginConfig:a}):s.jsx(A,{children:"No plugin config"}):s.jsx(A,{children:"No docs passed into Duplicator Tool"})}function z(e){let{draft:t,published:n,onComplete:i,pluginConfig:d}=e;const[l,r]=o.useState(!1);return{disabled:t,title:t?"Document must be Published to begin":null,label:"Duplicate to...",dialog:l&&n&&{type:"modal",title:"Cross Dataset Duplicator",content:s.jsx(L,{tool:{options:{mode:"action",docs:[n],pluginConfig:d}}}),onClose:()=>{i(),r(!1)}},onHandle:()=>r(!0),icon:a.LaunchIcon}}const N=e=>({title:"Duplicator",name:"duplicator",icon:a.LaunchIcon,component:L,options:{mode:"tool",docs:[],pluginConfig:e}}),q={tool:!0,types:[],filter:"",follow:["outbound"]},F=i.definePlugin((function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const n=t(t({},q),e),{types:i}=n;return{name:"@sanity/cross-dataset-duplicator",tools:e=>n.tool?[...e,N(n)]:e,document:{actions:(e,s)=>{let{schemaType:o}=s;return i&&i.includes(o)?[...e,e=>z(t(t({},e),{},{pluginConfig:n}))]:e}}}}));exports.crossDatasetDuplicator=F;
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
"use strict";const e=["pluginConfig"];function t(e,t){if(null==e)return{};var n,i,o=function(e,t){if(null==e)return{};var n,i,o={},s=Object.keys(e);for(i=0;i<s.length;i++)n=s[i],t.indexOf(n)>=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);for(i=0;i<s.length;i++)n=s[i],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}function n(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,i)}return n}function i(e){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{};t%2?n(Object(i),!0).forEach((function(t){o(e,t,i[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):n(Object(i)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))}))}return e}function o(e,t,n){return(t=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var i=n.call(e,t||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}Object.defineProperty(exports,"__esModule",{value:!0});var s=require("sanity"),a=require("react/jsx-runtime"),r=require("react"),d=require("@sanity/icons"),l=require("@sanity/studio-secrets"),c=require("@sanity/ui"),u=require("async/mapLimit"),h=require("async/asyncify"),p=require("@sanity/mutator"),f=require("dset"),g=require("@sanity/asset-utils");function x(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var m=x(r),j=x(u),b=x(h);function y(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return[1===e?"This Document contains":"These ".concat(e," Documents contain"),1===t?"1 Reference.":"".concat(t," References."),1===t?"That Document":"Those Documents","may have References too. If referenced Documents do not exist at the target Destination, this transaction will fail."].join(" ")}const v=function(){return{position:"sticky",top:0,zIndex:100,backgroundColor:!(arguments.length>0&&void 0!==arguments[0])||arguments[0]?"rgba(10,10,10,0.95)":"rgba(255,255,255,0.95)"}};async function S(e){const{fetchIds:t,client:n,pluginConfig:i,currentIds:o,projection:s}=e,a=[],r=["_id in $fetchIds",i.filter].filter(Boolean).join(" && "),d="*[".concat(r,"]").concat(null!=s?s:""),l=await n.fetch(d,{fetchIds:null!=t?t:[]});if(!(null==l?void 0:l.length))return[];const c=null!=o?o:new Set,u=new Set(l.map((e=>e._id)).filter((e=>(null==o?void 0:o.size)?!c.has(e):Boolean(e))));u.size&&(a.push(...l),c.add(...u),await Promise.all(l.map((async e=>{const t=p.extractWithPath(".._ref",e).map((e=>e.value));if(t.length){const e=new Set(t.filter((e=>!c.has(e))));if(e.size){const t=await S({fetchIds:Array.from(e),currentIds:c,client:n,pluginConfig:i});(null==t?void 0:t.length)&&a.push(...t)}}}))));return a.filter(Boolean).reduce(((e,t)=>e.some((e=>e._id===t._id))?e:[...e,t]),[])}const w=["All","None",null,"New","Existing","Older",null,"Documents","Assets"];function D(e){const{payload:t,setPayload:n}=e,[i,o]=r.useState([]);return r.useEffect((()=>{!(null==i?void 0:i.length)&&t.every((e=>e.include))&&o(["ALL"])}),[null==i?void 0:i.length,t]),a.jsx(c.Card,{padding:1,radius:3,shadow:1,children:a.jsx(c.Flex,{gap:2,children:w.map(((e,s)=>e?a.jsx(c.Button,{fontSize:1,mode:"bleed",padding:2,text:e,disabled:i.includes(e.toUpperCase()),onClick:()=>function(e){if(!e||!t.length)return;const i=[...t];switch(e){case"ALL":i.map((e=>e.include=!0));break;case"NONE":i.map((e=>e.include=!1));break;case"NEW":i.map((e=>e.include=Boolean("CREATE"===e.status)));break;case"EXISTING":i.map((e=>e.include=Boolean("EXISTS"===e.status)));break;case"OLDER":i.map((e=>e.include=Boolean("OVERWRITE"===e.status)));break;case"ASSETS":i.map((e=>e.include=g.isAssetId(e.doc._id)));break;case"DOCUMENTS":i.map((e=>e.include=!g.isAssetId(e.doc._id)))}o([e]),n(i)}(e.toUpperCase())},e):a.jsx(c.Card,{borderLeft:!0},"divider-".concat(s))))})})}const C={EXISTS:"primary",OVERWRITE:"critical",UPDATE:"caution",CREATE:"positive",UNPUBLISHED:"caution"},E={EXISTS:"critical",OVERWRITE:"critical",UPDATE:"critical",CREATE:"positive",UNPUBLISHED:"default"},T={EXISTS:"This document already exists at the Destination with the same ID with the same Updated time.",OVERWRITE:"A newer version of this document exists at the Destination, and it will be overwritten with this version.",UPDATE:"An older version of this document exists at the Destination, and it will be overwritten with this version.",CREATE:"This document will be created at the destination.",UNPUBLISHED:"A Draft version of this Document exists in this Dataset, but only the Published version will be duplicated to the destination."},I={EXISTS:"This Asset already exists at the Destination",OVERWRITE:"This Asset already exists at the Destination",UPDATE:"This Asset already exists at the Destination",CREATE:"This Asset does not yet exist at the Destination",UNPUBLISHED:""},A={EXISTS:"RE-UPLOAD",OVERWRITE:"RE-UPLOAD",UPDATE:"RE-UPLOAD",CREATE:"UPLOAD",UNPUBLISHED:""};function O(e){const{status:t,isAsset:n}=e;if(!t)return null;const i=n?E[t]:C[t];if(!i)return a.jsx(c.Badge,{muted:!0,padding:2,fontSize:1,mode:"outline",children:"Checking..."});const o=n?I[t]:T[t],s=n?A[t]:t;return a.jsx(c.Tooltip,{content:a.jsx(c.Box,{padding:3,style:{maxWidth:200},children:a.jsx(c.Text,{size:1,children:o})}),fallbackPlacements:["right","left"],placement:"top",portal:!0,children:a.jsx(c.Badge,{muted:!0,padding:2,fontSize:1,tone:i,mode:"outline",children:s})})}function _(e){const{children:t,tone:n="caution"}=e;return a.jsx(c.Card,{padding:3,radius:2,shadow:1,tone:n,children:a.jsx(c.Text,{size:1,children:t})})}const k={apiVersion:"2021-05-19"};function P(e){var t,n,o;const{docs:l,token:u,pluginConfig:h}=e,x=c.useTheme().sanity.color.dark,w=s.useClient(k),C=s.useSchema(),E=s.useWorkspaces(),T=E.map((e=>i(i({},e),{},{disabled:e.dataset===w.config().dataset}))),[I,A]=r.useState(E.length&&null!=(t=T.find((e=>!e.disabled)))?t:null),[P,R]=r.useState(null),[B,U]=r.useState([]),[L,z]=r.useState(!1),[N,q]=r.useState(!1),[F,W]=r.useState(!1),[X,V]=r.useState([0,0]);async function G(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];const t=e.length?e:B;if(!t.length||!(null==I?void 0:I.name))return;const n=t.map((e=>{let{doc:t}=e;return t._id})),o=w.withConfig(i(i({},k),{},{dataset:I.dataset,projectId:I.projectId})),s=await o.fetch("*[_id in $payloadIds]{ _id, _updatedAt }",{payloadIds:n}),a=t.map((e=>{var t;const n=s.find((t=>t._id===e.doc._id));return(null==n?void 0:n._updatedAt)&&(null==(t=null==e?void 0:e.doc)?void 0:t._updatedAt)?n._updatedAt===e.doc._updatedAt?e.status="EXISTS":n._updatedAt&&e.doc._updatedAt&&(e.status=new Date(n._updatedAt)>new Date(e.doc._updatedAt)?"OVERWRITE":"UPDATE"):e.status="CREATE",e}));U(a)}r.useEffect((()=>{const e=[],t=[];l.forEach((n=>{const i=p.extractWithPath(".._ref",n).map((e=>e.value));e.push(...i),t.push({include:!0,doc:n})})),U(t);const n=l.length,i=e.length;e.length&&(z(!0),R({tone:"caution",text:y(n,i)}))}),[l]),r.useEffect((()=>{G()}),[I]);const H=B.length,Q=B.findIndex((e=>{let{doc:t}=e;return"svg"===t.extension})),M=B.filter((e=>e.include&&!g.isAssetId(e.doc._id))).length,$=B.filter((e=>e.include&&g.isAssetId(e.doc._id))).length,Y=M+$,J=null!=(n=null==I?void 0:I.title)?n:null==I?void 0:I.name,K=new Set(T.map((e=>null==e?void 0:e.projectId)).filter(Boolean)).size>1,Z=[Y,"/",H,"Documents and Assets selected"].join(" "),ee=m.default.useMemo((()=>{const e=["Duplicate"];return M>1&&e.push(String(M),1===M?"Document":"Documents"),$>1&&e.push("and",String($),1===$?"Asset":"Assets"),w.config().projectId!==(null==I?void 0:I.projectId)&&e.push("between Projects"),e.push("to",String(J)),e.join(" ")}),[M,$,w,null==I?void 0:I.projectId,J]);return T.length<2?a.jsxs(_,{tone:"critical",children:[a.jsx("code",{children:"sanity.config.ts"})," must contain at least two Workspaces to use this plugin."]}):a.jsx(c.Container,{width:1,children:a.jsx(c.Card,{border:!0,children:a.jsx(c.Stack,{children:a.jsxs(a.Fragment,{children:[a.jsx(c.Card,{borderBottom:!0,padding:4,style:v(x),children:a.jsxs(c.Stack,{space:4,children:[a.jsxs(c.Flex,{gap:3,children:[a.jsxs(c.Stack,{style:{flex:1},space:3,children:[a.jsx(c.Label,{children:"Duplicate from"}),a.jsx(c.Select,{readOnly:!0,value:null==(o=T.find((e=>e.disabled)))?void 0:o.name,children:T.filter((e=>e.disabled)).map((e=>{var t;return a.jsxs("option",{value:e.name,disabled:e.disabled,children:[null!=(t=e.title)?t:e.name,K?" (".concat(e.projectId,")"):""]},e.name)}))})]}),a.jsx(c.Box,{padding:4,paddingTop:5,paddingBottom:0,children:a.jsx(c.Text,{size:3,children:a.jsx(d.ArrowRightIcon,{})})}),a.jsxs(c.Stack,{style:{flex:1},space:3,children:[a.jsx(c.Label,{children:"To Destination"}),a.jsx(c.Select,{onChange:function(e){if(!T.length)return;const t=T.find((t=>t.name===e.currentTarget.value));t&&A(t)},children:T.map((e=>{var t;return a.jsxs("option",{value:e.name,disabled:e.disabled,children:[null!=(t=e.title)?t:e.name,K?" (".concat(e.projectId,")"):"",e.disabled?" (Current)":""]},e.name)}))})]})]}),N&&a.jsx(c.Card,{border:!0,radius:2,children:a.jsx(c.Card,{style:{width:"100%",transform:"scaleX(".concat(X[0]/X[1],")"),transformOrigin:"left",transition:"transform .2s ease",boxSizing:"border-box"},padding:1,tone:"positive"})}),B.length>0&&a.jsxs(a.Fragment,{children:[a.jsx(c.Label,{children:Z}),a.jsx(D,{payload:B,setPayload:U})]})]})}),P&&a.jsx(c.Box,{paddingX:4,paddingTop:4,children:a.jsx(c.Card,{padding:3,radius:2,shadow:1,tone:P.tone,children:a.jsx(c.Text,{size:1,children:P.text})})}),B.length>0&&a.jsx(c.Stack,{padding:4,space:3,children:B.map(((e,t)=>{let{doc:n,include:i,status:o,hasDraft:r}=e;const d=C.get(n._type);return a.jsxs(m.default.Fragment,{children:[a.jsxs(c.Flex,{align:"center",children:[a.jsx(c.Checkbox,{checked:i,onChange:()=>function(e){const t=B.map((t=>(t.doc._id===e&&(t.include=!t.include),t)));U(t)}(n._id)}),a.jsx(c.Box,{flex:1,paddingX:3,children:d?a.jsx(s.Preview,{value:n,schemaType:d}):a.jsx(c.Card,{tone:"caution",children:"Invalid schema type"})}),a.jsxs(c.Flex,{align:"center",gap:2,children:[r?a.jsx(O,{status:"UNPUBLISHED",isAsset:!1}):null,a.jsx(O,{status:o,isAsset:g.isAssetId(n._id)})]})]}),"svg"===(null==n?void 0:n.extension)&&t===Q&&a.jsx(c.Card,{padding:3,radius:2,shadow:1,tone:"caution",children:a.jsxs(c.Text,{size:1,children:["Due to how SVGs are sanitized after first uploaded, duplicated SVG assets may have new ",a.jsx("code",{children:"_id"}),"'s at the destination. The newly generated ",a.jsx("code",{children:"_id"})," will be the same in each duplication, but it will never be the same ",a.jsx("code",{children:"_id"})," as the first time this Asset was uploaded. References to the asset will be updated to use the new"," ",a.jsx("code",{children:"_id"}),"."]})})]},n._id)}))}),a.jsxs(c.Stack,{space:2,padding:4,paddingTop:0,children:[L&&a.jsx(c.Button,{fontSize:2,padding:4,tone:"positive",mode:"ghost",icon:d.SearchIcon,onClick:async function(){W(!0);const e=l.map((e=>e._id)),t=await S({fetchIds:e,client:w,pluginConfig:h}),n=await S({fetchIds:e.map((e=>"drafts.".concat(e))),client:w,projection:"{_id}",pluginConfig:h}),i=new Set(n.map((e=>{let{_id:t}=e;return t}))),o=t.map((e=>({doc:e,include:!0,status:void 0,hasDraft:i.has("drafts.".concat(e._id))})));U(o),G(o),W(!1)},text:"Gather References",disabled:N||!Y||F}),a.jsx(c.Button,{fontSize:2,padding:4,tone:"positive",icon:d.LaunchIcon,onClick:async function(){if(!I)return;q(!0);const e=B.filter((e=>{let{doc:t,include:n}=e;return n&&g.isAssetId(t._id)})).length;let t=0;V([t,e]),R({text:"Duplicating...",tone:"default"});const n=w.withConfig(i(i({},k),{},{dataset:I.dataset,projectId:I.projectId})),o=[],s=[];async function a(i){if(g.isAssetId(i._id)){const a=g.isSanityFileAsset(i),r=a?i.url:"".concat(i.url,"?dlRaw=true"),d=a?{}:{headers:{Authorization:"Bearer ".concat(u)}};return await fetch(r,d).then((async e=>{const t=await e.blob(),r={filename:i.originalFilename},d=await n.assets.upload(a?"file":"image",t,r);"svg"===(null==i?void 0:i.extension)&&s.push({old:i._id,new:d._id}),o.push(d)})),t+=1,R({text:"Duplicating ".concat(t,"/").concat(e," ").concat("Assets"),tone:"default"}),V([t,e])}return o.push(i)}const r=new Promise(((e,t)=>{const n=B.filter((e=>e.include)).map((e=>e.doc));j.default(n,3,b.default(a),(n=>{n&&(q(!1),R({tone:"critical",text:"Duplication Failed"}),console.error(n),t(new Error("Duplication Failed"))),e()}))}));await r;const d=o.map((e=>{const t=p.extractWithPath(".._ref",e);return t.length?(t.forEach((t=>{var n;const i=null==(n=s.find((e=>e.old===t.value)))?void 0:n.new;if(i){const n=t.path.join(".");f.dset(e,n,i)}})),e):e})),l=n.transaction();d.forEach((e=>{l.createOrReplace(e)})),await l.commit().then((e=>{R({tone:"positive",text:"Duplication complete!"}),G()})).catch((e=>{R({tone:"critical",text:e.details.description})})),q(!1),V([0,0])},text:ee,disabled:N||!Y||F})]})]})})})})}function R(e){var t,n;const{token:i,pluginConfig:o}=e,d=s.useClient(k),l=s.useSchema().getTypeNames(),[u,h]=r.useState(""),[p,f]=r.useState({docs:[]});function g(e){e&&e.preventDefault(),d.fetch(u).then((e=>{const t=e.length?e.filter((e=>l.includes(e._type))).filter((e=>!e._id.startsWith("drafts."))):[];f({docs:t})})).catch((e=>console.error(e)))}return r.useEffect((()=>{var e;!(null==(e=p.docs)?void 0:e.length)&&u&&g()}),[]),a.jsx(c.Container,{width:[1,1,1,3],padding:[0,0,0,5],children:a.jsxs(c.Grid,{columns:[1,1,1,2],gap:[1,1,1,4],children:[a.jsx(c.Box,{padding:[2,2,2,0],children:a.jsx(c.Card,{padding:4,radius:3,border:!0,children:a.jsxs(c.Stack,{space:4,children:[a.jsx(c.Box,{children:a.jsx(c.Label,{children:"Initial Documents Query"})}),a.jsx(c.Box,{children:a.jsx(c.Text,{children:"Start with a valid GROQ query to load initial documents. The query will need to return an Array of Objects. Drafts will be removed from the results."})}),a.jsx("form",{onSubmit:g,children:a.jsxs(c.Flex,{children:[a.jsx(c.Box,{flex:1,paddingRight:2,children:a.jsx(c.TextInput,{style:{fontFamily:"monospace"},fontSize:2,onChange:e=>h(e.currentTarget.value),padding:4,placeholder:'*[_type == "article"]',value:null!=u?u:""})}),a.jsx(c.Button,{padding:2,paddingX:4,tone:"primary",onClick:g,text:"Query",disabled:!u})]})})]})})}),!(null==(t=p.docs)?void 0:t.length)||p.docs.length<1&&a.jsx(c.Container,{width:1,children:a.jsx(c.Card,{padding:5,children:u?"No Documents registered to the Schema match this query":"Start with a valid GROQ query"})}),(null==(n=p.docs)?void 0:n.length)>0&&a.jsx(P,{docs:p.docs,token:i,pluginConfig:o})]})})}function B(e){const{docs:t,token:n,pluginConfig:i}=e,[o,d]=r.useState([]),{follow:l=[]}=i,[u,h]=r.useState(1===l.length?l[0]:"outbound"),p=s.useClient();return r.useEffect((()=>{(async()=>{if(l.includes("inbound")){const n=await p.fetch("*[references($id)]",{id:t[0]._id});d([...e.docs,...n])}})()}),[]),a.jsxs(c.Container,{children:[l.length>1&&(l.includes("inbound")||l.includes("outbound"))?a.jsx(c.Card,{paddingX:4,paddingBottom:4,marginBottom:4,borderBottom:!0,children:a.jsxs(c.Grid,{columns:2,gap:4,children:[l.includes("outbound")?a.jsx(c.Button,{mode:"ghost",tone:"primary",selected:"outbound"===u,onClick:()=>h("outbound"),text:"Outbound"}):null,l.includes("inbound")?a.jsx(c.Button,{mode:"ghost",tone:"primary",selected:"inbound"===u,onClick:()=>h("inbound"),disabled:0===o.length,text:o.length>0?"Inbound (".concat(o.length,")"):"No inbound references"}):null]})}):null,a.jsx(P,{docs:"outbound"===u?t:o,token:n,pluginConfig:i})]})}const U="CrossDatasetDuplicator",L={tool:!0,types:[],filter:"",follow:["outbound"]};function z(){const e=s.useClient(k),t=m.default.useCallback((()=>{e.delete({query:'*[_id == "secrets.'.concat(U,'"]')})}),[e]);return a.jsx(c.Flex,{align:"center",justify:"flex-end",paddingX:[2,2,2,5],paddingY:5,children:a.jsx(c.Button,{text:"Reset Secret",onClick:t,mode:"ghost",tone:"critical",fontSize:1,padding:2})})}const N=r.createContext(L);function q(){return r.useContext(N)}const F=[{key:"bearerToken",title:"An API token with Viewer permissions is required to duplicate the original files of assets, and will be used for all Duplications. Create one at sanity.io/manage",description:""}];function W(e){const{mode:t="tool",docs:n=[]}=null!=e?e:{},i=q(),{loading:o,secrets:s}=l.useSecrets(U),[d,u]=r.useState(!1);return r.useEffect((()=>{s&&u(!(null==s?void 0:s.bearerToken))}),[s]),o?a.jsx(c.Flex,{justify:"center",align:"center",children:a.jsx(c.Box,{padding:5,children:a.jsx(c.Spinner,{})})}):!o&&d||!(null==s?void 0:s.bearerToken)?a.jsx(l.SettingsView,{title:"Token Required",namespace:U,keys:F,onClose:()=>u(!1)}):"tool"===t&&i?a.jsxs(a.Fragment,{children:[a.jsx(R,{token:null==s?void 0:s.bearerToken,pluginConfig:i}),a.jsx(z,{})]}):(null==n?void 0:n.length)?i?a.jsx(B,{docs:n,token:null==s?void 0:s.bearerToken,pluginConfig:i}):a.jsx(_,{children:"No plugin config"}):a.jsx(_,{children:"No docs passed into Duplicator Tool"})}function X(e){const{docs:t=[]}=e;return a.jsx(W,{mode:"action",docs:t})}const V=e=>{const{draft:t,published:n,onComplete:i}=e,[o,s]=r.useState(!1);return{disabled:t,title:t?"Document must be Published to begin":null,label:"Duplicate to...",dialog:o&&n&&{type:"modal",title:"Cross Dataset Duplicator",content:a.jsx(X,{docs:[n]}),onClose:()=>{i(),s(!1)}},onHandle:()=>s(!0),icon:d.LaunchIcon}};function G(e){var t;const{docs:n=[]}=null!=(t=e.tool.options)?t:{};return a.jsx(W,{mode:"tool",docs:n})}V.action="duplicateTo";const H=s.definePlugin((function(){let n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const o=i(i({},L),n),{types:s}=o;return{name:"@sanity/cross-dataset-duplicator",tools:e=>o.tool?[...e,{title:"Duplicator",name:"duplicator",icon:d.LaunchIcon,component:G,options:{docs:[]}}]:e,studio:{components:{layout:n=>function(n){const{pluginConfig:i}=n,o=t(n,e);return a.jsx(N.Provider,{value:i,children:n.renderDefault(o)})}(i(i({},n),{},{pluginConfig:o}))}},document:{actions:(e,t)=>{let{schemaType:n}=t;return s&&s.includes(n)?[...e,V]:e}}}}));exports.CrossDatasetDuplicatorAction=X,exports.DuplicateToAction=V,exports.crossDatasetDuplicator=H,exports.useCrossDatasetDuplicatorConfig=q;//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/helpers/index.ts","../src/helpers/getDocumentsInArray.ts","../src/components/SelectButtons.tsx","../src/components/StatusBadge.tsx","../src/components/Feedback.tsx","../src/helpers/clientConfig.ts","../src/components/Duplicator.tsx","../src/components/DuplicatorQuery.tsx","../src/components/DuplicatorWrapper.tsx","../src/helpers/constants.ts","../src/components/ResetSecret.tsx","../src/components/CrossDatasetDuplicator.tsx","../src/actions/DuplicateToAction.tsx","../src/tool/index.ts","../src/index.ts"],"sourcesContent":["import {CSSProperties} from 'react'\n\nexport function createInitialMessage(docCount = 0, refsCount = 0): string {\n const message = [\n docCount === 1 ? `This Document contains` : `These ${docCount} Documents contain`,\n refsCount === 1 ? `1 Reference.` : `${refsCount} References.`,\n refsCount === 1 ? `That Document` : `Those Documents`,\n `may have References too. If referenced Documents do not exist at the target Destination, this transaction will fail.`,\n ]\n\n return message.join(` `)\n}\n\nexport const stickyStyles = (isDarkMode = true): CSSProperties => ({\n position: 'sticky',\n top: 0,\n zIndex: 100,\n backgroundColor: isDarkMode ? `rgba(10,10,10,0.95)` : `rgba(255,255,255,0.95)`,\n})\n","import {extractWithPath} from '@sanity/mutator'\nimport {SanityClient, SanityDocument} from 'sanity'\nimport {PluginConfig} from '../types'\n\ntype OptionsBag = {\n fetchIds: string[]\n client: SanityClient\n pluginConfig: PluginConfig\n currentIds?: Set<string> | null\n projection?: string\n}\n\n// Recursively fetch Documents from an array of _id's and their references\n// Heavy use of Set is to avoid recursively querying for id's already in the payload\nexport async function getDocumentsInArray(options: OptionsBag): Promise<SanityDocument[]> {\n const {fetchIds, client, pluginConfig, currentIds, projection} = options\n const collection: SanityDocument[] = []\n\n // Find initial docs\n const filter = ['_id in $fetchIds', pluginConfig.filter].filter(Boolean).join(' && ')\n const query = `*[${filter}]${projection ?? ``}`\n const data: SanityDocument[] = await client.fetch(query, {\n fetchIds: fetchIds ?? [],\n })\n\n if (!data?.length) {\n return []\n }\n\n const localCurrentIds = currentIds ?? new Set<string>()\n\n // Find new ids in the returned data\n // Unless we started with an empty set, get the _ids from the data\n const newDataIds = new Set<string>(\n data\n .map((dataDoc) => dataDoc._id)\n .filter((id) => (currentIds?.size ? !localCurrentIds.has(id) : Boolean(id)))\n )\n\n if (newDataIds.size) {\n collection.push(...data)\n // @ts-ignore\n localCurrentIds.add(...newDataIds)\n\n // Check new data for more references\n await Promise.all(\n data.map(async (doc) => {\n const expr = `.._ref`\n const references: string[] = extractWithPath(expr, doc).map((ref) => ref.value as string)\n\n if (references.length) {\n // Find references not already in the Collection\n const newReferenceIds = new Set<string>(\n references.filter((ref) => !localCurrentIds.has(ref))\n )\n\n if (newReferenceIds.size) {\n // Recursive query for new documents\n const referenceDocs = await getDocumentsInArray({\n fetchIds: Array.from(newReferenceIds),\n currentIds: localCurrentIds,\n client,\n pluginConfig,\n })\n\n if (referenceDocs?.length) {\n collection.push(...referenceDocs)\n }\n }\n }\n })\n )\n }\n\n // Create a unique array of objects from collection\n // Set() wasn't working for unique id's ¯\\_(ツ)_/¯\n const uniqueCollection = collection.filter(Boolean).reduce((acc: SanityDocument[], cur) => {\n if (acc.some((doc) => doc._id === cur._id)) {\n return acc\n }\n\n return [...acc, cur]\n }, [])\n\n return uniqueCollection\n}\n","import React, {useState, useEffect} from 'react'\nimport {Button, Card, Flex} from '@sanity/ui'\n\nimport {PayloadItem} from './Duplicator'\nimport {isAssetId} from '@sanity/asset-utils'\n\nconst buttons = [`All`, `None`, null, `New`, `Existing`, `Older`, null, `Documents`, `Assets`]\n\ntype Action = 'ALL' | 'NONE' | 'NEW' | 'EXISTING' | 'OLDER' | 'ASSETS' | 'DOCUMENTS'\n\ntype SelectButtonsProps = {\n payload: PayloadItem[]\n setPayload: Function\n}\n\nexport default function SelectButtons(props: SelectButtonsProps) {\n const {payload, setPayload} = props\n const [disabledActions, setDisabledActions] = useState<Action[]>([])\n\n // Set intiial disabled button\n useEffect(() => {\n if (!disabledActions?.length && payload.every((item) => item.include)) {\n setDisabledActions([`ALL`])\n }\n }, [disabledActions?.length, payload])\n\n function handleSelectButton(action?: Action) {\n if (!action || !payload.length) return\n\n const newPayload = [...payload]\n\n switch (action) {\n case 'ALL':\n newPayload.map((item) => (item.include = true))\n break\n case 'NONE':\n newPayload.map((item) => (item.include = false))\n break\n case 'NEW':\n newPayload.map((item) => (item.include = Boolean(item.status === 'CREATE')))\n break\n case 'EXISTING':\n newPayload.map((item) => (item.include = Boolean(item.status === 'EXISTS')))\n break\n case 'OLDER':\n newPayload.map((item) => (item.include = Boolean(item.status === 'OVERWRITE')))\n break\n case 'ASSETS':\n newPayload.map((item) => (item.include = isAssetId(item.doc._id)))\n break\n case 'DOCUMENTS':\n newPayload.map((item) => (item.include = !isAssetId(item.doc._id)))\n break\n default:\n break\n }\n\n setDisabledActions([action])\n setPayload(newPayload)\n }\n\n return (\n <Card padding={1} radius={3} shadow={1}>\n <Flex gap={2}>\n {buttons.map((action, actionIndex) =>\n action ? (\n <Button\n key={action}\n fontSize={1}\n mode=\"bleed\"\n padding={2}\n text={action}\n disabled={disabledActions.includes(action.toUpperCase() as Action)}\n onClick={() => handleSelectButton(action.toUpperCase() as Action)}\n />\n ) : (\n // eslint-disable-next-line react/no-array-index-key\n <Card key={`divider-${actionIndex}`} borderLeft />\n )\n )}\n </Flex>\n </Card>\n )\n}\n","import React from 'react'\nimport {Box, Text, Badge, Tooltip} from '@sanity/ui'\nimport type {BadgeTone} from '@sanity/ui'\n\ntype StatusTones = {\n EXISTS: BadgeTone\n OVERWRITE: BadgeTone\n UPDATE: BadgeTone\n CREATE: BadgeTone\n UNPUBLISHED: BadgeTone\n}\n\nconst documentTones: StatusTones = {\n EXISTS: `primary`,\n OVERWRITE: `critical`,\n UPDATE: `caution`,\n CREATE: `positive`,\n UNPUBLISHED: `caution`,\n}\n\nconst assetTones: StatusTones = {\n EXISTS: `critical`,\n OVERWRITE: `critical`,\n UPDATE: `critical`,\n CREATE: `positive`,\n UNPUBLISHED: `default`,\n}\n\nexport type MessageTypes = {\n EXISTS: string\n OVERWRITE: string\n UPDATE: string\n CREATE: string\n UNPUBLISHED: string\n}\n\nconst documentMessages: MessageTypes = {\n // Only happens once document is copied the first time, and _updatedAt is the same\n EXISTS: `This document already exists at the Destination with the same ID with the same Updated time.`,\n // Is true immediately after transaction as _updatedAt is updated by API after mutation\n // Is also true if the document at the destination has been manually modified\n // Presently, the plugin doesn't actually compare the two documents\n OVERWRITE: `A newer version of this document exists at the Destination, and it will be overwritten with this version.`,\n // Document at destination is older\n UPDATE: `An older version of this document exists at the Destination, and it will be overwritten with this version.`,\n // Document at destination doesn't exist\n CREATE: `This document will be created at the destination.`,\n UNPUBLISHED: `A Draft version of this Document exists in this Dataset, but only the Published version will be duplicated to the destination.`,\n}\n\nconst assetMessages: MessageTypes = {\n EXISTS: `This Asset already exists at the Destination`,\n OVERWRITE: `This Asset already exists at the Destination`,\n UPDATE: `This Asset already exists at the Destination`,\n CREATE: `This Asset does not yet exist at the Destination`,\n UNPUBLISHED: ``,\n}\n\nconst assetStatus: MessageTypes = {\n EXISTS: `RE-UPLOAD`,\n OVERWRITE: `RE-UPLOAD`,\n UPDATE: `RE-UPLOAD`,\n CREATE: `UPLOAD`,\n UNPUBLISHED: ``,\n}\n\ntype StatusBadgeProps = {\n isAsset: boolean\n status?: keyof MessageTypes\n}\n\nexport default function StatusBadge(props: StatusBadgeProps) {\n const {status, isAsset} = props\n\n if (!status) {\n return null\n }\n\n const badgeTone = isAsset ? assetTones[status] : documentTones[status]\n\n if (!badgeTone) {\n return (\n <Badge muted padding={2} fontSize={1} mode=\"outline\">\n Checking...\n </Badge>\n )\n }\n\n const badgeText = isAsset ? assetMessages[status] : documentMessages[status]\n const badgeStatus = isAsset ? assetStatus[status] : status\n\n return (\n <Tooltip\n content={\n <Box padding={3} style={{maxWidth: 200}}>\n <Text size={1}>{badgeText}</Text>\n </Box>\n }\n fallbackPlacements={['right', 'left']}\n placement=\"top\"\n portal\n >\n <Badge muted padding={2} fontSize={1} tone={badgeTone} mode=\"outline\">\n {badgeStatus}\n </Badge>\n </Tooltip>\n )\n}\n","import React from 'react'\nimport {Card, Text} from '@sanity/ui'\nimport type {BadgeTone} from '@sanity/ui'\n\ntype FeedbackProps = {\n children?: React.ReactNode\n tone?: BadgeTone\n}\n\nexport default function Feedback(props: FeedbackProps) {\n const {children, tone = `caution`} = props\n\n return (\n <Card padding={3} radius={2} shadow={1} tone={tone}>\n <Text size={1}>{children}</Text>\n </Card>\n )\n}\n","export const clientConfig = {apiVersion: `2021-05-19`}\n","/* eslint-disable react/jsx-no-bind */\nimport React, {useState, useEffect} from 'react'\nimport {\n useClient,\n Preview,\n useSchema,\n useWorkspaces,\n WorkspaceSummary,\n SanityDocument,\n} from 'sanity'\n// @ts-ignore\nimport mapLimit from 'async/mapLimit'\n// @ts-ignore\nimport asyncify from 'async/asyncify'\nimport {extractWithPath} from '@sanity/mutator'\nimport {dset} from 'dset'\nimport {\n Card,\n Container,\n Text,\n Box,\n Button,\n Label,\n Stack,\n Select,\n Flex,\n Checkbox,\n CardTone,\n useTheme,\n} from '@sanity/ui'\nimport {ArrowRightIcon, SearchIcon, LaunchIcon} from '@sanity/icons'\nimport {SanityAssetDocument} from '@sanity/client'\nimport {isAssetId, isSanityFileAsset} from '@sanity/asset-utils'\n\nimport {stickyStyles, createInitialMessage} from '../helpers'\nimport {getDocumentsInArray} from '../helpers/getDocumentsInArray'\nimport SelectButtons from './SelectButtons'\nimport StatusBadge, {MessageTypes} from './StatusBadge'\nimport Feedback from './Feedback'\nimport {clientConfig} from '../helpers/clientConfig'\nimport {PluginConfig} from '../types'\n\nexport type DuplicatorProps = {\n docs: SanityDocument[]\n // TODO: Find out if this is even used?\n // draftIds: string[]\n token: string\n pluginConfig: PluginConfig\n}\n\nexport type PayloadItem = {\n doc: SanityDocument\n include: boolean\n status?: keyof MessageTypes\n hasDraft?: boolean\n}\n\ntype WorkspaceOption = WorkspaceSummary & {\n disabled: boolean\n}\n\ntype Message = {\n text: string\n tone: CardTone\n}\n\nexport default function Duplicator(props: DuplicatorProps) {\n const {docs, token, pluginConfig} = props\n const isDarkMode = useTheme().sanity.color.dark\n\n // Prepare origin (this Studio) client\n const originClient = useClient(clientConfig)\n\n const schema = useSchema()\n\n // Create list of dataset options\n // and set initial value of dropdown\n const workspaces = useWorkspaces()\n const workspacesOptions: WorkspaceOption[] = workspaces.map((workspace) => ({\n ...workspace,\n disabled: workspace.dataset === originClient.config().dataset,\n }))\n\n const [destination, setDestination] = useState<WorkspaceOption | null>(\n workspaces.length ? workspacesOptions.find((space) => !space.disabled) ?? null : null\n )\n const [message, setMessage] = useState<Message | null>(null)\n const [payload, setPayload] = useState<PayloadItem[]>([])\n\n const [hasReferences, setHasReferences] = useState(false)\n const [isDuplicating, setIsDuplicating] = useState(false)\n const [isGathering, setIsGathering] = useState(false)\n const [progress, setProgress] = useState<number[]>([0, 0])\n\n // Check for References and update message\n useEffect(() => {\n const expr = `.._ref`\n const initialRefs = []\n const initialPayload: PayloadItem[] = []\n\n docs.forEach((doc) => {\n const refs = extractWithPath(expr, doc).map((ref) => ref.value)\n initialRefs.push(...refs)\n initialPayload.push({include: true, doc})\n })\n\n setPayload(initialPayload)\n\n const docCount = docs.length\n const refsCount = initialRefs.length\n\n if (initialRefs.length) {\n setHasReferences(true)\n\n setMessage({\n tone: `caution`,\n text: createInitialMessage(docCount, refsCount),\n })\n }\n }, [docs])\n\n // Re-check payload on destination when value changes\n // (On initial render + select change)\n useEffect(() => {\n updatePayloadStatuses()\n }, [destination])\n\n // Check if payload documents exist at destination\n async function updatePayloadStatuses(newPayload: PayloadItem[] = []) {\n const payloadActual = newPayload.length ? newPayload : payload\n\n if (!payloadActual.length || !destination?.name) {\n return\n }\n\n const payloadIds = payloadActual.map(({doc}) => doc._id)\n const destinationClient = originClient.withConfig({\n ...clientConfig,\n dataset: destination.dataset,\n projectId: destination.projectId,\n })\n const destinationData: SanityDocument[] = await destinationClient.fetch(\n `*[_id in $payloadIds]{ _id, _updatedAt }`,\n {payloadIds}\n )\n\n const updatedPayload = payloadActual.map((item) => {\n const existingDoc = destinationData.find((doc) => doc._id === item.doc._id)\n\n if (existingDoc?._updatedAt && item?.doc?._updatedAt) {\n if (existingDoc._updatedAt === item.doc._updatedAt) {\n // Exact same document exists at destination\n // We don't compare by _rev because that is updated in a transaction\n item.status = `EXISTS`\n } else if (existingDoc._updatedAt && item.doc._updatedAt) {\n item.status =\n new Date(existingDoc._updatedAt) > new Date(item.doc._updatedAt)\n ? // Document at destination is newer\n `OVERWRITE`\n : // Document at destination is older\n `UPDATE`\n }\n } else {\n item.status = 'CREATE'\n }\n\n return item\n })\n\n setPayload(updatedPayload)\n }\n\n function handleCheckbox(_id: string) {\n const updatedPayload = payload.map((item) => {\n if (item.doc._id === _id) {\n item.include = !item.include\n }\n\n return item\n })\n\n setPayload(updatedPayload)\n }\n\n // Find and recursively follow references beginning with this document\n async function handleReferences() {\n setIsGathering(true)\n const docIds = docs.map((doc) => doc._id)\n\n const payloadDocs = await getDocumentsInArray({\n fetchIds: docIds,\n client: originClient,\n pluginConfig,\n })\n const draftDocs = await getDocumentsInArray({\n fetchIds: docIds.map((id) => `drafts.${id}`),\n client: originClient,\n projection: `{_id}`,\n pluginConfig,\n })\n const draftDocsIds = new Set(draftDocs.map(({_id}) => _id))\n\n // Shape it up\n const payloadShaped = payloadDocs.map((doc) => ({\n doc,\n // Include this in the transaction?\n include: true,\n // Does it exist at the destination?\n status: undefined,\n // Does it have any drafts?\n hasDraft: draftDocsIds.has(`drafts.${doc._id}`),\n }))\n\n setPayload(payloadShaped)\n updatePayloadStatuses(payloadShaped)\n setIsGathering(false)\n }\n\n // Duplicate payload to destination dataset\n async function handleDuplicate() {\n if (!destination) {\n return\n }\n\n setIsDuplicating(true)\n\n const assetsCount = payload.filter(({doc, include}) => include && isAssetId(doc._id)).length\n let currentProgress = 0\n setProgress([currentProgress, assetsCount])\n\n setMessage({text: 'Duplicating...', tone: `default`})\n\n const destinationClient = originClient.withConfig({\n ...clientConfig,\n dataset: destination.dataset,\n projectId: destination.projectId,\n })\n\n const transactionDocs: SanityDocument[] = []\n const svgMaps: {old: string; new: string}[] = []\n\n // Upload assets and then add to transaction\n async function fetchDoc(doc: SanityAssetDocument) {\n if (isAssetId(doc._id)) {\n // Download and upload asset\n // Get the *original* image with this dlRaw param to create the same determenistic _id\n const typeIsFile = isSanityFileAsset(doc)\n const downloadUrl = typeIsFile ? doc.url : `${doc.url}?dlRaw=true`\n const downloadConfig = typeIsFile ? {} : {headers: {Authorization: `Bearer ${token}`}}\n\n await fetch(downloadUrl, downloadConfig).then(async (res) => {\n const assetData = await res.blob()\n\n const options = {filename: doc.originalFilename}\n const assetDoc = await destinationClient.assets.upload(\n typeIsFile ? `file` : `image`,\n assetData,\n options\n )\n\n // SVG _id's need remapping before transaction\n if (doc?.extension === 'svg') {\n svgMaps.push({old: doc._id, new: assetDoc._id})\n }\n\n transactionDocs.push(assetDoc)\n })\n\n currentProgress += 1\n setMessage({\n text: `Duplicating ${currentProgress}/${assetsCount} ${\n assetsCount === 1 ? `Assets` : `Assets`\n }`,\n tone: 'default',\n })\n\n return setProgress([currentProgress, assetsCount])\n }\n\n return transactionDocs.push(doc)\n }\n\n // Promises are limited to three at once\n const result = new Promise((resolve, reject) => {\n const payloadIncludedDocs = payload.filter((item) => item.include).map((item) => item.doc)\n\n mapLimit(payloadIncludedDocs, 3, asyncify(fetchDoc), (err: Error) => {\n if (err) {\n setIsDuplicating(false)\n setMessage({tone: 'critical', text: `Duplication Failed`})\n console.error(err)\n reject(new Error('Duplication Failed'))\n }\n\n // @ts-ignore\n resolve()\n })\n })\n\n await result\n\n // Remap SVG references to new _id's\n const transactionDocsMapped = transactionDocs.map((doc) => {\n const expr = `.._ref`\n const references = extractWithPath(expr, doc)\n\n if (!references.length) {\n return doc\n }\n\n // For every found _ref, search for an SVG asset _id and update\n references.forEach((ref) => {\n const newRefValue = svgMaps.find((asset) => asset.old === ref.value)?.new\n\n if (newRefValue) {\n const refPath = ref.path.join('.')\n\n dset(doc, refPath, newRefValue)\n }\n })\n\n return doc\n })\n\n // Create transaction\n const transaction = destinationClient.transaction()\n\n transactionDocsMapped.forEach((doc) => {\n transaction.createOrReplace(doc)\n })\n\n await transaction\n .commit()\n .then((res) => {\n setMessage({tone: 'positive', text: 'Duplication complete!'})\n\n updatePayloadStatuses()\n })\n .catch((err) => {\n setMessage({tone: 'critical', text: err.details.description})\n })\n\n setIsDuplicating(false)\n setProgress([0, 0])\n }\n\n function handleChange(e: React.ChangeEvent<HTMLSelectElement>) {\n if (!workspacesOptions.length) {\n return\n }\n\n const targeted = workspacesOptions.find((space) => space.name === e.currentTarget.value)\n\n if (targeted) {\n setDestination(targeted)\n }\n }\n\n const payloadCount = payload.length\n const firstSvgIndex = payload.findIndex(({doc}) => doc.extension === 'svg')\n const selectedDocumentsCount = payload.filter(\n (item) => item.include && !isAssetId(item.doc._id)\n ).length\n const selectedAssetsCount = payload.filter(\n (item) => item.include && isAssetId(item.doc._id)\n ).length\n const selectedTotal = selectedDocumentsCount + selectedAssetsCount\n const destinationTitle = destination?.title ?? destination?.name\n const hasMultipleProjectIds =\n new Set(workspacesOptions.map((space) => space?.projectId).filter(Boolean)).size > 1\n\n const headingText = [selectedTotal, `/`, payloadCount, `Documents and Assets selected`].join(` `)\n\n const buttonText = React.useMemo(() => {\n const text = [`Duplicate`]\n\n if (selectedDocumentsCount > 1) {\n text.push(\n String(selectedDocumentsCount),\n selectedDocumentsCount === 1 ? `Document` : `Documents`\n )\n }\n\n if (selectedAssetsCount > 1) {\n text.push(`and`, String(selectedAssetsCount), selectedAssetsCount === 1 ? `Asset` : `Assets`)\n }\n\n if (originClient.config().projectId !== destination?.projectId) {\n text.push(`between Projects`)\n }\n\n text.push(`to`, String(destinationTitle))\n\n return text.join(` `)\n }, [\n selectedDocumentsCount,\n selectedAssetsCount,\n originClient,\n destination?.projectId,\n destinationTitle,\n ])\n\n if (workspacesOptions.length < 2) {\n return (\n <Feedback tone=\"critical\">\n <code>sanity.config.ts</code> must contain at least two Workspaces to use this plugin.\n </Feedback>\n )\n }\n\n return (\n <Container width={1}>\n <Card border>\n <Stack>\n <>\n <Card borderBottom padding={4} style={stickyStyles(isDarkMode)}>\n <Stack space={4}>\n <Flex gap={3}>\n <Stack style={{flex: 1}} space={3}>\n <Label>Duplicate from</Label>\n <Select\n readOnly\n value={workspacesOptions.find((space) => space.disabled)?.name}\n >\n {workspacesOptions\n .filter((space) => space.disabled)\n .map((space) => (\n <option key={space.name} value={space.name} disabled={space.disabled}>\n {space.title ?? space.name}\n {hasMultipleProjectIds ? ` (${space.projectId})` : ``}\n </option>\n ))}\n </Select>\n </Stack>\n <Box padding={4} paddingTop={5} paddingBottom={0}>\n <Text size={3}>\n <ArrowRightIcon />\n </Text>\n </Box>\n <Stack style={{flex: 1}} space={3}>\n <Label>To Destination</Label>\n <Select onChange={handleChange}>\n {workspacesOptions.map((space) => (\n <option key={space.name} value={space.name} disabled={space.disabled}>\n {space.title ?? space.name}\n {hasMultipleProjectIds ? ` (${space.projectId})` : ``}\n {space.disabled ? ` (Current)` : ``}\n </option>\n ))}\n </Select>\n </Stack>\n </Flex>\n\n {isDuplicating && (\n <Card border radius={2}>\n <Card\n style={{\n width: '100%',\n transform: `scaleX(${progress[0] / progress[1]})`,\n transformOrigin: 'left',\n transition: 'transform .2s ease',\n boxSizing: 'border-box',\n }}\n padding={1}\n tone=\"positive\"\n />\n </Card>\n )}\n {payload.length > 0 && (\n <>\n <Label>{headingText}</Label>\n <SelectButtons payload={payload} setPayload={setPayload} />\n </>\n )}\n </Stack>\n </Card>\n {message && (\n <Box paddingX={4} paddingTop={4}>\n <Card padding={3} radius={2} shadow={1} tone={message.tone}>\n <Text size={1}>{message.text}</Text>\n </Card>\n </Box>\n )}\n {payload.length > 0 && (\n <Stack padding={4} space={3}>\n {payload.map(({doc, include, status, hasDraft}, index) => {\n const schemaType = schema.get(doc._type)\n\n return (\n <React.Fragment key={doc._id}>\n <Flex align=\"center\">\n <Checkbox checked={include} onChange={() => handleCheckbox(doc._id)} />\n <Box flex={1} paddingX={3}>\n {schemaType ? (\n <Preview value={doc} schemaType={schemaType} />\n ) : (\n <Card tone=\"caution\">Invalid schema type</Card>\n )}\n </Box>\n <Flex align=\"center\" gap={2}>\n {hasDraft ? <StatusBadge status=\"UNPUBLISHED\" isAsset={false} /> : null}\n <StatusBadge status={status} isAsset={isAssetId(doc._id)} />\n </Flex>\n </Flex>\n {doc?.extension === 'svg' && index === firstSvgIndex && (\n <Card padding={3} radius={2} shadow={1} tone=\"caution\">\n <Text size={1}>\n Due to how SVGs are sanitized after first uploaded, duplicated SVG\n assets may have new <code>_id</code>'s at the destination. The newly\n generated <code>_id</code> will be the same in each duplication, but it\n will never be the same <code>_id</code> as the first time this Asset was\n uploaded. References to the asset will be updated to use the new{' '}\n <code>_id</code>.\n </Text>\n </Card>\n )}\n </React.Fragment>\n )\n })}\n </Stack>\n )}\n <Stack space={2} padding={4} paddingTop={0}>\n {hasReferences && (\n <Button\n fontSize={2}\n padding={4}\n tone=\"positive\"\n mode=\"ghost\"\n icon={SearchIcon}\n onClick={handleReferences}\n text=\"Gather References\"\n disabled={isDuplicating || !selectedTotal || isGathering}\n />\n )}\n <Button\n fontSize={2}\n padding={4}\n tone=\"positive\"\n icon={LaunchIcon}\n onClick={handleDuplicate}\n text={buttonText}\n disabled={isDuplicating || !selectedTotal || isGathering}\n />\n </Stack>\n </>\n </Stack>\n </Card>\n </Container>\n )\n}\n","import React, {useEffect, useState} from 'react'\nimport {Button, Stack, Box, Label, Text, Card, Flex, Grid, Container, TextInput} from '@sanity/ui'\nimport {useSchema, useClient, SanityDocument} from 'sanity'\n\nimport Duplicator from './Duplicator'\nimport {clientConfig} from '../helpers/clientConfig'\nimport {PluginConfig} from '../types'\n\ntype DuplicatorQueryProps = {\n token: string\n pluginConfig: PluginConfig\n}\n\ntype InitialData = {\n docs: SanityDocument[]\n // draftIds: string[]\n}\n\nexport default function DuplicatorQuery(props: DuplicatorQueryProps) {\n const {token, pluginConfig} = props\n\n const originClient = useClient(clientConfig)\n\n const schema = useSchema()\n const schemaTypes = schema.getTypeNames()\n\n const [value, setValue] = useState(``)\n const [initialData, setInitialData] = useState<InitialData>({\n docs: [],\n // draftIds: []\n })\n\n function handleSubmit(e?: any) {\n if (e) e.preventDefault()\n\n originClient\n .fetch(value)\n .then((res: SanityDocument[]) => {\n // Ensure queried docs are registered to the schema\n const registeredAndPublishedDocs = res.length\n ? res\n .filter((doc) => schemaTypes.includes(doc._type))\n .filter((doc) => !doc._id.startsWith(`drafts.`))\n : []\n // const initialDraftIds = res.length\n // ? res.filter((doc) => doc._id.startsWith(`drafts.`)).map((doc) => doc._id)\n // : []\n\n setInitialData({\n docs: registeredAndPublishedDocs,\n // draftIds: initialDraftIds\n })\n })\n .catch((err) => console.error(err))\n }\n\n // Auto-load initial textinput value\n useEffect(() => {\n if (!initialData.docs?.length && value) {\n handleSubmit()\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [])\n\n return (\n <Container width={[1, 1, 1, 3]} padding={[0, 0, 0, 5]}>\n <Grid columns={[1, 1, 1, 2]} gap={[1, 1, 1, 4]}>\n <Box padding={[2, 2, 2, 0]}>\n <Card padding={4} radius={3} border>\n <Stack space={4}>\n <Box>\n <Label>Initial Documents Query</Label>\n </Box>\n <Box>\n <Text>\n Start with a valid GROQ query to load initial documents. The query will need to\n return an Array of Objects. Drafts will be removed from the results.\n </Text>\n </Box>\n <form onSubmit={handleSubmit}>\n <Flex>\n <Box flex={1} paddingRight={2}>\n <TextInput\n style={{fontFamily: 'monospace'}}\n fontSize={2}\n // eslint-disable-next-line react/jsx-no-bind\n onChange={(event) => setValue(event.currentTarget.value)}\n padding={4}\n placeholder={`*[_type == \"article\"]`}\n value={value ?? ``}\n />\n </Box>\n <Button\n padding={2}\n paddingX={4}\n tone=\"primary\"\n onClick={handleSubmit}\n text=\"Query\"\n disabled={!value}\n />\n </Flex>\n </form>\n </Stack>\n </Card>\n </Box>\n {!initialData.docs?.length ||\n (initialData.docs.length < 1 && (\n <Container width={1}>\n <Card padding={5}>\n {value\n ? `No Documents registered to the Schema match this query`\n : `Start with a valid GROQ query`}\n </Card>\n </Container>\n ))}\n {initialData.docs?.length > 0 && (\n <Duplicator\n docs={initialData.docs}\n // draftIds={initialData.draftIds}\n token={token}\n pluginConfig={pluginConfig}\n />\n )}\n </Grid>\n </Container>\n )\n}\n","import React, {useState, useEffect} from 'react'\nimport {Grid, Card, Container, Button} from '@sanity/ui'\nimport {SanityDocument, useClient} from 'sanity'\n\nimport type {DuplicatorProps} from './Duplicator'\nimport Duplicator from './Duplicator'\n\nexport default function DuplicatorWrapper(props: DuplicatorProps) {\n const {docs, token, pluginConfig} = props\n const [inbound, setInbound] = useState<SanityDocument[]>([])\n const {follow = []} = pluginConfig\n\n // Make the first mode the default if there's only one\n const [mode, setMode] = useState<'inbound' | 'outbound'>(\n follow.length === 1 ? follow[0] : `outbound`\n )\n const client = useClient()\n\n // \"Inbound\" will start with all documents that reference the first one\n // And then you can gather \"Outbound\" references thereafter\n useEffect(() => {\n ;(async () => {\n if (follow.includes(`inbound`)) {\n const inboundReferences = await client.fetch(`*[references($id)]`, {id: docs[0]._id})\n setInbound([...props.docs, ...inboundReferences])\n }\n })()\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [])\n\n return (\n <Container>\n {follow.length > 1 && (follow.includes(`inbound`) || follow.includes(`outbound`)) ? (\n <Card paddingX={4} paddingBottom={4} marginBottom={4} borderBottom>\n <Grid columns={2} gap={4}>\n {follow.includes(`outbound`) ? (\n <Button\n mode=\"ghost\"\n tone=\"primary\"\n selected={mode === 'outbound'}\n onClick={() => setMode('outbound')}\n text=\"Outbound\"\n />\n ) : null}\n {follow.includes(`inbound`) ? (\n <Button\n mode=\"ghost\"\n tone=\"primary\"\n selected={mode === 'inbound'}\n onClick={() => setMode('inbound')}\n disabled={inbound.length === 0}\n text={inbound.length > 0 ? `Inbound (${inbound.length})` : 'No inbound references'}\n />\n ) : null}\n </Grid>\n </Card>\n ) : null}\n <Duplicator\n docs={mode === 'outbound' ? docs : inbound}\n token={token}\n // draftIds={[]}\n pluginConfig={pluginConfig}\n />\n </Container>\n )\n}\n","export const SECRET_NAMESPACE = `CrossDatasetDuplicator`\n","import React from 'react'\nimport {useClient} from 'sanity'\nimport {Button, Flex} from '@sanity/ui'\n\nimport {clientConfig} from '../helpers/clientConfig'\nimport {SECRET_NAMESPACE} from '../helpers/constants'\n\nexport default function ResetSecret() {\n const client = useClient(clientConfig)\n\n const handleClick = React.useCallback(() => {\n client.delete({query: `*[_id == \"secrets.${SECRET_NAMESPACE}\"]`})\n }, [client])\n\n return (\n <Flex align=\"center\" justify=\"flex-end\" paddingX={[2, 2, 2, 5]} paddingY={5}>\n <Button\n text=\"Reset Secret\"\n onClick={handleClick}\n mode=\"ghost\"\n tone=\"critical\"\n fontSize={1}\n padding={2}\n />\n </Flex>\n )\n}\n","import React, {useEffect, useState} from 'react'\nimport {useSecrets, SettingsView} from '@sanity/studio-secrets'\nimport {Flex, Box, Spinner} from '@sanity/ui'\nimport {SanityDocument, Tool} from 'sanity'\n\nimport DuplicatorQuery from './DuplicatorQuery'\nimport DuplicatorWrapper from './DuplicatorWrapper'\nimport ResetSecret from './ResetSecret'\nimport Feedback from './Feedback'\nimport {SECRET_NAMESPACE} from '../helpers/constants'\nimport {PluginConfig} from '../types'\n\n// Check for auth secret (required for asset uploads)\nconst secretConfigKeys = [\n {\n key: 'bearerToken',\n title:\n 'An API token with Viewer permissions is required to duplicate the original files of assets, and will be used for all Duplications. Create one at sanity.io/manage',\n description: '',\n },\n]\n\ntype Secrets = {\n bearerToken?: string\n}\n\nexport type MultiToolConfig = {\n mode: 'tool' | 'action'\n docs: SanityDocument[]\n pluginConfig: PluginConfig\n}\n\ntype CrossDatasetDuplicatorProps = {\n tool: Tool<MultiToolConfig>\n}\n\nexport default function CrossDatasetDuplicator(props: CrossDatasetDuplicatorProps) {\n const {mode = `tool`, docs = [], pluginConfig} = props.tool.options ?? {}\n\n const {loading, secrets} = useSecrets<Secrets>(SECRET_NAMESPACE)\n const [showSecretsPrompt, setShowSecretsPrompt] = useState(false)\n\n useEffect(() => {\n if (secrets) {\n setShowSecretsPrompt(!secrets?.bearerToken)\n }\n }, [secrets])\n\n if (loading) {\n return (\n <Flex justify=\"center\" align=\"center\">\n <Box padding={5}>\n <Spinner />\n </Box>\n </Flex>\n )\n }\n\n if ((!loading && showSecretsPrompt) || !secrets?.bearerToken) {\n return (\n <SettingsView\n title=\"Token Required\"\n namespace={SECRET_NAMESPACE}\n keys={secretConfigKeys}\n // eslint-disable-next-line react/jsx-no-bind\n onClose={() => setShowSecretsPrompt(false)}\n />\n )\n }\n\n if (mode === 'tool' && pluginConfig) {\n return (\n <>\n <DuplicatorQuery token={secrets?.bearerToken} pluginConfig={pluginConfig} />\n <ResetSecret />\n </>\n )\n }\n\n if (!docs?.length) {\n return <Feedback>No docs passed into Duplicator Tool</Feedback>\n }\n\n if (!pluginConfig) {\n return <Feedback>No plugin config</Feedback>\n }\n\n return (\n <DuplicatorWrapper\n docs={docs}\n token={secrets?.bearerToken}\n pluginConfig={pluginConfig}\n // draftIds={[]}\n />\n )\n}\n","import React, {useState} from 'react'\nimport {LaunchIcon} from '@sanity/icons'\nimport {DocumentActionProps} from 'sanity'\nimport {PluginConfig} from '../types'\n\nimport CrossDatasetDuplicator from '../components/CrossDatasetDuplicator'\n\ntype DuplicateToActionProps = DocumentActionProps & {pluginConfig: PluginConfig}\n\nexport default function DuplicateToAction({\n draft,\n published,\n onComplete,\n pluginConfig,\n}: DuplicateToActionProps) {\n const [dialogOpen, setDialogOpen] = useState(false)\n\n return {\n disabled: draft,\n title: draft ? `Document must be Published to begin` : null,\n label: 'Duplicate to...',\n dialog: dialogOpen &&\n published && {\n type: 'modal',\n title: 'Cross Dataset Duplicator',\n content: (\n <CrossDatasetDuplicator\n // TODO: Re-using the tool component was not clever\n // Undo that decision\n // @ts-ignore\n tool={{\n options: {\n mode: 'action',\n docs: [published],\n pluginConfig,\n },\n }}\n />\n ),\n onClose: () => {\n onComplete()\n setDialogOpen(false)\n },\n },\n onHandle: () => setDialogOpen(true),\n icon: LaunchIcon,\n }\n}\n","import type {Tool} from 'sanity'\nimport {LaunchIcon} from '@sanity/icons'\n\nimport CrossDatasetDuplicator, {MultiToolConfig} from '../components/CrossDatasetDuplicator'\nimport {PluginConfig} from '../types'\n\nexport const crossDatasetDuplicatorTool = (pluginConfig: PluginConfig): Tool<MultiToolConfig> => ({\n title: 'Duplicator',\n name: 'duplicator',\n icon: LaunchIcon,\n component: CrossDatasetDuplicator,\n options: {\n mode: 'tool',\n docs: [],\n pluginConfig,\n },\n})\n","import {definePlugin, DocumentActionProps} from 'sanity'\n\nimport DuplicateToAction from './actions/DuplicateToAction'\nimport {crossDatasetDuplicatorTool} from './tool'\nimport {PluginConfig} from './types'\n\nexport * from './types'\n\nconst DEFAULT_CONFIG: PluginConfig = {\n tool: true,\n types: [],\n filter: '',\n follow: ['outbound'],\n}\n\n/**\n * @sanity/cross-dataset-duplicator\n * @public\n */\nexport const crossDatasetDuplicator = definePlugin<PluginConfig | void>((config = {}) => {\n const pluginConfig = {...DEFAULT_CONFIG, ...config}\n const {types} = pluginConfig\n\n return {\n name: '@sanity/cross-dataset-duplicator',\n tools: (prev) =>\n pluginConfig.tool ? [...prev, crossDatasetDuplicatorTool(pluginConfig)] : prev,\n document: {\n actions: (prev, {schemaType}) => {\n return types && types.includes(schemaType)\n ? [...prev, (props: DocumentActionProps) => DuplicateToAction({...props, pluginConfig})]\n : prev\n },\n },\n }\n})\n"],"names":["createInitialMessage","docCount","refsCount","message","concat","join","stickyStyles","isDarkMode","position","top","zIndex","backgroundColor","async","getDocumentsInArray","options","fetchIds","client","pluginConfig","currentIds","projection","collection","filter","Boolean","query","data","fetch","length","localCurrentIds","Set","newDataIds","map","dataDoc","_id","id","size","has","push","add","Promise","all","references","extractWithPath","doc","ref","value","newReferenceIds","referenceDocs","Array","from","reduce","acc","cur","some","buttons","SelectButtons","props","payload","setPayload","disabledActions","setDisabledActions","useState","useEffect","every","item","include","jsx","Card","padding","radius","shadow","children","Flex","gap","action","actionIndex","Button","fontSize","mode","text","disabled","includes","toUpperCase","onClick","newPayload","status","isAssetId","handleSelectButton","borderLeft","documentTones","EXISTS","OVERWRITE","UPDATE","CREATE","UNPUBLISHED","assetTones","documentMessages","assetMessages","assetStatus","StatusBadge","isAsset","badgeTone","Badge","muted","badgeText","badgeStatus","Tooltip","content","Box","style","maxWidth","Text","fallbackPlacements","placement","portal","tone","Feedback","clientConfig","apiVersion","Duplicator","_a","_b","_c","docs","token","useTheme","sanity","color","dark","originClient","useClient","schema","useSchema","workspaces","useWorkspaces","workspacesOptions","workspace","dataset","config","destination","setDestination","find","space","setMessage","hasReferences","setHasReferences","isDuplicating","setIsDuplicating","isGathering","setIsGathering","progress","setProgress","updatePayloadStatuses","payloadActual","name","payloadIds","_ref","destinationClient","withConfig","projectId","destinationData","updatedPayload","existingDoc","_updatedAt","Date","initialRefs","initialPayload","forEach","refs","payloadCount","firstSvgIndex","findIndex","_ref4","extension","selectedDocumentsCount","selectedAssetsCount","selectedTotal","destinationTitle","title","hasMultipleProjectIds","headingText","buttonText","React","useMemo","String","jsxs","Container","width","border","Stack","Fragment","borderBottom","flex","Label","Select","readOnly","paddingTop","paddingBottom","ArrowRightIcon","onChange","e","targeted","currentTarget","transform","transformOrigin","transition","boxSizing","paddingX","_ref5","index","hasDraft","schemaType","get","_type","align","Checkbox","checked","handleCheckbox","Preview","icon","SearchIcon","docIds","payloadDocs","draftDocs","draftDocsIds","_ref2","payloadShaped","LaunchIcon","assetsCount","_ref3","currentProgress","transactionDocs","svgMaps","fetchDoc","typeIsFile","isSanityFileAsset","downloadUrl","url","downloadConfig","headers","Authorization","then","assetData","res","blob","filename","originalFilename","assetDoc","assets","upload","old","new","result","resolve","reject","payloadIncludedDocs","mapLimit","asyncify","err","console","error","Error","transactionDocsMapped","newRefValue","asset","refPath","path","dset","transaction","createOrReplace","commit","catch","details","description","DuplicatorQuery","schemaTypes","getTypeNames","setValue","initialData","setInitialData","handleSubmit","preventDefault","registeredAndPublishedDocs","startsWith","Grid","columns","onSubmit","paddingRight","TextInput","fontFamily","event","placeholder","DuplicatorWrapper","inbound","setInbound","follow","setMode","inboundReferences","marginBottom","selected","SECRET_NAMESPACE","ResetSecret","handleClick","useCallback","delete","justify","paddingY","secretConfigKeys","key","CrossDatasetDuplicator","tool","loading","secrets","useSecrets","showSecretsPrompt","setShowSecretsPrompt","bearerToken","Spinner","SettingsView","namespace","keys","onClose","DuplicateToAction","_ref6","draft","published","onComplete","dialogOpen","setDialogOpen","label","dialog","type","onHandle","crossDatasetDuplicatorTool","component","DEFAULT_CONFIG","types","crossDatasetDuplicator","definePlugin","arguments","undefined","_objectSpread","tools","prev","document","actions","_ref7"],"mappings":"q9CAEO,SAASA,IAA0D,IAArCC,yDAAW,EAAGC,yDAAY,EAC7D,MAAMC,EAAU,CACD,IAAbF,EAAiB,yBAAA,SAAAG,OAAoCH,EAAA,sBACvC,IAAdC,2BAAsCA,EAAA,gBACxB,IAAdA,oCAEF,wHAEO,OAAAC,EAAQE,KAAQ,IACzB,CAEa,MAAAC,EAAe,WAAA,IAACC,6DAAsC,MAAA,CACjEC,SAAU,SACVC,IAAK,EACLC,OAAQ,IACRC,gBAAiBJ,iDACnB,ECJAK,eAAsBC,EAAoBC,GACxC,MAAMC,SAACA,EAAUC,OAAAA,EAAAC,aAAQA,EAAcC,WAAAA,EAAAC,WAAYA,GAAcL,EAC3DM,EAA+B,GAG/BC,EAAS,CAAC,mBAAoBJ,EAAaI,QAAQA,OAAOC,SAASjB,KAAK,Q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