@mohsinonxrm/pptb-dataverse-request-studio 1.4.0-beta.3 → 1.5.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/CHANGELOG.md +375 -0
  2. package/README.md +81 -11
  3. package/SECURITY.md +8 -1
  4. package/dist/assets/AssociateMode-mu2ai0TV.js +1 -0
  5. package/dist/assets/AssociateTargetsEditor-BoH9Qxe8.js +1 -0
  6. package/dist/assets/BatchMode-BVAfFgPy.js +11 -0
  7. package/dist/assets/BinaryColumnPickers-DYpKoRIO.js +1 -0
  8. package/dist/assets/BulkDeleteMode-Df-XirlR.js +1 -0
  9. package/dist/assets/BulkWriteMode-UXREEvbe.js +6 -0
  10. package/dist/assets/DisassociateMode-CKBL5nUo.js +2 -0
  11. package/dist/assets/ExecuteWorkflowMode-4EWco-ze.js +1 -0
  12. package/dist/assets/ManageFileMode-BFNwxuEY.js +1 -0
  13. package/dist/assets/ManageImageMode-DX0AdPN1.js +1 -0
  14. package/dist/assets/MergeMode-BzyXLu1b.js +1 -0
  15. package/dist/assets/PredefinedQueryMode-BT-HdZHF.js +1 -0
  16. package/dist/assets/RetrieveNextLinkMode-QBuIwdgS.js +1 -0
  17. package/dist/assets/{cssMode-B4BP9f3X.js → cssMode-DRNC4UuD.js} +1 -1
  18. package/dist/assets/{freemarker2-DFKOu_2v.js → freemarker2-BITb8GyO.js} +1 -1
  19. package/dist/assets/{handlebars-cWHtgvCj.js → handlebars-BbDVduNH.js} +1 -1
  20. package/dist/assets/{html-DSPQITYl.js → html-Ru2Cy2VS.js} +1 -1
  21. package/dist/assets/{htmlMode-Cr-uAXsT.js → htmlMode-DeMh8vPt.js} +1 -1
  22. package/dist/assets/index-XmEQbXiX.js +703 -0
  23. package/dist/assets/{javascript-B3oRul8j.js → javascript-DLj2yjBO.js} +1 -1
  24. package/dist/assets/{jsonMode-_zXsQ367.js → jsonMode-DOHFeg2H.js} +1 -1
  25. package/dist/assets/{liquid-Cib5dNaW.js → liquid-udbJGOUP.js} +1 -1
  26. package/dist/assets/{mdx-8A_8JwPK.js → mdx-B6ABiFDH.js} +1 -1
  27. package/dist/assets/{monacoSetup-DObeMDBe.js → monacoSetup-CEhMjQNN.js} +3 -3
  28. package/dist/assets/{python-DsudPCj1.js → python-DDgBOsRh.js} +1 -1
  29. package/dist/assets/{razor-CrmV2uj7.js → razor-DGf0KCTP.js} +1 -1
  30. package/dist/assets/{tsMode-BnycW89y.js → tsMode-D4ZDTisA.js} +1 -1
  31. package/dist/assets/{typescript-Bs6iTDav.js → typescript-CJFgy1iR.js} +1 -1
  32. package/dist/assets/{xml-DuKZPRNV.js → xml-BXhJpCm5.js} +1 -1
  33. package/dist/assets/{yaml-DDDa6myK.js → yaml-B7iGwJkY.js} +1 -1
  34. package/dist/index.html +1 -1
  35. package/package.json +10 -3
  36. package/dist/assets/AssociateMode-Bs_R9XbQ.js +0 -1
  37. package/dist/assets/AssociateTargetsEditor-CVWE3tbv.js +0 -1
  38. package/dist/assets/BatchMode-XGXMc2XF.js +0 -11
  39. package/dist/assets/BinaryColumnPickers-mrnLqk3Z.js +0 -1
  40. package/dist/assets/BulkDeleteMode-DowWcbnA.js +0 -1
  41. package/dist/assets/BulkWriteMode-Dt3M0dGV.js +0 -6
  42. package/dist/assets/DisassociateMode-qIc2CUpE.js +0 -2
  43. package/dist/assets/ExecuteWorkflowMode-Ce6sKYci.js +0 -1
  44. package/dist/assets/ManageFileMode-CcNSQkJf.js +0 -1
  45. package/dist/assets/ManageImageMode-Dn4P4D6H.js +0 -1
  46. package/dist/assets/MergeMode-DzPQq2Ao.js +0 -1
  47. package/dist/assets/PredefinedQueryMode-CaQqp2lm.js +0 -1
  48. package/dist/assets/RetrieveNextLinkMode-BNbknSwe.js +0 -1
  49. package/dist/assets/index-D0g0tm7R.js +0 -702
@@ -1 +0,0 @@
1
- import{f as B,E as H,g as Be,a as le,b as oe,s as Ue,d as L,m as ie,j as _e,c as Xe,r as u,u as Ye,e as We,h as Ve,i as W,k as He,T as Je,l as Qe,F as ze,n as Ge,C as je,o as Ke,M as Se,p as Ze,L as et,q as tt,t,H as at,v as st,w as rt,x as ve,y as nt,z as lt,A as ot,B as E,D as R,G as it,R as ct,U as ut,S as dt,I as pt,J,K as ce,N as ke,O as $,P as mt,Q as z,V as ht,W as yt,X as ft,Y as A,Z as F,_ as bt,$ as gt,a0 as xt,a1 as jt,a2 as St,a3 as vt,a4 as kt,a5 as N,a6 as Q,a7 as wt,a8 as Nt,a9 as we,aa as Dt,ab as ue,ac as Tt,ad as de,ae as Ct}from"./index-D0g0tm7R.js";const pe={eq:"Equal",ne:"NotEqual",gt:"GreaterThan",ge:"GreaterEqual",lt:"LessThan",le:"LessEqual"},Et=new Set(["On","OnOrAfter","OnOrBefore","Today","Tomorrow","Yesterday","Last7Days","Next7Days","LastWeek","ThisWeek","NextWeek","LastMonth","ThisMonth","NextMonth","LastYear","ThisYear","NextYear","LastXHours","LastXDays","LastXWeeks","LastXMonths","LastXYears","NextXHours","NextXDays","NextXWeeks","NextXMonths","NextXYears","OlderThanXMinutes","OlderThanXHours","OlderThanXDays","OlderThanXWeeks","OlderThanXMonths","OlderThanXYears","ThisFiscalPeriod","ThisFiscalYear","LastFiscalPeriod","LastFiscalYear","NextFiscalPeriod","NextFiscalYear","LastXFiscalPeriods","LastXFiscalYears","NextXFiscalPeriods","NextXFiscalYears","InFiscalPeriod","InFiscalYear","InFiscalPeriodAndYear","InOrAfterFiscalPeriodAndYear","InOrBeforeFiscalPeriodAndYear","Between","NotBetween","In","NotIn","ContainValues","DoesNotContainValues","Above","AboveOrEqual","Under","UnderOrEqual","NotUnder","EqualUserId","NotEqualUserId","EqualBusinessId","NotEqualBusinessId","EqualRoleBusinessId","EqualUserLanguage","EqualUserTeams","EqualUserOrUserTeams","EqualUserOrUserHierarchy","EqualUserOrUserHierarchyAndTeams"]);function me(e){switch(e?.attributeType){case"Integer":case"Picklist":case"State":case"Status":case"MultiSelectPicklist":case"EntityName":return"System.Int32";case"BigInt":return"System.Int64";case"Decimal":case"Money":return"System.Decimal";case"Double":return"System.Double";case"Boolean":return"System.Boolean";case"DateTime":return"System.DateTime";case"Uniqueidentifier":case"Lookup":case"Customer":case"Owner":return"System.Guid";default:return"System.String"}}const Rt=e=>e.replace(/[[%_]/g,s=>`[${s}]`);function $t(e,s){const a=[],l=r=>{if(r.type==="rule"){if(r.col.includes("/"))return a.push(`"${r.col}" filters on a related table — not supported in a bulk delete query.`),null;if(r.valKind==="column")return a.push(`"${r.col}" compares two columns — not supported in a bulk delete query.`),null;const c=le(r.op),p=oe(e,r.col),h=r.val??"";if(c?.kind==="null-check")return{AttributeName:r.col,Operator:r.op==="is-null"?"Null":"NotNull",Values:[]};if(c?.kind==="comparison"&&pe[r.op])return{AttributeName:r.col,Operator:pe[r.op],Values:[{Type:me(p),Value:h}]};if(c?.kind==="odata-fn"){const{value:y}=Ue(h),f=Rt(y),d=r.op==="contains"?`%${f}%`:r.op==="startswith"?`${f}%`:`%${f}`;return{AttributeName:r.col,Operator:r.negated?"NotLike":"Like",Values:[{Type:"System.String",Value:d}]}}return a.push(`Operator "${r.op}" on "${r.col}" has no QueryExpression mapping.`),null}if(r.type==="function"){const c=le(r.op);if(!c||!Et.has(r.op))return a.push(`Query function "${r.op}" has no QueryExpression mapping.`),null;if(r.negated)return a.push(`"not ${r.op}" can't be expressed in a bulk delete query.`),null;if(r.col.includes("/"))return a.push(`"${r.col}" filters on a related table — not supported in a bulk delete query.`),null;const p=c.category==="hierarchy"?e.primaryKey:r.col,h=oe(e,r.col),y=c.kind==="dv-fn-array"?r.values??[]:c.kind==="dv-fn-2"?r.vals??["",""]:c.kind==="dv-fn-0"?[]:[r.val??""],f=c.kind==="dv-fn-1-int"||c.kind==="dv-fn-2"?"System.Int32":c.kind==="dv-fn-guid"?"System.Guid":me(h);return{AttributeName:p,Operator:r.op,Values:y.map(d=>({Type:f,Value:d}))}}return null},n=r=>{r.negated&&a.push('Negated groups ("not (…)") can’t be expressed in a bulk delete query.');const c={FilterOperator:r.combinator==="or"?"Or":"And",Conditions:[],Filters:[]};for(const p of r.rules)if(p.type==="group")c.Filters.push(n(p));else if(p.type==="lambda")a.push(`"${p.nav}/${p.lambda}(…)" filters on related records — not supported in a bulk delete query.`);else{const h=l(p);h&&c.Conditions.push(h)}return c},i=n(s);return{query:a.length?null:{EntityName:e.logicalName,Criteria:i},problems:a}}const Ot=/^\{?[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\}?$/i;function he(e){const s=e.split(/[\s,;]+/).map(n=>n.trim()).filter(Boolean),a=[],l=[];for(const n of s)Ot.test(n)?a.push(n.replace(/^\{|\}$/g,"").toLowerCase()):l.push(n);return{ids:[...new Set(a)],invalid:l}}const ye=e=>({"@odata.type":"Microsoft.Dynamics.CRM.activityparty",activitypartyid:e});function Ne(e){return e&&e>0?`FREQ=DAILY;INTERVAL=${Math.floor(e)}`:""}function At(e,s){if(e.startMode==="at"&&e.startAt){const a=new Date(e.startAt);if(!Number.isNaN(a.getTime()))return a.toISOString()}return s.toISOString()}function Ft(e){const s=a=>String(a).padStart(2,"0");return`${e.getFullYear()}-${s(e.getMonth()+1)}-${s(e.getDate())} ${s(e.getHours())}:${s(e.getMinutes())}`}function De(e,s){return`DRS bulk delete · ${e||"table"} · ${Ft(s)}`}function Te(e,s){const a=B(e.table);if(!a)return{body:null,problems:["Pick a target table first."],deletesAll:!1};const{query:l,problems:n}=$t(a,e.filter),i=he(e.toRecipients),r=he(e.ccRecipients),c=[...n];e.jobName.trim()||c.push("Give the job a name."),(i.invalid.length||r.invalid.length)&&c.push(`Not a systemuser id: ${[...i.invalid,...r.invalid].join(", ")}`),e.sendEmail&&i.ids.length===0&&c.push("Email notification needs at least one To recipient (systemuser id)."),e.startMode==="at"&&Number.isNaN(new Date(e.startAt).getTime())&&c.push("Pick a valid start date and time."),e.recurrenceDays!==null&&!(e.recurrenceDays>=1)&&c.push("Recurrence must be every 1 day or more.");const p=!!l&&Ce(l.Criteria);return{body:l?{QuerySet:[l],JobName:e.jobName.trim(),SendEmailNotification:e.sendEmail,ToRecipients:e.sendEmail?i.ids.map(ye):[],CCRecipients:e.sendEmail?r.ids.map(ye):[],RecurrencePattern:Ne(e.recurrenceDays),StartDateTime:At(e,s)}:null,problems:c,deletesAll:p}}function Ce(e){return e.Conditions.length===0&&e.Filters.every(Ce)}function Lt(e){const s=B(e.table),a="/BulkDelete",l=`${H.apiBase}${a}`;return{relativeUrl:l,relativeNoBase:a,bytes:l.length,queryParts:[],entitySet:s?.entitySetName??"",entityLogical:s?.logicalName??""}}function Mt(e){const s=B(e.table);if(!s)return null;const a=Be(e.filter,s),l=n=>encodeURIComponent(n).replace(/%2F/g,"/").replace(/%2C/g,",").replace(/%3D/g,"=").replace(/%24/g,"$").replace(/%28/g,"(").replace(/%29/g,")").replace(/%20/g," ").replace(/%27/g,"'").replace(/%3A/g,":");return`${s.entitySetName}?$select=${s.primaryKey}&$count=true&$top=1`+(a?`&$filter=${l(a)}`:"")}const Ee=5e3,Pt={0:"Ready",1:"Suspended",2:"Locked",3:"Completed"},fe={0:"Waiting for resources",10:"Waiting",20:"In progress",21:"Pausing",22:"Canceling",30:"Succeeded",31:"Failed",32:"Canceled"};function It(e){return`asyncoperations(${e})?$select=name,statecode,statuscode,message,friendlymessage,createdon,startedon,completedon,postponeuntil,recurrencepattern`}function qt(e){return`bulkdeleteoperations?$select=successcount,failurecount,statecode,statuscode,isrecurring&$filter=_asyncoperationid_value eq ${e}`}function Bt(e){const{dirty:s,...a}=e;return a}function Ut(e,s){return{...s,...e,dirty:new Set}}const Re=e=>{const s=typeof e=="object"&&e!==null?e:{};return s.message??s.innererror?.message??String(e)};async function _t(e){const s=Mt(e);if(!s)return{ok:!1,error:"Table metadata not loaded."};try{const l=(await L.queryData(s))["@odata.count"];return typeof l!="number"?{ok:!1,error:"The response had no @odata.count."}:{ok:!0,count:l,capped:l>=Ee}}catch(a){return{ok:!1,error:Re(a)}}}async function Xt(e){const{body:s,problems:a}=Te(e,new Date);if(!s||a.length)return ie({statusCode:400,message:a[0]??"Request incomplete."},0);const l=performance.now();try{const n=await L.execute({operationName:"BulkDelete",operationType:"action",parameters:s});return{status:200,statusText:"OK",ms:Math.round(performance.now()-l),bytes:_e(n??{}),ok:!0,outcome:"ok",body:n??{},headers:{"OData-Version":"4.0"}}}catch(n){return ie(n,Math.round(performance.now()-l))}}function Yt(e){if(!e||typeof e!="object")return null;const s=e.JobId;return typeof s=="string"?s:null}async function Wt(){const s=(await L.execute({operationName:"WhoAmI",operationType:"function"})).UserId;if(typeof s!="string")throw new Error("WhoAmI returned no UserId.");return s.toLowerCase()}async function Vt(e){try{const s=await L.queryData(It(e)),a=Array.isArray(s?.value)?s.value[0]??null:s??null;let l=null;try{l=(await L.queryData(qt(e)))?.value?.[0]??null}catch{}return{job:a,operation:l}}catch(s){return{job:null,operation:null,error:Re(s)}}}const q="bulk-delete",C="bulk",be=5e3,V=120,ge=()=>({table:"",filter:ve(),jobName:"",sendEmail:!1,toRecipients:"",ccRecipients:"",startMode:"now",startAt:"",recurrenceDays:null,headers:pt()});function Zt({themeMode:e}){const s=Xe(q),[a,l]=u.useState(()=>({...ge(),dirty:new Set})),{table:n}=Ye(a.table||null),{entities:i}=We(),[r,c]=u.useState("target"),[p,h]=u.useState("builder"),[y,f]=u.useState(null),[d,x]=u.useState(null),[w,j]=u.useState(!1),[g,D]=u.useState(!1),[U,S]=u.useState([]),[v,G]=u.useState(null),[K,Z]=u.useState(void 0),[ee,te]=u.useState(null),[_,$e]=u.useState(()=>new Date);u.useEffect(()=>{const o=window.setInterval(()=>$e(new Date),6e4);return()=>window.clearInterval(o)},[]);const k=B(a.table),O=u.useMemo(()=>Lt(a),[a,n]),{body:Oe,problems:X,deletesAll:M}=u.useMemo(()=>Te(a,_),[a,n,_]),P=u.useMemo(()=>Ve(a.filter),[a.filter]),ae=(o,m,Y)=>l(re=>{const ne=new Set(re.dirty);return ne.add(Y),{...re,[o]:m,dirty:ne}}),Ae=a.table?k?X.length>0?X[0]:a.headers.some(o=>o.enabled&&!o.name)?"Fix empty header name.":null:"Loading table metadata…":"Pick a target table first.",Fe=async()=>{D(!1),j(!0);const o=await Xt(a);f(o),x(o.ok?Yt(o.body):null),j(!1),h("results"),S(m=>[{id:`r-${Date.now()}`,modeId:q,url:O.relativeUrl,method:"POST",ts:Date.now(),status:o.status,ms:o.ms},...m].slice(0,8)),l(m=>({...m,dirty:new Set}))},I=u.useMemo(()=>Bt(a),[a]),Le=u.useMemo(()=>W(I),[I]),se=ee===null?!0:Le!==ee,Me=o=>{Z(o.id),te(W(o.state))},Pe=o=>{if(o.modeId!==q)return;const m=o.state;if(i.length>0&&!i.some(Y=>Y.logicalName===m.table)){G(`Can't load "${o.name}": table '${m.table}' isn't available in this environment.`);return}G(null),l(Ut(m,ge())),Z(o.id),te(W(m)),f(null),x(null),c("filter")};He(u.useMemo(()=>a.table?{state:I,modeId:q,dirty:se,lastSavedId:K,onSaved:Me,onLoadSaved:Pe}:null,[I,se,K,a.table]));const Ie=[{id:"target",label:"Target",meta:k?`${k.displayName} · ${k.entitySetName}`:"Pick a table",items:[{id:"target",icon:Qe,iconFilled:Je,label:k?.displayName??"Pick a table",dirty:a.dirty.has("target")}]},{id:"query",label:"Query",meta:P?`${P} condition${P===1?"":"s"}`:"all rows",items:[{id:"filter",icon:Ge,iconFilled:ze,label:"Criteria",code:!0,badge:M?"ALL":P||null,badgeAppearance:"tint",badgeColor:M?"danger":"brand",dirty:a.dirty.has("filter")}]},{id:"job",label:"Job",meta:a.recurrenceDays?`every ${a.recurrenceDays} d`:"run once",items:[{id:"job",icon:Ke,iconFilled:je,label:"Name & schedule",badge:a.startMode==="at"?"scheduled":null,dirty:a.dirty.has("job")},{id:"notify",icon:Ze,iconFilled:Se,label:"Email notification",badge:a.sendEmail?"on":null,dirty:a.dirty.has("notify")}]},{id:"headers",label:"Headers",meta:`${a.headers.filter(o=>o.enabled).length} active`,items:[{id:"headers",icon:tt,iconFilled:et,label:"HTTP headers",badge:a.headers.filter(o=>o.enabled).length||null,dirty:a.dirty.has("headers")}]}];let T=null;switch(r){case"target":T=t.jsx(rt,{table:a.table,onTableChange:o=>{l(m=>({...m,table:o,filter:ve(),jobName:m.jobName&&!m.jobName.startsWith("DRS bulk delete")?m.jobName:o?De(o,new Date):"",dirty:new Set(["target","filter"])})),f(null),x(null)},group:C,sub:"Rows of this table that match the query are deleted by an asynchronous system job. Switching the target clears the query."});break;case"filter":T=t.jsxs("div",{children:[t.jsx(Ht,{deletesAll:M,problems:X,tbl:k}),t.jsx(st,{table:a.table,tree:a.filter,setTree:o=>ae("filter",o,"filter"),group:C})]});break;case"job":T=t.jsx(Jt,{state:a,now:_,onChange:o=>l(m=>({...m,...o,dirty:new Set([...m.dirty,"job"])}))});break;case"notify":T=t.jsx(Qt,{state:a,onChange:o=>l(m=>({...m,...o,dirty:new Set([...m.dirty,"notify"])}))});break;case"headers":T=t.jsx(at,{items:a.headers,setItems:o=>ae("headers",o,"headers"),group:C});break}const qe={method:"POST",built:O,headers:nt(a.headers,null),body:Oe??{},entityLogical:O.entityLogical};return t.jsxs(lt,{sidebar:t.jsx(dt,{type:s,urlPreview:O.relativeNoBase,sections:Ie,activeNode:r,onSelect:o=>{c(o),h("builder")},recents:U}),urlBar:t.jsx(ut,{method:"POST",url:O.relativeUrl,executeVerb:s.executeVerb,disabledReason:Ae,loading:w,onExecute:async()=>D(!0)}),children:[t.jsxs(ot,{tab:p,onTabChange:h,resultCount:null,children:[p==="builder"&&t.jsxs(t.Fragment,{children:[v&&t.jsx(E,{intent:"error",style:{marginBottom:12},children:t.jsx(R,{children:v})}),T]}),p==="code"&&t.jsx(it,{themeMode:e,inputs:qe,group:C}),p==="results"&&(y?.ok&&d?t.jsx(Gt,{jobId:d,result:y}):t.jsx(ct,{result:y,mode:"single",table:a.table}))]}),g&&k&&t.jsx(zt,{state:a,tbl:k,deletesAll:M,onCancel:()=>D(!1),onConfirm:Fe})]})}function Ht({deletesAll:e,problems:s,tbl:a}){if(!a)return null;const l=s.filter(n=>/bulk delete query|mapping/.test(n));return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8,marginBottom:12},children:[e&&t.jsx(E,{intent:"error",layout:"multiline",children:t.jsxs(R,{children:[t.jsxs(J,{children:["No conditions — every ",a.displayName," row matches"]}),"Add at least one condition unless you really mean to empty the table."]})}),l.length>0&&t.jsx(E,{intent:"error",layout:"multiline",children:t.jsxs(R,{children:[t.jsx(J,{children:"Can't convert to a QueryExpression"}),t.jsx("ul",{style:{margin:"4px 0 0",paddingLeft:18},children:l.map(n=>t.jsx("li",{children:n},n))})]})}),t.jsx(E,{intent:"info",layout:"multiline",children:t.jsxs(R,{children:["BulkDelete takes a ",t.jsx("code",{children:"QueryExpression"}),", so this $filter is converted: comparisons, null checks, contains / starts / ends with (as ",t.jsx("code",{children:"Like"}),"), and the Dataverse query functions map 1:1. Related-table paths, any/all, column-to-column comparisons and negated groups or functions aren't supported. The confirmation counts matches with the same $filter before anything is submitted."]})})]})}function Jt({state:e,now:s,onChange:a}){return t.jsxs("div",{style:{maxWidth:640,display:"flex",flexDirection:"column",gap:14},children:[t.jsx(we,{icon:je,title:"Job",sub:"The bulk delete runs as a system job; it only deletes rows created before it starts.",group:C}),t.jsx(N,{label:"Job name",required:!0,children:t.jsx(Q,{value:e.jobName,placeholder:De(e.table,s),onChange:(l,n)=>a({jobName:n.value})})}),t.jsx(N,{label:"Start",children:t.jsxs(Dt,{value:e.startMode,onChange:(l,n)=>a({startMode:n.value}),children:[t.jsx(ue,{value:"now",label:"Immediately (StartDateTime = when you send)"}),t.jsx(ue,{value:"at",label:"At a specific time"})]})}),e.startMode==="at"&&t.jsx(N,{label:"Start date and time (your local time)",children:t.jsx(Q,{type:"datetime-local",value:e.startAt,onChange:(l,n)=>a({startAt:n.value})})}),t.jsx(z,{checked:e.recurrenceDays!==null,onChange:(l,n)=>a({recurrenceDays:n.checked?7:null}),label:"Repeat the job"}),e.recurrenceDays!==null&&t.jsx(N,{label:"Every N days",hint:t.jsxs(t.Fragment,{children:["RecurrencePattern ",t.jsx("code",{children:Ne(e.recurrenceDays)||"—"}),". A recurring job keeps deleting new matching rows until you cancel it in System Jobs."]}),children:t.jsx(Tt,{min:1,max:365,value:e.recurrenceDays,onChange:(l,n)=>{const i=n.value??Number(n.displayValue);Number.isFinite(i)&&a({recurrenceDays:Math.max(1,Math.floor(i))})}})})]})}function Qt({state:e,onChange:s}){const[a,l]=u.useState(null),n=async()=>{try{const i=await Wt();e.toRecipients.toLowerCase().includes(i)||s({toRecipients:[e.toRecipients.trim(),i].filter(Boolean).join(", ")}),l(null)}catch(i){l(i instanceof Error?i.message:String(i))}};return t.jsxs("div",{style:{maxWidth:640,display:"flex",flexDirection:"column",gap:14},children:[t.jsx(we,{icon:Se,title:"Email notification",sub:"Email users when the job finishes. Recipients are systemuser ids with a valid email address.",group:C}),t.jsx(z,{checked:e.sendEmail,onChange:(i,r)=>s({sendEmail:r.checked}),label:"Send an email when the job completes"}),e.sendEmail&&t.jsxs(t.Fragment,{children:[t.jsx(N,{label:"To (systemuser ids)",required:!0,hint:"Comma, space or new-line separated.",children:t.jsx(de,{value:e.toRecipients,onChange:(i,r)=>s({toRecipients:r.value}),rows:2})}),t.jsxs("div",{children:[t.jsx($,{icon:t.jsx(Ct,{}),onClick:()=>{n()},children:"Add me"}),a&&t.jsx(F,{style:{color:A.colorPaletteRedForeground1,marginLeft:8},children:a})]}),t.jsx(N,{label:"Cc (systemuser ids)",children:t.jsx(de,{value:e.ccRecipients,onChange:(i,r)=>s({ccRecipients:r.value}),rows:2})})]})]})}function zt({state:e,tbl:s,deletesAll:a,onCancel:l,onConfirm:n}){const[i,r]=u.useState(null),[c,p]=u.useState(""),[h,y]=u.useState(!1);u.useEffect(()=>{let j=!1;return _t(e).then(g=>{j||r(g)}),()=>{j=!0}},[]);const f=c.trim()===s.logicalName,d=i?.ok&&i.count===0,x=f&&i!==null&&(!a||h)&&!(d&&!e.recurrenceDays),w=e.startMode==="at"&&e.startAt?new Date(e.startAt).toLocaleString():"as soon as the system job runs";return t.jsx(bt,{open:!0,modalType:"alert",onOpenChange:(j,g)=>!g.open&&l(),children:t.jsx(gt,{style:{maxWidth:560},children:t.jsxs(xt,{children:[t.jsxs(jt,{children:["Delete ",s.displayName," rows in bulk?"]}),t.jsxs(St,{style:{display:"flex",flexDirection:"column",gap:10},children:[t.jsx(E,{intent:"error",layout:"multiline",children:t.jsxs(R,{children:[t.jsx(J,{children:"This permanently deletes data"}),"Deleted rows can't be restored, related rows follow the table's cascade rules, plug-ins and flows on Delete run for every row, and a failed job doesn't roll back what it already deleted."]})}),t.jsx("div",{children:i===null?t.jsx(vt,{size:"tiny",label:"Counting matching rows…",labelPosition:"after"}):i.ok?t.jsxs(ke,{weight:"semibold",size:400,children:[i.capped?`${Ee.toLocaleString()} or more`:i.count.toLocaleString()," ",s.displayName," row",i.count===1?"":"s"," match right now."]}):t.jsxs(F,{style:{color:A.colorPaletteRedForeground1},children:["Couldn't count matching rows: ",i.error]})}),d&&!e.recurrenceDays&&t.jsx(F,{children:"Nothing matches, so there's nothing to delete."}),t.jsxs(F,{children:["Job ",t.jsx("strong",{children:e.jobName||"(unnamed)"})," starts ",w,e.recurrenceDays?` and repeats every ${e.recurrenceDays} day${e.recurrenceDays===1?"":"s"}, deleting rows that match at each run`:"","."]}),a&&t.jsx(kt,{checked:h,onChange:(j,g)=>y(!!g.checked),label:`The query has no conditions — delete every ${s.displayName} row.`}),t.jsx(N,{label:t.jsxs(t.Fragment,{children:["Type the table name ",t.jsx("code",{children:s.logicalName})," to confirm"]}),children:t.jsx(Q,{value:c,onChange:(j,g)=>p(g.value),autoComplete:"off","aria-label":"Table logical name"})})]}),t.jsxs(wt,{children:[t.jsx($,{appearance:"secondary",onClick:l,children:"Cancel"}),t.jsx($,{appearance:"primary",icon:t.jsx(Nt,{}),disabled:!x,onClick:n,style:x?{backgroundColor:A.colorPaletteRedBackground3,color:A.colorNeutralForegroundOnBrand}:void 0,children:"Submit bulk delete job"})]})]})})})}function xe(e){return typeof e=="number"?e:void 0}function b(e,s,a){if(!e)return"—";const l=e[`${s}@OData.Community.Display.V1.FormattedValue`];if(typeof l=="string")return l;const n=e[s];return a&&typeof n=="number"?a[n]??String(n):n==null||n===""?"—":String(n)}function Gt({jobId:e,result:s}){const[a,l]=u.useState(null),[n,i]=u.useState(0),[r,c]=u.useState(!0),[p,h]=u.useState(!1),y=xe(a?.job?.statecode)===3,f=async()=>{const S=await Vt(e);l(S),i(v=>v+1)};u.useEffect(()=>{f()},[e]),u.useEffect(()=>{if(!r||y||n>=V)return;const S=window.setTimeout(()=>{f()},be);return()=>window.clearTimeout(S)},[r,y,n]);const d=a?.job??null,x=a?.operation??null,w=xe(d?.statuscode),j=w===30?"success":w===31||w===32?"danger":"info",g=H.host?`https://${H.host}/main.aspx?pagetype=entityrecord&etn=asyncoperation&id=${e}`:"",D={padding:"4px 12px 4px 0",verticalAlign:"top"},U=[["Job id",t.jsx("code",{children:e},"id")],["Name",b(d,"name")],["State",b(d,"statecode",Pt)],["Status",b(d,"statuscode",fe)],["Deleted",x?b(x,"successcount"):"—"],["Failed",x?b(x,"failurecount"):"—"],["Created",b(d,"createdon")],["Started",b(d,"startedon")],["Completed",b(d,"completedon")],["Recurrence",b(d,"recurrencepattern")],["Message",b(d,"friendlymessage")!=="—"?b(d,"friendlymessage"):b(d,"message")]];return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12,maxWidth:760},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[t.jsx(ce,{status:"success",code:s.status,ms:s.ms}),t.jsx(ke,{weight:"semibold",children:"Bulk delete job submitted"}),a&&t.jsx(ce,{status:j,code:b(d,"statuscode",fe)})]}),t.jsxs("div",{style:{display:"flex",gap:8,flexWrap:"wrap",alignItems:"center"},children:[t.jsx($,{icon:t.jsx(mt,{}),onClick:()=>{f()},children:"Refresh"}),t.jsx(z,{checked:r&&!y&&n<V,disabled:y||n>=V,onChange:(S,v)=>c(v.checked),label:y?"Job completed":`Auto-refresh every ${be/1e3} s`}),t.jsx($,{icon:t.jsx(yt,{}),onClick:()=>{ht(e).then(()=>h(!0))},children:p?"Copied":"Copy job id"}),g&&t.jsx($,{as:"a",href:g,target:"_blank",rel:"noreferrer",icon:t.jsx(ft,{}),appearance:"subtle",children:"Open system job"})]}),a?.error&&t.jsx(E,{intent:"warning",children:t.jsxs(R,{children:["Couldn't read the job: ",a.error]})}),t.jsx("table",{style:{borderCollapse:"collapse",fontSize:13},children:t.jsx("tbody",{children:U.map(([S,v])=>t.jsxs("tr",{children:[t.jsx("td",{style:{...D,color:A.colorNeutralForeground3},children:S}),t.jsx("td",{style:D,children:v})]},S))})}),t.jsxs(F,{children:["Status comes from ",t.jsxs("code",{children:["asyncoperations(",e,")"]}),"; deleted / failed counts from the matching ",t.jsx("code",{children:"bulkdeleteoperations"})," row once the job has run."]})]})}export{Zt as BulkDeleteMode};
@@ -1,6 +0,0 @@
1
- import{f as P,E as Je,af as Ze,ag as Ye,ah as xe,b as Qe,d as je,m as ge,ai as Xe,j as et,c as tt,r as y,u as st,e as at,aj as rt,ak as nt,al as it,am as ot,an as lt,i as X,k as dt,ao as ke,ap as ct,T as ut,l as pt,aq as ve,ar as ht,as as Se,at as mt,L as yt,q as gt,au as fe,av as ft,t,Z as M,aw as bt,H as wt,w as xt,y as be,z as jt,A as kt,B as $,D as R,G as vt,R as St,U as Ct,S as $t,a9 as ae,O as k,ax as Rt,ay as Ce,az as $e,W as re,aA as te,a5 as Mt,a6 as Re,aB as It,aC as Dt,aD as Ft,J as Me,Y as E,aE as ee,aF as Nt,aa as Bt,ab as At,a3 as Ut,K as Lt,N as Tt,V as Ot,_ as Et,$ as Pt,a0 as qt,a1 as Vt,a2 as _t,ad as Kt,a4 as zt,a7 as Gt,aG as Wt,I as Ht,aH as Jt}from"./index-D0g0tm7R.js";const Ie=["CreateMultiple","UpdateMultiple","UpsertMultiple","DeleteMultiple"],Zt=1e3,Yt=100,Qt=/^\{?[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\}?$/i,De=s=>Qt.test(s.trim()),Fe=s=>s.trim().replace(/^\{|\}$/g,"").toLowerCase();let Xt=1;function G(s){return{id:typeof crypto<"u"&&typeof crypto.randomUUID=="function"?`row_${crypto.randomUUID()}`:`row_${Date.now().toString(36)}_${(Xt++).toString(36)}`,key:s?.key??"",fieldValues:s?.fieldValues??{},nullFields:s?.nullFields??[]}}function es(s){return G({key:"",fieldValues:ts(s.fieldValues),nullFields:[...s.nullFields]})}function ts(s){return JSON.parse(JSON.stringify(s))}const q={CreateMultiple:{label:"Create multiple",description:"Creates every row in one request and returns the new ids.",keyRequired:!1,allowsAlternateKey:!1,usesFields:!0,fieldPurpose:"create",successStatus:200},UpdateMultiple:{label:"Update multiple",description:"Updates rows addressed by their primary key (GUID). Send only changed columns.",keyRequired:!0,allowsAlternateKey:!1,usesFields:!0,fieldPurpose:"update",successStatus:204},UpsertMultiple:{label:"Upsert multiple",description:"Creates or updates each row, addressed by primary key or an alternate key. Needs a table that supports both CreateMultiple and UpdateMultiple.",keyRequired:!0,allowsAlternateKey:!0,usesFields:!0,fieldPurpose:"upsert",successStatus:204},DeleteMultiple:{label:"Delete multiple",description:"Deletes rows by primary key. Elastic tables only — for standard tables use Bulk Delete.",keyRequired:!0,allowsAlternateKey:!1,usesFields:!0,fieldPurpose:"update",successStatus:204}};function ss(s,a){return Ze({table:s,fieldValues:a.fieldValues,nullFields:a.nullFields})}function as(s,a,e){const r=q[s.operation],i={"@odata.type":`Microsoft.Dynamics.CRM.${a.logicalName}`},o=r.usesFields?ss(s.table,e):{};Object.assign(i,o);const u=e.key.trim();let c;if(u?De(u)?i[a.primaryKey]=Fe(u):r.allowsAlternateKey?i["@odata.id"]=`${a.entitySetName}(${u})`:c=s.operation==="UpdateMultiple"?"Key must be a GUID — UpdateMultiple in the Web API does not accept alternate keys.":"Key must be a GUID.":r.keyRequired&&(c=s.operation==="UpsertMultiple"?"Missing key — a GUID or an alternate key such as name='value'.":"Missing primary key (GUID)."),!c&&s.operation!=="DeleteMultiple"&&Object.keys(o).length===0&&(c="No column values set."),!c&&s.operation==="CreateMultiple"){const l=rs(a,e);l.length>0&&(c=`Required column${l.length===1?"":"s"} unset: ${l.slice(0,3).join(", ")}${l.length>3?"…":""}`)}return{target:i,issue:c}}function rs(s,a){return s.columns.filter(e=>Ye(e)).filter(e=>{const r=a.fieldValues[e.logicalName];return r==null||r===""?!0:Array.isArray(r)?r.length===0:xe(e)?!r?.id:!1}).map(e=>e.logicalName)}function Ne(s){const a=P(s.table);if(!a)return{body:{Targets:[]},issues:[]};const e=[],r=new Map;return{body:{Targets:s.rows.map((o,u)=>{const{target:c,issue:l}=as(s,a,o);l&&e.push({rowIndex:u,rowId:o.id,message:l});const m=o.key.trim().toLowerCase();if(m){const h=r.get(m);h!==void 0?e.push({rowIndex:u,rowId:o.id,message:s.operation==="UpdateMultiple"?`Same key as row ${h+1} — UpdateMultiple applies only the first of them.`:`Same key as row ${h+1} — duplicate keys fail the request.`}):r.set(m,u)}return c})},issues:e}}function ns(s){const a=P(s.table);if(!a)return{relativeUrl:"",relativeNoBase:"",bytes:0,queryParts:[],entitySet:"",entityLogical:""};const e=`/${a.entitySetName}/Microsoft.Dynamics.CRM.${s.operation}`,r=`${Je.apiBase}${e}`;return{relativeUrl:r,relativeNoBase:e,bytes:r.length,queryParts:[],entitySet:a.entitySetName,entityLogical:a.logicalName}}function is(s){return s==="UpsertMultiple"?["CreateMultiple","UpdateMultiple"]:[s]}function os(s,a){const e=r=>`'${r.replace(/'/g,"''")}'`;return`sdkmessagefilters?$select=sdkmessagefilterid&$filter=sdkmessageid/name eq ${e(s)} and primaryobjecttypecode eq ${e(a)}`}function ls(s,a,e){const r=P(s.table);if(!s.table)return"Pick a target table first.";if(!r)return"Loading table metadata…";if(e.state==="unsupported")return e.message;if(s.rows.length===0)return"Add at least one row.";if(a.length>0){const i=a[0];return`Row ${i.rowIndex+1}: ${i.message}${a.length>1?` (+${a.length-1} more)`:""}`}return s.headers.some(i=>i.enabled&&!i.name)?"Fix empty header name.":null}function ds(s,a,e){return s==="DeleteMultiple"?`DeleteMultiple isn't available for '${a}'. It's supported on elastic tables only — use the Bulk Delete mode (an asynchronous job) for standard tables.`:s==="UpsertMultiple"?`UpsertMultiple needs both CreateMultiple and UpdateMultiple, and '${a}' doesn't support ${e.join(" or ")}.`:`'${a}' doesn't support ${s} (no sdkmessagefilter for this table).`}const cs=new Set(["@key","key","id","@odata.id"]);function us(s,a){const e=s.trim();if(!e)return{rows:[],skippedColumns:[],errors:[]};let r;if(e.startsWith("[")||e.startsWith("{")){let c;try{c=JSON.parse(e)}catch(m){return{rows:[],skippedColumns:[],errors:[`Invalid JSON: ${m instanceof Error?m.message:String(m)}`]}}const l=Array.isArray(c)?c:c&&typeof c=="object"?c.Targets??c.value:void 0;if(!Array.isArray(l))return{rows:[],skippedColumns:[],errors:['JSON must be an array of objects (or { "Targets": [ … ] }).']};r=l.filter(m=>!!m&&typeof m=="object")}else{const c=fs(e);if(c.length<2)return{rows:[],skippedColumns:[],errors:["CSV needs a header row and at least one data row."]};const[l,...m]=c;r=m.filter(h=>h.some(g=>g.trim()!=="")).map(h=>{const g={};return l.forEach((j,S)=>{const b=h[S];b!==void 0&&b!==""&&(g[j.trim()]=b)}),g})}const i=new Set,o=[];return{rows:r.map((c,l)=>{const m=G();for(const[h,g]of Object.entries(c)){const j=h.trim();if(j==="@odata.type"||j==="@odata.etag"||g===void 0)continue;if(cs.has(j.toLowerCase())||j.toLowerCase()===a.primaryKey){m.key=ps(String(g??""),a);continue}const S=/^(.+)@odata\.bind$/i.exec(j),b=hs(a,S?S[1]:j);if(!b){i.add(j);continue}if(g===null){m.nullFields.push(b.logicalName);continue}const w=ms(b,g);"error"in w?o.push(`Row ${l+1}, ${j}: ${w.error}`):m.fieldValues[b.logicalName]=w.value}return m}),skippedColumns:[...i],errors:o}}function ps(s,a){const e=/^\/?([A-Za-z0-9_]+)\((.*)\)$/.exec(s.trim());return e&&e[1]===a.entitySetName?e[2]:s.trim()}function hs(s,a){const e=a.toLowerCase(),r=Qe(s,e);if(r)return r;const i=s.columns.find(o=>xe(o)&&e.startsWith(`${o.logicalName}_`));return i||s.columns.find(o=>o.displayName.toLowerCase()===e)}function we(s,a){if(typeof a=="number")return a;const e=String(a).trim();return/^-?\d+$/.test(e)?Number(e):s.find(r=>r.label.toLowerCase()===e.toLowerCase())?.value}function ms(s,a){const e=typeof a=="string"?a.trim():a;switch(s.attributeType){case"Integer":case"BigInt":case"Decimal":case"Double":case"Money":{const r=typeof e=="number"?e:Number(String(e).replace(/,/g,""));return Number.isFinite(r)?(s.attributeType==="Integer"||s.attributeType==="BigInt")&&!Number.isInteger(r)?{error:`"${String(a)}" is not a whole number`}:{value:r}:{error:`"${String(a)}" is not a number`}}case"Boolean":{if(typeof e=="boolean")return{value:e};const r=String(e).toLowerCase();return["true","1","yes","y"].includes(r)?{value:!0}:["false","0","no","n"].includes(r)?{value:!1}:r===s.trueOption.label.toLowerCase()?{value:!0}:r===s.falseOption.label.toLowerCase()?{value:!1}:{error:`"${String(a)}" is not a yes/no value`}}case"Picklist":case"State":case"Status":case"EntityName":{const r=we(s.options,e);return r===void 0?{error:`unknown choice "${String(a)}"`}:{value:r}}case"MultiSelectPicklist":{const r=Array.isArray(e)?e:String(e).split(/[,;]/).map(o=>o.trim()).filter(Boolean),i=[];for(const o of r){const u=we(s.options,o);if(u===void 0)return{error:`unknown choice "${String(o)}"`};i.push(u)}return{value:i}}case"Lookup":case"Customer":case"Owner":{const r=String(e),i=/^\/?([A-Za-z0-9_]+)\(\{?([0-9a-fA-F-]{36})\}?\)$/.exec(r);if(i){const l=s.targets.find(m=>P(m)?.entitySetName===i[1]);return l?{value:{id:i[2].toLowerCase(),targetEntity:l}}:{error:`"${i[1]}" is not a target of ${s.logicalName}`}}const o=/^([A-Za-z0-9_]+):\s*(.+)$/.exec(r),u=o?o[1].toLowerCase():s.targets[0],c=o?o[2]:r;return De(c)?s.targets.includes(u)?{value:{id:Fe(c),targetEntity:u}}:{error:`"${u}" is not a target of ${s.logicalName}`}:{error:`"${r}" is not a GUID`}}case"File":case"Image":return{error:"file and image columns can’t be set in a bulk write"};default:return{value:typeof e=="string"?e:String(e)}}}function ys(s){const{dirty:a,...e}=s;return e}function gs(s,a){return{...a,...s,operation:Ie.includes(s.operation)?s.operation:"CreateMultiple",rows:(s.rows??[]).map(e=>({id:e.id||G().id,key:e.key??"",fieldValues:e.fieldValues??{},nullFields:e.nullFields??[]})),dirty:new Set}}function fs(s){const a=s.split(/\r?\n/,1)[0],e=a.includes(" ")&&!a.includes(",")?" ":",",r=[];let i=[],o="",u=!1;for(let c=0;c<s.length;c++){const l=s[c];if(u){l==='"'?s[c+1]==='"'?(o+='"',c++):u=!1:o+=l;continue}l==='"'&&o===""?u=!0:l===e?(i.push(o),o=""):l===`
2
- `||l==="\r"?(l==="\r"&&s[c+1]===`
3
- `&&c++,i.push(o),r.push(i),i=[],o=""):o+=l}return i.push(o),r.push(i),r}async function bs(s,a){try{const e=[];for(const r of is(a))(await je.queryData(os(r,s)))?.value?.length||e.push(r);return e.length===0?{state:"supported"}:{state:"unsupported",message:ds(a,s,e)}}catch(e){return{state:"unknown",message:`Couldn't check ${a} availability: ${e instanceof Error?e.message:String(e)}`}}}async function ws(s,a){const{body:e,issues:r}=Ne(s);if(r.length>0)return ge({statusCode:400,message:`Row ${r[0].rowIndex+1}: ${r[0].message}`},0);const i=Xe(a),o=performance.now();try{const u=await je.execute({operationName:s.operation,operationType:"action",entityName:s.table,parameters:e},i),c=Math.round(performance.now()-o),l=u&&Object.keys(u).length>0?u:null;return{status:l?200:204,statusText:l?"OK":"No Content",ms:c,bytes:et(l),ok:!0,outcome:"ok",body:l,headers:{"OData-Version":"4.0"}}}catch(u){return ge(u,Math.round(performance.now()-o),i)}}function se(s){if(!s||typeof s!="object")return[];const a=s.Ids;return Array.isArray(a)?a.filter(e=>typeof e=="string"):[]}const z="bulk-write",D="bulk",A=100,xs=25,Be=()=>({table:"",operation:"CreateMultiple",rows:[],headers:Ht(),bypass:Wt()}),js=()=>({...Be(),dirty:new Set}),O=s=>`row:${s}`;function Is({themeMode:s}){const a=tt(z),[e,r]=y.useState(js),{table:i}=st(e.table||null),{entities:o}=at(),[u,c]=y.useState("target"),[l,m]=y.useState("builder"),[h,g]=y.useState(null),[j,S]=y.useState("CreateMultiple"),[b,w]=y.useState(!1),[W,H]=y.useState([]),[x,v]=y.useState({state:"idle"}),[J,F]=y.useState(!1),[I,U]=y.useState(null),[Z,V]=y.useState(void 0),[ne,ie]=y.useState(null),C=P(e.table),L=y.useMemo(()=>ns(e),[e,i]),{body:Ae,issues:T}=y.useMemo(()=>Ne(e),[e,i]),Ue=q[e.operation];y.useEffect(()=>{if(!e.table){v({state:"idle"});return}if(!rt()){v({state:"unknown",message:"Not connected to Power Platform ToolBox — availability not checked."});return}let n=!1;return v({state:"checking"}),bs(e.table,e.operation).then(d=>{n||v(d)}),()=>{n=!0}},[e.table,e.operation]);const oe=(n,d)=>{const p=new Set(n.dirty);return p.add(d),p},Y=(n,d,p)=>r(f=>({...f,[n]:d,dirty:oe(f,p)})),B=n=>r(d=>({...d,rows:n(d.rows),dirty:oe(d,"rows")})),le=(n,d)=>B(p=>p.map(f=>f.id===n?{...f,...d}:f)),Le=()=>G({fieldValues:C&&e.operation==="CreateMultiple"?Jt(C):{}}),Te=n=>{const d=Le();B(p=>[...p,d])},de=n=>{const d=e.rows.find(f=>f.id===n);if(!d)return;const p=es(d);B(f=>{const We=f.findIndex(He=>He.id===n),ye=[...f];return ye.splice(We+1,0,p),ye})},ce=n=>{B(d=>d.filter(p=>p.id!==n)),u===O(n)&&c("rows")},_=y.useMemo(()=>nt(e.headers,e.bypass),[e.headers,e.bypass]),ue=y.useMemo(()=>[...it(e.bypass,"bypass"),...ot({op:"create",bypass:e.bypass})],[e.bypass]),Oe=lt(ue),Ee=ls(e,T,x)??(x.state==="checking"?`Checking ${e.operation} availability…`:null),Pe=async()=>{w(!0);const n=e.operation,d=await ws(e,be(_,null));g(d),S(n),w(!1),m("results");const p=se(d.body);H(f=>[{id:`r-${Date.now()}`,modeId:z,url:L.relativeUrl,method:"POST",ts:Date.now(),status:d.status,ms:d.ms,rowCount:d.ok?p.length||e.rows.length:0,summary:d.ok?`${p.length||e.rows.length} ${(p.length||e.rows.length)===1?"row":"rows"} written`:void 0},...f].slice(0,8)),r(f=>({...f,dirty:new Set}))},K=y.useMemo(()=>ys(e),[e]),qe=y.useMemo(()=>X(K),[K]),pe=ne===null?!0:qe!==ne,Ve=n=>{V(n.id),ie(X(n.state))},_e=n=>{if(n.modeId!==z)return;const d=n.state;if(o.length>0&&!o.some(p=>p.logicalName===d.table)){U(`Can't load "${n.name}": table '${d.table}' isn't available in this environment.`);return}U(null),r(gs(d,Be())),V(n.id),ie(X(d)),g(null),c("rows")};dt(y.useMemo(()=>e.table?{state:K,modeId:z,dirty:pe,lastSavedId:Z,onSaved:Ve,onLoadSaved:_e}:null,[K,pe,Z,e.table]));const Q=y.useMemo(()=>{const n=new Map;for(const d of T)n.has(d.rowId)||n.set(d.rowId,d.message);return n},[T]),he=(n,d)=>{const p=C?n.fieldValues[C.primaryName]:void 0,f=n.key||typeof p=="string"&&p||"";return f?`#${d+1} · ${f}`:`#${d+1}`},Ke=e.rows.slice(0,xs).map((n,d)=>{const p=Q.get(n.id),f=Object.keys(n.fieldValues).length+n.nullFields.length;return{id:O(n.id),icon:ct,iconFilled:ke,label:he(n,d),badge:p?"!":f||null,badgeAppearance:"tint",badgeColor:p?"danger":"success"}}),me=x.state==="supported"?{badge:"supported",color:"success"}:x.state==="unsupported"?{badge:"unsupported",color:"danger"}:x.state==="checking"?{badge:"…",color:"subtle"}:x.state==="unknown"?{badge:"?",color:"warning"}:{badge:null,color:"subtle"},ze=[{id:"target",label:"Target",meta:C?`${C.displayName} · ${C.entitySetName}`:"Pick a table",items:[{id:"target",icon:pt,iconFilled:ut,label:C?.displayName??"Pick a table",dirty:e.dirty.has("target")}]},{id:"operation",label:"Operation",meta:e.operation,items:[{id:"operation",icon:ht,iconFilled:ve,label:Ue.label,badge:me.badge,badgeAppearance:"tint",badgeColor:me.color,dirty:e.dirty.has("operation")}]},{id:"rows",label:"Rows",meta:`${e.rows.length} row${e.rows.length===1?"":"s"}`,items:[{id:"rows",icon:mt,iconFilled:Se,label:"All rows",badge:T.length||null,badgeAppearance:"tint",badgeColor:"danger",dirty:e.dirty.has("rows"),children:Ke}]},{id:"headers",label:"Headers",meta:`${_.filter(n=>n.enabled).length} active`,items:[{id:"headers",icon:gt,iconFilled:yt,label:"HTTP headers",badge:_.filter(n=>n.enabled).length||null,dirty:e.dirty.has("headers")},{id:"bypass",icon:fe,iconFilled:fe,label:"Bypass logic",badge:ft(e.bypass),badgeAppearance:e.bypass.businessLogic!=="none"||e.bypass.suppressFlows?"tint":"ghost",badgeColor:e.bypass.businessLogic!=="none"||e.bypass.suppressFlows?"warning":"subtle",dirty:e.dirty.has("bypass")}]}];let N=null;if(u.startsWith("row:")){const n=e.rows.findIndex(p=>O(p.id)===u),d=e.rows[n];N=d?t.jsx(Cs,{row:d,index:n,count:e.rows.length,table:e.table,tbl:C,operation:e.operation,issue:Q.get(d.id),themeMode:s,onPatch:p=>le(d.id,p),onNavigate:p=>c(O(e.rows[p].id)),onBack:()=>c("rows"),onDuplicate:()=>de(d.id),onRemove:()=>ce(d.id)},d.id):t.jsx(M,{children:"That row was removed."})}else switch(u){case"target":N=t.jsx(xt,{table:e.table,onTableChange:n=>{r(d=>({...d,table:n,rows:[],dirty:new Set(["target","rows"])})),g(null)},group:D,sub:"Every row in a bulk request targets the same table. Switching the target clears the rows."});break;case"operation":N=t.jsx(ks,{operation:e.operation,setOperation:n=>Y("operation",n,"operation"),support:x,table:e.table});break;case"rows":N=t.jsx(Ss,{state:e,tbl:C,issueByRow:Q,issueCount:T.length,rowLabel:he,onAdd:()=>Te(),onImport:()=>F(!0),onClear:()=>B(()=>[]),onEdit:n=>c(O(n)),onDuplicate:de,onRemove:ce,onKeyChange:(n,d)=>le(n,{key:d})});break;case"headers":N=t.jsx(wt,{items:e.headers,setItems:n=>Y("headers",n,"headers"),group:D,sendsHeaders:!0});break;case"bypass":N=t.jsx(bt,{value:e.bypass,onChange:n=>Y("bypass",n,"bypass"),group:D});break}const Ge={method:"POST",built:L,headers:be(_,null),body:Ae,entityLogical:L.entityLogical};return t.jsxs(jt,{sidebar:t.jsx($t,{type:a,urlPreview:L.relativeNoBase,sections:ze,activeNode:u,onSelect:n=>{c(n),m("builder")},recents:W}),urlBar:t.jsx(Ct,{method:"POST",url:L.relativeUrl,executeVerb:a.executeVerb,disabledReason:Ee??Oe,loading:b,onExecute:Pe,advisories:ue,onAdvisoryFocus:c}),children:[t.jsxs(kt,{tab:l,onTabChange:m,resultCount:h?.ok&&se(h.body).length||null,children:[l==="builder"&&t.jsxs(t.Fragment,{children:[I&&t.jsx($,{intent:"error",style:{marginBottom:12},children:t.jsx(R,{children:I})}),N]}),l==="code"&&t.jsx(vt,{themeMode:s,inputs:Ge,group:D}),l==="results"&&(h&&h.ok?t.jsx(Rs,{result:h,operation:j}):t.jsx(St,{result:h,mode:"single",table:e.table}))]}),t.jsx($s,{open:J,tbl:C,onClose:()=>F(!1),onImport:(n,d)=>{B(p=>d?n:[...p,...n]),F(!1),c("rows")}})]})}function ks({operation:s,setOperation:a,support:e,table:r}){return t.jsxs("div",{style:{maxWidth:760},children:[t.jsx(ae,{icon:ve,title:"Operation",sub:"One request, many rows of the same table. On standard tables the whole request rolls back if any row fails.",group:D}),t.jsx(Bt,{value:s,onChange:(i,o)=>a(o.value),"aria-label":"Bulk operation",children:Ie.map(i=>t.jsx(At,{value:i,label:t.jsxs("span",{children:[t.jsx("code",{children:i}),t.jsx("br",{}),t.jsx(M,{children:q[i].description})]})},i))}),t.jsxs("div",{style:{marginTop:16,display:"flex",flexDirection:"column",gap:8},children:[r?e.state==="checking"?t.jsx(Ut,{size:"tiny",label:`Checking ${s} availability for ${r}…`}):e.state==="supported"?t.jsx($,{intent:"success",children:t.jsxs(R,{children:[t.jsx("code",{children:r})," supports ",s,"."]})}):e.state==="unsupported"?t.jsx($,{intent:"error",layout:"multiline",children:t.jsxs(R,{children:[t.jsx(Me,{children:"Not available"}),e.message]})}):e.state==="unknown"?t.jsx($,{intent:"warning",layout:"multiline",children:t.jsx(R,{children:e.message})}):null:t.jsx($,{intent:"info",children:t.jsxs(R,{children:["Pick a table to check whether it supports ",s,"."]})}),t.jsx($,{intent:"info",layout:"multiline",children:t.jsxs(R,{children:["Availability comes from the table's ",t.jsx("code",{children:"sdkmessagefilters"}),"."," ",t.jsx("code",{children:"UpsertMultiple"})," has no filter of its own — it's available where both"," ",t.jsx("code",{children:"CreateMultiple"})," and ",t.jsx("code",{children:"UpdateMultiple"})," are. Send 100–1,000 rows per request on standard tables (",Yt," on elastic tables); there's no fixed cap, but large payloads hit size and time limits."," ",t.jsx("a",{href:"https://learn.microsoft.com/en-us/power-apps/developer/data-platform/bulk-operations",target:"_blank",rel:"noreferrer",children:"Use bulk operation messages"})]})})]})]})}function vs(s,a){const e=a?.primaryKey??"primary key";switch(s){case"CreateMultiple":return`optional ${e} GUID`;case"UpsertMultiple":return`${e} GUID or key='value'`;default:return`${e} GUID`}}function Ss({state:s,tbl:a,issueByRow:e,issueCount:r,rowLabel:i,onAdd:o,onImport:u,onClear:c,onEdit:l,onDuplicate:m,onRemove:h,onKeyChange:g}){const[j,S]=y.useState(0),b=Math.max(1,Math.ceil(s.rows.length/A)),w=Math.min(j,b-1),W=s.rows.slice(w*A,(w+1)*A),H=q[s.operation],x={padding:"4px 8px",borderBottom:`1px solid ${E.colorNeutralStroke2}`};return t.jsxs("div",{children:[t.jsxs(ae,{icon:Se,title:"Rows",sub:`Each row becomes one item in Targets. ${H.keyRequired?"Every row needs a key.":"A key is optional."}`,group:D,children:[t.jsx(k,{icon:t.jsx(Dt,{}),onClick:o,disabled:!a,children:"Add row"}),t.jsx(k,{icon:t.jsx(Ft,{}),onClick:u,disabled:!a,children:"Import CSV / JSON…"}),t.jsx(k,{icon:t.jsx(te,{}),appearance:"subtle",onClick:c,disabled:s.rows.length===0,children:"Clear"})]}),!a&&t.jsx($,{intent:"info",children:t.jsx(R,{children:"Pick a target table first."})}),s.rows.length>Zt&&t.jsx($,{intent:"warning",layout:"multiline",style:{marginBottom:8},children:t.jsxs(R,{children:[t.jsxs(Me,{children:[s.rows.length.toLocaleString()," rows"]}),"Microsoft recommends 100–1,000 rows per request. Larger requests are more likely to hit message-size or time limits, and on standard tables a failure rolls back every row. Consider splitting the rows into several requests."]})}),r>0&&t.jsx($,{intent:"error",style:{marginBottom:8},children:t.jsxs(R,{children:[r," row issue",r===1?"":"s"," — fix them before sending."]})}),a&&s.rows.length===0&&t.jsx(M,{children:"No rows yet. Add rows one by one, or import them from CSV (header row of column names — Excel copy-paste works) or a JSON array of objects."}),s.rows.length>0&&t.jsxs("table",{style:{borderCollapse:"collapse",width:"100%",fontSize:13},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{textAlign:"left"},children:[t.jsx("th",{style:x,children:"#"}),t.jsx("th",{style:x,children:"Key"}),t.jsx("th",{style:x,children:"Columns"}),t.jsx("th",{style:x,children:"Status"}),t.jsx("th",{style:x,"aria-label":"Actions"})]})}),t.jsx("tbody",{children:W.map((v,J)=>{const F=w*A+J,I=[...Object.keys(v.fieldValues),...v.nullFields],U=e.get(v.id);return t.jsxs("tr",{children:[t.jsx("td",{style:x,children:F+1}),t.jsx("td",{style:{...x,minWidth:220},children:t.jsx(Re,{size:"small",value:v.key,placeholder:vs(s.operation,a),onChange:(Z,V)=>g(v.id,V.value),"aria-label":`Row ${F+1} key`,style:{width:"100%"}})}),t.jsx("td",{style:x,children:t.jsx(M,{title:I.join(", "),children:I.length===0?"—":`${I.length}: ${I.slice(0,3).join(", ")}${I.length>3?"…":""}`})}),t.jsx("td",{style:x,children:U?t.jsx(M,{style:{color:E.colorPaletteRedForeground1},children:U}):t.jsx(M,{style:{color:E.colorPaletteGreenForeground1},children:"Ready"})}),t.jsxs("td",{style:{...x,whiteSpace:"nowrap"},children:[t.jsx(ee,{content:`Edit ${i(v,F)}`,relationship:"label",children:t.jsx(k,{size:"small",appearance:"subtle",icon:t.jsx(Nt,{}),onClick:()=>l(v.id)})}),t.jsx(ee,{content:"Duplicate row",relationship:"label",children:t.jsx(k,{size:"small",appearance:"subtle",icon:t.jsx(re,{}),onClick:()=>m(v.id)})}),t.jsx(ee,{content:"Remove row",relationship:"label",children:t.jsx(k,{size:"small",appearance:"subtle",icon:t.jsx(te,{}),onClick:()=>h(v.id)})})]})]},v.id)})})]}),b>1&&t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:8},children:[t.jsx(k,{size:"small",icon:t.jsx(Ce,{}),disabled:w===0,onClick:()=>S(w-1),"aria-label":"Previous page"}),t.jsxs(M,{children:["Rows ",w*A+1,"–",Math.min((w+1)*A,s.rows.length)," of"," ",s.rows.length]}),t.jsx(k,{size:"small",icon:t.jsx($e,{}),disabled:w>=b-1,onClick:()=>S(w+1),"aria-label":"Next page"})]})]})}function Cs({row:s,index:a,count:e,table:r,tbl:i,operation:o,issue:u,themeMode:c,onPatch:l,onNavigate:m,onBack:h,onDuplicate:g,onRemove:j}){const S=q[o];return t.jsxs("div",{children:[t.jsxs(ae,{icon:ke,title:`Row ${a+1} of ${e}`,sub:o==="DeleteMultiple"?"Only the key (and partitionid on partitioned elastic tables) is needed.":void 0,group:D,children:[t.jsx(k,{icon:t.jsx(Rt,{}),appearance:"subtle",onClick:h,children:"All rows"}),t.jsx(k,{icon:t.jsx(Ce,{}),disabled:a===0,onClick:()=>m(a-1),"aria-label":"Previous row"}),t.jsx(k,{icon:t.jsx($e,{}),disabled:a>=e-1,onClick:()=>m(a+1),"aria-label":"Next row"}),t.jsx(k,{icon:t.jsx(re,{}),onClick:g,children:"Duplicate"}),t.jsx(k,{icon:t.jsx(te,{}),appearance:"subtle",onClick:j,children:"Remove"})]}),t.jsx(Mt,{label:S.keyRequired?"Key (required)":"Key (optional)",hint:o==="UpsertMultiple"?`A ${i?.primaryKey??"primary key"} GUID, or an alternate key segment such as name='Contoso' — sent as @odata.id.`:o==="CreateMultiple"?`Leave empty to let Dataverse assign the id, or set a ${i?.primaryKey??"primary key"} GUID.`:`The ${i?.primaryKey??"primary key"} GUID of the row.`,validationState:u?"error":"none",validationMessage:u,style:{maxWidth:520,marginBottom:12},children:t.jsx(Re,{value:s.key,onChange:(b,w)=>l({key:w.value})})}),S.usesFields&&t.jsx(It,{table:r,values:s.fieldValues,setValues:b=>l({fieldValues:b}),nullFields:s.nullFields,setNullFields:b=>l({nullFields:b}),group:D,themeMode:c,purpose:S.fieldPurpose})]})}function $s({open:s,tbl:a,onClose:e,onImport:r}){const[i,o]=y.useState(""),[u,c]=y.useState(!1),l=y.useMemo(()=>a?us(i,a):{rows:[],skippedColumns:[],errors:[]},[i,a]),m=async h=>{h&&o(await h.text())};return t.jsx(Et,{open:s,onOpenChange:(h,g)=>!g.open&&e(),children:t.jsx(Pt,{style:{maxWidth:760},children:t.jsxs(qt,{children:[t.jsxs(Vt,{children:["Import rows",a?` into ${a.displayName}`:""]}),t.jsxs(_t,{style:{display:"flex",flexDirection:"column",gap:10},children:[t.jsxs(M,{children:["Paste CSV / tab-separated text with a header row of column logical (or display) names, or a JSON array of objects. A ",t.jsx("code",{children:a?.primaryKey??"primary key"}),","," ",t.jsx("code",{children:"id"})," or ",t.jsx("code",{children:"@key"})," column fills the row key. Lookups take a GUID (first target) or ",t.jsx("code",{children:"table:guid"}),"; choices take the value or the label."]}),t.jsx(Kt,{value:i,onChange:(h,g)=>o(g.value),rows:12,"aria-label":"Rows to import",placeholder:`name,numberofemployees
4
- Contoso,10
5
- Fabrikam,25`,textarea:{style:{fontFamily:E.fontFamilyMonospace,fontSize:12}}}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,flexWrap:"wrap"},children:[t.jsx("input",{type:"file",accept:".csv,.tsv,.txt,.json","aria-label":"Load rows from a file",onChange:h=>{m(h.target.files?.[0])}}),t.jsx(zt,{checked:u,onChange:(h,g)=>c(!!g.checked),label:"Replace existing rows"})]}),i.trim()&&t.jsx($,{intent:l.errors.length?"warning":l.rows.length?"success":"info",layout:"multiline",children:t.jsxs(R,{children:[l.rows.length," row",l.rows.length===1?"":"s"," parsed.",l.skippedColumns.length>0&&t.jsxs(t.Fragment,{children:[" Skipped columns (not on this table): ",l.skippedColumns.join(", "),"."]}),l.errors.length>0&&t.jsxs("ul",{style:{margin:"4px 0 0",paddingLeft:18},children:[l.errors.slice(0,6).map(h=>t.jsx("li",{children:h},h)),l.errors.length>6&&t.jsxs("li",{children:["…and ",l.errors.length-6," more"]})]})]})})]}),t.jsxs(Gt,{children:[t.jsx(k,{appearance:"secondary",onClick:e,children:"Cancel"}),t.jsxs(k,{appearance:"primary",disabled:l.rows.length===0,onClick:()=>{r(l.rows,u),o("")},children:["Import ",l.rows.length||""," row",l.rows.length===1?"":"s"]})]})]})})})}function Rs({result:s,operation:a}){const e=se(s.body),[r,i]=y.useState(!1);return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12,maxWidth:760},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[t.jsx(Lt,{status:"success",code:s.status,ms:s.ms}),t.jsxs(Tt,{weight:"semibold",children:[a," ",e.length>0?`created ${e.length} row${e.length===1?"":"s"}`:"completed"]})]}),e.length>0?t.jsxs(t.Fragment,{children:[t.jsx("div",{children:t.jsx(k,{icon:t.jsx(re,{}),onClick:()=>{Ot(e.join(`
6
- `)).then(()=>i(!0))},children:r?"Copied":"Copy ids"})}),t.jsx("ol",{style:{margin:0,paddingLeft:32,fontFamily:E.fontFamilyMonospace,fontSize:12,maxHeight:480,overflow:"auto"},children:e.map(o=>t.jsx("li",{children:o},o))})]}):t.jsxs(M,{children:[a," returns 204 No Content — Dataverse doesn't report per-row results for it. Every row in the request succeeded (a failure would have rolled back the request on a standard table)."]})]})}export{Is as BulkWriteMode};
@@ -1,2 +0,0 @@
1
- import{c as ke,b7 as Ie,bX as ae,r as n,u as Pe,e as Ne,bY as Ce,bZ as we,f as L,b_ as Ee,bQ as G,b$ as Re,bb as De,i as W,k as Me,T as Fe,l as $e,bS as Ae,bT as Be,bH as Z,bI as He,L as Le,q as ze,t as e,H as qe,w as Ue,bV as Ve,y as We,z as Oe,A as _e,G as Ye,R as Ze,bW as O,U as Ge,S as Je,I as Ke,bn as Qe,a9 as se,B as _,D as Y,J as re,au as Xe,Y as d,Z as C,a3 as et,c0 as tt,b6 as at,b0 as st,aU as rt,bo as nt,bm as ot}from"./index-D0g0tm7R.js";import{N as lt,A as it}from"./AssociateTargetsEditor-CVWE3tbv.js";const dt=()=>({table:"",sourceId:null,navProperty:null,targetIds:[],targetNames:{},headers:Ke(),dirty:new Set});function mt({themeMode:l}){const y=ke("disassociate"),g=Ie("disassociate",ae,dt),[t,o]=n.useState(g.state),{table:S}=Pe(t.table||null),{entities:j}=Ne(),[w,c]=n.useState("source"),[b,E]=n.useState("builder"),[R,z]=n.useState(null),[le,J]=n.useState(!1),[ie,de]=n.useState([]),[D,M]=n.useState(g.lastSavedId),[F,$]=n.useState(g.lastSavedHash),[K,q]=n.useState(""),[m,x]=n.useState(null),[Q,T]=n.useState(!1),[U,A]=n.useState(null),k=n.useMemo(()=>Ce(t),[t,S]),v=n.useMemo(()=>we(t),[t,S]),p=L(t.table),r=t.navProperty?p?.navigationProperties.find(a=>a.name===t.navProperty):void 0,ce=r?Ee(r):!1,h=r?G(r):!1,I=h?"PATCH":"DELETE";n.useEffect(()=>{let a=!1;if(A(null),!h||!t.sourceId||!p||!r){x(null),T(!1);return}if(typeof window>"u"||!window.dataverseAPI?.queryData){x(null),T(!1),A("The PPTB host is not available, so the current value cannot be read.");return}x(null),T(!0);const s=`_${r.referencingAttribute||r.name}_value`,u=`/${p.entitySetName}(${t.sourceId})?$select=${s}`;return window.dataverseAPI.queryData(u).then(i=>{if(a)return;const N=i?.value,H=Array.isArray(N)?N[0]??null:N&&typeof N=="object"?N:i&&typeof i=="object"&&(s in i||p.primaryKey in i)?i:null;if(!H)A("Dataverse returned no row for the source record.");else{const te=String(H[s]??""),je=String(H[`${s}@OData.Community.Display.V1.FormattedValue`]??""),Te=String(H[`${s}@Microsoft.Dynamics.CRM.lookuplogicalname`]??"");x(te?{id:te,name:je||null,entity:Te||null}:null)}T(!1)}).catch(i=>{a||(x(null),T(!1),A(i instanceof Error?i.message:String(i)))}),()=>{a=!0}},[h,t.sourceId,t.navProperty,p,r]);const V=a=>o(s=>{const u=new Set(s.dirty);return u.add(a),{...s,dirty:u}}),B=(a,s,u)=>{o(i=>({...i,[a]:s})),u&&V(u)},ue=p?t.sourceId?t.navProperty?ce&&t.targetIds.length===0?"Pick at least one target record to disassociate.":h&&m===null&&!Q&&!U?"Source's lookup is already empty — nothing to disassociate.":t.headers.some(a=>a.enabled&&!a.name)?"Fix empty header name.":null:"Pick a navigation property.":"Pick a source record.":"Pick a source table first.",ge=async()=>{J(!0);const a=await rt.disassociate(t);z(a),J(!1),E("results"),de(s=>[{id:`r-${Date.now()}`,snapshot:f,modeId:"disassociate",url:k.relativeUrl,method:I,ts:Date.now(),status:a.status,ms:a.ms,rowCount:O(a,v.length)??0,summary:`${O(a,v.length)??0} of ${v.length} unlinked`},...s].slice(0,8)),o(s=>({...s,dirty:new Set}))},f=n.useMemo(()=>Re(t),[t]);De("disassociate",f,D,F);const he=n.useMemo(()=>W(f),[f]),X=F===null?!0:he!==F,ye=a=>{M(a.id),$(W(a.state))},ee=a=>{if(a.modeId!=="disassociate")return;const s=a.state;if(j.length>0&&!j.some(u=>u.logicalName===s.table)){Qe(`Can't load "${a.name}": entity \`${s.table}\` isn't available in this environment. The solution may have been removed or you may be connected to a different org.`);return}o(ae(s)),M(a.id),$(W(s)),z(null),q(""),c("source")},me=a=>{const s=nt(a,"disassociate");if(!s)return;const u=D,i=F;ee(s),M(u),$(i)};Me(n.useMemo(()=>t.table?{state:f,modeId:"disassociate",dirty:X,lastSavedId:D,onSaved:ye,onLoadSaved:ee}:null,[f,X,D,t.table]));const pe=[{id:"source",label:"Target",meta:p?.displayName??"Pick a table",items:[{id:"source",icon:$e,iconFilled:Fe,label:t.sourceId?K||`${p?.displayName??""} (selected)`:"Pick a record",badge:r?I:null,badgeAppearance:"tint",badgeColor:"brand",dirty:t.dirty.has("source")}]},{id:"relationship",label:"Relationship",meta:r?oe(r.cardinality):"pick one",items:[{id:"nav",icon:Be,iconFilled:Ae,label:r?r.name:"Navigation property",code:!!r,badge:r?oe(r.cardinality):null,badgeAppearance:"ghost",dirty:t.dirty.has("nav")}]},{id:"target",label:"Related",meta:h?m?`clear: ${m.name??m.id.slice(0,8)}…`:U?"value unknown":"lookup empty":t.targetIds.length?`${t.targetIds.length} target${t.targetIds.length===1?"":"s"}`:"none",items:[{id:"target",icon:He,iconFilled:Z,label:h?"Target — implicit":t.targetIds.length>1?"Target records":"Target record",badge:h?"∅":t.targetIds.length||null,badgeAppearance:"tint",badgeColor:t.targetIds.length>0?"success":"subtle",dirty:t.dirty.has("target")}]},{id:"headers",label:"Headers",meta:`${t.headers.filter(a=>a.enabled).length} active`,items:[{id:"headers",icon:ze,iconFilled:Le,label:"HTTP headers",badge:t.headers.filter(a=>a.enabled).length||null,dirty:t.dirty.has("headers")}]}];let P;switch(w){case"source":P=e.jsx(Ue,{table:t.table,onTableChange:a=>{o(s=>({...s,table:a,sourceId:null,navProperty:null,targetIds:[],targetNames:{},dirty:new Set(["source","nav","target"])})),q(""),x(null),z(null),M(void 0),$(null)},recordId:t.sourceId,onRecordChange:(a,s)=>{B("sourceId",a,"source"),q(s??"")},group:"relate",sub:"Pick the source record holding the relationship link to remove."});break;case"nav":P=e.jsx("div",{children:e.jsx(lt,{table:t.table,value:t.navProperty,onChange:a=>{o(s=>({...s,navProperty:a,targetIds:[],targetNames:{}})),V("nav"),V("target")},group:"relate",forOperation:"disassociate",footer:r&&e.jsx(ut,{nav:r})})});break;case"target":P=e.jsx(ct,{state:t,setTargetIds:a=>B("targetIds",a,"target"),targetNames:t.targetNames,setTargetNames:a=>B("targetNames",a),currentLookup:m,currentLookupLoading:Q,currentLookupError:U});break;case"headers":P=e.jsx(qe,{items:t.headers,setItems:a=>B("headers",a,"headers"),group:"relate"});break}const be=Ve(I,We(t.headers,null)),ve=v[0],xe={method:I,built:k,headers:be,body:ve?.body,entityLogical:k.entityLogical,multiRequests:v.length>1?v.map(a=>({method:a.method,relativeUrl:a.relativeUrl,body:a.body,description:a.targetId?`target ${a.targetId}`:"clear lookup (null)"})):void 0},fe=h?m?.name?[m.name]:[]:t.targetIds.map(a=>t.targetNames[a]).filter(a=>!!a),Se=h?m?1:0:t.targetIds.length;return e.jsx(Oe,{sidebar:e.jsx(Je,{type:y,urlPreview:k.relativeNoBase,sections:pe,activeNode:w,onSelect:a=>{c(a),E("builder")},recents:ie,onRecentClick:me}),urlBar:e.jsx(Ge,{method:I,url:k.relativeUrl,executeVerb:y.executeVerb,disabledReason:ue,loading:le,onExecute:ge}),children:e.jsxs(_e,{tab:b,onTabChange:E,resultCount:O(R,v.length),children:[b==="builder"&&P,b==="code"&&e.jsx(Ye,{themeMode:l,inputs:xe}),b==="results"&&e.jsx(Ze,{result:R,mode:"single",table:t.table,writeContext:{operation:"disassociate",table:t.table,recordId:t.sourceId,recordName:K||null,navProperty:t.navProperty??void 0,targetCount:Se,targetNames:fe,targetNameById:t.targetNames}})]})})}function ct({state:l,setTargetIds:y,targetNames:g,setTargetNames:t,currentLookup:o,currentLookupLoading:S,currentLookupError:j}){const w=L(l.table),c=l.navProperty?w?.navigationProperties.find(R=>R.name===l.navProperty):void 0;if(!c)return e.jsxs("div",{children:[e.jsx(se,{icon:Z,title:"Target record",sub:"Pick a navigation property first.",group:"relate"}),e.jsx(_,{layout:"multiline",intent:"info",style:{maxWidth:720},children:e.jsxs(Y,{children:["Switch to the ",e.jsx("strong",{children:"Relationship"})," pane and pick a navigation property."]})})]});const b=L(c.targetEntity);return G(c)?e.jsxs("div",{children:[e.jsx(se,{icon:Z,title:"Target — implicit (single-valued)",sub:e.jsxs(e.Fragment,{children:["Single-valued nav props don't take a target id. The ",e.jsx("code",{children:"PATCH"})," body"," ",e.jsx("code",{children:`{ "${c.name}@odata.bind": null }`})," clears the lookup on the source row."]}),group:"relate"}),e.jsx(_,{layout:"multiline",intent:"warning",icon:e.jsx(Xe,{}),style:{maxWidth:880,marginBottom:14},children:e.jsxs(Y,{children:[e.jsx(re,{children:"This clears the lookup."}),e.jsx("code",{children:c.name})," on the source row becomes ",e.jsx("code",{children:"null"}),". The related row is"," ",e.jsx("strong",{children:"not"})," deleted — only the link is removed."]})}),e.jsxs("div",{style:{border:`1px solid ${d.colorNeutralStroke2}`,borderRadius:d.borderRadiusMedium,padding:12,maxWidth:560},children:[e.jsxs(C,{style:{color:d.colorNeutralForeground3,display:"block",marginBottom:8},children:["Current lookup value",S?" (loading…)":""]}),S?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx(et,{size:"tiny"}),e.jsx(C,{children:"Fetching the lookup's current value from Dataverse…"})]}):o?e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsx(tt,{size:28,name:o.name??void 0,color:"colorful"}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:12,fontWeight:600},children:o.name??"(name not available)"}),e.jsxs("div",{style:{fontFamily:d.fontFamilyMonospace,fontSize:10,color:d.colorNeutralForeground3},children:["/",(o.entity&&L(o.entity)?.entitySetName)??b?.entitySetName??c.targetEntity,"(",o.id,")"]})]})]}),o.entity&&o.entity!==c.targetEntity&&e.jsxs(C,{style:{display:"block",marginTop:8,color:d.colorNeutralForeground3},children:["The lookup currently references a ",e.jsx("code",{children:o.entity})," row, not"," ",e.jsx("code",{children:c.targetEntity}),"."]})]}):j?e.jsx(_,{layout:"multiline",intent:"warning",children:e.jsxs(Y,{children:[e.jsx(re,{children:"Couldn't read the current value."}),"Execute still sends the ",e.jsx("code",{children:"PATCH"}),"; if the lookup is already empty it changes nothing. ",e.jsx("code",{children:j})]})}):e.jsx(C,{style:{color:d.colorNeutralForeground3,fontStyle:"italic"},children:"Source's lookup is already empty — the PATCH would be a no-op."})]})]}):e.jsx(it,{table:l.table,navProperty:l.navProperty,targets:l.targetIds,setTargets:y,targetNames:g,setTargetNames:t,group:"relate",resolvedMethod:null,verb:"DELETE",sub:e.jsxs(e.Fragment,{children:["Pick one or more ",e.jsx("code",{children:b?.logicalName})," rows to remove from the collection. Each fires a separate DELETE request per docs — the target rows are ",e.jsx("strong",{children:"not"})," ","deleted, only the links."]})})}function ut({nav:l}){const y=at(),g=G(l);return e.jsxs("div",{className:st(y.inlineCard),style:{padding:12},children:[e.jsx("strong",{style:{fontSize:12,display:"block",marginBottom:8},children:"URL shape per cardinality"}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(2, 1fr)",gap:10},children:[e.jsx(ne,{label:"Collection-valued (1:N / N:N)",syntax:"DELETE /<set>(<id>)/<nav>(<related-id>)/$ref",note:"One DELETE per target id.",active:!g}),e.jsx(ne,{label:"Single-valued (N:1)",syntax:`PATCH /<set>(<id>)
2
- { "<nav>@odata.bind": null }`,note:"Clears the lookup — docs-preferred over DELETE/$ref (and the only path PPTB exposes).",active:g})]})]})}function ne({label:l,syntax:y,note:g,active:t}){return e.jsxs("div",{style:{padding:10,border:`1px solid ${t?d.colorBrandStroke1:d.colorNeutralStroke2}`,background:t?d.colorBrandBackground2:"transparent",borderRadius:d.borderRadiusMedium,opacity:t?1:.55},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,marginBottom:4},children:[e.jsx("strong",{style:{fontSize:11},children:l}),t&&e.jsx(ot,{appearance:"tint",color:"brand",size:"extra-small",style:{marginLeft:"auto",fontWeight:700},children:"ACTIVE"})]}),e.jsx("code",{style:{fontFamily:d.fontFamilyMonospace,fontSize:11,wordBreak:"break-all",display:"block",whiteSpace:"pre-wrap"},children:y}),e.jsx(C,{style:{display:"block",marginTop:4,color:d.colorNeutralForeground3},children:g})]})}function oe(l){switch(l){case"OneToMany":return"1:N";case"ManyToOne":return"N:1";case"ManyToMany":return"N:N"}}export{mt as DisassociateMode};
@@ -1 +0,0 @@
1
- import{b6 as Q,t as e,b0 as ge,Y as w,r as o,Z as v,a3 as ee,B as C,D as q,J as z,bm as b,c as xe,b7 as ke,c2 as Y,c3 as be,c4 as je,u as Se,f as ve,e as Ee,c5 as Ie,bb as Te,i as O,k as Ne,c6 as R,c7 as Pe,T as J,l as Ae,L as Ce,q as qe,H as Re,a9 as te,a5 as re,b5 as Le,y as X,z as Me,A as We,G as Be,R as $e,U as Fe,S as De,c8 as He,O as Oe,P as ze,bk as Ve,b4 as Z,I as Ue,bn as Ge,aU as _e,bo as Ke}from"./index-D0g0tm7R.js";function Ye({rows:i,keyWidth:s,className:d}){const r=Q(),n=s!=null?{gridTemplateColumns:`${typeof s=="number"?`${s}px`:s} 1fr`}:void 0;return e.jsx("div",{className:ge(r.kvGrid,d),style:n,children:i.map((c,l)=>e.jsx(Je,{k:c.k,v:c.v,mono:c.mono},l))})}function Je({k:i,v:s,mono:d}){const r=Q();return e.jsxs(e.Fragment,{children:[e.jsx("span",{className:r.kvKey,children:i}),e.jsx("span",{className:d?r.kvValMono:r.kvVal,children:s==null||s===""?e.jsx("em",{style:{color:w.colorNeutralForeground4},children:"—"}):s})]})}const Xe="http://schemas.microsoft.com/winfx/2006/xaml",Ze=new Set(["InputEntities","CreatedEntities"]);function Qe(i){if(!i||typeof DOMParser>"u")return[];let s;try{s=new DOMParser().parseFromString(i,"application/xml")}catch{return[]}if(s.getElementsByTagName("parsererror").length>0)return[];const d=[],r=s.getElementsByTagNameNS(Xe,"Property");for(const n of Array.from(r)){const c=n.getAttribute("Name"),l=/^(In|InOut)Argument\((.*)\)$/.exec((n.getAttribute("Type")??"").trim());if(!c||!l||Ze.has(c))continue;let y=!1,h=null;for(const g of Array.from(n.getElementsByTagName("*"))){const a=g.getAttribute("Value");g.localName==="ArgumentRequiredAttribute"&&(y=a?.toLowerCase()==="true"),g.localName==="ArgumentDescriptionAttribute"&&a&&(h=a)}d.push({name:c,direction:l[1],type:l[2].trim(),required:y,description:h})}return d}function et(i){return i.replace(/\b[a-z]+:/g,"")}function tt({workflowId:i}){const[s,d]=o.useState({status:"loading"});o.useEffect(()=>{if(typeof window>"u"||!window.dataverseAPI?.queryData){d({status:"ready",args:[]});return}let n=!1;return d({status:"loading"}),window.dataverseAPI.queryData(`workflows?$select=xaml&$filter=workflowid eq ${i}`).then(c=>{if(n)return;const l=c?.value?.[0],y=typeof l?.xaml=="string"?l.xaml:null;d({status:"ready",args:Qe(y)})}).catch(c=>{n||d({status:"error",message:c instanceof Error?c.message:String(c)})}),()=>{n=!0}},[i]);const r={color:w.colorNeutralForeground3,display:"block",marginTop:10};return s.status==="loading"?e.jsxs(v,{style:{...r,display:"flex",alignItems:"center",gap:6},children:[e.jsx(ee,{size:"extra-tiny"})," Reading the workflow's input arguments…"]}):s.status==="error"?e.jsxs(v,{style:r,children:["Couldn't read the workflow definition to check for input arguments: ",s.message]}):s.args.length===0?e.jsxs(v,{style:r,children:["No input arguments declared — ",e.jsx("code",{children:"EntityId"})," is the whole request body."]}):e.jsx(C,{layout:"multiline",intent:"warning",style:{marginTop:12},children:e.jsxs(q,{children:[e.jsxs(z,{children:["This workflow declares ",s.args.length," input argument",s.args.length===1?"":"s"]}),"The Web API ",e.jsx("code",{children:"ExecuteWorkflow"})," action only takes ",e.jsx("code",{children:"EntityId"}),", so these can't be set from here; the workflow runs with their default values.",e.jsx("ul",{style:{margin:"6px 0 0",paddingLeft:18},children:s.args.map(n=>e.jsxs("li",{children:[e.jsx("code",{children:n.name})," ",e.jsx(b,{appearance:"outline",size:"small",children:et(n.type)}),n.direction==="InOut"&&e.jsx(b,{appearance:"tint",size:"small",style:{marginLeft:4},children:"in/out"}),n.required&&e.jsx(b,{appearance:"tint",color:"danger",size:"small",style:{marginLeft:4},children:"required"}),n.description&&e.jsxs("span",{style:{color:w.colorNeutralForeground3},children:[" — ",n.description]})]},n.name))})]})})}const rt=()=>({workflowId:null,entityId:null,headers:Ue(),dirty:new Set});function ot({themeMode:i}){const s=xe("exec-workflow"),d=ke("exec-workflow",Y,rt),[r,n]=o.useState(d.state),[c,l]=o.useState("pick"),[y,h]=o.useState("builder"),[g,a]=o.useState(null),[p,j]=o.useState(!1),[L,M]=o.useState([]),E=o.useMemo(()=>be(r),[r]),se=o.useMemo(()=>je(r),[r]),[T,V]=o.useState([]),[ne,W]=o.useState(!1),[ae,B]=o.useState(null),[oe,ie]=o.useState(0),le=typeof window<"u"&&!!window.dataverseAPI?.queryData;o.useEffect(()=>{let t=!1;if(typeof window>"u"||!window.dataverseAPI?.queryData){V([]),B("Workflows can only be loaded from a live Dataverse connection (PPTB).");return}return W(!0),B(null),window.dataverseAPI.queryData("workflows?$select=workflowid,name,uniquename,primaryentity,description&$filter=(statecode eq 1 and type eq 1 and ondemand eq true and category eq 0)&$orderby=name asc").then(f=>{if(t)return;const x=f?.value??[];V(x.map(k=>({id:String(k.workflowid??""),name:String(k.name??"(unnamed)"),uniqueName:k.uniquename!=null?String(k.uniquename):null,primaryEntity:String(k.primaryentity??""),description:k.description!=null?String(k.description):null}))),W(!1)}).catch(f=>{t||(B(f instanceof Error?f.message:String(f)),W(!1))}),()=>{t=!0}},[oe]);const u=r.workflowId?T.find(t=>t.id===r.workflowId):void 0;Se(u?.primaryEntity??null);const I=u?ve(u.primaryEntity):void 0,{entities:U}=Ee(),[N,$]=o.useState(d.lastSavedId),[P,F]=o.useState(d.lastSavedHash),[de,D]=o.useState(""),H=t=>n(m=>{const f=new Set(m.dirty);return f.add(t),{...m,dirty:f}}),G=(t,m,f)=>{n(x=>({...x,[t]:m})),f&&H(f)},ce=u?r.entityId?r.headers.some(t=>t.enabled&&!t.name)?"Fix empty header name.":null:`Pick a ${u.primaryEntity} record to run the workflow on.`:"Pick a workflow.",ue=async()=>{j(!0);const t=await _e.workflow(r,X(r.headers,null));a(t),j(!1),h("results"),M(m=>[{id:`r-${Date.now()}`,snapshot:S,modeId:"exec-workflow",url:E.relativeUrl,method:"POST",ts:Date.now(),status:t.status,ms:t.ms,rowCount:t.ok?1:0},...m].slice(0,8)),n(m=>({...m,dirty:new Set}))},S=o.useMemo(()=>Ie(r),[r]);Te("exec-workflow",S,N,P);const me=o.useMemo(()=>O(S),[S]),_=P===null?!0:me!==P,fe=t=>{$(t.id),F(O(t.state))},K=t=>{if(t.modeId!=="exec-workflow")return;const m=t.state,f=T.find(x=>x.id===m.workflowId);if(f&&U.length>0&&!U.some(x=>x.logicalName===f.primaryEntity)){Ge(`Can't load "${t.name}": workflow's primary entity \`${f.primaryEntity}\` isn't available in this environment.`);return}n(Y(m)),$(t.id),F(O(m)),a(null),D(""),l("pick")},ye=t=>{const m=Ke(t,"exec-workflow");if(!m)return;const f=N,x=P;K(m),$(f),F(x)};Ne(o.useMemo(()=>r.workflowId?{state:S,modeId:"exec-workflow",dirty:_,lastSavedId:N,onSaved:fe,onLoadSaved:K}:null,[S,_,N,r.workflowId,T]));const he=[{id:"workflow",label:"Target",meta:u?.name??"pick one",items:[{id:"pick",icon:Pe,iconFilled:R,label:u?.name??"Pick on-demand workflow",dirty:r.dirty.has("pick")}]},{id:"target",label:"Bound to",meta:u?`${I?.displayName??u.primaryEntity} record`:"—",items:[{id:"target",icon:Ae,iconFilled:J,label:r.entityId?`${I?.displayName??""} (selected)`:"Pick a record",badge:r.entityId?"✓":null,badgeAppearance:"ghost",dirty:r.dirty.has("target")}]},{id:"headers",label:"Headers",meta:`${r.headers.filter(t=>t.enabled).length} active`,items:[{id:"headers",icon:qe,iconFilled:Ce,label:"HTTP headers",badge:r.headers.filter(t=>t.enabled).length||null,dirty:r.dirty.has("headers")}]}];let A;switch(c){case"pick":A=e.jsx(st,{workflows:T,loading:ne,error:ae,onRetry:le?()=>ie(t=>t+1):void 0,workflowId:r.workflowId,setWorkflowId:t=>{n(m=>({...m,workflowId:t,entityId:null})),D(""),H("pick"),H("target")}});break;case"target":A=u?e.jsxs("div",{children:[e.jsx(te,{icon:J,title:"Target record",sub:`The ${I?.displayName??u.primaryEntity} record the workflow operates on. Slots into the request body as "EntityId".`,group:"execute"}),e.jsxs("div",{style:{maxWidth:480},children:[e.jsx(re,{label:`${I?.displayName??u.primaryEntity} record`,children:e.jsx(Le,{table:u.primaryEntity,selectedId:r.entityId,onPick:t=>{G("entityId",t?.id??null,"target"),D(t?.primary??"")},placeholder:`Search ${I?.displayName??u.primaryEntity} records…`})}),e.jsx(tt,{workflowId:u.id})]})]}):e.jsx(C,{layout:"multiline",intent:"info",children:e.jsx(q,{children:"Pick a workflow first."})});break;case"headers":A=e.jsx(Re,{items:r.headers,setItems:t=>G("headers",t,"headers"),group:"execute",sendsHeaders:!0});break}const pe=X(r.headers,null),we={method:"POST",built:E,headers:pe,body:se,entityLogical:E.entityLogical};return e.jsx(Me,{sidebar:e.jsx(De,{type:s,urlPreview:E.relativeNoBase,sections:he,activeNode:c,onSelect:t=>{l(t),h("builder")},recents:L,onRecentClick:ye}),urlBar:e.jsx(Fe,{method:"POST",url:E.relativeUrl,executeVerb:s.executeVerb,executeIcon:R,disabledReason:ce,loading:p,onExecute:ue}),children:e.jsxs(We,{tab:y,onTabChange:h,resultCount:g?.ok?1:null,children:[y==="builder"&&A,y==="code"&&e.jsx(Be,{themeMode:i,inputs:we}),y==="results"&&e.jsx($e,{result:g,mode:"single",table:u?.primaryEntity??"",writeContext:{operation:"workflow",table:u?.primaryEntity??"",recordId:r.entityId,recordName:de||null,operationName:u?.name??void 0}})]})})}function st({workflows:i,loading:s,error:d,onRetry:r,workflowId:n,setWorkflowId:c}){const l=n?i.find(a=>a.id===n):void 0,[y,h]=o.useState("");o.useEffect(()=>{h(l?.name??"")},[l?.name]);const g=o.useMemo(()=>{const a=y.trim().toLowerCase();return!a||a===(l?.name??"").toLowerCase()?i:i.filter(p=>p.name.toLowerCase().includes(a)||(p.uniqueName?.toLowerCase().includes(a)??!1)||p.primaryEntity.toLowerCase().includes(a)||(p.description?.toLowerCase().includes(a)??!1))},[i,y,l]);return e.jsxs("div",{children:[e.jsx(te,{icon:R,title:"On-demand workflow",sub:"Pick an activated workflow (type=Definition, category=Workflow). The workflow's primary entity drives the Target picker.",group:"execute",children:s?e.jsx(b,{appearance:"ghost",icon:e.jsx(ee,{size:"extra-tiny"}),children:"loading…"}):d?null:e.jsxs(b,{appearance:"ghost",children:[i.length," workflow",i.length===1?"":"s"]})}),d&&!s&&e.jsxs(C,{intent:"error",layout:"multiline",style:{marginBottom:12,maxWidth:760},children:[e.jsxs(q,{children:[e.jsx(z,{children:"Couldn't load workflows"}),d]}),r&&e.jsx(He,{containerAction:e.jsx(Oe,{appearance:"primary",size:"small",icon:e.jsx(ze,{}),onClick:r,children:"Retry"})})]}),e.jsxs("div",{style:{maxWidth:760},children:[e.jsx(re,{label:"Workflow",children:e.jsxs(Ve,{freeform:!0,clearable:!0,value:y,selectedOptions:n?[n]:[],onChange:a=>{const p=a.target.value;h(p),p===""&&n&&c(null)},onOptionSelect:(a,p)=>{const j=p.optionValue??null;if(c(j),j){const L=i.find(M=>M.id===j);h(L?.name??"")}else h("")},placeholder:s?"Loading workflows…":d?"Workflows didn’t load":i.length===0?"No activated workflows in this environment":"Search workflows…",disabled:s||i.length===0,listbox:{style:{maxHeight:420}},children:[g.length===0&&y.trim()&&e.jsx(Z,{value:"__none",text:"",disabled:!0,children:e.jsxs(v,{style:{color:w.colorNeutralForeground3},children:['No workflows match "',y.trim(),'"']})}),g.map(a=>e.jsx(Z,{value:a.id,text:a.name,children:e.jsxs("div",{style:{display:"flex",flexDirection:"column"},children:[e.jsx("span",{children:a.name}),e.jsxs(v,{style:{color:w.colorNeutralForeground3},children:["Primary entity:"," ",e.jsx("span",{style:{fontFamily:w.fontFamilyMonospace},children:a.primaryEntity}),a.description?` · ${a.description}`:""]})]})},a.id))]})}),l&&e.jsxs("div",{style:{marginTop:16,padding:12,border:`1px solid ${w.colorNeutralStroke2}`,borderRadius:w.borderRadiusMedium,background:w.colorNeutralBackground1},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:8},children:[e.jsx(R,{style:{color:w.colorBrandForeground1}}),e.jsx("strong",{style:{fontSize:13},children:l.name}),e.jsx(b,{appearance:"ghost",children:l.primaryEntity}),e.jsx("span",{style:{flexGrow:1}}),e.jsx(b,{appearance:"filled",color:"success",style:{fontWeight:700},children:"POST"})]}),e.jsx(v,{style:{color:w.colorNeutralForeground2,display:"block",marginBottom:8},children:l.description}),e.jsx(Ye,{keyWidth:120,rows:[{k:"Workflow id",v:l.id,mono:!0},{k:"Primary entity",v:l.primaryEntity,mono:!0},{k:"URL shape",v:`POST /workflows(${l.id})/Microsoft.Dynamics.CRM.ExecuteWorkflow`,mono:!0},{k:"Body shape",v:'{ "EntityId": "<target-guid>" }',mono:!0},{k:"Response",v:"204 No Content — workflow runs async"}]}),e.jsx(C,{layout:"multiline",intent:"info",style:{marginTop:12},children:e.jsxs(q,{children:[e.jsx(z,{children:"Workflow runs are asynchronous."}),"The 204 only confirms the request was accepted. Check the ",e.jsx("code",{children:"workflowlogs"})," ","/ ",e.jsx("code",{children:"asyncoperations"})," tables for completion + result."]})})]})]})]})}export{ot as ExecuteWorkflowMode,st as WorkflowPickerPane};
@@ -1 +0,0 @@
1
- import{c as ge,b7 as be,c9 as Y,r,u as ye,ca as fe,cb as xe,f as ke,e as je,cc as Se,bb as ve,i as L,k as Fe,aj as we,cd as Ce,t as e,ce as Q,cf as Be,T as Te,l as ze,cg as J,ch as Z,aL as H,aM as Me,bU as Ae,ci as Pe,L as Ne,q as Re,cj as P,H as De,ck as Ue,cl as Ie,cm as Ee,w as Le,y as He,cn as qe,z as Ge,A as Oe,G as $e,R as We,U as Ve,co as _e,cp as Ke,cq as Ye,S as Je,I as Ze,bn as Qe,B as z,D as M,J as A,a9 as q,a5 as g,aa as X,ab as b,Y as o,Z as u,ac as v,b6 as Xe,cr as ea,b0 as aa,aU as la,bo as sa}from"./index-D0g0tm7R.js";import{F as oa}from"./BinaryColumnPickers-mrnLqk3Z.js";const ta=()=>({table:"",recordId:null,fileColumn:"",operation:"upload",uploadMethod:{kind:"chunked-patch",chunkSize:2*1024*1024},downloadMethod:{kind:"single-request"},source:{kind:"file"},fileName:"",fileSize:0,mimeType:"application/octet-stream",bodyBase64:"",bodyUrl:"",headers:Ze(),dirty:new Set});function pa({themeMode:s}){const n=ge("manage-file"),d=be("manage-file",Y,ta),[a,i]=r.useState(d.state),{table:y}=ye(a.table||null),[G,N]=r.useState("pipeline"),[F,R]=r.useState("builder"),[O,D]=r.useState(null),[ee,$]=r.useState(!1),[ae,le]=r.useState([]),x=r.useMemo(()=>fe(a),[a,y]),p=r.useMemo(()=>xe(a),[a,y]),k=ke(a.table),j=r.useMemo(()=>(k?.columns??[]).find(l=>l.attributeType==="File"&&l.logicalName===a.fileColumn),[k,a.fileColumn]),se=l=>i(t=>{const h=new Set(t.dirty);return h.add(l),{...t,dirty:h}}),c=(l,t,h)=>{i(E=>({...E,[l]:t})),h&&se(h)},U=p[0]?.method??"PATCH",oe=k?a.recordId?a.fileColumn?a.operation==="upload"&&a.source.kind==="file"&&!a.bodyBase64&&a.source.kind==="file"&&!a.fileName?"Choose a file to upload.":a.headers.some(l=>l.enabled&&!l.name)?"Fix empty header name.":null:"Pick a file column.":"Pick a source record.":"Pick a target table first.",[te,W]=r.useState(""),ne=async()=>{$(!0);const l=await la.manageFile(a);D(l),$(!1),R("results"),le(t=>[{id:`r-${Date.now()}`,snapshot:f,modeId:"manage-file",url:x.relativeUrl,method:U,ts:Date.now(),status:l.status,ms:l.ms,rowCount:l.ok?1:0},...t].slice(0,8)),i(t=>({...t,dirty:new Set}))},{entities:V}=je(),[w,C]=r.useState(d.lastSavedId),[B,T]=r.useState(d.lastSavedHash),f=r.useMemo(()=>Se(a),[a]);ve("manage-file",f,w,B);const ie=r.useMemo(()=>L(f),[f]),_=B===null?!0:ie!==B,re=l=>{C(l.id),T(L(l.state))},K=l=>{if(l.modeId!=="manage-file")return;const t=l.state;if(V.length>0&&t.table&&!V.some(h=>h.logicalName===t.table)){Qe(`Can't load "${l.name}": entity \`${t.table}\` isn't available in this environment.`);return}i(Y(t)),C(l.id),T(L(t)),D(null),W(""),N("pipeline")},de=l=>{const t=sa(l,"manage-file");if(!t)return;const h=w,E=B;K(t),C(h),T(E)};Fe(r.useMemo(()=>a.table?{state:f,modeId:"manage-file",dirty:_,lastSavedId:w,onSaved:re,onLoadSaved:K}:null,[f,_,w,a.table]));const ce=r.useMemo(()=>we()?[Ce.warn("binary-host-unsupported","header","File operations run externally",e.jsxs("span",{children:["PPTB's ",e.jsx("code",{children:"dataverseAPI"})," doesn't expose file column endpoints. Build the request here, then copy a snippet from the ",e.jsx("strong",{children:"Code"})," tab (fetch / curl / C# / PowerShell) and run it from there. Execute will return ",e.jsx("code",{children:"501 Not Implemented"}),"."]}),"pipeline","https://learn.microsoft.com/en-us/power-apps/developer/data-platform/file-column-data")]:[],[]),S=a.operation==="upload"?"UPLOAD":a.operation==="download"?"DOWNLOAD":"DELETE",ue=a.operation==="delete"?"danger":"brand",I=a.operation==="upload"?a.uploadMethod.kind:a.operation==="download"?a.downloadMethod.kind:"simple",he=[{id:"operation",label:"Operation",meta:S.toLowerCase(),items:[{id:"operation",icon:Be,iconFilled:Q,label:S.charAt(0)+S.slice(1).toLowerCase(),badge:S,badgeAppearance:"tint",badgeColor:ue,dirty:a.dirty.has("operation")}]},{id:"target",label:"Target",meta:k?.displayName??"?",items:[{id:"target",icon:ze,iconFilled:Te,label:a.recordId?`${k?.displayName??""} (selected)`:"Pick a record",badge:a.recordId?"✓":null,badgeAppearance:"ghost",dirty:a.dirty.has("target")},{id:"column",icon:Z,iconFilled:J,label:a.fileColumn||"Pick a file column",code:!!a.fileColumn,badge:j?P((j.maxSizeInKB??32768)*1024):null,badgeAppearance:"ghost",dirty:a.dirty.has("column")}]},...a.operation!=="delete"?[{id:"method",label:"Method",meta:I,items:[{id:"method",icon:Me,iconFilled:H,label:a.operation==="upload"?"Upload method":"Download method",badge:I,badgeAppearance:"ghost",dirty:a.dirty.has("method")}]}]:[],...a.operation==="upload"?[{id:"payload",label:"Payload",meta:a.fileName||"—",items:[{id:"source",icon:Z,iconFilled:J,label:"Source",badge:a.source.kind,badgeAppearance:"ghost",dirty:a.dirty.has("source")}]}]:[],{id:"pipe",label:"Pipeline",meta:`${p.length} request${p.length===1?"":"s"}`,items:[{id:"pipeline",icon:Pe,iconFilled:Ae,label:"Generated requests",badge:p.length||null,badgeAppearance:"tint",badgeColor:"brand",dirty:a.dirty.has("pipeline")}]},{id:"headers",label:"Headers",meta:`${a.headers.filter(l=>l.enabled).length} active`,items:[{id:"headers",icon:Re,iconFilled:Ne,label:"HTTP headers",badge:a.headers.filter(l=>l.enabled).length||null,dirty:a.dirty.has("headers")}]}];let m;switch(G){case"operation":m=e.jsx(na,{value:a.operation,onChange:l=>c("operation",l,"operation")});break;case"target":m=e.jsx(Le,{table:a.table,onTableChange:l=>{i(t=>({...t,table:l,recordId:null,fileColumn:null,dirty:new Set(["target","column"])})),D(null),C(void 0),T(null)},recordId:a.recordId,onRecordChange:(l,t)=>{c("recordId",l,"target"),W(t??"")},group:"binary",sub:"Pick the entity + record that holds the file column."});break;case"column":m=e.jsx(oa,{table:a.table,value:a.fileColumn,onChange:l=>c("fileColumn",l,"column")});break;case"method":m=a.operation==="upload"?e.jsx(ia,{value:a.uploadMethod,onChange:l=>c("uploadMethod",l,"method")}):e.jsx(ra,{value:a.downloadMethod,onChange:l=>c("downloadMethod",l,"method")});break;case"source":m=e.jsx(Ee,{source:a.source,setSource:l=>c("source",l,"source"),fileName:a.fileName,setFileName:l=>c("fileName",l,"source"),fileSize:a.fileSize,setFileSize:l=>c("fileSize",l,"source"),mimeType:a.mimeType,setMimeType:l=>c("mimeType",l,"source"),bodyBase64:a.bodyBase64,setBodyBase64:l=>c("bodyBase64",l,"source"),bodyUrl:a.bodyUrl,setBodyUrl:l=>c("bodyUrl",l,"source"),group:"binary"});break;case"pipeline":m=e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:14},children:[e.jsx(da,{state:a,fileCol:j}),e.jsx(Ue,{steps:p,title:`${S} pipeline — ${I}`,sub:p.length>1?"Each request fires sequentially.":void 0,sizeAdvisory:a.operation==="upload"?Ie(a.fileSize,j?.maxSizeInKB?j.maxSizeInKB*1024:void 0,"file"):null})]});break;case"headers":m=e.jsx(De,{items:a.headers,setItems:l=>c("headers",l,"headers"),group:"binary"});break}const pe=He(a.headers,null),me={method:U,built:x,...qe(p,pe),entityLogical:x.entityLogical};return e.jsx(Ge,{sidebar:e.jsx(Je,{type:n,urlPreview:x.relativeNoBase,sections:he,activeNode:G,onSelect:l=>{N(l),R("builder")},recents:ae,onRecentClick:de}),urlBar:e.jsx(Ve,{method:U,url:x.relativeUrl,executeVerb:a.operation==="upload"?"Upload":a.operation==="download"?"Download":"Delete",executeIcon:a.operation==="upload"?_e:a.operation==="download"?Ke:Ye,disabledReason:oe,loading:ee,onExecute:ne,advisories:ce,onAdvisoryFocus:N}),children:e.jsxs(Oe,{tab:F,onTabChange:R,resultCount:O?.ok?p.length:null,children:[F==="builder"&&m,F==="code"&&e.jsx($e,{themeMode:s,inputs:me}),F==="results"&&e.jsx(We,{result:O,mode:"single",table:a.table,writeContext:{operation:"manage-file",table:a.table,recordId:a.recordId,recordName:te||null,fileOperation:a.operation,columnName:a.fileColumn??void 0,fileName:a.fileName||void 0}})]})})}function na({value:s,onChange:n}){const d=Xe(),a=[{id:"upload",label:"Upload",sub:"PATCH or message-based upload pipeline.",tone:"brand"},{id:"download",label:"Download",sub:"GET /$value, ranged GET, message pipeline, or SAS URL.",tone:"brand"},{id:"delete",label:"Delete",sub:"DELETE /<set>(<id>)/<col> · clears the column value.",tone:"danger"}];return e.jsxs("div",{children:[e.jsx(q,{icon:Q,title:"Operation",sub:"What to do with the file column — drives the URL bar method + pipeline shape.",group:"binary"}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:12,maxWidth:960},children:a.map(i=>{const y=s===i.id;return e.jsxs("button",{type:"button",onClick:()=>n(i.id),className:aa(d.inlineCard),style:{textAlign:"left",padding:14,cursor:"pointer",background:y?i.tone==="danger"?o.colorPaletteRedBackground2:o.colorBrandBackground2:o.colorNeutralBackground1,border:`1px solid ${y?i.tone==="danger"?o.colorPaletteRedBorderActive:o.colorBrandStroke1:o.colorNeutralStroke2}`,borderRadius:o.borderRadiusMedium},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx("strong",{style:{fontSize:13},children:i.label}),y&&e.jsx(ea,{style:{marginLeft:"auto",color:i.tone==="danger"?o.colorPaletteRedForeground1:o.colorBrandForeground1},"aria-label":"Selected"})]}),e.jsx(u,{style:{color:o.colorNeutralForeground2,lineHeight:1.4,marginTop:6,display:"block"},children:i.sub})]},i.id)})})]})}function ia({value:s,onChange:n}){return e.jsxs("div",{children:[e.jsx(q,{icon:H,title:"Upload method",sub:"Per file-column-data — three supported approaches.",group:"binary"}),e.jsxs("div",{style:{maxWidth:760,display:"flex",flexDirection:"column",gap:14},children:[e.jsx(g,{label:"Approach",children:e.jsxs(X,{value:s.kind,onChange:(d,a)=>{switch(a.value){case"single-request":n({kind:"single-request"});break;case"chunked-patch":n({kind:"chunked-patch",chunkSize:s.kind==="chunked-patch"?s.chunkSize:2*1024*1024});break;case"dataverse-messages":n({kind:"dataverse-messages",blockSize:s.kind==="dataverse-messages"?s.blockSize:4*1024*1024});break}},children:[e.jsx(b,{value:"single-request",label:e.jsxs("span",{children:[e.jsx("strong",{children:"Single-request PATCH"})," ",e.jsx("code",{style:{fontFamily:o.fontFamilyMonospace,fontSize:11},children:"PATCH /(set)(id)/col"}),e.jsx(u,{style:{display:"block",color:o.colorNeutralForeground3,marginTop:2},children:"Fastest for files up to ~128 MB. Body = raw bytes; x-ms-file-name header. No init/commit ceremony."})]})}),e.jsx(b,{value:"chunked-patch",label:e.jsxs("span",{children:[e.jsx("strong",{children:"Chunked PATCH"})," ",e.jsx("code",{style:{fontFamily:o.fontFamilyMonospace,fontSize:11},children:"x-ms-transfer-mode: chunked"}),e.jsx(u,{style:{display:"block",color:o.colorNeutralForeground3,marginTop:2},children:"Init PATCH returns Location + x-ms-chunk-size. Each chunk = PATCH with Content-Range. Server commits on final chunk."})]})}),e.jsx(b,{value:"dataverse-messages",label:e.jsxs("span",{children:[e.jsx("strong",{children:"Dataverse messages"})," ",e.jsx("code",{style:{fontFamily:o.fontFamilyMonospace,fontSize:11},children:"InitializeFileBlocksUpload / UploadBlock / CommitFileBlocksUpload"}),e.jsx(u,{style:{display:"block",color:o.colorNeutralForeground3,marginTop:2},children:"Three OData actions. Up to 10 GB. Returns FileId on commit. Use for files > 128 MB or when you need parallel block uploads."})]})})]})}),s.kind==="chunked-patch"&&e.jsxs(g,{label:"Chunk size (bytes)",hint:"Defaults to 2 MB. Server may suggest a different size via x-ms-chunk-size on init.",children:[e.jsx(v,{value:s.chunkSize,min:64*1024,max:64*1024*1024,step:1024*1024,onChange:(d,a)=>n({kind:"chunked-patch",chunkSize:Number(a.value??a.displayValue??s.chunkSize)})}),e.jsxs(u,{style:{marginTop:4,display:"block",color:o.colorNeutralForeground3},children:["≈ ",P(s.chunkSize)," per chunk."]})]}),s.kind==="dataverse-messages"&&e.jsxs(g,{label:"Block size (bytes)",hint:"Default = 4 MB. The docs cap each UploadBlock at 4 MB; smaller is fine.",children:[e.jsx(v,{value:s.blockSize,min:64*1024,max:4*1024*1024,step:1024*1024,onChange:(d,a)=>n({kind:"dataverse-messages",blockSize:Number(a.value??a.displayValue??s.blockSize)})}),e.jsxs(u,{style:{marginTop:4,display:"block",color:o.colorNeutralForeground3},children:["≈ ",P(s.blockSize)," per block."]})]})]})]})}function ra({value:s,onChange:n}){return e.jsxs("div",{children:[e.jsx(q,{icon:H,title:"Download method",sub:"Per file-column-data + getfilesasurl — four supported approaches.",group:"binary"}),e.jsxs("div",{style:{maxWidth:760,display:"flex",flexDirection:"column",gap:14},children:[e.jsx(g,{label:"Approach",children:e.jsxs(X,{value:s.kind,onChange:(d,a)=>{switch(a.value){case"single-request":n({kind:"single-request"});break;case"ranged":n({kind:"ranged",rangeStart:0,rangeEnd:4*1024*1024-1});break;case"dataverse-messages":n({kind:"dataverse-messages",blockSize:4*1024*1024});break;case"sas-url":n({kind:"sas-url"});break}},children:[e.jsx(b,{value:"single-request",label:e.jsxs("span",{children:[e.jsx("strong",{children:"GET /$value"}),e.jsx(u,{style:{display:"block",color:o.colorNeutralForeground3,marginTop:2},children:"Stream the entire file in one request. Returns raw bytes. Easy but not great for huge files."})]})}),e.jsx(b,{value:"ranged",label:e.jsxs("span",{children:[e.jsx("strong",{children:"Ranged GET"})," ",e.jsx("code",{style:{fontFamily:o.fontFamilyMonospace,fontSize:11},children:"Range: bytes=A-B"}),e.jsx(u,{style:{display:"block",color:o.colorNeutralForeground3,marginTop:2},children:"Partial content — server returns 206. Use for resume / parallel download."})]})}),e.jsx(b,{value:"dataverse-messages",label:e.jsxs("span",{children:[e.jsx("strong",{children:"Dataverse messages"})," ",e.jsx("code",{style:{fontFamily:o.fontFamilyMonospace,fontSize:11},children:"InitializeFileBlocksDownload + DownloadBlock"}),e.jsx(u,{style:{display:"block",color:o.colorNeutralForeground3,marginTop:2},children:"Block-by-block download. Returns FileName + FileSizeInBytes + FileContinuationToken from init."})]})}),e.jsx(b,{value:"sas-url",label:e.jsxs("span",{children:[e.jsx("strong",{children:"GetFileSasUrl"})," ",e.jsx("code",{style:{fontFamily:o.fontFamilyMonospace,fontSize:11},children:"GET /GetFileSasUrl(…)"}),e.jsx(u,{style:{display:"block",color:o.colorNeutralForeground3,marginTop:2},children:"Returns a 1-hour SAS URL that anyone can use to download directly from Azure Storage. Skips Web API roundtrip on the actual download."})]})})]})}),s.kind==="ranged"&&e.jsxs("div",{style:{display:"flex",gap:10,maxWidth:480},children:[e.jsx(g,{label:"Range start (bytes)",children:e.jsx(v,{value:s.rangeStart,min:0,onChange:(d,a)=>n({kind:"ranged",rangeStart:Number(a.value??a.displayValue??0),rangeEnd:s.rangeEnd})})}),e.jsx(g,{label:"Range end (bytes)",children:e.jsx(v,{value:s.rangeEnd,min:0,onChange:(d,a)=>n({kind:"ranged",rangeStart:s.rangeStart,rangeEnd:Number(a.value??a.displayValue??0)})})})]}),s.kind==="dataverse-messages"&&e.jsx(g,{label:"Block size (bytes)",children:e.jsx(v,{value:s.blockSize,min:64*1024,max:4*1024*1024,step:1024*1024,onChange:(d,a)=>n({kind:"dataverse-messages",blockSize:Number(a.value??a.displayValue??s.blockSize)})})}),s.kind==="sas-url"&&e.jsx(z,{layout:"multiline",intent:"info",children:e.jsxs(M,{children:[e.jsx(A,{children:"SAS URL caveats"}),e.jsxs("ul",{style:{margin:"4px 0 0",paddingLeft:18,lineHeight:1.6},children:[e.jsx("li",{children:"Only works for image columns that support full-size images."}),e.jsx("li",{children:"SAS URL valid for 1 hour from generation."}),e.jsx("li",{children:"Does NOT work for environments using BYOK encryption — migrate to CMK first."}),e.jsx("li",{children:"Caller must have access to the record; the resulting URL grants anonymous access for 1 hour."})]})]})})]})]})}function da({state:s,fileCol:n}){const d=(n?.maxSizeInKB??32768)*1024;if(s.operation==="upload"){const a=s.fileSize>4194304,i=s.fileSize>128*1024*1024;return e.jsx(z,{layout:"multiline",intent:i?"warning":"info",children:e.jsxs(M,{children:[e.jsx(A,{children:"Upload"}),i?e.jsxs(e.Fragment,{children:["File is over ",e.jsx("strong",{children:"128 MB"})," — single-request PATCH won't work. Use the Dataverse messages path which supports up to 10 GB."]}):a?e.jsxs(e.Fragment,{children:["File is over ",e.jsx("strong",{children:"4 MB"})," — chunked PATCH (or Dataverse messages) is recommended; single-request still works up to 128 MB."]}):e.jsxs(e.Fragment,{children:["Small enough for single-request PATCH. Column max: ",P(d),"."]})]})})}return s.operation==="download"?e.jsx(z,{layout:"multiline",intent:"info",children:e.jsxs(M,{children:[e.jsx(A,{children:"Download"}),"Retrieving a file column returns the ",e.jsx("strong",{children:"file id"})," (not bytes) — use the operations below to fetch actual content. GET /$value is the simplest; SAS URL skips the Web API roundtrip when an anonymous browser-side download is fine."]})}):e.jsx(z,{layout:"multiline",intent:"warning",children:e.jsxs(M,{children:[e.jsx(A,{children:"Delete"}),"Clears the file column value + the ",e.jsx("code",{children:"_name"})," companion. The underlying file is removed by Dataverse. Alternative equivalent paths: PATCH the column to null, or call the"," ",e.jsx("code",{children:"DeleteFile"})," action with the column's current FileId."]})})}export{pa as ManageFileMode};
@@ -1 +0,0 @@
1
- import{c as fe,b7 as xe,cs as _,r as s,u as je,ct as Se,cu as ve,f as we,e as Fe,cv as Ie,bb as Te,i as D,k as Be,aj as ze,cd as Ce,t as e,ce as Y,cf as Ne,T as ke,l as Pe,cw as E,cx as w,aL as Z,aM as Me,bU as Ae,ci as De,L as Re,q as Ue,H as Ee,ck as G,cl as K,cm as Q,w as Le,y as He,cn as $e,z as Oe,A as qe,G as We,R as _e,U as Ge,co as Ke,cp as Ve,cq as Je,S as Ye,I as Ze,bn as Qe,B as N,D as k,J as R,b6 as X,Y as i,bm as U,Z as F,b0 as ee,a9 as ae,a5 as Xe,aa as ea,ab as V,aU as aa,bo as oa}from"./index-D0g0tm7R.js";import{I as la}from"./BinaryColumnPickers-mrnLqk3Z.js";function J(l){if(!l)return 0;const n=l.endsWith("==")?2:l.endsWith("=")?1:0;return Math.max(0,Math.floor(l.length*3/4)-n)}const ia=()=>({table:"",recordId:null,imageColumn:"",operation:"upload",downloadSize:"thumbnail",source:{kind:"file"},fileName:"",bodyBase64:"",bodyUrl:"",mimeType:"image/png",headers:Ze(),dirty:new Set});function ma({themeMode:l}){const n=fe("manage-image"),u=xe("manage-image",_,ia),[a,t]=s.useState(u.state),{table:p}=je(a.table||null),[I,x]=s.useState("preview"),[h,j]=s.useState("builder"),[L,P]=s.useState(null),[oe,H]=s.useState(!1),[le,ie]=s.useState([]),S=s.useMemo(()=>Se(a),[a,p]),b=s.useMemo(()=>ve(a),[a,p]),v=we(a.table),d=s.useMemo(()=>(v?.columns??[]).find(o=>o.attributeType==="Image"&&o.logicalName===a.imageColumn),[v,a.imageColumn]),ne=o=>t(r=>{const g=new Set(r.dirty);return g.add(o),{...r,dirty:g}}),c=(o,r,g)=>{t(A=>({...A,[o]:r})),g&&ne(g)},M=b[0]?.method??"PATCH",re=v?a.recordId?a.imageColumn?a.operation==="upload"&&!a.bodyBase64&&a.source.kind==="file"?"Pick an image file.":a.operation==="download"&&a.downloadSize==="full"&&!d?.canStoreFullImage?`${a.imageColumn} doesn't store full-size images (canStoreFullImage = false).`:a.headers.some(o=>o.enabled&&!o.name)?"Fix empty header name.":null:"Pick an image column.":"Pick a source record.":"Pick a target table first.",[te,$]=s.useState(""),se=async()=>{H(!0);const o=await aa.manageImage(a);P(o),H(!1),j("results"),ie(r=>[{id:`r-${Date.now()}`,snapshot:y,modeId:"manage-image",url:S.relativeUrl,method:M,ts:Date.now(),status:o.status,ms:o.ms,rowCount:o.ok?1:0},...r].slice(0,8)),t(r=>({...r,dirty:new Set}))},{entities:O}=Fe(),[T,B]=s.useState(u.lastSavedId),[z,C]=s.useState(u.lastSavedHash),y=s.useMemo(()=>Ie(a),[a]);Te("manage-image",y,T,z);const de=s.useMemo(()=>D(y),[y]),q=z===null?!0:de!==z,ce=o=>{B(o.id),C(D(o.state))},W=o=>{if(o.modeId!=="manage-image")return;const r=o.state;if(O.length>0&&r.table&&!O.some(g=>g.logicalName===r.table)){Qe(`Can't load "${o.name}": entity \`${r.table}\` isn't available in this environment.`);return}t(_(r)),B(o.id),C(D(r)),P(null),$(""),x("preview")},ue=o=>{const r=oa(o,"manage-image");if(!r)return;const g=T,A=z;W(r),B(g),C(A)};Be(s.useMemo(()=>a.table?{state:y,modeId:"manage-image",dirty:q,lastSavedId:T,onSaved:ce,onLoadSaved:W}:null,[y,q,T,a.table]));const me=s.useMemo(()=>ze()?[Ce.warn("binary-host-unsupported","header","Image operations run externally",e.jsxs("span",{children:["PPTB's ",e.jsx("code",{children:"dataverseAPI"})," doesn't expose image column endpoints. Build the request here, then copy a snippet from the ",e.jsx("strong",{children:"Code"})," tab (fetch / curl / C# / PowerShell) and run it from there. Execute will return ",e.jsx("code",{children:"501 Not Implemented"}),"."]}),"preview","https://learn.microsoft.com/en-us/power-apps/developer/data-platform/image-column-data")]:[],[]),f=a.operation==="upload"?"UPLOAD":a.operation==="download"?"DOWNLOAD":"DELETE",ge=a.operation==="delete"?"danger":"brand",pe="?",be=[{id:"operation",label:"Operation",meta:f.toLowerCase(),items:[{id:"operation",icon:Ne,iconFilled:Y,label:f.charAt(0)+f.slice(1).toLowerCase(),badge:f,badgeAppearance:"tint",badgeColor:ge,dirty:a.dirty.has("operation")}]},{id:"target",label:"Target",meta:v?.displayName??"?",items:[{id:"target",icon:Pe,iconFilled:ke,label:a.recordId?`${v?.displayName??""} (selected)`:"Pick a record",badge:a.recordId?"✓":null,badgeAppearance:"ghost",dirty:a.dirty.has("target")},{id:"column",icon:w,iconFilled:E,label:a.imageColumn||"Pick an image column",code:!!a.imageColumn,badge:d?.isPrimaryImage?"primary":d?.canStoreFullImage?"full":"thumb",badgeAppearance:"tint",badgeColor:d?.canStoreFullImage?"success":"brand",dirty:a.dirty.has("column")}]},...d?[{id:"deriv",label:"Derivatives",meta:"3 companion columns",items:[{id:"d1",icon:w,label:`${d.logicalName}id`,code:!0,badge:"guid",badgeAppearance:"ghost"},{id:"d2",icon:w,label:`${d.logicalName}_Timestamp`,code:!0,badge:"bigint",badgeAppearance:"ghost"},{id:"d3",icon:w,label:`${d.logicalName}_URL`,code:!0,badge:"url",badgeAppearance:"ghost"}]}]:[],...a.operation==="upload"?[{id:"payload",label:"Payload",meta:a.fileName||"—",items:[{id:"source",icon:w,iconFilled:E,label:"Source",badge:a.source.kind,badgeAppearance:"ghost",dirty:a.dirty.has("source")}]}]:[],...a.operation==="download"?[{id:"options",label:"Options",meta:a.downloadSize,items:[{id:"options",icon:Me,iconFilled:Z,label:"Download size",badge:a.downloadSize,badgeAppearance:"tint",badgeColor:"brand",dirty:a.dirty.has("options")}]}]:[],{id:"pipe",label:"Pipeline",meta:`${b.length} request${b.length===1?"":"s"}`,items:[{id:"pipeline",icon:De,iconFilled:Ae,label:"Generated requests",badge:b.length||null,badgeAppearance:"tint",badgeColor:"brand",dirty:a.dirty.has("pipeline")}]},{id:"headers",label:"Headers",meta:`${a.headers.filter(o=>o.enabled).length} active`,items:[{id:"headers",icon:Ue,iconFilled:Re,label:"HTTP headers",badge:a.headers.filter(o=>o.enabled).length||null,dirty:a.dirty.has("headers")}]}];let m;switch(I){case"operation":m=e.jsx(ra,{value:a.operation,onChange:o=>c("operation",o,"operation")});break;case"target":m=e.jsx(Le,{table:a.table,onTableChange:o=>{t(r=>({...r,table:o,recordId:null,imageColumn:null,dirty:new Set(["target","column"])})),P(null),B(void 0),C(null)},recordId:a.recordId,onRecordChange:(o,r)=>{c("recordId",o,"target"),$(r??"")},group:"binary",sub:"Pick the entity + record that holds the image column."});break;case"column":m=e.jsx(la,{table:a.table,value:a.imageColumn,onChange:o=>c("imageColumn",o,"column")});break;case"source":m=e.jsx(Q,{source:a.source,setSource:o=>c("source",o,"source"),fileName:a.fileName,setFileName:o=>c("fileName",o,"source"),fileSize:0,setFileSize:()=>{},mimeType:a.mimeType,setMimeType:o=>c("mimeType",o,"source"),bodyBase64:a.bodyBase64,setBodyBase64:o=>c("bodyBase64",o,"source"),bodyUrl:a.bodyUrl,setBodyUrl:o=>c("bodyUrl",o,"source"),accept:"image/png,image/jpeg,image/gif,image/bmp,image/tiff",group:"binary"});break;case"options":m=e.jsx(ta,{downloadSize:a.downloadSize,setDownloadSize:o=>c("downloadSize",o,"options"),canStoreFullImage:d?.canStoreFullImage??!1});break;case"preview":m=e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:14},children:[e.jsx(sa,{state:a,imageCol:d}),e.jsx(na,{state:a,imageCol:d,initials:pe,setSource:o=>c("source",o,"source"),setBodyBase64:o=>c("bodyBase64",o,"source"),setFileName:o=>c("fileName",o,"source"),setMimeType:o=>c("mimeType",o,"source")}),e.jsx(G,{steps:b,title:`${f} pipeline`,sizeAdvisory:a.operation==="upload"?K(J(a.bodyBase64),d?.maxSizeInKB?d.maxSizeInKB*1024:void 0,"image"):null})]});break;case"pipeline":m=e.jsx(G,{steps:b,title:`${f} pipeline`,sizeAdvisory:a.operation==="upload"?K(J(a.bodyBase64),d?.maxSizeInKB?d.maxSizeInKB*1024:void 0,"image"):null});break;case"headers":m=e.jsx(Ee,{items:a.headers,setItems:o=>c("headers",o,"headers"),group:"binary"});break}const he=He(a.headers,null),ye={method:M,built:S,...$e(b,he),entityLogical:S.entityLogical};return e.jsx(Oe,{sidebar:e.jsx(Ye,{type:n,urlPreview:S.relativeNoBase,sections:be,activeNode:I,onSelect:o=>{x(o),j("builder")},recents:le,onRecentClick:ue}),urlBar:e.jsx(Ge,{method:M,url:S.relativeUrl,executeVerb:a.operation==="upload"?"Upload":a.operation==="download"?"Download":"Delete",executeIcon:a.operation==="upload"?Ke:a.operation==="download"?Ve:Je,disabledReason:re,loading:oe,onExecute:se,advisories:me,onAdvisoryFocus:x}),children:e.jsxs(qe,{tab:h,onTabChange:j,resultCount:L?.ok?1:null,children:[h==="builder"&&m,h==="code"&&e.jsx(We,{themeMode:l,inputs:ye}),h==="results"&&e.jsx(_e,{result:L,mode:"single",table:a.table,writeContext:{operation:"manage-image",table:a.table,recordId:a.recordId,recordName:te||null,fileOperation:a.operation,columnName:a.imageColumn??void 0,fileName:a.fileName||void 0}})]})})}function na({state:l,imageCol:n,initials:u,setSource:a,setBodyBase64:t,setFileName:p,setMimeType:I}){const x=X(),h=n?.isPrimaryImage&&!n?.canStoreFullImage;return e.jsxs("div",{className:ee(x.inlineCard),style:{padding:14,maxWidth:880},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:12},children:[e.jsx(E,{style:{color:i.colorBrandForeground1}}),e.jsx("strong",{style:{fontSize:13},children:"Preview · Source"}),e.jsx(U,{appearance:"tint",color:"brand",children:n?.isPrimaryImage?"primary image":"custom image column"}),h&&e.jsx(U,{appearance:"ghost",children:"144×144 only"}),n?.canStoreFullImage&&e.jsx(U,{appearance:"tint",color:"success",children:"full-size enabled"})]}),e.jsxs("div",{style:{display:"flex",gap:20,alignItems:"flex-start"},children:[e.jsxs("div",{children:[e.jsxs(F,{style:{color:i.colorNeutralForeground3,display:"block",marginBottom:4},children:[l.operation==="upload"?"Preview":l.downloadSize==="full"?"Full-size":"Thumbnail"," ","· 144×144"]}),e.jsx("div",{style:{width:144,height:144,background:l.bodyBase64?`url(data:${l.mimeType};base64,${l.bodyBase64}) center/cover`:i.colorNeutralBackground3,borderRadius:i.borderRadiusMedium,display:"flex",alignItems:"center",justifyContent:"center",color:l.bodyBase64?"#fff":i.colorNeutralForeground3,fontWeight:700,fontSize:40,border:`1px solid ${i.colorNeutralStroke2}`},children:!l.bodyBase64&&u}),l.bodyBase64&&e.jsxs(F,{style:{color:i.colorNeutralForeground3,display:"block",marginTop:4},children:[l.fileName," · ",l.mimeType]})]}),l.operation==="upload"&&e.jsx("div",{style:{flex:1},children:e.jsx(Q,{source:l.source,setSource:a,fileName:l.fileName,setFileName:p,fileSize:0,setFileSize:()=>{},mimeType:l.mimeType,setMimeType:j=>I(j),bodyBase64:l.bodyBase64,setBodyBase64:t,bodyUrl:l.bodyUrl,setBodyUrl:()=>{},accept:"image/png,image/jpeg,image/gif,image/bmp,image/tiff",group:"binary"})}),l.operation!=="upload"&&e.jsxs("div",{style:{flex:1,fontSize:11,color:i.colorNeutralForeground3,lineHeight:1.6},children:[l.operation==="download"&&e.jsxs(e.Fragment,{children:[e.jsx("strong",{style:{color:i.colorNeutralForeground2},children:"Download:"})," server returns the"," ",l.downloadSize==="full"?"original full-size":"auto-cropped 144×144 thumbnail"," ","as raw bytes. The Content-Type matches the stored image's MIME type (one of image/png · image/jpeg · image/gif · image/bmp · image/tiff)."]}),l.operation==="delete"&&e.jsxs(e.Fragment,{children:[e.jsx("strong",{style:{color:i.colorNeutralForeground2},children:"Delete:"})," clears the image data + companion columns (",e.jsxs("code",{style:{fontFamily:i.fontFamilyMonospace},children:[n?.logicalName,"id"]}),", ",e.jsx("code",{style:{fontFamily:i.fontFamilyMonospace},children:"_Timestamp"}),","," ",e.jsx("code",{style:{fontFamily:i.fontFamilyMonospace},children:"_URL"}),"). Equivalent forms: PATCH set null, PUT /col with body ",e.jsx("code",{children:'{"value":null}'}),", or DELETE /col (shown)."]})]})]})]})}function ra({value:l,onChange:n}){const u=X(),a=[{id:"upload",label:"Upload",sub:"PATCH /<set>(<id>) with body {col: <base64>}.",tone:"brand"},{id:"download",label:"Download",sub:"GET /<set>(<id>)/<col>/$value (?size=full for full).",tone:"brand"},{id:"delete",label:"Delete",sub:"DELETE / PATCH null / PUT /col body=null — three equivalents.",tone:"danger"}];return e.jsxs("div",{children:[e.jsx(ae,{icon:Y,title:"Operation",group:"binary"}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:12,maxWidth:960},children:a.map(t=>{const p=l===t.id;return e.jsxs("button",{type:"button",onClick:()=>n(t.id),className:ee(u.inlineCard),style:{textAlign:"left",padding:14,cursor:"pointer",background:p?t.tone==="danger"?i.colorPaletteRedBackground2:i.colorBrandBackground2:i.colorNeutralBackground1,border:`1px solid ${p?t.tone==="danger"?i.colorPaletteRedBorderActive:i.colorBrandStroke1:i.colorNeutralStroke2}`,borderRadius:i.borderRadiusMedium},children:[e.jsx("strong",{style:{fontSize:13,display:"block"},children:t.label}),e.jsx(F,{style:{color:i.colorNeutralForeground2,lineHeight:1.4,marginTop:6,display:"block"},children:t.sub})]},t.id)})})]})}function ta({downloadSize:l,setDownloadSize:n,canStoreFullImage:u}){return e.jsxs("div",{children:[e.jsx(ae,{icon:Z,title:"Download options",sub:"Image columns can store both thumbnail + full-size when CanStoreFullImage is true.",group:"binary"}),e.jsx("div",{style:{maxWidth:720},children:e.jsx(Xe,{label:"Size",children:e.jsxs(ea,{value:l,onChange:(a,t)=>n(t.value),children:[e.jsx(V,{value:"thumbnail",label:e.jsxs("span",{children:[e.jsx("strong",{children:"Thumbnail (144×144)"}),e.jsx(F,{style:{display:"block",color:i.colorNeutralForeground3,marginTop:2},children:"Default for all image columns. Center-cropped square."})]})}),e.jsx(V,{value:"full",disabled:!u,label:e.jsxs("span",{children:[e.jsx("strong",{children:"Full-size"})," ",e.jsx("code",{style:{fontFamily:i.fontFamilyMonospace,fontSize:11},children:"?size=full"}),e.jsxs(F,{style:{display:"block",color:i.colorNeutralForeground3,marginTop:2},children:["Only available when the column has CanStoreFullImage = true. Server returns 204 if not configured.",!u&&e.jsxs(e.Fragment,{children:[" ","·"," ",e.jsx("span",{style:{color:i.colorPaletteRedForeground1},children:"this column doesn't support full-size"})]})]})]})})]})})})]})}function sa({state:l,imageCol:n}){return n?l.operation==="upload"?e.jsx(N,{layout:"multiline",intent:"info",children:e.jsxs(k,{children:[e.jsx(R,{children:n.isPrimaryImage?"Primary image — thumbnail only":"Custom image column"}),n.isPrimaryImage?e.jsxs(e.Fragment,{children:[e.jsx("code",{children:n.logicalName})," is the table's primary image (auto-cropped 144×144). Full-size data is discarded. To store full-resolution images, create a custom image column with ",e.jsx("code",{children:"CanStoreFullImage = true"}),"."]}):n.canStoreFullImage?e.jsxs(e.Fragment,{children:[e.jsx("code",{children:n.logicalName})," supports full-size (max"," ",((n.maxSizeInKB??10240)/1024).toFixed(0)," MB). Upload via PATCH; for files > 4 MB use the file-column chunked upload path on the underlying file storage."]}):e.jsxs(e.Fragment,{children:[e.jsx("code",{children:n.logicalName})," stores thumbnail only (CanStoreFullImage = false). Full-size won't be retained."]})]})}):l.operation==="download"?e.jsx(N,{layout:"multiline",intent:"info",children:e.jsxs(k,{children:[e.jsx(R,{children:"Download"}),"GET /$value returns the"," ",l.downloadSize==="full"?"full-size original":"144×144 thumbnail",". Image companion columns (",e.jsxs("code",{children:[n.logicalName,"_URL"]})," etc.) let you compose a download URL for browser-side use."]})}):e.jsx(N,{layout:"multiline",intent:"warning",children:e.jsxs(k,{children:[e.jsx(R,{children:"Delete"}),"Clears ",e.jsx("code",{children:n.logicalName})," + its companion columns (id / _Timestamp / _URL). Three equivalent paths per docs: DELETE /col (shown), PATCH set null, or PUT /col with body"," ",e.jsx("code",{children:'{"value":null}'}),"."]})}):e.jsx(N,{layout:"multiline",intent:"info",children:e.jsx(k,{children:"Pick an image column on the left to see operation-specific guidance."})})}export{ma as ManageImageMode};
@@ -1 +0,0 @@
1
- import{f as M,r as b,bp as Xe,bq as me,ah as ce,br as Ye,t as e,B as E,D as $,a9 as _,bs as J,a6 as ae,bt as Ze,aE as Te,O as et,bu as tt,bv as rt,bm as Q,Y as n,b6 as we,Z as P,aa as at,ab as te,ax as Fe,b0 as st,bw as it,bx as se,bk as ie,b4 as ne,by as nt,Q as oe,ac as ot,ad as lt,bz as dt,bA as ct,c as ut,b7 as pt,bB as ye,u as gt,e as Ne,bC as bt,bD as ht,bE as ft,bF as mt,ak as yt,al as xt,am as jt,an as St,bG as vt,bb as kt,i as re,k as Tt,bH as De,bI as wt,bJ as xe,aL as Ie,aM as Ft,L as Nt,q as Dt,au as le,av as It,aw as Ct,H as Mt,y as je,z as Pt,A as Lt,G as Rt,R as Bt,U as At,S as Ot,I as zt,aG as Et,bK as $t,bn as Vt,J as Ce,a5 as Me,b5 as Ut,T as Ht,aU as Gt,bo as _t,bL as Wt}from"./index-D0g0tm7R.js";const qt=new Set(["createdon","modifiedon","createdby","modifiedby","createdonbehalfby","modifiedonbehalfby","versionnumber","importsequencenumber","overriddencreatedon","utcconversiontimezonecode","timezoneruleversionnumber","statecode","statuscode"]),Kt=s=>qt.has(s.logicalName)||s.attributeType==="File"||s.attributeType==="Image"||s.attributeType==="Uniqueidentifier"&&s.isPrimaryKey===!0;function Jt(s){const{table:a,target:i,sub:t,fieldChoices:d,customValues:c,setFieldChoice:p,setCustomValue:o}=s,u=M(a),[h,S]=b.useState(""),[k,D]=b.useState(!0),T=b.useMemo(()=>!u||!i||!t?[]:u.columns.filter(x=>!Kt(x)&&x.isValidForUpdate!==!1&&!Xe(x)).map(x=>{const v=me(i,x),w=me(t,x),V=v==null||v==="",I=w==null||w==="";let N;return V&&I?N="both-empty":V&&!I?N="auto-fill":!V&&I?N="sub-empty":ce(x)?N=Ye(v,w)?"same":"differs":N=String(v)===String(w)?"same":"differs",{col:x,targetVal:v,subVal:w,state:N}}),[u,i,t]),L=b.useMemo(()=>{let m=T;if(k&&(m=m.filter(y=>y.state==="differs"||y.state==="auto-fill")),h){const y=h.toLowerCase();m=m.filter(x=>x.col.displayName.toLowerCase().includes(y)||x.col.logicalName.toLowerCase().includes(y))}return m},[T,k,h]),F=b.useMemo(()=>{const m=Object.values(d).filter(v=>v!=="target").length,y=T.filter(v=>v.state==="differs").length,x=T.filter(v=>v.state==="auto-fill").length;return{overrides:m,differs:y,autoFill:x}},[d,T]);return u?!i||!t?e.jsxs("div",{children:[e.jsx(_,{icon:J,title:"Field comparison",sub:"Pick both Target and Subordinate to see a side-by-side diff.",group:"write"}),e.jsx(E,{layout:"multiline",intent:"info",style:{maxWidth:720},children:e.jsx($,{children:!i&&!t?"Pick a Target (the record that survives) and a Subordinate (the duplicate to merge away) to start.":i?"Pick a Subordinate record on the left rail.":"Pick a Target record on the left rail."})})]}):e.jsxs("div",{children:[e.jsxs(_,{icon:J,title:"Field comparison",sub:e.jsxs("span",{children:["For each differing field, pick what the merged row should carry — the Target's value, the Subordinate's value, or your own."," ",e.jsx("strong",{children:"Empty Target fields get auto-filled"})," from the Subordinate by the server."]}),group:"write",children:[e.jsx(ae,{contentBefore:e.jsx(Ze,{}),"aria-label":"Filter fields",placeholder:"Filter fields…",value:h,onChange:(m,y)=>S(y.value),size:"small",style:{width:220}}),e.jsx(Te,{content:k?"Showing only differing / auto-fill rows":"Showing every column",relationship:"description",children:e.jsx(et,{size:"small",appearance:k?"primary":"outline",icon:k?e.jsx(tt,{}):e.jsx(rt,{}),onClick:()=>D(m=>!m),children:k?"Diff only":"All fields"})}),e.jsxs(Q,{appearance:"tint",color:F.overrides>0?"brand":"subtle",children:[F.overrides," override",F.overrides===1?"":"s"]}),e.jsxs(Q,{appearance:"ghost",children:[F.differs," differ · ",F.autoFill," auto-fill"]})]}),e.jsx("div",{style:{maxWidth:1200,overflowX:"auto"},children:e.jsxs("table",{style:{width:"100%",borderCollapse:"separate",borderSpacing:0},children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(q,{style:{width:"20%"},children:"Field"}),e.jsx(q,{tone:"target",children:"Target (survives)"}),e.jsx(q,{tone:"sub",children:"Subordinate"}),e.jsx(q,{style:{width:"34%"},children:"Final value"})]})}),e.jsxs("tbody",{children:[L.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:4,style:{padding:"24px 8px",textAlign:"center",color:n.colorNeutralForeground3,fontStyle:"italic"},children:k?'No differing fields. Toggle "All fields" to see the full row.':"No fields match the search."})}),L.map(m=>e.jsx(Qt,{tbl:u,row:m,choice:d[m.col.logicalName]??"target",customValue:c[m.col.logicalName],onChoice:y=>p(m.col.logicalName,y),onCustom:y=>o(m.col.logicalName,y)},m.col.logicalName))]})]})})]}):e.jsx(E,{layout:"multiline",intent:"error",children:e.jsxs($,{children:["Unknown table ",e.jsx("code",{children:a}),"."]})})}function Qt({tbl:s,row:a,choice:i,customValue:t,onChoice:d,onCustom:c}){const p=we(),{col:o,targetVal:u,subVal:h,state:S}=a,k=S==="differs",D=S==="auto-fill",T=!(h==null||h==="");return e.jsxs("tr",{children:[e.jsx(K,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:2},children:[e.jsx("span",{style:{fontWeight:500,color:n.colorNeutralForeground1,fontSize:12},children:o.displayName}),e.jsxs(P,{style:{color:n.colorNeutralForeground3,fontFamily:n.fontFamilyMonospace,fontSize:10},children:[o.logicalName," ·"," ",e.jsx("span",{style:{color:n.colorBrandForeground2},children:o.attributeType})]}),D&&e.jsx(Te,{content:"Target is empty — server will auto-fill from Subordinate. No override needed.",relationship:"description",children:e.jsx(Q,{appearance:"tint",color:"success",size:"extra-small",style:{alignSelf:"flex-start"},children:"auto-fill"})})]})}),e.jsx(K,{tone:"target",children:e.jsx(Se,{col:o,value:u,tbl:s})}),e.jsx(K,{tone:"sub",children:e.jsx(Se,{col:o,value:h,tbl:s})}),e.jsx(K,{children:e.jsxs("div",{className:st(p.inlineCard),style:{padding:"6px 8px"},children:[e.jsxs(at,{layout:"horizontal",value:i,onChange:(L,F)=>d(F.value),children:[e.jsx(te,{value:"target",label:e.jsxs("span",{style:{fontSize:11},children:["Target",!k&&!D&&e.jsx("span",{style:{color:n.colorNeutralForeground3},children:" · default"})]})}),e.jsx(te,{value:"subordinate",disabled:!T,label:e.jsxs("span",{style:{fontSize:11},children:["Subordinate",!T&&e.jsx("span",{style:{color:n.colorNeutralForeground3},children:" · empty"})]})}),e.jsx(te,{value:"custom",label:e.jsx("span",{style:{fontSize:11},children:"Custom"})})]}),i==="custom"&&e.jsx("div",{style:{marginTop:6},children:e.jsx(Xt,{col:o,value:t,onChange:c,fallback:typeof u=="object"?"":String(u??""),parentTable:s.logicalName})}),i==="subordinate"&&e.jsxs("div",{style:{marginTop:6,display:"flex",alignItems:"center",gap:6},children:[e.jsx(Fe,{style:{width:14,height:14,color:n.colorBrandForeground1}}),e.jsxs(P,{style:{color:n.colorBrandForeground2,fontWeight:500},children:["Will overwrite Target with: ",e.jsx("strong",{children:Pe(o,h)})]})]})]})})]})}function q({children:s,style:a,tone:i}){const t=i==="target"?{background:"rgba(31,127,56,.08)",color:n.colorPaletteGreenForeground1}:i==="sub"?{background:"rgba(242,176,80,.08)",color:n.colorPaletteDarkOrangeForeground1}:{};return e.jsx("th",{style:{textAlign:"left",padding:"8px 10px",fontSize:11,fontWeight:600,color:n.colorNeutralForeground2,borderBottom:`2px solid ${n.colorNeutralStroke2}`,whiteSpace:"nowrap",...t,...a},children:s})}function K({children:s,tone:a}){const i=a==="target"?{background:"rgba(31,127,56,.025)",borderLeft:`2px solid ${n.colorPaletteGreenBorderActive}`}:a==="sub"?{background:"rgba(242,176,80,.025)",borderLeft:`2px solid ${n.colorPaletteDarkOrangeBorderActive}`}:{};return e.jsx("td",{style:{padding:"8px 10px",verticalAlign:"top",borderBottom:`1px solid ${n.colorNeutralStroke3}`,fontSize:12,...i},children:s})}function Se({col:s,value:a,tbl:i}){if(a==null||a==="")return e.jsx("span",{style:{color:n.colorNeutralForeground3,fontStyle:"italic",fontSize:11},children:"(empty)"});const t=Pe(s,a);return e.jsx("span",{style:{fontFamily:s.attributeType==="Uniqueidentifier"||ce(s)&&!a.name?n.fontFamilyMonospace:n.fontFamilyBase,fontSize:12,color:n.colorNeutralForeground1,wordBreak:"break-word"},children:t})}function Pe(s,a){if(a==null||a==="")return"(empty)";if(s.attributeType==="Boolean")return a===!0||a==="1"||a===1?s.trueOption.label:s.falseOption.label;if(ce(s)&&typeof a=="object"&&"id"in a)return dt(a);const i=se(s);if(i){const t=Number(a);if(Number.isFinite(t)){const d=i.find(c=>c.value===t);if(d)return`${d.label} · ${t}`}if(s.attributeType==="MultiSelectPicklist"&&typeof a=="string")return a.split(",").map(d=>{const c=i.find(p=>String(p.value)===d);return c?c.label:d}).join(", ")}if(s.attributeType==="Money"){const t=Number(a);if(Number.isFinite(t))return t.toLocaleString(void 0,{style:"currency",currency:"USD"})}return s.attributeType==="DateTime"&&typeof a=="string"?ct(a,s):String(a)}function Xt({col:s,value:a,onChange:i,fallback:t,parentTable:d}){switch(it(d,s.logicalName),s.attributeType){case"Memo":return e.jsx(lt,{"aria-label":`${s.displayName} (custom value)`,rows:2,size:"small",value:a??t,onChange:(c,p)=>i(p.value),style:{fontFamily:n.fontFamilyMonospace,fontSize:12}});case"Integer":case"BigInt":case"Decimal":case"Double":case"Money":return e.jsx(ot,{"aria-label":`${s.displayName} (custom value)`,size:"small",value:Number(a??0),onChange:(c,p)=>{const o=p.value??Number(p.displayValue??0);Number.isFinite(o)&&i(o)}});case"Boolean":return e.jsx(oe,{checked:a===!0,onChange:(c,p)=>i(p.checked),label:a===!0?s.trueOption.label:s.falseOption.label});case"Picklist":case"State":case"Status":case"EntityName":{const c=se(s)??[],p=c.find(o=>o.value===a);return e.jsx(ie,{"aria-label":`${s.displayName} (custom value)`,size:"small",value:p?.label??(a!=null?String(a):""),selectedOptions:a!=null?[String(a)]:[],onOptionSelect:(o,u)=>u.optionValue&&i(Number(u.optionValue)),placeholder:"Pick a value…",children:c.map(o=>e.jsx(ne,{value:String(o.value),text:o.label,children:o.label},o.value))})}case"Lookup":case"Customer":case"Owner":return e.jsx(nt,{col:s,value:a,onChange:i});case"MultiSelectPicklist":{const c=se(s)??[],p=Array.isArray(a)?a:typeof a=="string"&&a?a.split(",").map(o=>Number(o.trim())).filter(o=>Number.isFinite(o)):[];return e.jsx(ie,{"aria-label":`${s.displayName} (custom value)`,size:"small",multiselect:!0,value:p.map(o=>c.find(u=>u.value===o)?.label??String(o)).join(", "),selectedOptions:p.map(String),onOptionSelect:(o,u)=>{const h=(u.selectedOptions??[]).map(S=>Number(S)).filter(S=>Number.isFinite(S));i(h)},placeholder:"Pick one or more…",children:c.map(o=>e.jsx(ne,{value:String(o.value),text:o.label,children:o.label},o.value))})}case"DateTime":return e.jsx(ae,{"aria-label":`${s.displayName} (custom value)`,size:"small",type:s.format==="DateOnly"?"date":"datetime-local",value:typeof a=="string"?a.slice(0,16):"",onChange:(c,p)=>i(p.value),style:{fontFamily:n.fontFamilyMonospace,fontSize:12}});default:return e.jsx(ae,{"aria-label":`${s.displayName} (custom value)`,size:"small",value:a??t,onChange:(c,p)=>i(p.value)})}}const de=["account","contact","lead","incident"],Le="account, contact, lead, and incident",Yt=s=>de.includes(s),Zt=()=>({table:"",targetId:null,subordinateId:null,fieldChoices:{},customValues:{},performParentingChecks:!0,suppressDuplicateDetection:!1,bypass:Et(),headers:zt(),dirty:new Set,targetSnapshot:null,subordinateSnapshot:null}),z=$t;function nr({themeMode:s}){const a=ut("merge"),i=pt("merge",ye,Zt),[t,d]=b.useState(i.state),{table:c}=gt(t.table||null),{entities:p}=Ne(),[o,u]=b.useState("target"),[h,S]=b.useState("builder"),[k,D]=b.useState(null),[T,L]=b.useState(!1),[F,m]=b.useState([]),[y,x]=b.useState(i.lastSavedId),[v,w]=b.useState(i.lastSavedHash),[V,I]=b.useState(!1),[N,X]=b.useState(!1),j=M(t.table),Y=b.useMemo(()=>{const r=t.subordinateSnapshot;if(!j||!r)return[];const g=new Set;for(const[l,f]of Object.entries(t.fieldChoices)){if(f!=="subordinate")continue;const A=j.columns.find(Qe=>Qe.logicalName===l),O=A&&bt(r,A)?.targetEntity;O&&g.add(O)}return[...g].sort()},[j,t.subordinateSnapshot,t.fieldChoices]),Re=Y.join("|"),[Be,Ae]=b.useState([]);b.useEffect(()=>{for(const r of Y)M(r)||ht.getTable(r).catch(()=>{}).then(g=>{g||Ae(l=>l.includes(r)?l:[...l,r])})},[Re]);const W=Y.filter(r=>!M(r)),ue=W.filter(r=>Be.includes(r)),U=b.useMemo(()=>ft(t),[t,c]),Oe=W.join("|"),ze=b.useMemo(()=>mt(t),[t,c,Oe]);b.useEffect(()=>{let r=!1;if(!t.table||!t.targetId||!j||!z(t.targetId)){d(l=>({...l,targetSnapshot:null}));return}if(typeof window>"u"||!window.dataverseAPI?.queryData)return;I(!0);const g=`/${j.entitySetName}(${t.targetId})`;return window.dataverseAPI.queryData(g).then(l=>{if(r)return;const f=l?.value,A=Array.isArray(f)?f[0]??null:f&&typeof f=="object"?f:l&&typeof l=="object"&&j.primaryKey in l?l:null;d(O=>({...O,targetSnapshot:A})),I(!1)}).catch(()=>{r||(d(l=>({...l,targetSnapshot:null})),I(!1))}),()=>{r=!0}},[t.table,t.targetId,j]),b.useEffect(()=>{let r=!1;if(!t.table||!t.subordinateId||!j||!z(t.subordinateId)){d(l=>({...l,subordinateSnapshot:null}));return}if(typeof window>"u"||!window.dataverseAPI?.queryData)return;X(!0);const g=`/${j.entitySetName}(${t.subordinateId})`;return window.dataverseAPI.queryData(g).then(l=>{if(r)return;const f=l?.value,A=Array.isArray(f)?f[0]??null:f&&typeof f=="object"?f:l&&typeof l=="object"&&j.primaryKey in l?l:null;d(O=>({...O,subordinateSnapshot:A})),X(!1)}).catch(()=>{r||(d(l=>({...l,subordinateSnapshot:null})),X(!1))}),()=>{r=!0}},[t.table,t.subordinateId,j]);const pe=r=>d(g=>{const l=new Set(g.dirty);return l.add(r),{...g,dirty:l}}),R=(r,g,l)=>{d(f=>({...f,[r]:g})),l&&pe(l)},Ee=(r,g)=>{d(l=>{const f={...l.fieldChoices};return g==="target"?delete f[r]:f[r]=g,{...l,fieldChoices:f,dirty:new Set(l.dirty).add("fielddiff")}})},$e=(r,g)=>{d(l=>({...l,customValues:{...l.customValues,[r]:g},dirty:new Set(l.dirty).add("fielddiff")}))},Z=t.targetSnapshot,ee=t.subordinateSnapshot,H=Object.values(t.fieldChoices).filter(r=>r!=="target").length,Ve=j?Yt(j.logicalName)?t.targetId?z(t.targetId)?t.subordinateId?z(t.subordinateId)?t.targetId===t.subordinateId?"Target and Subordinate must be different records.":t.headers.some(r=>r.enabled&&!r.name)?"Fix empty header name.":ue.length>0?`Couldn't load metadata for ${ue.join(", ")}, so a lookup kept from the Subordinate can’t be bound. Pick Target or Custom for it instead.`:W.length>0?`Loading metadata for ${W.join(", ")} to bind the lookups kept from the Subordinate…`:null:"Subordinate record id is not a valid GUID.":"Pick a Subordinate record (the loser).":"Target record id is not a valid GUID.":"Pick a Target record (the winner).":`Merge is only supported for ${Le}.`:"Pick a target table first.",Ue=async()=>{L(!0);const r=await Gt.merge(t,je(ge,null));D(r),L(!1),S("results"),m(g=>[{id:`r-${Date.now()}`,snapshot:B,modeId:"merge",url:U.relativeUrl,method:"POST",ts:Date.now(),status:r.status,ms:r.ms,rowCount:r.ok?1:0},...g].slice(0,8)),d(g=>({...g,dirty:new Set}))},ge=b.useMemo(()=>{let r=[...t.headers];return t.suppressDuplicateDetection&&r.push({id:"__sup-dupe",name:"MSCRM.SuppressDuplicateDetection",value:"true",enabled:!0,builtin:!0,hint:"Skips duplicate detection rules when applying UpdateContent overrides."}),r=yt(r,t.bypass),r},[t.headers,t.suppressDuplicateDetection,t.bypass]),be=b.useMemo(()=>{const r=[...xt(t.bypass,"bypass"),...jt({op:"merge",bypass:t.bypass})];return t.targetId&&!z(t.targetId)&&r.push({id:"merge-bad-target-guid",severity:"error",source:"validation",focusNode:"target",title:"Invalid Target record id",body:`"${t.targetId}" isn't a valid GUID. The merge will fail at the wire.`}),t.subordinateId&&!z(t.subordinateId)&&r.push({id:"merge-bad-sub-guid",severity:"error",source:"validation",focusNode:"subordinate",title:"Invalid Subordinate record id",body:`"${t.subordinateId}" isn't a valid GUID. The merge will fail at the wire.`}),r},[t.bypass,t.targetId,t.subordinateId]),He=St(be),B=b.useMemo(()=>vt(t),[t]);kt("merge",B,y,v);const Ge=b.useMemo(()=>re(B),[B]),he=v===null?!0:Ge!==v,_e=r=>{x(r.id),w(re(r.state))},fe=r=>{if(r.modeId!=="merge")return;const g=r.state;if(p.length>0&&!p.some(l=>l.logicalName===g.table)){Vt(`Can't load "${r.name}": entity \`${g.table}\` isn't available in this environment. The solution may have been removed or you may be connected to a different org.`);return}d(ye(g)),x(r.id),w(re(g)),D(null),u("target")},We=r=>{const g=_t(r,"merge");if(!g)return;const l=y,f=v;fe(g),x(l),w(f)};Tt(b.useMemo(()=>t.table?{state:B,modeId:"merge",dirty:he,lastSavedId:y,onSaved:_e,onLoadSaved:fe}:null,[B,he,y,t.table]));const qe=[{id:"target",label:"Target",meta:j?.displayName??"Pick a table",items:[{id:"target",icon:wt,iconFilled:De,label:"Master (survives)",badge:t.targetId?"✓":null,badgeAppearance:"ghost",dirty:t.dirty.has("target")||t.dirty.has("entity")}]},{id:"subordinate-section",label:"Subordinate",meta:t.subordinateId?"will be deactivated":"pick a record",items:[{id:"subordinate",icon:xe,iconFilled:J,label:"Subordinate record",badge:t.subordinateId?"✓":null,badgeAppearance:"ghost",dirty:t.dirty.has("subordinate")}]},{id:"override",label:"Override fields",meta:`${H} override${H===1?"":"s"}`,items:[{id:"fielddiff",icon:xe,iconFilled:J,label:"Field comparison",badge:H||null,badgeAppearance:"tint",badgeColor:H>0?"brand":"subtle",dirty:t.dirty.has("fielddiff")}]},{id:"settings",label:"Settings",meta:(t.performParentingChecks?1:0)+(t.suppressDuplicateDetection?1:0)==0?"defaults":`${(t.performParentingChecks?1:0)+(t.suppressDuplicateDetection?1:0)} set`,items:[{id:"options",icon:Ft,iconFilled:Ie,label:"Merge options",badge:(t.performParentingChecks?1:0)+(t.suppressDuplicateDetection?1:0)||null,badgeAppearance:"ghost",dirty:t.dirty.has("options")}]},{id:"headers",label:"Headers",meta:`${t.headers.filter(r=>r.enabled).length} active`,items:[{id:"headers",icon:Dt,iconFilled:Nt,label:"HTTP headers",badge:t.headers.filter(r=>r.enabled).length||null,dirty:t.dirty.has("headers")},{id:"bypass",icon:le,iconFilled:le,label:"Bypass logic",badge:It(t.bypass),badgeAppearance:t.bypass.businessLogic!=="none"||t.bypass.suppressFlows?"tint":"ghost",badgeColor:t.bypass.businessLogic!=="none"||t.bypass.suppressFlows?"warning":"subtle",dirty:t.dirty.has("bypass")}]}];let C;switch(o){case"target":C=e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:14},children:[e.jsx(rr,{state:t,setState:d,markDirty:pe,onEntityChange:()=>{x(void 0),w(null)}}),e.jsx(ke,{title:"Master record",sub:"The record that keeps its identity. Subordinate is merged into it.",table:t.table,selectedId:t.targetId,onPick:r=>R("targetId",r,"target")})]});break;case"subordinate":C=e.jsx(ke,{title:"Subordinate (deactivated)",sub:"The duplicate to merge away. Its relationships re-parent to the Target; the row gets statecode=Inactive.",table:t.table,selectedId:t.subordinateId,onPick:r=>R("subordinateId",r,"subordinate"),conflictWith:t.targetId});break;case"fielddiff":C=e.jsxs("div",{children:[e.jsx(er,{overrideCount:H,subordinateName:G(j,ee??void 0)}),e.jsx(tr,{table:t.table,target:Z??void 0,subordinate:ee??void 0,targetLoading:V,subordinateLoading:N}),e.jsx(Jt,{table:t.table,target:t.targetSnapshot??null,sub:t.subordinateSnapshot??null,fieldChoices:t.fieldChoices,customValues:t.customValues,setFieldChoice:Ee,setCustomValue:$e})]});break;case"options":C=e.jsx(ar,{performParentingChecks:t.performParentingChecks,setPerformParentingChecks:r=>R("performParentingChecks",r,"options"),suppressDuplicateDetection:t.suppressDuplicateDetection,setSuppressDuplicateDetection:r=>R("suppressDuplicateDetection",r,"options")});break;case"headers":C=e.jsx(Mt,{items:t.headers,setItems:r=>R("headers",r,"headers"),group:"write"});break;case"bypass":C=e.jsx(Ct,{value:t.bypass,onChange:r=>R("bypass",r,"bypass"),group:"write"});break}const Ke=je(ge,null),Je={method:"POST",built:U,headers:Ke,body:ze,entityLogical:U.entityLogical};return e.jsx(Pt,{sidebar:e.jsx(Ot,{type:a,urlPreview:U.relativeNoBase,sections:qe,activeNode:o,onSelect:r=>{u(r),S("builder")},recents:F,onRecentClick:We}),urlBar:e.jsx(At,{method:"POST",url:U.relativeUrl,executeVerb:a.executeVerb,disabledReason:Ve??He,loading:T,onExecute:Ue,advisories:be,onAdvisoryFocus:u}),children:e.jsxs(Lt,{tab:h,onTabChange:S,resultCount:k?.ok?1:null,children:[h==="builder"&&C,h==="code"&&e.jsx(Rt,{themeMode:s,inputs:Je}),h==="results"&&e.jsx(Bt,{result:k,mode:"single",table:t.table,writeContext:{operation:"merge",table:t.table,recordId:t.targetId,recordName:G(j,Z??void 0),targetName:G(j,Z??void 0),subordinateName:G(j,ee??void 0)}})]})})}function er({overrideCount:s,subordinateName:a}){return e.jsx(E,{layout:"multiline",intent:"warning",icon:e.jsx(le,{}),style:{marginBottom:14},children:e.jsxs($,{children:[e.jsx(Ce,{children:"Merge is irreversible."}),a?e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:a})," will be deactivated,"," "]}):"The subordinate will be deactivated, ","its related records re-parent to the Target, and ",e.jsx("strong",{children:s})," field",s===1?"":"s"," on the Target will be overwritten by your overrides. The server also auto-fills any empty Target fields from the Subordinate."]})})}function tr({table:s,target:a,subordinate:i,targetLoading:t,subordinateLoading:d}){const c=we(),p=M(s);return p?e.jsxs("div",{className:c.inlineCard,style:{padding:14,marginBottom:14,display:"grid",gridTemplateColumns:"1fr 44px 1fr",gap:10,alignItems:"stretch"},children:[e.jsx(ve,{tone:"target",chip:"TARGET",chipDescription:"survives the merge",row:a,tbl:p,emptyHint:t?"Loading Target record…":"Pick a Target record."}),e.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",color:n.colorNeutralForeground3},children:e.jsx(Fe,{style:{width:28,height:28}})}),e.jsx(ve,{tone:"sub",chip:"SUBORDINATE",chipDescription:"will be deactivated",row:i,tbl:p,emptyHint:d?"Loading Subordinate record…":"Pick a Subordinate record."})]}):null}function ve({tone:s,chip:a,chipDescription:i,row:t,tbl:d,emptyHint:c}){const p=s==="target"?{border:`1px solid ${n.colorPaletteGreenBorderActive}`,background:n.colorPaletteGreenBackground1}:{border:`1px solid ${n.colorPaletteDarkOrangeBorderActive}`,background:n.colorPaletteDarkOrangeBackground1},o=s==="target"?n.colorPaletteGreenForeground1:n.colorPaletteDarkOrangeForeground1,u=G(d,t),h=t?String(t[d.primaryKey]??""):null,S=t?.createdon?String(t.createdon):null,k=S?new Date(S).toLocaleDateString(void 0,{year:"numeric",month:"short"}):null;return e.jsxs("div",{style:{...p,borderRadius:n.borderRadiusMedium,padding:12},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:8},children:[e.jsx(Q,{appearance:"filled",style:{background:o,color:n.colorNeutralForegroundOnBrand,fontWeight:700,letterSpacing:.4},children:a}),e.jsx(P,{style:{color:n.colorNeutralForeground3},children:i})]}),t?e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:8},children:[e.jsx(Wt,{size:"small",name:u??"?",avatar:{color:"colorful"}}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:13,fontWeight:600},children:u??"(no name)"}),e.jsx("div",{style:{fontFamily:n.fontFamilyMonospace,fontSize:10,color:n.colorNeutralForeground3},children:h??""})]})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:2,fontSize:11,color:n.colorNeutralForeground3},children:[k&&e.jsxs("div",{children:["Created:"," ",e.jsx("strong",{style:{color:n.colorNeutralForeground2},children:k})]}),t.accountnumber!=null&&e.jsxs("div",{children:["Account #:"," ",e.jsx("strong",{style:{color:n.colorNeutralForeground2,fontFamily:n.fontFamilyMonospace},children:String(t.accountnumber)})]}),t.revenue!=null&&e.jsxs("div",{children:["Revenue:"," ",e.jsx("strong",{style:{color:n.colorNeutralForeground2},children:Number(t.revenue).toLocaleString(void 0,{style:"currency",currency:"USD",maximumFractionDigits:0})})]}),t.emailaddress1!=null&&e.jsxs("div",{children:["Email:"," ",e.jsx("strong",{style:{color:n.colorNeutralForeground2},children:String(t.emailaddress1)})]})]})]}):e.jsx("div",{style:{padding:"20px 4px",color:n.colorNeutralForeground3,fontSize:12,fontStyle:"italic",textAlign:"center"},children:c})]})}function rr({state:s,setState:a,markDirty:i,onEntityChange:t}){const d=M(s.table),{allEntities:c,allLoading:p}=Ne(),o=b.useMemo(()=>de.map(u=>c.find(h=>h.logicalName===u)).filter(u=>!!u),[c]);return e.jsxs("div",{children:[e.jsx(_,{icon:Ht,title:"Merge entity type",sub:`Pick the table to merge. The Merge action is restricted to ${Le}.`,group:"write"}),e.jsxs("div",{style:{maxWidth:560},children:[e.jsx(Me,{label:"Entity",hint:p?"Loading tables…":o.length===0?`No Merge-supported table (${de.join(", ")}) was found in this environment.`:void 0,children:e.jsx(ie,{value:d?.displayName??"",selectedOptions:[s.table],onOptionSelect:(u,h)=>{h.optionValue&&(a(S=>({...S,table:h.optionValue,targetId:null,subordinateId:null,fieldChoices:{},customValues:{},targetSnapshot:null,subordinateSnapshot:null})),i("entity"),i("target"),i("subordinate"),i("fielddiff"),t())},children:o.map(u=>e.jsx(ne,{value:u.logicalName,text:u.displayName,children:e.jsxs("div",{style:{display:"flex",flexDirection:"column"},children:[e.jsx("span",{children:u.displayName}),e.jsxs(P,{style:{color:n.colorNeutralForeground3},children:[u.entitySetName," · supports Merge"]})]})},u.logicalName))})}),e.jsx(E,{layout:"multiline",intent:"info",style:{marginTop:14},children:e.jsxs($,{children:["Merge requires both records be the ",e.jsx("strong",{children:"same entity type"}),"."," ",e.jsx("code",{children:"incident"})," behaves differently — per docs, the ",e.jsx("code",{children:"UpdateContent"})," ","parameter is ",e.jsx("strong",{children:"ignored"})," for incident, and the merge runs in the user's security context (not system)."]})})]})]})}function ke({title:s,sub:a,table:i,selectedId:t,onPick:d,conflictWith:c}){const p=M(i),o=c&&t&&c===t;return e.jsxs("div",{children:[e.jsx(_,{icon:De,title:s,sub:a,group:"write"}),e.jsxs("div",{style:{maxWidth:480},children:[e.jsx(Me,{label:"Record",children:e.jsx(Ut,{table:i,selectedId:t,onPick:u=>d(u?.id??null),placeholder:`Search ${p?.displayName??""} records…`})}),o&&e.jsx(E,{layout:"multiline",intent:"error",style:{marginTop:14},children:e.jsx($,{children:"Target and Subordinate must be different records."})}),!t&&e.jsx(P,{style:{display:"block",marginTop:8,color:n.colorNeutralForeground3},children:"Tip: use the search box to filter by primary name (e.g. account name, contact full name)."})]})]})}function ar({performParentingChecks:s,setPerformParentingChecks:a,suppressDuplicateDetection:i,setSuppressDuplicateDetection:t}){return e.jsxs("div",{children:[e.jsx(_,{icon:Ie,title:"Merge options",sub:"Controls applied during the merge operation.",group:"write"}),e.jsxs("div",{style:{maxWidth:720,display:"flex",flexDirection:"column",gap:16},children:[e.jsx("div",{style:{padding:12,border:`1px solid ${n.colorNeutralStroke2}`,borderRadius:n.borderRadiusMedium},children:e.jsx(oe,{checked:s,onChange:(d,c)=>a(c.checked),label:e.jsxs("span",{children:[e.jsx("strong",{children:"PerformParentingChecks"}),e.jsx(P,{style:{display:"block",color:n.colorNeutralForeground3,marginTop:2},children:"When enabled, the merge fails if the Target and Subordinate have different parent records. Useful for child entities (e.g. contacts under different accounts)."})]})})}),e.jsx("div",{style:{padding:12,border:`1px solid ${n.colorNeutralStroke2}`,borderRadius:n.borderRadiusMedium},children:e.jsx(oe,{checked:i,onChange:(d,c)=>t(c.checked),label:e.jsxs("span",{children:[e.jsx("strong",{children:"MSCRM.SuppressDuplicateDetection"})," ",e.jsx("code",{style:{fontFamily:n.fontFamilyMonospace,fontSize:11},children:"= true"}),e.jsxs(P,{style:{display:"block",color:n.colorNeutralForeground3,marginTop:2},children:["Skip duplicate detection rules when applying ",e.jsx("code",{children:"UpdateContent"})," to the Target. Adds the ",e.jsx("code",{children:"MSCRM.SuppressDuplicateDetection: true"})," request header."]})]})})}),e.jsx(E,{layout:"multiline",intent:"warning",children:e.jsxs($,{children:[e.jsx(Ce,{children:"Merge is destructive."}),"The Subordinate is deactivated (",e.jsx("code",{children:"statecode=Inactive"}),") and most of its relationships re-parent to the Target. Some Target fields take Subordinate's value only when the Target's value is empty. Use ",e.jsx("strong",{children:"UpdateContent"})," (the Field comparison pane) to override that."]})})]})]})}function G(s,a){if(!s||!a)return null;const i=a[s.primaryName];return i!=null?String(i):null}export{nr as MergeMode};
@@ -1 +0,0 @@
1
- import{aW as Re,aX as Be,aY as Le,aZ as Ee,a_ as Qe,a$ as De,b0 as J,b1 as He,r as c,b2 as Oe,u as K,t,a5 as X,b3 as Ae,b4 as A,Z as f,Y as p,a3 as be,b5 as Xe,f as ge,c as Ge,b6 as We,b7 as _e,b8 as ie,e as Ve,b9 as Ue,ba as Ye,bb as Ze,i as Y,k as Je,bc as Ke,bd as et,F as oe,n as tt,be as at,bf as rt,aL as nt,aM as st,L as lt,q as it,aN as de,H as ot,aO as dt,bg as ct,a9 as ut,B as ce,D as ue,J as pe,bh as pt,w as mt,bi as yt,bj as me,bk as ht,bl as Z,bm as C,aE as ft,y as bt,z as gt,A as xt,G as vt,R as jt,U as St,S as kt,aS as wt,aT as Nt,bn as Tt,aU as qt,aV as Ft,bo as Pt}from"./index-D0g0tm7R.js";const Ct=(n,r)=>{const u=Re("group-label"),{label:o}=n;return{components:{root:"div",label:"span"},root:Le(Ee("div",{ref:r,role:"group","aria-labelledby":o?u:void 0,...n}),{elementType:"div"}),label:Be(o,{defaultProps:{id:u,role:"presentation"},elementType:"span"})}},$t=n=>Qe(n.root,{children:[n.label&&De(n.label,{children:n.label.children}),n.root.children]}),ye={root:"fui-OptionGroup",label:"fui-OptionGroup__label"},zt=He({root:{mc9l5x:"f22iagw",Beiy3e4:"f1vx9l62",Belr9w4:"fiut8dr",B8lkq7l:"f1xxzjds",eii1in:0,H93o2g:0,Gwp8xu:0,Bd39igo:"f16cmn8k",om0q45:"f5642y",Hl9o3s:"ffdf81h",sl1c2c:0,z4hxbw:0,B0i58d9:0,Bi9x0x4:0,Bgurq3m:"f1bsn9kn"},label:{Beyfa6y:0,Bbmb7ep:0,Btl43ni:0,B7oj6ja:0,Dimara:"ft85np5",sj55zd:"f11d4kpn",mc9l5x:"ftgm304",Be2twd7:"fy9rknc",Bhrd7zp:"fl43uef",Bg96gwp:"fwrc4pm",Byoj8tv:0,uwmqm3:0,z189sj:0,z8tnut:0,B0ocmuz:"f1mpq0zz"}},{d:[".f22iagw{display:flex;}",".f1vx9l62{flex-direction:column;}",".fiut8dr{row-gap:var(--spacingHorizontalXXS);}",'.f1xxzjds:not(:last-child)::after{content:"";}',[".f16cmn8k:not(:last-child)::after{border-bottom:var(--strokeWidthThin) solid var(--colorNeutralStroke2);}",{p:-1}],".f5642y:not(:last-child)::after{display:block;}",".ffdf81h:not(:last-child)::after{padding-bottom:var(--spacingHorizontalXS);}",[".f1bsn9kn:not(:last-child)::after{margin:0 calc(var(--spacingHorizontalXS) * -1) var(--spacingVerticalXS);}",{p:-1}],[".ft85np5{border-radius:var(--borderRadiusMedium);}",{p:-1}],".f11d4kpn{color:var(--colorNeutralForeground3);}",".ftgm304{display:block;}",".fy9rknc{font-size:var(--fontSizeBase200);}",".fl43uef{font-weight:var(--fontWeightSemibold);}",".fwrc4pm{line-height:var(--lineHeightBase200);}",[".f1mpq0zz{padding:var(--spacingHorizontalS) var(--spacingHorizontalSNudge);}",{p:-1}]]}),It=n=>{"use no memo";const r=zt();return n.root.className=J(ye.root,r.root,n.root.className),n.label&&(n.label.className=J(ye.label,r.label,n.label.className)),n},ee=c.forwardRef((n,r)=>{const u=Ct(n,r);return It(u),Oe("useOptionGroupStyles_unstable")(u),$t(u)});ee.displayName="OptionGroup";function Mt(n){const r=new Set,u=[];for(const o of n.navigationProperties){if(o.cardinality==="OneToMany")continue;const a=`${o.relationshipName}|${o.targetEntity}`;r.has(a)||(r.add(a),u.push({relationshipName:o.relationshipName,sourceTable:o.targetEntity,via:o.referencingAttribute??o.name,manyToMany:o.cardinality==="ManyToMany"}))}return u.sort((o,a)=>o.sourceTable.localeCompare(a.sourceTable)||o.relationshipName.localeCompare(a.relationshipName))}function Rt(n,r,u){return n.navigationProperties.find(a=>a.relationshipName===r&&a.cardinality!=="ManyToOne"&&a.targetEntity===u)?.name??null}function Bt({table:n,value:r,onChange:u}){const o=c.useMemo(()=>Mt(n),[n]),{table:a,loading:y}=K(r.sourceTable||null);c.useEffect(()=>{if(!a||!r.relationshipName)return;const l=Rt(a,r.relationshipName,n.logicalName)??"";l!==r.navProperty&&u({...r,navProperty:l})},[a,r.relationshipName,n.logicalName]);const h=l=>`${l.relationshipName}|${l.sourceTable}`,g=o.find(l=>l.relationshipName===r.relationshipName&&l.sourceTable===r.sourceTable),x=l=>`${ge(l.sourceTable)?.displayName??l.sourceTable} · ${l.relationshipName}`;return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[t.jsx(X,{label:"Relationship",hint:o.length?`Rows of ${n.displayName} related to one row of another table.`:void 0,validationState:o.length?"none":"warning",validationMessage:o.length?void 0:`${n.displayName} has no lookups or many-to-many relationships.`,children:t.jsx(Ae,{placeholder:"Pick a relationship…",value:g?x(g):"",selectedOptions:g?[h(g)]:[],onOptionSelect:(l,N)=>{const v=o.find($=>h($)===N.optionValue);v&&u({sourceTable:v.sourceTable,relationshipName:v.relationshipName,navProperty:"",recordId:v.sourceTable===r.sourceTable?r.recordId:null,recordName:v.sourceTable===r.sourceTable?r.recordName:void 0})},listbox:{style:{maxHeight:360}},children:o.map(l=>t.jsx(A,{value:h(l),text:x(l),children:t.jsxs("div",{style:{display:"flex",flexDirection:"column",minWidth:0},children:[t.jsx("span",{children:x(l)}),t.jsx(f,{style:{color:p.colorNeutralForeground3,fontFamily:p.fontFamilyMonospace},children:l.manyToMany?`many-to-many · ${l.via}`:`via ${l.via}`})]})},h(l)))})}),r.sourceTable&&y&&!a&&t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx(be,{size:"tiny"}),t.jsxs(f,{children:["Loading ",r.sourceTable," metadata…"]})]}),a&&r.relationshipName&&!r.navProperty&&t.jsxs(f,{style:{color:p.colorPaletteRedForeground1},children:[a.displayName," has no collection navigation property for ",r.relationshipName,"."]}),a&&r.navProperty&&t.jsx(X,{label:`${a.displayName} row`,hint:t.jsxs("span",{children:["Collection: ",t.jsx("code",{children:`${a.entitySetName}(…)/${r.navProperty}`})]}),children:t.jsx(Xe,{table:a.logicalName,selectedId:r.recordId,onPick:l=>u({...r,recordId:l?.id??null,recordName:l?.primary})})})]})}const Lt=()=>({table:"",queryId:null,queryType:"savedQuery",top:50,prefer:{...Nt(),formattedValues:!0},headers:wt(),dirty:new Set}),he={sourceTable:"",relationshipName:"",navProperty:"",recordId:null};function fe(n){if(!n)return[];const r=[...n.matchAll(/<cell\s+([^>]+?)\s*\/?>/g)],u=[];for(const o of r){const a=o[1],y=/name="([^"]+)"/.exec(a);if(!y)continue;const h=y[1],g=/width="([^"]+)"/.exec(a),x=g&&parseInt(g[1],10)||100,l=h.indexOf(".");l>=0?u.push({fullName:h,width:x,isLink:!0,linkAlias:h.slice(0,l),attr:h.slice(l+1)}):u.push({fullName:h,width:x,isLink:!1,attr:h})}return u}function Et(n){switch(n){case 0:return"Main view";case 1:return"Advanced Find";case 2:return"Subgrid";case 4:return"Quick Find";case 8:return"Reserved";case 16:return"Lookup";case 32:return"Marketing list";case 64:return"Address book";case 128:return"Main (no subj)";case 256:return"Outlook filter";case 512:return"Reserved";case 1024:return"Offline filter";case 2048:return"Outlook template";case 4096:return"Reserved";case 8192:return"Svc mgmt app";default:return`Type ${n}`}}function Dt({themeMode:n}){const r=Ge("predefined-query"),u=We(),o=_e("predefined-query",ie,Lt),[a,y]=c.useState(o.state),{table:h}=K(a.table||null),{entities:g}=Ve(),[x,l]=c.useState("target"),[N,v]=c.useState("builder"),[$,te]=c.useState(null),[xe,ae]=c.useState(!1),[ve,je]=c.useState([]),[z,I]=c.useState(o.lastSavedId),[M,R]=c.useState(o.lastSavedHash),[T,B]=c.useState([]),[G,W]=c.useState(!1),[re,_]=c.useState(null),[k,L]=c.useState(""),{table:Se}=K(a.related?.sourceTable||null),E=c.useMemo(()=>Ue(a),[a,h,Se]),V=ge(a.table),d=T.find(e=>e.id===a.queryId)??null,Q=T.filter(e=>e.kind==="savedQuery"),D=T.filter(e=>e.kind==="userQuery"),H=c.useMemo(()=>{const e=k.trim().toLowerCase();return e?Q.filter(i=>i.name.toLowerCase().includes(e)):Q},[Q,k]),O=c.useMemo(()=>{const e=k.trim().toLowerCase();return e?D.filter(i=>i.name.toLowerCase().includes(e)):D},[D,k]);c.useEffect(()=>{L(d?.name??"")},[d?.name,a.table]),c.useEffect(()=>{let e=!1;if(!a.table){B([]),_(null);return}if(typeof window>"u"||!window.dataverseAPI?.queryData){B([]);return}W(!0),_(null);const i="savedqueryid,name,description,fetchxml,layoutxml,returnedtypecode,querytype,isdefault,isquickfindquery,iscustomizable,ismanaged",m="userqueryid,name,description,fetchxml,layoutxml,returnedtypecode,querytype",b=`savedqueries?$select=${i}&$filter=returnedtypecode eq '${a.table}' and statecode eq 0&$orderby=name asc`,ze=`userqueries?$select=${m}&$filter=returnedtypecode eq '${a.table}' and statecode eq 0&$orderby=name asc`;return Promise.all([window.dataverseAPI.queryData(b).catch(j=>{throw j instanceof Error?j:new Error(String(j))}),window.dataverseAPI.queryData(ze).catch(()=>({value:[]}))]).then(([j,U])=>{if(e)return;const Ie=j?.value??[],Me=U?.value??[],le=[...Ie.map(s=>{const S=s.layoutxml!=null?String(s.layoutxml):null;return{id:String(s.savedqueryid??""),name:String(s.name??"(unnamed)"),description:s.description!=null?String(s.description):null,fetchXml:s.fetchxml!=null?String(s.fetchxml):null,layoutXml:S,layoutColumns:fe(S),returnedTypeCode:String(s.returnedtypecode??a.table),queryType:typeof s.querytype=="number"?s.querytype:0,isDefault:s.isdefault===!0,isQuickFind:s.isquickfindquery===!0,isCustom:s.iscustomizable?.Value===!0,isManaged:s.ismanaged===!0,kind:"savedQuery"}}),...Me.map(s=>{const S=s.layoutxml!=null?String(s.layoutxml):null;return{id:String(s.userqueryid??""),name:String(s.name??"(unnamed)"),description:s.description!=null?String(s.description):null,fetchXml:s.fetchxml!=null?String(s.fetchxml):null,layoutXml:S,layoutColumns:fe(S),returnedTypeCode:String(s.returnedtypecode??a.table),queryType:typeof s.querytype=="number"?s.querytype:0,isDefault:!1,isQuickFind:!1,isCustom:!0,isManaged:!1,kind:"userQuery"}})];le.sort((s,S)=>s.kind!==S.kind?s.kind==="savedQuery"?-1:1:s.isDefault!==S.isDefault?s.isDefault?-1:1:s.name.localeCompare(S.name)),B(le),W(!1)}).catch(j=>{if(e)return;const U=j instanceof Error?j.message:String(j);_(U),B([]),W(!1)}),()=>{e=!0}},[a.table]);const P=e=>y(i=>{const m=new Set(i.dirty);return m.add(e),{...i,dirty:m}}),w=(e,i,m)=>{y(b=>({...b,[e]:i})),m&&P(m)},ke=e=>{y(i=>({...i,table:e,queryId:null})),P("target"),I(void 0),R(null)},we=async()=>{ae(!0);const e=await qt.predefined(a);te(e),ae(!1),v("results"),je(i=>[{id:`r-${Date.now()}`,snapshot:q,modeId:"predefined-query",url:E.relativeUrl,method:"GET",ts:Date.now(),status:e.status,ms:e.ms,rowCount:Ft(e.body)??0},...i].slice(0,8)),y(i=>({...i,dirty:new Set}))},Ne=a.table?a.queryId?a.related&&!(a.related.navProperty&&a.related.recordId)?"Pick the relationship and the row whose related records to query.":null:"Pick a saved query or user view.":"Pick a table first.",q=c.useMemo(()=>Ye(a),[a]);Ze("predefined-query",q,z,M);const Te=c.useMemo(()=>Y(q),[q]),ne=M===null?!0:Te!==M,qe=e=>{I(e.id),R(Y(e.state))},se=e=>{if(e.modeId!=="predefined-query")return;const i=e.state;if(g.length>0&&!g.some(m=>m.logicalName===i.table)){Tt(`Can't load "${e.name}": entity \`${i.table}\` isn't available in this environment. The solution may have been removed or you may be connected to a different org.`);return}y(ie(i)),I(e.id),R(Y(i)),te(null),l("target")},Fe=e=>{const i=Pt(e,"predefined-query");if(!i)return;const m=z,b=M;se(i),I(m),R(b)};Je(c.useMemo(()=>a.table?{state:q,modeId:"predefined-query",dirty:ne,lastSavedId:z,onSaved:qe,onLoadSaved:se}:null,[q,ne,z,a.table]));const Pe=[{id:"target",label:"Target",meta:V?.displayName,items:[{id:"target",icon:et,iconFilled:Ke,label:d?.name??(a.table?"Pick a query":"Pick a table"),badge:d?.kind==="savedQuery"?"system":d?.kind==="userQuery"?"user":null,badgeAppearance:"ghost",dirty:a.dirty.has("target")}]},{id:"conditions",label:"Conditions",items:[{id:"conditions",icon:tt,iconFilled:oe,label:"Filter (read-only)",badge:d?"inherited":null,badgeAppearance:"ghost"}]},{id:"top",label:"Top",items:[{id:"top",icon:rt,iconFilled:at,label:"$top",code:!0,badge:a.top?a.top.toString():"default",badgeAppearance:"ghost",dirty:a.dirty.has("top")}]},{id:"prefer",label:"Prefer",items:[{id:"prefer",icon:st,iconFilled:nt,label:"Prefer header",badge:de(a.prefer)?"on":null,badgeAppearance:"ghost",dirty:a.dirty.has("prefer")}]},{id:"headers",label:"Headers",meta:`${a.headers.filter(e=>e.enabled).length} active`,items:[{id:"headers",icon:it,iconFilled:lt,label:"HTTP headers",badge:a.headers.filter(e=>e.enabled).length||null,dirty:a.dirty.has("headers")}]}];let F;switch(x){case"target":F=t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[t.jsx(mt,{table:a.table,onTableChange:e=>{ke(e),a.related&&w("related",he)},group:"read",sub:"Pick the table whose saved queries (system views) or user queries (personal views) you want to execute."}),a.table&&t.jsxs("div",{style:{maxWidth:640,display:"flex",flexDirection:"column",gap:14},children:[t.jsx(X,{label:"Run against",hint:a.related?"The query runs over one row’s related records: /<set>(<id>)/<nav>?savedQuery=…":"The query runs over the whole table: /<set>?savedQuery=…",children:t.jsxs(yt,{ariaLabel:"Run the query against",children:[t.jsx(me,{checked:!a.related,onClick:()=>{a.related&&w("related",null,"target")},children:"Table"}),t.jsx(me,{checked:!!a.related,onClick:()=>{a.related||w("related",he,"target")},children:"Related records of a row"})]})}),a.related&&V&&t.jsx(Bt,{table:V,value:a.related,onChange:e=>w("related",e,"target")}),t.jsx(X,{label:"View",hint:T.length>0?`${Q.length} system · ${D.length} personal`:void 0,children:t.jsxs(ht,{freeform:!0,clearable:!0,value:k,selectedOptions:a.queryId?[a.queryId]:[],placeholder:G?"Loading queries…":T.length===0?"No queries on this table":"Search views by name…",disabled:G,onChange:e=>{const i=e.target.value;L(i),i===""&&a.queryId&&(y(m=>({...m,queryId:null})),P("target"))},onOptionSelect:(e,i)=>{if(!i.optionValue){y(b=>({...b,queryId:null})),L(""),P("target");return}const m=T.find(b=>b.id===i.optionValue);m&&(y(b=>({...b,queryId:m.id,queryType:m.kind})),L(m.name),P("target"))},listbox:{style:{maxHeight:420}},children:[H.length===0&&O.length===0&&k.trim()&&t.jsx(A,{value:"__none",text:"",disabled:!0,children:t.jsxs(f,{style:{color:p.colorNeutralForeground3},children:['No views match "',k.trim(),'"']})}),H.length>0&&t.jsx(ee,{label:`System views (${H.length})`,children:H.map(e=>t.jsx(A,{value:e.id,text:e.name,children:t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:1,minWidth:0},children:[t.jsx(Z,{style:{fontWeight:e.isDefault?600:400},children:e.name}),e.description&&t.jsx(f,{style:{color:p.colorNeutralForeground3},children:e.description})]})},e.id))}),O.length>0&&t.jsx(ee,{label:`Personal views (${O.length})`,children:O.map(e=>t.jsx(A,{value:e.id,text:e.name,children:t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:1,minWidth:0},children:[t.jsx(Z,{children:e.name}),e.description&&t.jsx(f,{style:{color:p.colorNeutralForeground3},children:e.description})]})},e.id))})]})}),G&&t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,color:p.colorNeutralForeground3},children:[t.jsx(be,{size:"tiny"}),t.jsx(f,{children:"Fetching saved + user queries…"})]}),re&&t.jsx(ce,{intent:"error",layout:"multiline",children:t.jsxs(ue,{children:[t.jsx(pe,{children:"Couldn't load queries"}),re]})}),d&&t.jsxs("div",{className:J(u.inlineCard),style:{padding:14,display:"flex",flexDirection:"column",gap:10},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexWrap:"wrap"},children:[t.jsx(Z,{style:{fontWeight:600},children:d.name}),t.jsx(C,{appearance:"ghost",size:"small",children:Et(d.queryType)}),d.isDefault&&t.jsx(C,{appearance:"tint",color:"brand",size:"small",children:"default view"}),d.isQuickFind&&t.jsx(C,{appearance:"tint",color:"informative",size:"small",children:"quick find"}),d.kind==="savedQuery"&&d.isManaged&&t.jsx(C,{appearance:"ghost",size:"small",children:"managed"}),d.kind==="savedQuery"&&!d.isManaged&&t.jsx(C,{appearance:"ghost",size:"small",children:"unmanaged"})]}),t.jsxs("div",{children:[t.jsx(f,{style:{fontWeight:600,color:p.colorNeutralForeground2},children:"Query GUID"}),t.jsx("div",{children:t.jsx("code",{style:{fontFamily:p.fontFamilyMonospace,fontSize:11,color:p.colorNeutralForeground2},children:d.id})})]}),d.layoutColumns.length>0&&t.jsxs("div",{children:[t.jsxs(f,{style:{fontWeight:600,color:p.colorNeutralForeground2},children:["Result columns (",d.layoutColumns.length,") — from layoutxml"]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,marginTop:4},children:d.layoutColumns.map(e=>t.jsx(ft,{relationship:"label",content:e.isLink?`${e.fullName} — joined column via link alias \`${e.linkAlias}\` · width ${e.width}px`:`${e.fullName} — width ${e.width}px`,children:t.jsx("span",{style:{fontFamily:p.fontFamilyMonospace,fontSize:11,padding:"2px 6px",borderRadius:4,background:e.isLink?p.colorPaletteBlueBackground2:p.colorNeutralBackground3,color:e.isLink?p.colorPaletteBlueForeground2:p.colorNeutralForeground1,cursor:"help"},children:e.isLink?`${e.linkAlias}.${e.attr}`:e.attr})},e.fullName))}),d.layoutColumns.some(e=>e.isLink)&&t.jsx(f,{style:{display:"block",marginTop:6,color:p.colorNeutralForeground3},children:"Blue pills are joined columns (link-entity in FetchXml)."})]})]})]})]});break;case"conditions":F=t.jsxs("div",{children:[t.jsx(ut,{icon:oe,title:"Conditions",sub:"Read-only summary — predefined queries embed their own FetchXml. Edit the saved query in the model-driven app to change conditions."}),t.jsx(ce,{layout:"multiline",intent:"warning",style:{marginBottom:12},children:t.jsxs(ue,{children:[t.jsx(pe,{children:"$select / $filter / $orderby / $expand are locked"}),"With ",t.jsx("code",{children:"?savedQuery=…"})," / ",t.jsx("code",{children:"?userQuery=…"}),", the FetchXml in the query owns column projection, filter, sort and joins. Only ",t.jsx("code",{children:"$top"})," and"," ",t.jsx("code",{children:"Prefer"})," headers remain editable."]})}),d?.fetchXml?t.jsx("div",{style:{border:`1px solid ${p.colorNeutralStroke2}`,borderRadius:p.borderRadiusMedium,overflow:"hidden",height:480},children:t.jsx(pt,{height:"100%",language:"xml",value:d.fetchXml,theme:n==="dark"?"vs-dark":"light",options:{readOnly:!0,domReadOnly:!0,lineNumbers:"on",renderLineHighlight:"line",minimap:{enabled:!1},scrollBeyondLastLine:!1,fontFamily:"Cascadia Mono, Consolas, monospace",fontSize:13,tabSize:2,wordWrap:"on",automaticLayout:!0,padding:{top:12,bottom:12},bracketPairColorization:{enabled:!0},guides:{bracketPairs:!0,indentation:!0},smoothScrolling:!0}})}):d?t.jsx(f,{style:{color:p.colorNeutralForeground3},children:"(No FetchXml available for this query — it may be a layout-only definition.)"}):t.jsx(f,{style:{color:p.colorNeutralForeground3},children:"Pick a query in Target to see its FetchXml."})]});break;case"top":F=t.jsx(ct,{top:a.top,setTop:e=>w("top",e,"top"),maxPageSize:a.prefer.maxpagesize});break;case"prefer":F=t.jsx(dt,{spec:a.prefer,setSpec:e=>w("prefer",e,"prefer"),sendsPageSize:!0});break;case"headers":F=t.jsx(ot,{items:a.headers,setItems:e=>w("headers",e,"headers")});break}const Ce=bt(a.headers,de(a.prefer)),$e={method:"GET",built:E,headers:Ce};return t.jsx(gt,{sidebar:t.jsx(kt,{type:r,urlPreview:E.relativeNoBase,sections:Pe,activeNode:x,onSelect:e=>{l(e),v("builder")},recents:ve,onRecentClick:Fe}),urlBar:t.jsx(St,{method:"GET",url:E.relativeUrl,executeVerb:r.executeVerb,disabledReason:Ne,loading:xe,onExecute:we}),children:t.jsxs(xt,{tab:N,onTabChange:v,resultCount:$?.body?.value?.length??null,children:[N==="builder"&&F,N==="code"&&t.jsx(vt,{themeMode:n,inputs:$e}),N==="results"&&t.jsx(jt,{result:$,mode:"multi",table:a.table,preferredColumnOrder:d?.layoutColumns.map(e=>e.fullName)})]})})}export{Dt as PredefinedQueryMode};
@@ -1 +0,0 @@
1
- import{c as G,aI as I,r as o,aJ as O,aK as R,az as q,aL as V,aM as W,L as J,q as _,aN as L,t as e,H as K,aO as Q,a9 as X,B as S,D as w,J as T,aE as k,O as j,aP as Y,aQ as Z,a5 as ee,ad as te,Y as i,Z as ae,aR as se,X as re,y as ne,z as oe,A as ie,G as le,R as de,U as ce,S as ue,aS as he,aT as pe,aU as xe,aV as me}from"./index-D0g0tm7R.js";const ye=()=>({url:"",prefer:pe(),headers:he(),dirty:new Set});function ge(y,l){const d={ok:!1,url:null,host:"",path:"",entitySet:null,skiptoken:null,params:[],errors:[]};if(!y.trim())return d;let t;try{t=new URL(y)}catch{return{...d,errors:["Not a valid URL — paste the full https://… string."]}}const n=[];t.protocol!=="https:"&&n.push("Must be https:// — Dataverse rejects plain HTTP.");const c=t.pathname.match(/^\/api\/data\/v\d+\.\d+\/([^/?]+)/);c||n.push("Path doesn't look like a Dataverse Web API URL (expected /api/data/v<x>.<x>/<entityset>)."),l&&t.host&&t.host.toLowerCase()!==l.toLowerCase()&&n.push(`URL host (${t.host}) doesn't match the connected environment (${l}). Switch connections or paste a URL from the current org.`);const h=[];t.searchParams.forEach((p,g)=>h.push({key:g,value:p}));const u=t.searchParams.get("$skiptoken");return{ok:n.length===0,url:t,host:t.host,path:t.pathname,entitySet:c?c[1]:null,skiptoken:u,params:h,errors:n}}function fe({themeMode:y}){const l=G("retrieve-nextlink"),d=I(),[t,n]=o.useState(ye),[c,h]=o.useState("url"),[u,p]=o.useState("builder"),[g,P]=o.useState(null),[C,v]=o.useState(!1),[U,F]=o.useState([]),f=o.useMemo(()=>O(t),[t]),r=o.useMemo(()=>ge(t.url,d.host),[t.url,d.host]),N=a=>n(s=>{const m=new Set(s.dirty);return m.add(a),{...s,dirty:m}}),x=(a,s,m)=>{n(A=>({...A,[a]:s})),m&&N(m)},M=o.useMemo(()=>r.errors.map((a,s)=>({id:`nl-err-${s}`,severity:"error",source:"validation",focusNode:"url",title:"Invalid next-link URL",body:a})),[r]),B=async()=>{if(!r.ok)return;v(!0);const a=await xe.nextLink(t);P(a),v(!1),p("results"),F(s=>[{id:`r-${Date.now()}`,modeId:"retrieve-nextlink",url:t.url,method:"GET",ts:Date.now(),status:a.status,ms:a.ms,rowCount:me(a.body)??0},...s].slice(0,8)),n(s=>({...s,dirty:new Set}))},E=t.url.trim()?r.ok?null:r.errors[0]??"URL is not safe to follow.":"Paste an @odata.nextLink URL first.",$=async()=>{try{const a=await navigator.clipboard?.readText();a&&x("url",a.trim(),"url")}catch{}},z=[{id:"url",label:"Target",meta:"Server-issued",items:[{id:"url",icon:q,iconFilled:R,label:"@odata.nextLink",badge:r.entitySet??(t.url?"invalid":"empty"),badgeAppearance:"ghost",badgeColor:r.errors.length?"danger":r.entitySet?"informative":"subtle",dirty:t.dirty.has("url")}]},{id:"prefer",label:"Prefer",items:[{id:"prefer",icon:W,iconFilled:V,label:"Prefer header",badge:L(t.prefer)?"on":null,badgeAppearance:"ghost",dirty:t.dirty.has("prefer")}]},{id:"headers",label:"Headers",meta:`${t.headers.filter(a=>a.enabled).length} active`,items:[{id:"headers",icon:_,iconFilled:J,label:"HTTP headers",badge:t.headers.filter(a=>a.enabled).length||null,dirty:t.dirty.has("headers")}]}];let b;switch(c){case"url":b=e.jsxs("div",{children:[e.jsx(X,{icon:R,title:"Next-link URL",sub:"Paste the @odata.nextLink returned by the previous page. The URL is opaque — clauses are not editable here."}),e.jsx(S,{layout:"multiline",intent:"info",style:{marginBottom:12},children:e.jsxs(w,{children:[e.jsx(T,{children:"Why no clause editor?"}),"The next page must use the ",e.jsx("strong",{children:"same shape"})," as the original query. Dataverse encodes paging state in a ",e.jsx("code",{children:"$skiptoken"})," cookie — editing any other clause invalidates the cursor."]})}),e.jsxs("div",{style:{display:"flex",gap:8,marginBottom:8},children:[e.jsx(k,{content:"Paste from clipboard",relationship:"label",children:e.jsx(j,{icon:e.jsx(Y,{}),appearance:"outline",size:"small",onClick:$,children:"Paste"})}),e.jsx(k,{content:"Clear the URL field",relationship:"label",children:e.jsx(j,{icon:e.jsx(Z,{}),appearance:"subtle",size:"small",disabled:!t.url,onClick:()=>x("url","","url"),children:"Clear"})})]}),e.jsx(ee,{label:"@odata.nextLink",hint:"The full URL including https://. Skiptoken cookies are URL-encoded inside.",children:e.jsx(te,{rows:6,value:t.url,onChange:(a,s)=>x("url",s.value,"url"),placeholder:`https://${d.host}/api/data/v9.2/<entityset>?$select=…&$skiptoken=…`,style:{fontFamily:i.fontFamilyMonospace,fontSize:11}})}),r.errors.map((a,s)=>e.jsx(S,{intent:"error",layout:"multiline",style:{marginTop:12},children:e.jsxs(w,{children:[e.jsx(T,{children:"Can't follow this URL"}),a]})},s)),r.url&&r.ok&&e.jsxs("div",{style:{marginTop:16,padding:12,border:`1px solid ${i.colorNeutralStroke2}`,borderRadius:i.borderRadiusMedium,background:i.colorNeutralBackground1},children:[e.jsx(ae,{style:{display:"block",fontWeight:600,marginBottom:8,color:i.colorNeutralForeground2},children:"Parsed (read-only)"}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"120px 1fr",rowGap:4,columnGap:12,fontFamily:i.fontFamilyMonospace,fontSize:11},children:[e.jsx("span",{style:{color:i.colorNeutralForeground3},children:"host"}),e.jsx("span",{children:r.host}),e.jsx("span",{style:{color:i.colorNeutralForeground3},children:"entityset"}),e.jsx("span",{children:r.entitySet??"—"}),r.params.map((a,s)=>e.jsxs("span",{style:{display:"contents"},children:[e.jsx("span",{style:{color:i.colorBrandForeground1},children:a.key}),e.jsx("span",{style:{wordBreak:"break-all"},children:se(a.value)})]},s))]})]}),r.ok&&e.jsx("div",{style:{marginTop:16},children:e.jsx(k,{content:"Open the parsed URL in a new tab (auth will be required)",relationship:"description",children:e.jsx(j,{icon:e.jsx(re,{}),appearance:"outline",onClick:()=>window.open(t.url,"_blank","noopener"),children:"Open in new tab"})})})]});break;case"prefer":b=e.jsx(Q,{spec:t.prefer,setSpec:a=>x("prefer",a,"prefer"),sendsPageSize:!0});break;case"headers":b=e.jsx(K,{items:t.headers,setItems:a=>x("headers",a,"headers")});break}const D=ne(t.headers,L(t.prefer)),H={method:"GET",built:f,headers:D,isNextLink:!0,rawNextLink:t.url};return e.jsx(oe,{sidebar:e.jsx(ue,{type:l,urlPreview:f.relativeNoBase,sections:z,activeNode:c,onSelect:a=>{h(a),p("builder")},recents:U}),urlBar:e.jsx(ce,{method:"GET",url:f.relativeUrl,executeVerb:l.executeVerb,disabledReason:E,loading:C,onExecute:B,advisories:M,onAdvisoryFocus:a=>h(a)}),children:e.jsxs(ie,{tab:u,onTabChange:p,resultCount:g?.body?.value?.length??null,children:[u==="builder"&&b,u==="code"&&e.jsx(le,{themeMode:y,inputs:H}),u==="results"&&e.jsx(de,{result:g,mode:"next"})]})})}export{fe as RetrieveNextLinkMode};