@boltic/swirl 1.0.2-sit.48 → 1.0.2-sit.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/swirl.es.js +2 -1
- package/dist/swirl.umd.js +1 -1
- package/package.json +1 -1
package/dist/swirl.es.js
CHANGED
|
@@ -100421,7 +100421,8 @@ const O2 = (e) => !e.field || typeof e.field == "object" && Object.keys(e.field)
|
|
|
100421
100421
|
current_query: or
|
|
100422
100422
|
},
|
|
100423
100423
|
headers: {
|
|
100424
|
-
"Content-Type": "application/json"
|
|
100424
|
+
"Content-Type": "application/json",
|
|
100425
|
+
"x-request-source": "workflow"
|
|
100425
100426
|
}
|
|
100426
100427
|
};
|
|
100427
100428
|
try {
|
package/dist/swirl.umd.js
CHANGED
|
@@ -436,7 +436,7 @@ $2`).replace(/lambda\s+([^:]+):\n/g,"lambda $1: ").replace(/[ \t]+/g," ").trim()
|
|
|
436
436
|
`),sFe=(e,t)=>t?(...n)=>e(...n).locale(t):e;class Jl{constructor({locale:t,formats:n}={}){this.isMUIAdapter=!0,this.isTimezoneCompatible=!0,this.lib="dayjs",this.dayjs=void 0,this.locale=void 0,this.formats=void 0,this.escapedCharacters={start:"[",end:"]"},this.formatTokenMap=iFe,this.setLocaleToValue=r=>{const i=this.getCurrentLocaleCode();return i===r.locale()?r:r.locale(i)},this.hasUTCPlugin=()=>typeof xn.utc<"u",this.hasTimezonePlugin=()=>typeof xn.tz<"u",this.isSame=(r,i,o)=>{const s=this.setTimezone(i,this.getTimezone(r));return r.format(o)===s.format(o)},this.cleanTimezone=r=>{switch(r){case"default":return;case"system":return xn.tz.guess();default:return r}},this.createSystemDate=r=>{if(this.hasUTCPlugin()&&this.hasTimezonePlugin()){const i=xn.tz.guess();return i!=="UTC"?xn.tz(r,i):xn(r)}return xn(r)},this.createUTCDate=r=>{if(!this.hasUTCPlugin())throw new Error(xP);return xn.utc(r)},this.createTZDate=(r,i)=>{if(!this.hasUTCPlugin())throw new Error(xP);if(!this.hasTimezonePlugin())throw new Error(uX);const o=r!==void 0&&!r.endsWith("Z");return xn(r).tz(this.cleanTimezone(i),o)},this.getLocaleFormats=()=>{const r=xn.Ls,i=this.locale||"en";let o=r[i];return o===void 0&&(process.env.NODE_ENV!=="production"&&lX(["MUI X: Your locale has not been found.","Either the locale key is not a supported one. Locales supported by dayjs are available here: https://github.com/iamkun/dayjs/tree/dev/src/locale.","Or you forget to import the locale from 'dayjs/locale/{localeUsed}'","fallback on English locale."]),o=r.en),o.formats},this.adjustOffset=r=>{if(!this.hasTimezonePlugin())return r;const i=this.getTimezone(r);if(i!=="UTC"){const o=r.tz(this.cleanTimezone(i),!0);if(o.$offset===(r.$offset??0))return r;r.$offset=o.$offset}return r},this.date=(r,i="default")=>{if(r===null)return null;let o;return i==="UTC"?o=this.createUTCDate(r):i==="system"||i==="default"&&!this.hasTimezonePlugin()?o=this.createSystemDate(r):o=this.createTZDate(r,i),this.locale===void 0?o:o.locale(this.locale)},this.getInvalidDate=()=>xn(new Date("Invalid date")),this.getTimezone=r=>{if(this.hasTimezonePlugin()){const i=r.$x?.$timezone;if(i)return i}return this.hasUTCPlugin()&&r.isUTC()?"UTC":"system"},this.setTimezone=(r,i)=>{if(this.getTimezone(r)===i)return r;if(i==="UTC"){if(!this.hasUTCPlugin())throw new Error(xP);return r.utc()}if(i==="system")return r.local();if(!this.hasTimezonePlugin()){if(i==="default")return r;throw new Error(uX)}return xn.tz(r,this.cleanTimezone(i))},this.toJsDate=r=>r.toDate(),this.parse=(r,i)=>r===""?null:this.dayjs(r,i,this.locale,!0),this.getCurrentLocaleCode=()=>this.locale||"en",this.is12HourCycleInCurrentLocale=()=>/A|a/.test(this.getLocaleFormats().LT||""),this.expandFormat=r=>{const i=this.getLocaleFormats(),o=s=>s.replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,(a,l,u)=>l||u.slice(1));return r.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,(s,a,l)=>{const u=l&&l.toUpperCase();return a||i[l]||o(i[u])})},this.isValid=r=>r==null?!1:r.isValid(),this.format=(r,i)=>this.formatByString(r,this.formats[i]),this.formatByString=(r,i)=>this.dayjs(r).format(i),this.formatNumber=r=>r,this.isEqual=(r,i)=>r===null&&i===null?!0:r===null||i===null?!1:r.toDate().getTime()===i.toDate().getTime(),this.isSameYear=(r,i)=>this.isSame(r,i,"YYYY"),this.isSameMonth=(r,i)=>this.isSame(r,i,"YYYY-MM"),this.isSameDay=(r,i)=>this.isSame(r,i,"YYYY-MM-DD"),this.isSameHour=(r,i)=>r.isSame(i,"hour"),this.isAfter=(r,i)=>r>i,this.isAfterYear=(r,i)=>this.hasUTCPlugin()?!this.isSameYear(r,i)&&r.utc()>i.utc():r.isAfter(i,"year"),this.isAfterDay=(r,i)=>this.hasUTCPlugin()?!this.isSameDay(r,i)&&r.utc()>i.utc():r.isAfter(i,"day"),this.isBefore=(r,i)=>r<i,this.isBeforeYear=(r,i)=>this.hasUTCPlugin()?!this.isSameYear(r,i)&&r.utc()<i.utc():r.isBefore(i,"year"),this.isBeforeDay=(r,i)=>this.hasUTCPlugin()?!this.isSameDay(r,i)&&r.utc()<i.utc():r.isBefore(i,"day"),this.isWithinRange=(r,[i,o])=>r>=i&&r<=o,this.startOfYear=r=>this.adjustOffset(r.startOf("year")),this.startOfMonth=r=>this.adjustOffset(r.startOf("month")),this.startOfWeek=r=>this.adjustOffset(this.setLocaleToValue(r).startOf("week")),this.startOfDay=r=>this.adjustOffset(r.startOf("day")),this.endOfYear=r=>this.adjustOffset(r.endOf("year")),this.endOfMonth=r=>this.adjustOffset(r.endOf("month")),this.endOfWeek=r=>this.adjustOffset(this.setLocaleToValue(r).endOf("week")),this.endOfDay=r=>this.adjustOffset(r.endOf("day")),this.addYears=(r,i)=>this.adjustOffset(i<0?r.subtract(Math.abs(i),"year"):r.add(i,"year")),this.addMonths=(r,i)=>this.adjustOffset(i<0?r.subtract(Math.abs(i),"month"):r.add(i,"month")),this.addWeeks=(r,i)=>this.adjustOffset(i<0?r.subtract(Math.abs(i),"week"):r.add(i,"week")),this.addDays=(r,i)=>this.adjustOffset(i<0?r.subtract(Math.abs(i),"day"):r.add(i,"day")),this.addHours=(r,i)=>this.adjustOffset(i<0?r.subtract(Math.abs(i),"hour"):r.add(i,"hour")),this.addMinutes=(r,i)=>this.adjustOffset(i<0?r.subtract(Math.abs(i),"minute"):r.add(i,"minute")),this.addSeconds=(r,i)=>this.adjustOffset(i<0?r.subtract(Math.abs(i),"second"):r.add(i,"second")),this.getYear=r=>r.year(),this.getMonth=r=>r.month(),this.getDate=r=>r.date(),this.getHours=r=>r.hour(),this.getMinutes=r=>r.minute(),this.getSeconds=r=>r.second(),this.getMilliseconds=r=>r.millisecond(),this.setYear=(r,i)=>this.adjustOffset(r.set("year",i)),this.setMonth=(r,i)=>this.adjustOffset(r.set("month",i)),this.setDate=(r,i)=>this.adjustOffset(r.set("date",i)),this.setHours=(r,i)=>this.adjustOffset(r.set("hour",i)),this.setMinutes=(r,i)=>this.adjustOffset(r.set("minute",i)),this.setSeconds=(r,i)=>this.adjustOffset(r.set("second",i)),this.setMilliseconds=(r,i)=>this.adjustOffset(r.set("millisecond",i)),this.getDaysInMonth=r=>r.daysInMonth(),this.getWeekArray=r=>{const i=this.startOfWeek(this.startOfMonth(r)),o=this.endOfWeek(this.endOfMonth(r));let s=0,a=i;const l=[];for(;a<o;){const u=Math.floor(s/7);l[u]=l[u]||[],l[u].push(a),a=this.addDays(a,1),s+=1}return l},this.getWeekNumber=r=>r.week(),this.getYearRange=([r,i])=>{const o=this.startOfYear(r),s=this.endOfYear(i),a=[];let l=o;for(;this.isBefore(l,s);)a.push(l),l=this.addYears(l,1);return a},this.dayjs=sFe(xn,t),this.locale=t,this.formats=de({},oFe,n),xn.extend(W6e)}getDayOfWeek(t){return t.day()+1}}const bP=e=>!e.field||typeof e.field=="object"&&Object.keys(e.field).length===0?"Filter name cannot be empty.":e.type?e.value?!0:"Lookup Value cannot be empty.":"Operator cannot be empty.",hp=e=>t=>{const n=/{{[^{}]+}}/g;let r=!1;if(typeof t=="string"&&n.test(t)&&(r=!0,t=t.replace(n,"")),e.is_nullable===!0&&(t==null||t===void 0))return!0;if((r&&t!==""||!r)&&(e.is_nullable&&t!==""||!e.is_nullable))switch(e.type){case"text":case"long-text":case"encrypted":if(typeof t!="string")return`${e.name} should be a valid text input.`;if(t.length===0&&!e.is_nullable)return`${e.name} is a required field and cannot be empty.`;break;case"email":{if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t))return`Please provide a valid email address for ${e.name}.`;break}case"date-time":if(t!==""&&isNaN(Date.parse(t)))return`The value for ${e.name} should be a valid date and time format.`;break;case"number":case"currency":if(isNaN(t))return`${e.name} should be a numeric value.`;break;case"phone-number":{if(!/^\+?[0-9\s-]+$/.test(t))return`Please enter a valid phone number for ${e.name}.`;break}case"checkbox":if(typeof t!="boolean")return`${e.name} must be either true or false.`;break;case"dropdown":try{const i=e.selectable_items||[];if(Array.isArray(t)){if(!t.every(o=>i.includes(o)))return`All selected values for ${e.name} must be from the allowed options: ${i.join(", ")}.`}else if(typeof t=="string"){if(!i.includes(t))return`The value for ${e.name} must be one of the allowed options: ${i.join(", ")}.`}else return`${e.name} has an invalid input type. Please choose from the allowed options.`}catch{return`There seems to be an issue with the configuration of ${e.name}.`}break;case"link":{if(!/^((https?|ftp):\/\/)?(localhost|(\d{1,3}(\.\d{1,3}){3})|(([a-zA-Z\d-]+\.)+[a-zA-Z]{2,}))(\:\d+)?([\/?#][^\s]*)?$/.test(t))return`Please provide a valid URL for ${e.name}.`;break}case"json":try{typeof t=="string"&&JSON.parse(t)}catch{return`The value for ${e.name} should be a valid JSON string.`}break;default:return!0}return!0},vv=e=>{switch(e){case"text":return"Enter text";case"email":return"Enter email address";case"link":return"Enter URL";case"phone-number":return"Enter phone number";case"date-time":return"Select date and time";case"long-text":return"Enter long text";case"json":return"Enter JSON data";case"number":return"Enter number";case"currency":return"Enter amount";case"encrypted":return"Enter text (will be encrypted)";default:return"Enter value"}},aFe=({label:e="",required:t=!1,infoMsg:n="",helperText:r="",nodeId:i="",onChange:o,value:s,name:a,isLoop:l,...u})=>{const[c,d]=_.useState("Static"),{MCP_INTEGRATION_FORM:p}=aa();_.useEffect(()=>{if(typeof s=="string"&&s.trim().startsWith("{{")){d("Dynamic");return}if(s==null||s===""){d("Static");return}let m=!1;const g=s;if(g&&typeof g=="object")g instanceof Date?m=!isNaN(g.getTime()):"isValid"in g&&typeof g.isValid=="function"&&(m=g.isValid());else if(typeof g=="string"){const O=new Date(g);m=!isNaN(O.getTime())}d(m?"Static":"Dynamic")},[s]);const h=new Date(Date.now()-360*60*60*1e3),A=m=>{if(m==null||m===""||typeof m=="string"&&m.trim().startsWith("{{"))return null;if(m&&typeof m=="object"&&"isValid"in m&&typeof m.isValid=="function")return m.isValid()?m:null;if(typeof m=="string"||m instanceof Date){const g=xn(m);return g.isValid()?g:null}return null};return f.jsx(E.FormControl,{fullWidth:!0,children:f.jsxs(E.Stack,{children:[e&&f.jsxs(E.Stack,{direction:"row",justifyContent:"space-between",alignItems:"flex-end",children:[f.jsx(_r,{label:e,description:r,required:t}),!p&&f.jsx(E.Stack,{pb:.5,children:f.jsx(Ts,{variant:"normal",tabs:[{title:"Static"},{title:"Dynamic"}],selectedTab:c,setSelectedTab:()=>{c==="Static"?(o(""),d("Dynamic")):(o(h),d("Static"))}})})]}),c==="Static"?f.jsx(Xo.DateTimePicker,{slotProps:{textField:{error:!!u?.errorMsg,helperText:u?.errorMsg}},value:A(s),onChange:m=>o(m),...u}):f.jsx(ao,{id:i,language:"plaintext",value:s,isLoop:l,editorId:`${i}-${a}`,showSuggestions:!0,handleChange:m=>{o(m)},name:a,loading:null,...u})]})})},Ap=e=>{const{isLoading:t,data:n,name:r,type:i,id:o,label:s,helperTextForDropdown:a,helperTextForTextField:l,control:u,isMultiple:c=!1,onTabChange:d,value:p,eventName:h="",fieldName:A,isLoop:m=!1,viewOnly:g=!1,required:O=!1,refreshData:y,refreshing:T=!1,placeholder:v="",refreshTooltip:C="",handleSearchOptions:x=null,handleChange:b=null,onOpen:w=null,customValidations:D={},virtualized:I=!1}=e,{MCP_INTEGRATION_FORM:P}=aa(),[k,L]=_.useState(p&&!Et(p)&&cue(p)?"Dynamic":"Static"),N=M=>{L(M),d()};return f.jsx(E.Grid,{item:!0,xs:12,children:k==="Static"?f.jsx(Kt,{virtualized:I,required:O,name:r,control:u,meta:{options:n,displayProps:{loading:t,refreshing:T},displayName:s,searchFieldPlaceholder:"Search",placeholder:v||`Select ${s}`,description:Ir(i,a),handleSearchOptions:M=>{x&&x(M)}},validationRules:{...O&&{required:`${s} is required`},...D&&{validate:D}},viewOnly:g,id:o,multiple:c,renderFieldValue:M=>c?Array.isArray(M)?M:[]:n.some(B=>B.value===M)?M:"",getSelectedValue:M=>c?M.map(B=>n.find(V=>V.value===B)).filter(B=>B?.title):null,endItem:!P&&f.jsx(Ts,{variant:"normal",tabs:[{title:"Static"},{title:"Dynamic"}],sx:{marginBottom:.5,"& .MuiButtonBase-root":{px:.5,fontSize:"12px"},"& .MuiButtonBase-root.Mui-selected":{px:.5,fontSize:"12px"}},selectedTab:k,setSelectedTab:M=>N(M)}),refreshOptions:y?()=>{y(s)}:null,refreshTooltip:C,handleChange:M=>{b&&b(M)},onOpen:()=>{w&&w()}}):f.jsx(E.Grid,{item:!0,xs:12,children:f.jsx(E.FormControl,{fullWidth:!0,children:f.jsx(qn,{name:r,control:u,meta:{displayName:s,description:Ir(i,l),placeholder:v||`Enter ${s}`,htmlProps:{rightLabel:!P&&f.jsx(Ts,{variant:"normal",tabs:[{title:"Static"},{title:"Dynamic"}],sx:{marginBottom:.5,"& .MuiButtonBase-root":{px:.5,fontSize:"12px"},"& .MuiButtonBase-root.Mui-selected":{px:.5,fontSize:"12px"}},selectedTab:k,setSelectedTab:M=>N(M)})}},validationRules:{...O&&{required:`${s} is required`},...D&&{validate:D}},showSuggestions:!0,id:o,fullWidth:!0,editorId:`${i}-${h}-${A}`,isLoop:m,viewOnly:g,required:O,handleChange:M=>{b&&b(M)}})})})})},CP=xc(({control:e,label:t="",required:n=!1,showInfoIcon:r=!1,infoMsg:i="",helperText:o="",nodeId:s="",id:a,name:l,isLoop:u,validationRules:c={},inputProps:d=null,placeholder:p="",showSuggestions:h=!1,onChange:A,...m})=>{const[g,O]=_.useState("Static"),[y,T]=_.useState(!1),{setValue:v,watch:C}=Qn(),{MCP_INTEGRATION_FORM:x}=aa(),b=C(l);return _.useEffect(()=>{y||(typeof b=="string"&&b.trim().startsWith("{{")?O("Dynamic"):O("Static"))},[y,b]),f.jsx(E.FormControl,{fullWidth:!0,children:f.jsxs(E.Stack,{children:[t&&f.jsxs(E.Stack,{direction:"row",justifyContent:"space-between",alignItems:"flex-end",children:[f.jsx(_r,{label:t,description:o,required:n}),!x&&f.jsx(E.Stack,{pb:.5,children:f.jsx(Ts,{variant:"normal",tabs:[{title:"Static"},{title:"Dynamic"}],selectedTab:g,setSelectedTab:()=>{v(l,""),g==="Static"?(T(!0),O("Dynamic")):(T(!0),O("Static"))}})})]}),g==="Dynamic"?f.jsx(qn,{control:e,meta:{placeholder:p},validationRules:c,id:a,language:"plaintext",isLoop:u,editorId:`${s}-${l}`,showSuggestions:h,name:l,handleChange:()=>{T(!0)},loading:null,...m}):f.jsx(bn,{name:l,control:e,rules:{...c,valueAsNumber:!0},render:({field:w,fieldState:{error:D}})=>{const{onChange:I,...P}=w;return f.jsx(ao,{...m,...P,value:w.value??"",fullWidth:!0,type:"number",name:l,isLoop:u,inputProps:d||{step:1,min:1},placeholder:p,handleChange:k=>{T(!0);let L;k===""?(I(""),A?.("")):(L=Number(k),isNaN(L)||(I(L),A?.(L)))},error:!!D?.message,errorMsg:D?.message})}})]})})}),lFe=e=>{function t(q){return oue.filter(ie=>ie.appliesTo.includes(q)).map(ie=>({operator:ie.operator,filterName:ie.filterName}))}const{watch:n,setValue:r,control:i,getValues:o}=Qn(),s=n("properties"),{FRONTEND_URL:a,ENTITY_ID:l,viewOnly:u=!1,type:c,isLoop:d,id:p}=e,h=location.pathname.split("/");let A="";h.length>=5&&(A=h[2]);const m=E.useTheme(),g=ht.useDispatch(),[O,y]=_.useState([]),[T,v]=_.useState([]),[C,x]=_.useState([]),[b,w]=_.useState(!1),[D,I]=_.useState(!1),[P,k]=_.useState(!1),[L,N]=_.useState([]),[M,B]=_.useState([]),[V,W]=_.useState(!1),K=e.ATHENA_MAIN_URL,F=()=>{W(!0);const q=o("properties.database")||"",ie=o("properties.connector")||"boltic";let se=C.find(ue=>ue.id===q);!se&&q&&(se={id:q,resource_id:"boltic"});const pe=se?.resource_id||"boltic",ee={name:"Workflow Table",is_ai_generated_schema:!0},ne={};q&&(ne.db_id=q),ne.resource_id=pe,qt.post(K,{data:ee,params:ne}).then(ue=>{ue?.data?.data?.id&&(q==""&&z(ie),H(null,ue.data.data.id)),W(!1),g({type:Kn,payload:{open:!0,title:"Table created successfully",type:"success"}});const te=ue?.data?.data?.id,le=new URLSearchParams({connector:ie,database:q,resource:pe}).toString(),fe=`${a}/accounts/${l}/tables/create/${te}?${le}`;r("properties.table",""),r("properties.record_id",""),r("properties.updates",[]),r("properties.filters",[]),window.open(fe)}).catch(ue=>{W(!1),g({type:Kn,payload:{open:!0,title:"Table creation failed",type:"error"}}),An(ue,g)})};_.useEffect(()=>{r("properties.org_id",A||null)},[A]),_.useEffect(()=>{Y()},[]),_.useEffect(()=>{Et(s)||((s.event=="create_record"||s.event=="update_record"||s.event=="list_record"||s.event=="bulk_update")&&s.table&&s?.table&&U(s?.table),s?.record_id&&R(s?.table),s.event==="list_record"&&s?.filter?.field?.type&&t(s?.filter?.field?.type))},[]),_.useEffect(()=>{Et(s)||(s.event=="create_record"&&s.table&&U(s?.table),s&&s?.record_id&&R(s?.table))},[s.event]),_.useEffect(()=>{try{const q=s?.filters;if(Array.isArray(q)&&q.length){const ie=q.map(pe=>{const ee=pe?.field?.type,ne=Array.isArray(pe?.filterList)&&pe.filterList.length>0;return{...pe,filterList:ne&&ee?pe.filterList:ee?t(ee):[]}});ie.some((pe,ee)=>{const ne=q[ee],ue=Array.isArray(ne?.filterList)?ne.filterList.length:0,te=Array.isArray(pe?.filterList)?pe.filterList.length:0;return te>0&&te!==ue})&&r("properties.filters",ie,{shouldValidate:!1,shouldDirty:!1})}}catch{}},[s?.table,L,s?.filters]),_.useEffect(()=>{r("properties.org_id",A||null)},[A]);const H=async(q=null,ie=null,se=null,pe=null)=>{const ee=o("properties.database")||"";let ue=(pe??C).find(Oe=>Oe.id===ee);if(!ue&&ee&&(ue={id:ee,resource_id:"boltic"}),!ee||!ue){se&&se(!1);return}const te=Yt(K,`/list?db_id=${ee}`),le=[{field:"name",operator:"ILIKE",values:[""]},{field:"resource_id",operator:"=",values:[ue.resource_id||"boltic"]},{field:"db_id",operator:"=",values:[ee]}],fe={data:{page:{page_no:1,page_size:999},filters:le,sort:[{field:"created_at",direction:"desc"}]}};if(q&&Array.isArray(q)){const Oe=q.find(Ae=>Ae.field==="name");if(Oe){fe.data.filters[0]=Oe;const Ae=q.filter(ge=>!["name","resource_id","db_id"].includes(ge.field));fe.data.filters.push(...Ae)}}qt.post(te,fe).then(Oe=>{if(y(Oe?.data?.data||[]),ie){const{payload:Ae,...ge}=s||{};r("properties",{...ge,table:ie})}}).catch(Oe=>{An(Oe,g)}).finally(()=>{se&&se(!1)})},U=async q=>{const ie=s?.database||"";if(!ie){w(!1);return}w(!0);const se=Yt(K,`/${q}/fields/list?db_id=${ie}`);qt.post(se,{data:{page:{page_no:1,page_size:999},filters:[],sort:[{field:"name",direction:"desc"}]}}).then(pe=>{w(!1);const ee=pe?.data?.data.filter(ne=>ne.type!=="button");(pe?.data?.data.length==0||ee.length===0)&&An({message:"No field found in table"},g),N(pe?.data?.data||[])}).catch(pe=>{An(pe,g),w(!1)})},R=async(q,ie=null)=>{const se=s?.database||"";if(!se)return;const pe=Yt(K,`/${q}/records/list?db_id=${se}`),ee={data:{page:{page_no:1,page_size:999},filters:[],sort:[],field_names:["id"]}};ie&&(ee.data.filters=ie),qt.post(pe,ee).then(ne=>{B(ne?.data?.data||[])}).catch(ne=>{An(ne,g)})};function $(q){for(const ie in q)typeof q[ie]=="number"&&(q[ie]=q[ie].toString()),typeof q[ie]=="object"&&q[ie]!==null&&q[ie]!==void 0&&(Array.isArray(q[ie])||(q[ie]=JSON.stringify(q[ie])));return q}const j=async(q,ie)=>{if(q&&await U(q),ie){const se=s?.database||"";if(!se)return;const pe=Yt(K,`/${q}/records/${ie}?db_id=${se}&show_decrypted=true`),ee=await qt.get(pe).catch(ue=>{An(ue,g)}),ne=$(ee?.data?.data);r("properties.payload",{...s.payload,...ne})}},Y=async()=>{if(!K){I(!1);return}I(!0);const q=Yt(K,"/connectors/list");qt.post(q,{data:{page:{page_no:1,page_size:999},filters:[],sort:[]}}).then(ie=>{I(!1);const se=[{id:"boltic",name:"Boltic Cloud"},...ie?.data?.data||[]];v(se);const ee=n("properties")?.connector;if(!ee&&se.length>0){const ne=se[0].id;r("properties.connector",ne),z(ne)}else ee&&z(ee)}).catch(ie=>{An(ie,g),I(!1)})},z=async q=>{if(!q)return[];k(!0);try{const ie={page:{page_no:1,page_size:1e3},filters:[{field:"status",operator:"=",values:["ACTIVE"]}],sort:[]},se=`${K}/databases/list?connector_id=${q}`,ee=(await qt.post(se,{data:ie}))?.data?.data||[];x(ee);const ue=n("properties")?.database;if(!ue&&ee.length>0){const te=ee[0].id;r("properties.database",te),setTimeout(()=>{H()},100)}else ue&&setTimeout(()=>{H(null,null,null,ee)},100);return ee}catch(ie){return An(ie,g),[]}finally{k(!1)}},G=(q,ie)=>{r(`properties.payload.${q}`,ie)},Q=q=>{if((s||{})?.payload){const{[q]:ie,...se}=(s||{}).payload;r("properties.payload",se)}},X=[{id:!0,name:"True"},{id:!1,name:"False"}],Z=q=>{if(["created_at","updated_at","id"].includes(q.name))return null;const ie=JSON.parse(JSON.stringify(s?.payload?.[q.name]??null)),se=ne=>{G(q.name,ne)},pe=(ne,ue=!1,te="xs")=>ne==="text"?f.jsx(E.Grid,{container:!0,gap:1,children:f.jsx(E.Grid,{item:!0,xs:12,children:f.jsx(E.FormControl,{fullWidth:!0,children:f.jsx(qn,{viewOnly:u,editorId:`bolticTableAcitivity-${q.name}`,id:e.id,isLoop:e.isLoop,language:"plaintext",name:`properties.payload.${q.name}`,value:ie,showSuggestions:!0,variant:"outlined",type:ne,required:!q.is_nullable,size:te,control:i,meta:{displayName:ne=="text"?q.name:null,description:q.help_text,placeholder:vv(q.type)},validationRules:{validate:hp(q)},handleChange:le=>{const{value:fe}=le;se(fe)}})})},q.name)}):f.jsx(E.Grid,{container:!0,gap:1,children:f.jsx(E.Grid,{item:!0,xs:12,children:f.jsx(E.FormControl,{fullWidth:!0,children:f.jsx(CP,{control:i,name:`properties.payload.${q.name}`,label:q.name,helperText:q.help_text,placeholder:vv(q.type),required:!q.is_nullable,showSuggestions:!0,isLoop:e.isLoop,id:e.id,nodeId:`bolticTableAcitivity-${q.name}`,validationRules:{validate:hp(q)},onChange:le=>{se(le)},disabled:u})})},q.name)}),ee=()=>f.jsx(E.Grid,{container:!0,gap:1,children:f.jsx(E.Grid,{item:!0,xs:12,children:f.jsx(E.FormControl,{fullWidth:!0,children:f.jsx(bn,{name:`properties.payload.${q.name}`,control:i,rules:{validate:hp(q)},render:({field:ne,fieldState:{error:ue}})=>{let te=null;if(ie)if(typeof ie=="string"&&ie.trim().startsWith("{{"))te=ie;else{const le=xn(ie);te=le.isValid()?le:null}return f.jsx(aFe,{...ne,disabled:u,nodeId:`bolticTableAcitivity-${q.name}`,id:e.id,isLoop:e.isLoop,label:q.name,name:q.name,value:te,showSuggestions:!0,helperText:q.help_text,onChange:le=>{if(typeof le=="string"||le===null)ne.onChange(le),se(le);else{const fe=le.toISOString();ne.onChange(fe),se(fe)}},variant:"outlined",required:!q.is_nullable,errorMsg:ue?.message})}})})},q.name)});switch(q.type){case"text":case"email":case"link":case"phone-number":case"encrypted":return pe("text");case"date-time":return f.jsx(Xo.LocalizationProvider,{dateAdapter:Jl,children:ee()});case"long-text":case"json":return pe("text",!0,"sm");case"number":case"currency":return pe("number");case"checkbox":return f.jsx(E.Grid,{container:!0,gap:1,children:f.jsx(E.Grid,{item:!0,xs:12,children:f.jsx(E.FormControl,{fullWidth:!0,children:f.jsx(Ap,{viewOnly:u,id:e.id,helperTextForTextField:"",isLoading:!1,label:q.name,type:e.type,helperTextForDropdown:"Select True or False",isMultiple:!1,data:Ur(X),value:ie,placeholder:"Select true or false",handleChange:ne=>{const{value:ue}=ne;se(ue)},onTabChange:()=>Q(q.name),eventName:s.event,fieldName:q.name,isLoop:e.isLoop,required:!q.is_nullable,name:`properties.payload.${q.name}`,control:i,customValidations:{validate:hp(q)}})})},q.name)});case"dropdown":return q.multiple_selections?f.jsx(E.Grid,{container:!0,gap:1,children:f.jsx(E.Grid,{item:!0,xs:12,children:f.jsx(E.FormControl,{fullWidth:!0,children:f.jsx(Ap,{viewOnly:u,helperTextForDropdown:q.help_text,helperTextForTextField:q.help_text,id:e.id,isLoading:!1,label:q.name,type:e.type,isMultiple:q.multiple_selections,data:q.selectable_items?q.selectable_items.map(ne=>({value:ne,title:ne})):[],value:(Array.isArray(ie)&&ie?.length,ie),onTabChange:()=>Q(q.name),eventName:s.event,fieldName:q.name,placeholder:vv(q.type),isLoop:e.isLoop,handleChange:ne=>{const{value:ue}=ne;Array.isArray(ue)&&ue.length?r(`properties.payload.${q.name}`,Et(ue)?null:ue.map(te=>te)):ue[0]?.id?se(ue[0]?.id):se(null)},name:`properties.payload.${q.name}`,control:i,customValidations:{customValidation:hp(q)}})})},q.name)}):f.jsx(E.Grid,{container:!0,gap:1,children:f.jsx(E.Grid,{item:!0,xs:12,children:f.jsx(E.FormControl,{fullWidth:!0,children:f.jsx(Ap,{viewOnly:u,id:e.id,helperTextForDropdown:q.help_text,helperTextForTextField:q.help_text,isLoading:!1,label:q.name,type:e.type,isMultiple:!1,data:q.selectable_items?q.selectable_items.map(ne=>({value:ne,title:ne})):[],value:Array.isArray(ie)&&ie?.length?ie[0]?.id?ie[0]?.id:ie?ie?.[0]:"":ie,placeholder:vv(q.type),onTabChange:()=>Q(q.name),eventName:s.event,fieldName:q.name,isLoop:e.isLoop,handleChange:ne=>{const{value:ue}=ne;se(ue)},name:`properties.payload.${q.name}`,control:i,customValidations:{customValidation:hp(q)}})})},q.name)});case"vector":case"halfvec":case"sparsevec":return f.jsx(E.Grid,{container:!0,gap:1,children:f.jsx(E.Grid,{item:!0,xs:12,children:f.jsx(E.FormControl,{fullWidth:!0,children:f.jsx(qn,{viewOnly:u,editorId:`bolticTableAcitivity-${q.name}`,id:p,isLoop:d,language:"json",name:`properties.payload.${q.name}`,value:ie,showSuggestions:!0,variant:"outlined",multiline:!0,rows:3,required:!q.is_nullable,control:i,meta:{displayName:q.name,description:q.help_text||(q.type==="sparsevec"?'Enter sparse vector (e.g. "{1:1,3:2,5:3}/5"':"Enter vector (e.g. [1.2, 3.4, 5.6])"),placeholder:q.type==="sparsevec"?'Enter sparse vector (e.g. "{1:1,3:2,5:3}/5")':"Enter vector (e.g. [1.2, 3.4, 5.6])"},validationRules:{validate:hp(q)},handleChange:ne=>{const{value:ue}=ne;se(ue)}})})},q.name)});default:return null}},J=Ia((q,ie=null)=>{H(q,null,ie)},300),oe=Ia((q,ie)=>{R(q,ie)},300);return f.jsxs(E.Stack,{gap:2.5,children:[f.jsx(no,{children:f.jsx(E.Grid,{container:!0,gap:1,children:f.jsx(E.Grid,{item:!0,xs:12,children:f.jsx(E.FormControl,{fullWidth:!0,children:f.jsx(Kt,{name:"properties.event",control:i,meta:{options:Xle,displayName:"Event",searchFieldPlaceholder:"Search Event",placeholder:"Select Event"},validationRules:{required:"Event is required"},viewOnly:u,fullWidth:!0,id:"event",required:!0,handleChange:q=>{const{value:ie}=q;r("properties.event",ie),r("properties.connector",""),r("properties.database",""),r("properties.table",""),r("properties.record_id",""),r("properties.updates",[]),r("properties.filters",[]),v([]),x([]),y([]),N([]),ie&&ie!=="sql_query"&&Y()}})})})})}),s?.event&&f.jsx(E.Divider,{}),s?.event&&f.jsx(Mr,{children:f.jsxs(E.Grid,{container:!0,gap:1.5,children:[s?.event&&s?.event!="sql_query"&&f.jsx(E.Grid,{item:!0,xs:12,children:f.jsx(E.FormControl,{fullWidth:!0,children:f.jsx(Kt,{name:"properties.connector",control:i,meta:{options:(T||[]).map(q=>({value:q.id,title:q.name||q.id})),displayName:"Connector",searchFieldPlaceholder:"Search Connector",placeholder:"Select Connector",isLoading:D},validationRules:{required:"Connector is required"},viewOnly:u,fullWidth:!0,id:"connector",required:!0,handleChange:q=>{const{value:ie}=q;r("properties.connector",ie),r("properties.database",""),r("properties.table",""),r("properties.record_id",""),r("properties.updates",[]),r("properties.filters",[]),x([]),y([]),N([]),ie&&z(ie)}})})}),s?.event&&s?.event!="sql_query"&&s?.connector&&f.jsxs(E.Grid,{item:!0,xs:12,children:[f.jsx(E.FormControl,{fullWidth:!0,children:f.jsx(Kt,{name:"properties.database",control:i,meta:{options:(C||[]).map(q=>({value:q.id,title:q.db_name||q.id,...s?.connector&&s.connector!=="boltic"&&q?.resource_name?{description:q.resource_name}:{}})),displayName:"Database",searchFieldPlaceholder:"Search Database",placeholder:"Select Database",isLoading:P},viewOnly:u,fullWidth:!0,id:"database",required:!0,handleChange:q=>{const{value:ie}=q;r("properties.database",ie),r("properties.table",""),r("properties.record_id",""),r("properties.updates",[]),r("properties.filters",[]),y([]),N([]),ie&&H()}})}),!P&&C.length===0&&f.jsx(E.Typography,{variant:"caption",sx:{mt:.5,display:"block",color:"text.secondary"},children:"No database is present, please create your first table to create a database."})]}),s?.event&&s?.event!="sql_query"&&(s?.database||s?.database=="")&&f.jsx(E.Grid,{item:!0,xs:12,children:f.jsx(E.Grid,{container:!0,gap:1.5,children:f.jsx(E.Grid,{item:!0,xs:12,children:f.jsx(SP,{viewOnly:u,type:"bolticTableActivity",value:s.table||"",title:"Table",show:!0,buttonName:"Create New Table",loadingState:V,loadDataFromApi:async q=>{O?.length||await H(),q(!1)},required:!0,onTextInputChange:async(q,ie)=>{q(!0),J([{field:"name",operator:"ILIKE",values:[ie]}],q)},handleChange:q=>{const{value:ie}=q;N([]),r("properties.table",ie),(s?.event==="bulk_update"||s?.event==="list_record")&&(r("properties.updates",[]),r("properties.filters",[])),r("properties.record_id",""),s?.event=="create_record"||s?.event=="list_record"||s?.event=="bulk_update"?ie&&U(ie):(s?.event=="delete_record"||s?.event=="update_record")&&R(ie)},onAddButtonClick:F,name:"properties.table",options:Ur(O),validationRules:{required:"Table is required"}})})})}),f.jsx(E.Grid,{item:!0,xs:12,children:(s?.event==="delete_record"||s?.event==="update_record")&&s?.table&&f.jsx(E.Grid,{container:!0,gap:1,children:f.jsx(E.Grid,{item:!0,xs:12,children:f.jsx(E.FormControl,{fullWidth:!0,children:f.jsx(Kt,{required:!0,name:"properties.record_id",control:i,viewOnly:u,id:p,meta:{options:(()=>{const q=[...M];return s.record_id&&!M.some(ie=>ie.id===s.record_id)&&q.unshift({id:s.record_id}),q.map(ie=>({value:ie.id,title:ie.id}))})(),displayName:"Record ID",searchFieldPlaceholder:"Search Record ID",placeholder:"Select a record ID",handleSearchOptions:q=>{if(s?.table){const ie=[{field:"id",operator:"ILIKE",values:[q]}];oe(s.table,ie)}}},validationRules:{required:"Record ID is required"},renderFieldValue:q=>{const ie=[...M];return s.record_id&&!M.some(pe=>pe.id===s.record_id)&&ie.unshift({id:s.record_id}),ie.map(pe=>({value:pe.id,title:pe.id})).some(pe=>pe.value===q)?q:""},handleChange:q=>{const{value:ie}=q;s.event==="update_record"&&j(s.table,ie),r("properties.record_id",ie)}},s.event)})},"record_id")})}),(s?.event==="create_record"&&s?.table||s?.event==="update_record"&&s?.table&&s?.record_id)&&f.jsxs(f.Fragment,{children:[b&&f.jsx(E.Stack,{sx:{width:"100%",justifyContent:"center",alignItems:"center",height:"5rem",margin:"0 0 2rem 0"},children:f.jsx(E.CircularProgress,{})}),L.length>0&&JSON.parse(JSON.stringify(L)).map(q=>Z(q))]}),s?.event==="list_record"&&s?.table&&f.jsxs(E.Grid,{container:!0,children:[f.jsx(E.Grid,{item:!0,xs:12,children:f.jsx(E.FormControl,{fullWidth:!0,children:f.jsx(CP,{control:i,name:"properties.page",viewOnly:u,editorId:"bolticTableAcitivity-page",id:e.id,isLoop:e.isLoop,language:"plaintext",label:"Page Number",showSuggestions:!0,placeholder:"Enter a page number",required:!0,variant:"outlined",inputProps:{min:1,max:1e4},helperText:`Which set of records you want to receive (starting from 1).
|
|
437
437
|
e.g entering 2 will give you the next set of records after the first 10.`})})}),f.jsx(E.Grid,{item:!0,sx:{mt:1},xs:12,children:f.jsx(E.FormControl,{fullWidth:!0,children:f.jsx(CP,{control:i,viewOnly:u,editorId:"bolticTableAcitivity-limit",id:e.id,isLoop:e.isLoop,language:"plaintext",label:"Page Size",name:"properties.limit",value:s.limit??1e3,showSuggestions:!0,placeholder:"Enter a pagesize",required:!0,variant:"outlined",inputProps:{min:1,max:1e3},helperText:`How many records you want to receive at once.
|
|
438
438
|
e.g entering 10 will return 10 records.
|
|
439
|
-
Maximum supported page size: 1000`})})})]}),s?.event=="bulk_update"&&s?.table&&L.length>0&&f.jsxs(E.Grid,{container:!0,gap:1,children:[f.jsx(E.Grid,{item:!0,xs:12,children:f.jsx(E.Typography,{variant:"smMedium",children:"Update Fields"})}),s.updates?.map((q,ie)=>f.jsx(E.Paper,{sx:{width:"100%"},children:f.jsxs(E.Grid,{container:!0,alignItems:"end",children:[f.jsx(E.Grid,{item:!0,xs:12,sm:4,children:f.jsx(E.FormControl,{fullWidth:!0,children:f.jsx(Kt,{required:!0,name:`properties.updates.${ie}.field`,control:i,meta:{options:L.filter(se=>!["button"].includes(se.type)&&!["id","created_at","updated_at"].includes(se.name)).map(se=>({value:JSON.stringify({type:se.type,name:se.name,id:se.id,...se.type==="dropdown"&&{multiple_selections:se.multiple_selections,selectable_items:se.selectable_items}}),title:se.name})),displayName:"Field Name",searchFieldPlaceholder:"Search Field Name",placeholder:"Select Field Name"},validationRules:{required:"Field Name is required"},viewOnly:u,id:e.id,handleChange:se=>{const{value:pe}=se,ee=JSON.parse(pe);r(`properties.updates.${ie}.field`,ee)},renderFieldValue:se=>{if(!se?.id)return;if(typeof se=="string")return se;const pe=L.filter(ee=>!["button"].includes(ee.type)&&!["id","created_at","updated_at"].includes(ee.name)).map(ee=>({value:JSON.stringify({type:ee.type,name:ee.name,id:ee.id,...ee.type==="dropdown"&&{multiple_selections:ee.multiple_selections,selectable_items:ee.selectable_items}}),id:ee.id})).find(ee=>typeof se=="object"&&se.id&&ee.id===se.id||ee.name===se.name&&ee.type===se.type);return pe?pe.value:""}})})}),f.jsxs(E.Grid,{item:!0,xs:12,sm:7,sx:{pl:1,pr:1},children:[q?.field?.multiple_selections!==!0&&f.jsx(E.FormControl,{fullWidth:!0,children:f.jsx(E.Box,{sx:{overflow:"hidden"},children:f.jsx(qn,{id:p,name:`properties.updates.${ie}.value`,control:i,meta:{displayName:"Value",placeholder:"Enter new value"},viewOnly:u,editorId:`${c}-base_url-${d}`,showSuggestions:!0,isLoop:d,variant:"outlined"})})}),q?.field?.type==="dropdown"&&q?.field?.multiple_selections===!0&&f.jsx(E.FormControl,{fullWidth:!0,children:f.jsx(E.Box,{sx:{overflow:"hidden",p:"4px"},children:f.jsx(Ap,{viewOnly:u,helperTextForDropdown:"",helperTextForTextField:"",id:p,isLoading:!1,label:"Value",type:c,isMultiple:q.field.multiple_selections,data:q.field.selectable_items?q.field.selectable_items.map(se=>({title:se,value:se})):[],value:(Array.isArray(q?.value)&&q?.value.length,q?.value),placeholder:"Enter new value",handleChange:se=>{const{value:pe}=se;r(`properties.updates.${ie}.value`,pe)},onTabChange:()=>{r(`properties.updates.${ie}.value`,"")},eventName:s.event,fieldName:`update_value_${ie}`,isLoop:e.isLoop,name:`properties.updates.${ie}.value`,control:i},s.event)})})]}),f.jsx(E.Grid,{item:!0,xs:12,sm:1,sx:{textAlign:"center",alignSelf:"center"},children:f.jsx(E.IconButton,{disabled:u,sx:{p:"8px",border:se=>`1px solid ${se.palette.grey.brainstem}`,borderRadius:8,fontSize:"0.9rem",display:"flex",mt:2,"&:hover":{backgroundColor:"transparent"}},color:"error",onClick:()=>{r("properties.updates",s.updates.filter((se,pe)=>pe!==ie))},children:f.jsx(je,{src:"ic_delete",width:m.icons.sm,height:m.icons.sm,sx:{path:{fill:m.palette.error.main}}})})})]})},ie)),f.jsx(E.Box,{sx:{textAlign:"right",width:"100%"},children:f.jsx(E.IconButton,{disabled:u,onClick:()=>{const q=s.updates||[];r("properties.updates",[...q,{field:{},value:""}],{shouldValidate:!0})},sx:{mt:"5px",p:.75,border:q=>`1px solid ${q.palette.grey.brainstem}`,borderRadius:8,fontSize:"1rem"},color:"primary",children:f.jsx(je,{src:"ic_plus",width:m.icons.md,height:m.icons.md,sx:{path:{fill:m.palette.primary.main}}})})})]}),L.filter(q=>q.type!=="button"&&q.type!=="json").length>0&&f.jsxs(E.Grid,{sx:{mt:1},children:[(s?.event==="list_record"||s?.event==="bulk_update")&&s?.table&&f.jsx(E.Typography,{variant:"smMedium",children:"Filters"}),(s?.event==="list_record"||s?.event==="bulk_update")&&s?.table&&f.jsxs(f.Fragment,{children:[(s?.filters?.length===0||!s?.filters)&&f.jsx(E.Box,{sx:{marginTop:"10px",textAlign:"right"},children:f.jsx(E.IconButton,{disabled:u,onClick:()=>{r("properties.filters",[...s.filters||[],{field:{},type:"",value:"",filterList:[]}],{shouldValidate:!0})},sx:{mt:"5px",p:.75,border:q=>`1px solid ${q.palette.grey.brainstem}`,borderRadius:8,fontSize:"1rem"},color:"primary",children:f.jsx(je,{src:"ic_plus",width:m.icons.md,height:m.icons.md,sx:{path:{fill:m.palette.primary.main}}})})}),s.filters?.map((q,ie)=>f.jsxs(E.Box,{sx:{margin:ie!==0?"30px 0px 0px 0px":"0"},children:[f.jsxs(E.Stack,{gap:1.5,sx:{p:"12px 8px",mb:2,borderRadius:4,alignItems:"flex-end",border:`1px solid ${m.palette.grey.outlined.border}`},children:[f.jsx(E.IconButton,{disabled:u,sx:{width:"fit-content",p:"8px",border:se=>`1px solid ${se.palette.grey.brainstem}`,borderRadius:8,fontSize:"0.9rem","&:hover":{backgroundColor:"transparent"}},color:"error",onClick:()=>{r("properties.filters",s.filters.filter((se,pe)=>pe!==ie))},children:f.jsx(je,{src:"ic_delete",width:m.icons.sm,height:m.icons.sm,sx:{path:{fill:m.palette.error.main}}})}),f.jsx(E.FormControl,{fullWidth:!0,children:f.jsx(Kt,{name:`properties.filters.${ie}.field`,control:i,meta:{options:L.filter(se=>(se.type==="encrypted"?se.is_deterministic:!0)&&se.type!=="button"&&se.type!=="json").map(se=>({value:JSON.stringify({type:se.type,name:se.name,id:se.id}),title:se.name})),displayName:"Field Name",searchFieldPlaceholder:"Search Field Name",placeholder:"Select Field Name"},validationRules:{required:"Field Name is required",validate:bP(q)},handleChange:se=>{const{value:pe}=se,ee=JSON.parse(pe),ne=[...s.filters],ue=t(ee.type);r(`properties.filters.${ie}`,{...ne[ie],field:ee,filterList:ue})},renderFieldValue:se=>!se?.id||typeof se=="string"?se:L.filter(ee=>(ee.type==="encrypted"?ee.is_deterministic:!0)&&ee.type!=="button"&&ee.type!=="json").map(ee=>({value:JSON.stringify({type:ee.type,name:ee.name,id:ee.id}),id:ee.id})).find(ee=>ee.id===se.id)?.value||"",renderValue:se=>{const pe=L.find(ee=>ee.id===se);return pe?pe.name:""},viewOnly:u,fullWidth:!0,id:`field_name_${ie}`,required:!0})}),f.jsx(E.FormControl,{fullWidth:!0,children:f.jsx(Kt,{name:`properties.filters.${ie}.type`,control:i,meta:{options:q?.filterList?.map(se=>({value:se.operator,title:se.filterName})),displayName:"Operator",searchFieldPlaceholder:"Search Operator",placeholder:"Select Operator"},validationRules:{required:"Operator is required",validate:bP(q)},handleChange:se=>{const{value:pe}=se,ee=[...s.filters];ee[ie]={...ee[ie],type:pe,value:pe==="IS EMPTY"?"":ee[ie]?.value},r(`properties.filters.${ie}`,ee[ie])},viewOnly:u,fullWidth:!0,id:`operator_${ie}`,required:!0,value:q?.type||""})}),q?.type!=="IS EMPTY"&&f.jsx(E.Grid,{container:!0,gap:1,children:f.jsx(E.Grid,{item:!0,xs:12,children:f.jsx(E.FormControl,{fullWidth:!0,children:f.jsx(qn,{name:`properties.filters.${ie}.value`,control:i,meta:{displayName:"Lookup Value",placeholder:"Enter Lookup Value"},validationRules:{required:"Lookup Value is required",validate:bP(q)},viewOnly:u,editorId:`bolticTableAcitivity-filter-text-${ie}`,id:e.id,isLoop:d,language:"plaintext",required:!0,value:q?.value||"",showSuggestions:!0,helperText:"",placeholder:"",variant:"outlined",type:"text"})})})})]}),s.filters?.length-1==ie&&s?.filters?.length<5&&f.jsx(E.Box,{sx:{marginTop:"10px",textAlign:"right"},children:f.jsx(E.IconButton,{disabled:u,onClick:()=>{r("properties.filters",[...s.filters,{field:{},type:"",value:"",filterList:[]}])},sx:{mt:"5px",p:.75,border:se=>`1px solid ${se.palette.grey.brainstem}`,borderRadius:8,fontSize:"1rem"},color:"primary",children:f.jsx(je,{src:"ic_plus",width:m.icons.md,height:m.icons.md,sx:{path:{fill:m.palette.primary.main}}})})})]},`filter-${ie}`))]})]}),!d&&f.jsx(E.Grid,{item:!0,xs:12,children:f.jsx(Bi,{viewOnly:u,type:c})})]})})]})},uFe=[{label:"DISTINCT",type:"keyword"},{label:"COUNT(*)",type:"function"},{label:"SUM()",type:"function"},{label:"AVG()",type:"function"},{label:"MAX()",type:"function"},{label:"MIN()",type:"function"}],cFe=[{label:"WHERE",type:"keyword"},{label:"JOIN",type:"keyword"},{label:"LEFT JOIN",type:"keyword"},{label:"RIGHT JOIN",type:"keyword"},{label:"INNER JOIN",type:"keyword"},{label:"GROUP BY",type:"keyword"},{label:"ORDER BY",type:"keyword"},{label:"LIMIT",type:"keyword"},{label:"HAVING",type:"keyword"}],dFe=[{label:"FROM",type:"keyword"},{label:",",type:"separator"}],fFe=[{label:"ON",type:"keyword"},{label:"AS",type:"keyword"}],pFe=[{label:"HAVING",type:"keyword"},{label:"ORDER BY",type:"keyword"},{label:"LIMIT",type:"keyword"},{label:"ASC",type:"keyword"},{label:"DESC",type:"keyword"}],hFe=["COUNT","SUM","AVG","MAX","MIN"],AFe=(e,t,n)=>{const r=e.toLowerCase();if(/select\s+$/i.test(r))return{type:"AFTER_SELECT"};const i=/from\s+"?([\w\s-]+)"?(?:\s+(?:as\s+\w+)?)?\s*$/i.exec(r),o=Object.keys(t).find(c=>c.toLowerCase()===i?.[1]?.toLowerCase());if(i&&o)return{type:"AFTER_FROM_TABLE",tableName:o};if(/from\s+("?[\w]*"?\s*)$/i.test(r))return{type:"AFTER_FROM"};if(/join\s+$/i.test(r))return{type:"AFTER_JOIN"};if(/where\s+$/i.test(r))return{type:"AFTER_WHERE"};if(/on\s+$/i.test(r))return{type:"AFTER_ON"};if(/insert\s+into\s+(""|"|$)/i.test(r))return{type:"AFTER_INSERT_INTO"};if(/update\s+$/i.test(r))return{type:"AFTER_UPDATE"};if(/set\s+$/i.test(r))return{type:"AFTER_SET"};if(/delete\s+from\s+$/i.test(r))return{type:"AFTER_DELETE_FROM"};const s=/"(?<table>[^"]+)"\.(?=[\w"]*$)/i.exec(r)||/(?<table>\w+)\.(?=[\w"]*$)/i.exec(r);if(s?.groups?.table)return{type:"AFTER_TABLE_DOT",tableName:s.groups.table};if(/group\s+by\s+$/i.test(r))return{type:"AFTER_GROUP_BY"};if(/order\s+by\s+$/i.test(r))return{type:"AFTER_ORDER_BY"};if(/join\s+\w+\s+(on\s+)?$/i.test(r))return{type:"JOIN_CONDITION"};if(/select\s+\*/i.test(r)&&!/from\s+/i.test(r))return{type:"AFTER_SELECT_STAR"};if(/select(?!.*from\b).+$/is.test(r))return{type:"SELECT_COLUMN_LIST"};const a=/join\s+(\w+)(?:\s+(?:as\s+\w+)?)?\s*$/i.exec(r);if(a&&Object.keys(t).includes(a[1]))return{type:"AFTER_JOIN_TABLE",tableName:a[1]};if(/from\s+\w+\s+as\s+\w+\s*$/i.test(r)||/from\s+\w+\s+\w+\s*$/i.test(r))return{type:"AFTER_TABLE_ALIAS"};const u=n(/[\w\.\-"]*/);return u&&u.from!==u.to?{type:"PARTIAL_WORD",word:u.text.toLowerCase()}:{type:"DEFAULT"}},mFe=(e,t)=>{const n=[...e.matchAll(/from\s+"([^"]+)"|from\s+(\w+)/gi)],r=[...e.matchAll(/join\s+"([^"]+)"|join\s+(\w+)/gi)],i=[];return n.forEach(o=>{const s=o[1]||o[2];s&&t[s]&&i.push(s)}),r.forEach(o=>{const s=o[1]||o[2];s&&t[s]&&i.push(s)}),i.length?[...new Set(i)]:Object.keys(t)},gFe=(e,t)=>{if(e.length<2)return[];const n=[],r=e[e.length-1];for(let i=0;i<e.length-1;i++){const o=e[i];for(const s of t[o]||[]){s.endsWith("_id")&&s.replace("_id","")===r&&n.push({label:`"${o}.${s}" = ${r}.id`,type:"join_condition"});for(const a of t[r]||[])a.endsWith("_id")&&a.replace("_id","")===o&&n.push({label:`"${r}.${a}" = ${o}.id`,type:"join_condition"})}}return n},EFe=wo(e=>{const[t,n]=_.useState(!0),r=E.useTheme(),{watch:i,setValue:o,control:s}=Qn(),{ATHENA_MAIN_URL:a,onChange:l,suggestionsData:u,viewOnly:c=!1,isLoop:d,name:p,WORKFLOW_URLS:h}=e,A=i("properties")||{},[m,g]=_.useState(null),O=_.useRef(null),y=ht.useDispatch(),[T,v]=_.useState([]),[C,x]=_.useState({}),[b,w]=_.useState([]),[D,I]=_.useState([]),[P,k]=_.useState([]),L=_.useRef(null),N=_.useRef(null),M=_.useRef(null),[B,V]=_.useState({}),[W,K]=_.useState(!1),[F,H]=_.useState(""),[U,R]=_.useState(!1),[$,j]=_.useState(""),[Y,z]=_.useState(""),[G,Q]=_.useState(!1),[X,Z]=_.useState([]),[J,oe]=_.useState(""),[q,ie]=_.useState(""),[se,pe]=_.useState(""),[ee,ne]=_.useState(""),[ue,te]=_.useState(!1),[le,fe]=_.useState(""),[Oe,Ae]=_.useState(""),[ge,we]=_.useState(!1),[Ee,ye]=_.useState(!1),[Ve,Qe]=_.useState(!1),[Ue,nt]=_.useState(!1),[Ge,Xe]=_.useState([]),[Pe,Ke]=_.useState(uFe),[Je,ve]=_.useState(cFe),[_e,Ie]=_.useState(dFe),[re,me]=_.useState(fFe),[Ce,Le]=_.useState(pFe),[Me,qe]=_.useState(hFe),dt=E.debounce(Bt=>{Lt(Bt=Bt)},300),Tt=_.useRef([]);Tt.current=T;const{loopSuggestionsData:xe={}}=ht.useSelector(Bt=>Bt.loopActivity);_.useEffect(()=>{(async()=>{if(a)try{const Zt=Yt(a,"/query/editor-keywords"),Rn=(await qt.get(Zt)).data?.data||{};if(Rn.SQL_KEYWORDS&&Array.isArray(Rn.SQL_KEYWORDS)){const yn=Rn.SQL_KEYWORDS.map(Un=>({label:Un,type:"keyword"}));Xe(yn)}Rn.DEFAULT_SELECT_FUNCTION_OPTIONS&&Ke(Rn.DEFAULT_SELECT_FUNCTION_OPTIONS),Rn.SQL_POST_TABLE_KEYWORDS&&ve(Rn.SQL_POST_TABLE_KEYWORDS),Rn.SQL_AFTER_SELECT_STAR_OPTIONS&&Ie(Rn.SQL_AFTER_SELECT_STAR_OPTIONS),Rn.SQL_AFTER_JOIN_TABLE_OPTIONS&&me(Rn.SQL_AFTER_JOIN_TABLE_OPTIONS),Rn.SQL_AFTER_GROUP_ORDER_OPTIONS&&Le(Rn.SQL_AFTER_GROUP_ORDER_OPTIONS),Rn.SQL_FUNCTION_TEMPLATES&&qe(Rn.SQL_FUNCTION_TEMPLATES)}catch{}})()},[a]),_.useEffect(()=>{se&&(async()=>{try{const Zt=se||"",Zn=Zt?`${a}/query/suggestions?db_id=${Zt}`:`${a}/query/suggestions`,yn=(await qt.get(Zn)).data?.data||{},Un=Object.keys(yn);x(yn);const Jn=Un.map(Hn=>({label:`"${Hn}"`,type:"table"}));v(Jn)}catch{}})()},[se]);const ut=async()=>{if(!a){Qe(!1);return}Qe(!0);const Bt=Yt(a,"/connectors/list");qt.post(Bt,{data:{page:{page_no:1,page_size:999},filters:[],sort:[]}}).then(Zt=>{Qe(!1);const Zn=[{id:"boltic",name:"Boltic Cloud"},...Zt?.data?.data||[]];I(Zn);const yn=i("properties")?.connector;if(!yn&&Zn.length>0){const Un=Zn[0].id;o("properties.connector",Un),ie(Un),mt(Un)}else yn&&(ie(yn),mt(yn))}).catch(Zt=>{An(Zt,y),Qe(!1)})},mt=async Bt=>{if(!Bt)return[];nt(!0);try{const Zt={page:{page_no:1,page_size:1e3},filters:[{field:"status",operator:"=",values:["ACTIVE"]}],sort:[]},Zn=`${a}/databases/list?add_default_if_missing=true&connector_id=${Bt}`,yn=(await qt.post(Zn,{data:Zt}))?.data?.data||[];k(yn);const Jn=i("properties")?.database;if(!Jn&&yn.length>0){const Hn=yn[0].id;o("properties.database",Hn),pe(Hn),setTimeout(()=>{Lt()},100)}else Jn&&(pe(Jn),setTimeout(()=>{Lt()},100));return yn}catch(Zt){return An(Zt,y),[]}finally{nt(!1)}};_.useEffect(()=>{ut()},[]),_.useEffect(()=>{const Bt=A.connector||"",Zt=A.database||"";Bt!==q&&(ie(Bt),Bt&&!q&&mt(Bt)),Zt!==se&&pe(Zt)},[A.connector,A.database]);const bt=_.useCallback(Bt=>{const Zt=C,Zn=[...Je],{state:Rn,pos:yn}=Bt,Jn=Rn.doc.toString().slice(0,yn),Hn=AFe(Jn,Zt,ae=>Bt.matchBefore(ae)),Nr=/from\s+/i.test(Jn),Or=Nr?mFe(Jn,Zt):[],Lr=200,Jr=[];if(Nr&&Or.length>0)for(const ae of Or){const be=Zt[ae]||[];for(const We of be){if(Jr.length>=Lr)break;Jr.push({label:`"${ae}"."${We}"`,type:"field"},{label:`"${We}"`,type:"field"})}if(Jr.length>=Lr)break}const Wi=Bt.matchBefore(/[\w\.\-"]*/);if(!Wi&&!Bt.explicit)return null;let zn=[];switch(Hn.type){case"AFTER_INSERT_INTO":case"AFTER_UPDATE":case"AFTER_DELETE_FROM":zn=Object.keys(Zt).map(ur=>({label:`"${ur}"`,type:"table"}));break;case"AFTER_SET":zn=Or.flatMap(ur=>(Zt[ur]||[]).map(Kr=>({label:`"${Kr}"`,type:"field"})));break;case"AFTER_SELECT":if(zn=[{label:"*",type:"keyword"}],Nr&&Or.length>0)Or.forEach(ur=>{zn.push({label:`"${ur}".*`,type:"keyword"})}),zn.push(...Jr);else{zn.push(...Pe);const Kr=Object.keys(Zt).slice(0,100).map(Xr=>({label:`"${Xr}"`,type:"table"}));zn.push(...Kr)}zn.sort((ur,Kr)=>ur.label==="*"?-1:Kr.label==="*"?1:0);break;case"AFTER_SELECT_STAR":zn=[..._e];break;case"SELECT_COLUMN_LIST":const ae=/(?:BOLTIC_ENCRYPT|BOLTIC_DECRYPT)\s*\(/i.test(Jn);if(zn=[{label:",",type:"separator"},{label:"FROM",type:"keyword"}],ae){const Kr=Object.keys(Zt),Xr=[];for(const Ci of Kr){if(Xr.length>=100)break;const qs=Zt[Ci]||[];for(const Ys of qs){if(Xr.length>=100)break;Xr.push({label:`"${Ci}"."${Ys}"`,type:"field"},{label:`"${Ys}"`,type:"field"})}}zn.push(...Xr)}else zn.push(...Jr);const be=50;if(Nr&&Or.length>0&&Jr.length>0){const ur=Me.filter(Xr=>!["BOLTIC_ENCRYPT","BOLTIC_DECRYPT"].includes(Xr));let Kr=0;for(const Xr of Jr){if(Kr>=be)break;for(const Ci of ur){if(Kr>=be)break;zn.push({label:`${Ci}(${Xr.label})`,type:"function"}),Kr++}}zn.push({label:"BOLTIC_ENCRYPT(",type:"function"}),zn.push({label:"BOLTIC_DECRYPT(",type:"function"})}else ae||(zn.push({label:"BOLTIC_ENCRYPT(",type:"function"}),zn.push({label:"BOLTIC_DECRYPT(",type:"function"}));break;case"AFTER_FROM":case"AFTER_JOIN":zn=Object.keys(Zt).filter(ur=>!Or.includes(ur)||Hn.type==="AFTER_FROM").map(ur=>({label:`"${ur}"`,type:"table"}));break;case"AFTER_FROM_TABLE":case"AFTER_TABLE_ALIAS":zn=[...Zn,{label:"AS",type:"keyword"}];break;case"AFTER_JOIN_TABLE":zn=[...re];break;case"AFTER_WHERE":zn=[...Jr,{label:"EXISTS (",type:"keyword"},{label:"NOT EXISTS (",type:"keyword"}];break;case"JOIN_CONDITION":case"AFTER_ON":zn=[...gFe(Or,Zt),...Jr];break;case"AFTER_TABLE_DOT":{const ur=Hn.tableName,Kr=Object.keys(Zt).find(Xr=>Xr.toLowerCase()===ur.toLowerCase());Kr&&(zn=Zt[Kr].map(Xr=>({label:`"${Xr}"`,type:"field"})));break}case"AFTER_GROUP_BY":case"AFTER_ORDER_BY":zn=[...Jr,...Ce];break;case"PARTIAL_WORD":const ct=Hn.word,Dt=Ge.filter(ur=>ur.label.toLowerCase().startsWith(ct)),en=/(?:BOLTIC_ENCRYPT|BOLTIC_DECRYPT)\s*\(/i.test(Jn),er=Object.keys(Zt),rr=er.filter(ur=>ur.toLowerCase().startsWith(ct)).map(ur=>({label:`"${ur}"`,type:"table"})),li=100,Hr=[],ba=en||!Nr||Or.length===0?er:Or;for(const ur of ba){if(Hr.length>=li)break;const Kr=Zt[ur]||[];for(const Xr of Kr){if(Hr.length>=li)break;const Ci=`"${ur}"."${Xr}"`,qs=`"${Xr}"`;en&&(!ct||ct==='"')?(Hr.push({label:Ci,type:"field"}),Hr.push({label:qs,type:"field"})):Ci.toLowerCase().startsWith(ct)?Hr.push({label:Ci,type:"field"}):qs.toLowerCase().startsWith(ct)&&Hr.push({label:qs,type:"field"})}}const Rl=["BOLTIC_ENCRYPT","BOLTIC_DECRYPT"].filter(ur=>ur.toLowerCase().startsWith(ct.toLowerCase())).map(ur=>({label:`${ur}(`,type:"function"}));zn=[...Dt,...rr,...Hr,...Rl];break;default:const Es=Nr?Jr:[],os=Object.keys(Zt).slice(0,100).map(ur=>({label:`"${ur}"`,type:"table"}));zn=[...Ge,...os,...Es,{label:"BOLTIC_ENCRYPT(",type:"function"},{label:"BOLTIC_DECRYPT(",type:"function"}]}let io=Wi?Wi.from:yn;return Hn.type==="AFTER_TABLE_DOT"&&(io=yn),{from:io,options:zn,validFor:/[\w\.\-"]*$/}},[C,Ge,Pe,Je,_e,re,Ce,Me]),wt=async Bt=>{Q(!0);const Zt=N.current?.state.doc.toString()||"";H(Zt);const Zn={data:{prompt:Bt,current_query:Zt},headers:{"Content-Type":"application/json"}};try{const Rn=await qt.post(a+"/query/text-to-sql?db_id="+se,Zn);ne(""),Ae("");const yn=Rn?.data?.data||"";if(U)if(typeof yn=="string"&&!yn.toLowerCase().startsWith("error")){let Un;try{Un=Lz(yn,{language:"postgresql"})}catch{Un=yn}ue?(we(!0),fe(Un)):(K(!0),N.current&&N.current.dispatch({changes:{from:0,to:N.current.state.doc.length,insert:Un}}))}else ue?(Ae(yn),we(!1)):(ne(yn),K(!1))}catch(Rn){const yn=Rn?.meta?.[0]?Rn?.meta?.[0]:"Something went wrong.";ue?Ae(yn):ne(yn)}finally{Q(!1)}},Xt=async Bt=>{const Zt=Yt(a,`/${Bt}/fields/list`);qt.post(Zt,{data:{page:{page_no:1,page_size:999},filters:[],sort:[{field:"name",direction:"desc"}]}}).then(Zn=>{const Rn=(Zn?.data?.data||[]).sort((yn,Un)=>{const Jn=yn.field_order===-1?Number.MAX_SAFE_INTEGER:yn.field_order,Hn=Un.field_order===-1?Number.MAX_SAFE_INTEGER:Un.field_order;return Jn-Hn});Z(Rn||[])}).catch(Zn=>{An(Zn,y)})};_.useEffect(()=>{N.current?.state.doc.toString()&&o("properties.query",N.current?.state.doc.toString())},[N.current?.state.doc.toString()]),_.useEffect(()=>{if(Lt(),!L.current)return;const Bt=Pt.updateListener.of(Un=>{if(Un.docChanged||Un.selectionSet){const Jn=Un.state.doc.toString();c||l?.(Jn);const Hn=Un.state.selection.main.head;if(Jn.slice(0,Hn).endsWith("")){const Or=L.current;if(!Or)return;const Lr=Or.querySelector(".cm-cursor");Lr&&g(Lr)}else g(null)}}),Zt=Pt.theme({"&":{fontFamily:"ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace",fontSize:"14px"},"&.cm-focused":{outline:"none",boxShadow:"none"},"&.cm-editor":{height:"100%"},".cm-content":{caretColor:r.palette.common.white},".cm-line":{lineHeight:"1.6"},".cm-scroller":{borderRadius:"4px"}}),Zn=i(p)||"",Rn=Rr.create({doc:Zn,extensions:[DD,dD(),Xy({override:[bt]}),Bt,Zt,Pt.lineWrapping,Pt.editable.of(!c),PI(`SELECT * FROM "table name" WHERE "table name"."User Name"='john doe' AND "table name"."age">28`)]}),yn=new Pt({state:Rn,parent:L.current});return N.current=yn,()=>yn.destroy()},[bt]);const Lt=async(Bt=null)=>{const Zt=se||"";let Zn=P.find(Jn=>Jn.id===Zt);if(!Zn&&Zt&&(Zn={id:Zt,resource_id:"boltic"}),!Zt||!Zn)return;ye(!0);const Rn=Yt(a,`list?db_id=${Zt}`),yn=[{field:"name",operator:"ILIKE",values:[""]},{field:"resource_id",operator:"=",values:[Zn.resource_id||"boltic"]},{field:"db_id",operator:"=",values:[Zt]}],Un={data:{page:{page_no:1,page_size:999},filters:yn,sort:[{field:"created_at",direction:"desc"}]}};if(Bt&&Array.isArray(Bt)){const Jn=Bt.find(Hn=>Hn.field==="name");if(Jn){Un.data.filters[0]=Jn;const Hn=Bt.filter(Nr=>!["name","resource_id","db_id"].includes(Nr.field));Un.data.filters.push(...Hn)}}qt.post(Rn,Un).then(Jn=>{ye(!1),w(Jn?.data?.data||[])}).catch(Jn=>{ye(!1),An(Jn,y)})},He=()=>{R(Bt=>!Bt),W&&K(!1),N.current&&N.current.dispatch({changes:{from:0,to:N.current.state.doc.length,insert:F}}),j(""),z("")},it=_.useRef(null),[Ye,lt]=_.useState(!1),{canvasWorkflow:Ot,activityExecutionData:yt}=ht.useSelector(Bt=>Bt.canvas),{getNodes:Ct,setNodes:Re,getEdges:ot}=Rt.useReactFlow(),Ze=Ct(),{ENTITY_ID:De="",analytics:at,openAddonModal:gt,currentSubscription:rn}=eo(),{VORTEX_MAIN_URL:pn="",GYRATE_MAIN_URL:Ln=""}=h||{},Er=To(),ar=Cr(Er),un=Cr(Nn.VERSION)||ar,Dn=async Bt=>{const Zt=[...Array.isArray(Ze)?Ze:[]],Zn={workflow_json:[gc({...Bt})],result:W0(Ot,Ze,yt,Bt?.id,ot())};lt(!0);const{success:Rn,isError:yn,data:Un}=await G0(Bt,y,pn,De,Zt,Ze,Zn,it,at,un,gt,rn);return Rn&&!yn?(lt(!1),Da(Re,Bt,{...Bt.data.blt_node_states,test:"completed",node:"completed"}),Rn):(yn&&(delete Un.singleRunFailure,Da(Re,Bt,{...Bt.data.blt_node_states,test:"error",node:"failed"}),Object.keys(Un).forEach(Hn=>{QO(Un[Hn]).forEach(Or=>{y({type:Kn,payload:{open:!0,title:typeof Or!="string"?JSON.stringify(Or):Or,type:"error",width:"30rem",duration:3e3}})})})),lt(!1),!1)},Br=async Bt=>{const Zt=Ze?.find(Zn=>Zn?.id===Bt);Zt&&await Dn(Zt)};return f.jsx(Mr,{children:f.jsxs(E.Stack,{style:{width:"100%"},ref:O,spacing:2,children:[" ",f.jsx(E.Grid,{container:!0,gap:1,children:f.jsx(E.Grid,{item:!0,xs:12,children:f.jsx(E.FormControl,{fullWidth:!0,children:f.jsx(Kt,{name:"properties.connector",control:s,meta:{options:(D||[]).map(Bt=>({value:Bt.id,title:Bt.name||Bt.id})),displayName:"Connector",searchFieldPlaceholder:"Search Connector",placeholder:"Select Connector",isLoading:Ve},validationRules:{required:"Connector is required"},viewOnly:c,fullWidth:!0,id:"connector",required:!0,handleChange:Bt=>{const{value:Zt}=Bt;ie(Zt),o("properties.connector",Zt),pe(""),o("properties.database",""),oe(""),k([]),w([]),Z([]),Zt&&mt(Zt)}})})})}),q&&f.jsx(E.Grid,{container:!0,gap:1,children:f.jsx(E.Grid,{item:!0,xs:12,children:f.jsx(E.FormControl,{fullWidth:!0,children:f.jsx(Kt,{name:"properties.database",control:s,meta:{options:(P||[]).map(Bt=>({value:Bt.id,title:Bt.db_name||Bt.id,...q&&q!=="boltic"&&Bt?.resource_name?{description:Bt.resource_name}:{}})),displayName:"Database",searchFieldPlaceholder:"Search Database",placeholder:"Select Database",isLoading:Ue},viewOnly:c,fullWidth:!0,id:"database",required:!0,handleChange:Bt=>{const{value:Zt}=Bt;pe(Zt),o("properties.database",Zt),o("properties.table",null),oe(""),w([]),Z([]),Zt&&Lt()}})})})}),q&&se&&f.jsxs(f.Fragment,{children:[!c&&f.jsx(So,{open:ue,handleClose:()=>{j(Y),te(!1),ne(""),fe(""),z(""),K(!1),we(!1)},title:"Generate using AI",content:ge?f.jsxs(E.Box,{sx:{width:"100%"},children:[f.jsx(lo,{height:"27vh",value:le,language:"sql",viewOnly:c}),f.jsxs(E.Box,{display:"flex",justifyContent:"center",gap:2,mt:2,children:[f.jsx(E.Button,{variant:"contained",onClick:()=>{N.current&&N.current.dispatch({changes:{from:0,to:N.current.state.doc.length,insert:le}}),K(!1),te(!1),fe(""),R(!1),we(!1),j(""),z(""),V({})},children:"Accept"}),f.jsx(E.Button,{variant:"outlined",onClick:()=>{N.current&&N.current.dispatch({changes:{from:0,to:N.current.state.doc.length,insert:F}}),j(Y),K(!1),fe(""),we(!1),V({})},children:"Reject"})]})]}):f.jsxs(E.Box,{sx:{display:"flex",flexDirection:"column",width:"100%"},children:[f.jsx(E.Typography,{sx:{mb:"8px"},children:"Use AI to generate a SQL query. Write a prompt below to get started."}),f.jsx(E.TextField,{name:"prompt",size:"medium",placeholder:"e.g., Show all users who signed up in the last 30 days",fullWidth:!0,multiline:!0,rows:6,value:Y,onChange:Bt=>z(Bt.target.value),onKeyDown:Bt=>{Bt.key==="Enter"&&!G&&Y.trim().length&&!Bt.shiftKey&&(Bt.preventDefault(),wt(Y))}}),Oe&&f.jsx(E.Typography,{sx:{color:r.palette.error.main,mt:1,fontWeight:500},children:Oe}),f.jsxs(E.Box,{display:"flex",justifyContent:"center",gap:2,mt:3,children:[f.jsx(E.Button,{disabled:G||!Y,variant:"contained",onClick:()=>{wt(Y),ne("")},endIcon:G?f.jsx(E.CircularProgress,{size:20}):null,children:"Generate"}),f.jsx(E.Button,{variant:"outlined",onClick:()=>{te(!1),z(""),ne(""),j(Y)},children:"Cancel"})]})]})}),f.jsxs(E.Stack,{ref:L,className:"rounded-lg overflow-hidden",style:{height:"400px",width:"100%",border:B?.sql_query?`2px solid ${r.palette.error.main}`:"2px solid rgba(0, 132, 255, 0.3)",borderRadius:3,position:"relative"},children:[f.jsx(xw,{anchorEl:m,suggestionsData:e.isLoop?xe:u,setAnchorEl:()=>g(null),ref:O,handleSuggestionClick:({label:Bt})=>{if(c)return;const Zt=N.current;if(!Zt)return;const Zn=Zt.state.selection.main.head;Zt.dispatch({changes:{from:Zn,to:Zn,insert:`'{{${Bt}}}'`}}),g(null)},runActivity:Br,isLoading:Ye}),!c&&W&&f.jsx(E.Box,{sx:{position:"absolute",bottom:"-5.0rem",right:"1rem",backgroundColor:r.palette.common.white,borderRadius:1,boxShadow:`0px 2px 10px ${r.palette.secondary.main}`,zIndex:15,minWidth:"160px",transition:"all 0.2s ease-in-out",transform:W?"scale(1)":"scale(0.95)",opacity:1},children:f.jsxs(E.Stack,{spacing:1,children:[f.jsx(E.Box,{display:"flex",alignItems:"center",justifyContent:"space-between",sx:{cursor:"pointer"},onClick:()=>{K(!1),R(!1),j(""),z(""),ne(""),Ae(""),V({})},children:f.jsxs(E.IconButton,{sx:{width:"100%",display:"flex",justifyContent:"flex-start"},children:[f.jsx(E.Box,{component:"span",sx:{fontSize:18,display:"inline-flex",alignItems:"center"},children:f.jsx(je,{src:"ic_done",width:20,height:20})}),f.jsx(E.Typography,{sx:{marginLeft:1},children:"Accept"})]})}),f.jsx(E.Box,{display:"flex",alignItems:"center",justifyContent:"space-between",sx:{cursor:"pointer"},onClick:()=>{N.current&&N.current.dispatch({changes:{from:0,to:N.current.state.doc.length,insert:F}}),ne(""),Ae(""),K(!1),V({}),setTimeout(()=>M.current?.focus(),0)},children:f.jsxs(E.IconButton,{sx:{width:"100%",display:"flex",justifyContent:"flex-start"},children:[f.jsx(E.Box,{component:"span",sx:{fontSize:18,display:"inline-flex",alignItems:"center"},children:f.jsx(je,{src:"ic_close",width:20,height:20})}),f.jsx(E.Typography,{sx:{marginLeft:1},children:"Reject"})]})})]})}),!c&&f.jsxs(E.Box,{sx:{position:"absolute",bottom:6,left:6,right:6,borderRadius:2,zIndex:10,display:"flex",alignItems:"center",flexDirection:"column",boxShadow:Bt=>Bt.shadows?.overlay||"0 4px 20px rgba(0,0,0,0.16)",background:r.palette.common.white,transform:U?"scale(1)":"scale(0.8)",opacity:U?1:0,transition:"transform 250ms ease, opacity 250ms ease",transformOrigin:"bottom right",visibility:U?"visible":"hidden",pointerEvents:U?"auto":"none"},children:[ee&&f.jsxs(E.Box,{sx:{position:"relative",backgroundColor:r.palette.error.soft.bg,color:r.palette.error.main,px:2,py:1,borderRadius:2,paddingRight:4,width:"100%",fontSize:13,fontWeight:500,maxWidth:"100%",boxShadow:`0 1px 3px ${r.palette.secondary.main}`,paddingBottom:3,marginBottom:-2},children:[f.jsx(E.IconButton,{onClick:()=>ne(""),size:"small",sx:{position:"absolute",top:4,right:4,padding:"2px",color:r.palette.error.main,"& svg":{fontSize:"14px"}},children:f.jsx(je,{src:"ic_close",width:20,height:20})}),ee]}),f.jsx(E.TextField,{inputRef:M,variant:"outlined",fullWidth:!0,multiline:!0,placeholder:"Ask AI something...",value:$,onChange:Bt=>j(Bt.target.value),disabled:G||W,onKeyDown:Bt=>{Bt.key==="Enter"&&!G&&$.trim().length&&!Bt.shiftKey&&(Bt.preventDefault(),wt($))},InputProps:{disableUnderline:!0,sx:{backgroundColor:r.palette.common.white,alignItems:"flex-end","&.MuiOutlinedInput-root:hover .MuiOutlinedInput-notchedOutline":{borderColor:r.palette.primary.main}},endAdornment:f.jsx(E.InputAdornment,{position:"end",sx:{pr:1,mt:"auto",display:"flex",alignItems:"flex-end",marginRight:1,marginBottom:.5},children:G?f.jsx(E.CircularProgress,{sx:{position:"absolute",right:10,bottom:10},size:20}):f.jsx(E.IconButton,{onClick:()=>{$.trim().length&&wt($)},disableRipple:!0,disabled:$?.trim().length==0||W,sx:{padding:.2,fontSize:.9,cursor:"pointer",...$.trim().length>0&&{color:r.palette.primary.main},"&:hover":{color:$.trim().length>0?r.palette.primary.main:"transparent"}},edge:"end",children:f.jsx(je,{src:"ic_east",width:20,height:20})})})},minRows:4,maxRows:4,inputProps:{style:{overflow:"auto",textOverflow:"unset",whiteSpace:"pre-wrap",wordBreak:"break-word"}}})]}),!c&&U==!0?f.jsxs(E.Stack,{style:{position:"absolute",bottom:76,right:11,display:"flex",flexDirection:"row",zIndex:12},children:[f.jsx(E.IconButton,{style:{marginRight:2,background:r.palette.common.white,padding:0,width:22,cursor:G||W?"not-allowed":"pointer"},disabled:G||W,onClick:()=>{te(!0),z($)},children:f.jsx(je,{src:"ic_maximize",fill:r.palette.neutral.solid.bg})}),f.jsx(E.IconButton,{style:{marginRight:1,background:r.palette.common.white,padding:0,cursor:G||W?"not-allowed":"pointer"},disabled:G||W,onClick:()=>{U&&W&&He(),R(!1),ne(""),j(""),z("")},children:f.jsx(je,{src:"ic_close",width:24,height:24})})]}):c?null:f.jsx(E.Tooltip,{title:"Ask AI",arrow:!0,children:f.jsx(E.IconButton,{style:{position:"absolute",bottom:13,right:10,cursor:"pointer",zIndex:12,background:r.palette.common.white,padding:0},onClick:()=>{U&&W&&He(),R(!0)},children:f.jsx("img",{src:"https://cdn.pixelbin.io/v2/fyndcloud/original/icons/genai_icon.svg",width:32,height:32})})})]}),f.jsx(E.FormHelperText,{sx:{marginTop:"4px !important"},error:!0,children:B?.sql_query}),f.jsxs(E.FormHelperText,{style:{color:r.palette.grey[700]},component:"div",children:["By default, a limit of ",f.jsx("strong",{children:"100 rows"})," will be applied to your query. To retrieve all results without any limit, add ",f.jsx("strong",{children:"NOLIMIT"})," at the end of your query. ",f.jsx(E.Link,{href:`${Ln}/docs/workflow-builder/activities/tables#sql-editor`,target:"_blank",rel:"noopener noreferrer",underline:"always",children:"Need help?"}),f.jsxs(E.Box,{mt:.5,children:[f.jsx("strong",{style:{color:r.palette.grey[700]},children:"Note:"})," Only",f.jsx("strong",{children:"PostgreSQL"})," supported queries can be executed here."]})," "]}),f.jsx(E.Stack,{children:f.jsx(E.Stack,{sx:{borderRadius:1,px:1,py:.5,border:`1px solid ${r.palette.grey[200]}`},children:f.jsxs(E.Accordion,{expanded:t,onChange:()=>n(!t),children:[f.jsx(E.AccordionSummary,{"aria-controls":"panel1-content",id:"panel1-header",expandIcon:null,sx:{pl:0,flexDirection:"row-reverse","& .MuiAccordionSummary-content":{margin:.5}},children:f.jsxs(E.Box,{display:"flex",alignItems:"center",gap:1,children:[t?f.jsx(je,{src:"ic_arrow_up",width:20,height:20}):f.jsx(je,{src:"ic_arrow_down",width:20,height:20}),f.jsx(E.Box,{display:"flex",alignItems:"center",gap:.5,children:f.jsx(E.Typography,{variant:"subtitle1",fontWeight:"600",children:"Schema"})})]})}),f.jsxs(E.AccordionDetails,{children:[f.jsx(E.Box,{sx:{marginBottom:1,px:"6px"},children:f.jsx(SP,{value:J||"",disableClearable:!0,handleChange:Bt=>{const{value:Zt}=Bt;oe(Zt),Xt(Zt)},viewOnly:c,type:"bolticTableActivity",name:"table",title:"Table",options:b,loadDataFromApi:async Bt=>{b?.length||await Lt(),Bt(!1)},required:!0,onTextInputChange:(Bt,Zt)=>{Bt(!0),dt([{field:"name",operator:"ILIKE",values:[Zt]}])},selectedValueTitle:J,loadingState:Ee,renderFieldValue:()=>J})}),X.length>0&&f.jsx(E.List,{sx:{paddingBottom:1},dense:!0,children:X.map(Bt=>f.jsx(E.ListItem,{children:f.jsxs(E.Box,{display:"flex",justifyContent:"space-between",width:"100%",children:[f.jsx(E.Typography,{sx:{fontWeight:"500",flexGrow:1,color:r.palette.text.primary},children:Bt.name}),f.jsxs(E.Typography,{textAlign:"right",minWidth:100,children:[Bt.type," (",Bt.sql_field_type,")"]})]})},Bt.name))})]})]})})}),!d&&f.jsx(E.Grid,{item:!0,xs:12,children:f.jsx(Bi,{viewOnly:c})})]})]})})}),OFe=e=>{const{watch:t,setValue:n,control:r}=Qn(),o=t("properties").tabIndex??0,[s,a]=_.useState(o),{viewOnly:l=!1}=e;_.useEffect(()=>{o!==s&&a(o)},[o,s]);const u=d=>{a(d),n("properties.tabIndex",d)},c=(d,p)=>{if(l)return;const h=p?1:0;h!==s&&u(h)};return f.jsx(E.Box,{children:f.jsxs(E.Stack,{sx:{paddingBottom:2,borderRadius:2},children:[!l&&f.jsxs(E.Stack,{sx:{width:"100%",justifyContent:"space-between",flexDirection:"row",pt:2,pb:2},children:[f.jsx("span",{children:s===0?"Switch to SQL editor":"Switch to GUI"}),f.jsx(E.Switch,{checked:s===1,onChange:c,disabled:l})]}),f.jsxs(E.Box,{children:[s===0&&f.jsx(lFe,{...e}),s===1&&f.jsx(E.Grid,{children:f.jsx(bn,{name:"properties.query",control:r,rules:{required:"SQL query is required",validate:{validSql:d=>d.trim()?!0:"SQL query cannot be empty."}},render:({field:d})=>f.jsx(EFe,{...d,onChange:p=>{d.onChange(p),n("properties.event","sql_query")},name:"properties.query",...e})})})]})]})})},yFe=_.forwardRef((e,t)=>{const n=ht.useDispatch(),{ENTITY_ID:r,TESSERACT_MAIN_URL:i,FRONTEND_URL:o,type:s,id:a,isLoop:l=!1,openIntegrationDrawer:u,suggestionsData:c,INTEGRATION_DATA:d,VORTEX_MAIN_URL:p,WORKFLOW_URLS:h,viewOnly:A=!1}=e,{GYRATE_MAIN_URL:m}=h,[g,O]=_.useState([]),[y,T]=_.useState(!1),{setValue:v,control:C,watch:x,formState:{errors:b}}=Qn(),w=x("properties"),D=()=>{T(!0);const P={page_size:999,current_page:1,type:"BOTH"},k=Yt(i,"/v1/integrations/entity/BROWSERBASE");qt.get(k,{params:P}).then(({data:L})=>{O(Ko(L.data))}).catch(L=>{An(L,n)}).finally(()=>{T(!1)})};_.useEffect(()=>{Et(w)||D()},[]),_.useEffect(()=>{d?._id&&d?.meta?.entity==="BROWSERBASE"&&(D(),v("properties.secret",d._id))},[d]);const I=P=>{try{return new URL(P),!0}catch{return!1}};return _.useEffect(()=>{w?.operation==="custom_action"?v("properties.script",`const context = await browser.contexts()[0];
|
|
439
|
+
Maximum supported page size: 1000`})})})]}),s?.event=="bulk_update"&&s?.table&&L.length>0&&f.jsxs(E.Grid,{container:!0,gap:1,children:[f.jsx(E.Grid,{item:!0,xs:12,children:f.jsx(E.Typography,{variant:"smMedium",children:"Update Fields"})}),s.updates?.map((q,ie)=>f.jsx(E.Paper,{sx:{width:"100%"},children:f.jsxs(E.Grid,{container:!0,alignItems:"end",children:[f.jsx(E.Grid,{item:!0,xs:12,sm:4,children:f.jsx(E.FormControl,{fullWidth:!0,children:f.jsx(Kt,{required:!0,name:`properties.updates.${ie}.field`,control:i,meta:{options:L.filter(se=>!["button"].includes(se.type)&&!["id","created_at","updated_at"].includes(se.name)).map(se=>({value:JSON.stringify({type:se.type,name:se.name,id:se.id,...se.type==="dropdown"&&{multiple_selections:se.multiple_selections,selectable_items:se.selectable_items}}),title:se.name})),displayName:"Field Name",searchFieldPlaceholder:"Search Field Name",placeholder:"Select Field Name"},validationRules:{required:"Field Name is required"},viewOnly:u,id:e.id,handleChange:se=>{const{value:pe}=se,ee=JSON.parse(pe);r(`properties.updates.${ie}.field`,ee)},renderFieldValue:se=>{if(!se?.id)return;if(typeof se=="string")return se;const pe=L.filter(ee=>!["button"].includes(ee.type)&&!["id","created_at","updated_at"].includes(ee.name)).map(ee=>({value:JSON.stringify({type:ee.type,name:ee.name,id:ee.id,...ee.type==="dropdown"&&{multiple_selections:ee.multiple_selections,selectable_items:ee.selectable_items}}),id:ee.id})).find(ee=>typeof se=="object"&&se.id&&ee.id===se.id||ee.name===se.name&&ee.type===se.type);return pe?pe.value:""}})})}),f.jsxs(E.Grid,{item:!0,xs:12,sm:7,sx:{pl:1,pr:1},children:[q?.field?.multiple_selections!==!0&&f.jsx(E.FormControl,{fullWidth:!0,children:f.jsx(E.Box,{sx:{overflow:"hidden"},children:f.jsx(qn,{id:p,name:`properties.updates.${ie}.value`,control:i,meta:{displayName:"Value",placeholder:"Enter new value"},viewOnly:u,editorId:`${c}-base_url-${d}`,showSuggestions:!0,isLoop:d,variant:"outlined"})})}),q?.field?.type==="dropdown"&&q?.field?.multiple_selections===!0&&f.jsx(E.FormControl,{fullWidth:!0,children:f.jsx(E.Box,{sx:{overflow:"hidden",p:"4px"},children:f.jsx(Ap,{viewOnly:u,helperTextForDropdown:"",helperTextForTextField:"",id:p,isLoading:!1,label:"Value",type:c,isMultiple:q.field.multiple_selections,data:q.field.selectable_items?q.field.selectable_items.map(se=>({title:se,value:se})):[],value:(Array.isArray(q?.value)&&q?.value.length,q?.value),placeholder:"Enter new value",handleChange:se=>{const{value:pe}=se;r(`properties.updates.${ie}.value`,pe)},onTabChange:()=>{r(`properties.updates.${ie}.value`,"")},eventName:s.event,fieldName:`update_value_${ie}`,isLoop:e.isLoop,name:`properties.updates.${ie}.value`,control:i},s.event)})})]}),f.jsx(E.Grid,{item:!0,xs:12,sm:1,sx:{textAlign:"center",alignSelf:"center"},children:f.jsx(E.IconButton,{disabled:u,sx:{p:"8px",border:se=>`1px solid ${se.palette.grey.brainstem}`,borderRadius:8,fontSize:"0.9rem",display:"flex",mt:2,"&:hover":{backgroundColor:"transparent"}},color:"error",onClick:()=>{r("properties.updates",s.updates.filter((se,pe)=>pe!==ie))},children:f.jsx(je,{src:"ic_delete",width:m.icons.sm,height:m.icons.sm,sx:{path:{fill:m.palette.error.main}}})})})]})},ie)),f.jsx(E.Box,{sx:{textAlign:"right",width:"100%"},children:f.jsx(E.IconButton,{disabled:u,onClick:()=>{const q=s.updates||[];r("properties.updates",[...q,{field:{},value:""}],{shouldValidate:!0})},sx:{mt:"5px",p:.75,border:q=>`1px solid ${q.palette.grey.brainstem}`,borderRadius:8,fontSize:"1rem"},color:"primary",children:f.jsx(je,{src:"ic_plus",width:m.icons.md,height:m.icons.md,sx:{path:{fill:m.palette.primary.main}}})})})]}),L.filter(q=>q.type!=="button"&&q.type!=="json").length>0&&f.jsxs(E.Grid,{sx:{mt:1},children:[(s?.event==="list_record"||s?.event==="bulk_update")&&s?.table&&f.jsx(E.Typography,{variant:"smMedium",children:"Filters"}),(s?.event==="list_record"||s?.event==="bulk_update")&&s?.table&&f.jsxs(f.Fragment,{children:[(s?.filters?.length===0||!s?.filters)&&f.jsx(E.Box,{sx:{marginTop:"10px",textAlign:"right"},children:f.jsx(E.IconButton,{disabled:u,onClick:()=>{r("properties.filters",[...s.filters||[],{field:{},type:"",value:"",filterList:[]}],{shouldValidate:!0})},sx:{mt:"5px",p:.75,border:q=>`1px solid ${q.palette.grey.brainstem}`,borderRadius:8,fontSize:"1rem"},color:"primary",children:f.jsx(je,{src:"ic_plus",width:m.icons.md,height:m.icons.md,sx:{path:{fill:m.palette.primary.main}}})})}),s.filters?.map((q,ie)=>f.jsxs(E.Box,{sx:{margin:ie!==0?"30px 0px 0px 0px":"0"},children:[f.jsxs(E.Stack,{gap:1.5,sx:{p:"12px 8px",mb:2,borderRadius:4,alignItems:"flex-end",border:`1px solid ${m.palette.grey.outlined.border}`},children:[f.jsx(E.IconButton,{disabled:u,sx:{width:"fit-content",p:"8px",border:se=>`1px solid ${se.palette.grey.brainstem}`,borderRadius:8,fontSize:"0.9rem","&:hover":{backgroundColor:"transparent"}},color:"error",onClick:()=>{r("properties.filters",s.filters.filter((se,pe)=>pe!==ie))},children:f.jsx(je,{src:"ic_delete",width:m.icons.sm,height:m.icons.sm,sx:{path:{fill:m.palette.error.main}}})}),f.jsx(E.FormControl,{fullWidth:!0,children:f.jsx(Kt,{name:`properties.filters.${ie}.field`,control:i,meta:{options:L.filter(se=>(se.type==="encrypted"?se.is_deterministic:!0)&&se.type!=="button"&&se.type!=="json").map(se=>({value:JSON.stringify({type:se.type,name:se.name,id:se.id}),title:se.name})),displayName:"Field Name",searchFieldPlaceholder:"Search Field Name",placeholder:"Select Field Name"},validationRules:{required:"Field Name is required",validate:bP(q)},handleChange:se=>{const{value:pe}=se,ee=JSON.parse(pe),ne=[...s.filters],ue=t(ee.type);r(`properties.filters.${ie}`,{...ne[ie],field:ee,filterList:ue})},renderFieldValue:se=>!se?.id||typeof se=="string"?se:L.filter(ee=>(ee.type==="encrypted"?ee.is_deterministic:!0)&&ee.type!=="button"&&ee.type!=="json").map(ee=>({value:JSON.stringify({type:ee.type,name:ee.name,id:ee.id}),id:ee.id})).find(ee=>ee.id===se.id)?.value||"",renderValue:se=>{const pe=L.find(ee=>ee.id===se);return pe?pe.name:""},viewOnly:u,fullWidth:!0,id:`field_name_${ie}`,required:!0})}),f.jsx(E.FormControl,{fullWidth:!0,children:f.jsx(Kt,{name:`properties.filters.${ie}.type`,control:i,meta:{options:q?.filterList?.map(se=>({value:se.operator,title:se.filterName})),displayName:"Operator",searchFieldPlaceholder:"Search Operator",placeholder:"Select Operator"},validationRules:{required:"Operator is required",validate:bP(q)},handleChange:se=>{const{value:pe}=se,ee=[...s.filters];ee[ie]={...ee[ie],type:pe,value:pe==="IS EMPTY"?"":ee[ie]?.value},r(`properties.filters.${ie}`,ee[ie])},viewOnly:u,fullWidth:!0,id:`operator_${ie}`,required:!0,value:q?.type||""})}),q?.type!=="IS EMPTY"&&f.jsx(E.Grid,{container:!0,gap:1,children:f.jsx(E.Grid,{item:!0,xs:12,children:f.jsx(E.FormControl,{fullWidth:!0,children:f.jsx(qn,{name:`properties.filters.${ie}.value`,control:i,meta:{displayName:"Lookup Value",placeholder:"Enter Lookup Value"},validationRules:{required:"Lookup Value is required",validate:bP(q)},viewOnly:u,editorId:`bolticTableAcitivity-filter-text-${ie}`,id:e.id,isLoop:d,language:"plaintext",required:!0,value:q?.value||"",showSuggestions:!0,helperText:"",placeholder:"",variant:"outlined",type:"text"})})})})]}),s.filters?.length-1==ie&&s?.filters?.length<5&&f.jsx(E.Box,{sx:{marginTop:"10px",textAlign:"right"},children:f.jsx(E.IconButton,{disabled:u,onClick:()=>{r("properties.filters",[...s.filters,{field:{},type:"",value:"",filterList:[]}])},sx:{mt:"5px",p:.75,border:se=>`1px solid ${se.palette.grey.brainstem}`,borderRadius:8,fontSize:"1rem"},color:"primary",children:f.jsx(je,{src:"ic_plus",width:m.icons.md,height:m.icons.md,sx:{path:{fill:m.palette.primary.main}}})})})]},`filter-${ie}`))]})]}),!d&&f.jsx(E.Grid,{item:!0,xs:12,children:f.jsx(Bi,{viewOnly:u,type:c})})]})})]})},uFe=[{label:"DISTINCT",type:"keyword"},{label:"COUNT(*)",type:"function"},{label:"SUM()",type:"function"},{label:"AVG()",type:"function"},{label:"MAX()",type:"function"},{label:"MIN()",type:"function"}],cFe=[{label:"WHERE",type:"keyword"},{label:"JOIN",type:"keyword"},{label:"LEFT JOIN",type:"keyword"},{label:"RIGHT JOIN",type:"keyword"},{label:"INNER JOIN",type:"keyword"},{label:"GROUP BY",type:"keyword"},{label:"ORDER BY",type:"keyword"},{label:"LIMIT",type:"keyword"},{label:"HAVING",type:"keyword"}],dFe=[{label:"FROM",type:"keyword"},{label:",",type:"separator"}],fFe=[{label:"ON",type:"keyword"},{label:"AS",type:"keyword"}],pFe=[{label:"HAVING",type:"keyword"},{label:"ORDER BY",type:"keyword"},{label:"LIMIT",type:"keyword"},{label:"ASC",type:"keyword"},{label:"DESC",type:"keyword"}],hFe=["COUNT","SUM","AVG","MAX","MIN"],AFe=(e,t,n)=>{const r=e.toLowerCase();if(/select\s+$/i.test(r))return{type:"AFTER_SELECT"};const i=/from\s+"?([\w\s-]+)"?(?:\s+(?:as\s+\w+)?)?\s*$/i.exec(r),o=Object.keys(t).find(c=>c.toLowerCase()===i?.[1]?.toLowerCase());if(i&&o)return{type:"AFTER_FROM_TABLE",tableName:o};if(/from\s+("?[\w]*"?\s*)$/i.test(r))return{type:"AFTER_FROM"};if(/join\s+$/i.test(r))return{type:"AFTER_JOIN"};if(/where\s+$/i.test(r))return{type:"AFTER_WHERE"};if(/on\s+$/i.test(r))return{type:"AFTER_ON"};if(/insert\s+into\s+(""|"|$)/i.test(r))return{type:"AFTER_INSERT_INTO"};if(/update\s+$/i.test(r))return{type:"AFTER_UPDATE"};if(/set\s+$/i.test(r))return{type:"AFTER_SET"};if(/delete\s+from\s+$/i.test(r))return{type:"AFTER_DELETE_FROM"};const s=/"(?<table>[^"]+)"\.(?=[\w"]*$)/i.exec(r)||/(?<table>\w+)\.(?=[\w"]*$)/i.exec(r);if(s?.groups?.table)return{type:"AFTER_TABLE_DOT",tableName:s.groups.table};if(/group\s+by\s+$/i.test(r))return{type:"AFTER_GROUP_BY"};if(/order\s+by\s+$/i.test(r))return{type:"AFTER_ORDER_BY"};if(/join\s+\w+\s+(on\s+)?$/i.test(r))return{type:"JOIN_CONDITION"};if(/select\s+\*/i.test(r)&&!/from\s+/i.test(r))return{type:"AFTER_SELECT_STAR"};if(/select(?!.*from\b).+$/is.test(r))return{type:"SELECT_COLUMN_LIST"};const a=/join\s+(\w+)(?:\s+(?:as\s+\w+)?)?\s*$/i.exec(r);if(a&&Object.keys(t).includes(a[1]))return{type:"AFTER_JOIN_TABLE",tableName:a[1]};if(/from\s+\w+\s+as\s+\w+\s*$/i.test(r)||/from\s+\w+\s+\w+\s*$/i.test(r))return{type:"AFTER_TABLE_ALIAS"};const u=n(/[\w\.\-"]*/);return u&&u.from!==u.to?{type:"PARTIAL_WORD",word:u.text.toLowerCase()}:{type:"DEFAULT"}},mFe=(e,t)=>{const n=[...e.matchAll(/from\s+"([^"]+)"|from\s+(\w+)/gi)],r=[...e.matchAll(/join\s+"([^"]+)"|join\s+(\w+)/gi)],i=[];return n.forEach(o=>{const s=o[1]||o[2];s&&t[s]&&i.push(s)}),r.forEach(o=>{const s=o[1]||o[2];s&&t[s]&&i.push(s)}),i.length?[...new Set(i)]:Object.keys(t)},gFe=(e,t)=>{if(e.length<2)return[];const n=[],r=e[e.length-1];for(let i=0;i<e.length-1;i++){const o=e[i];for(const s of t[o]||[]){s.endsWith("_id")&&s.replace("_id","")===r&&n.push({label:`"${o}.${s}" = ${r}.id`,type:"join_condition"});for(const a of t[r]||[])a.endsWith("_id")&&a.replace("_id","")===o&&n.push({label:`"${r}.${a}" = ${o}.id`,type:"join_condition"})}}return n},EFe=wo(e=>{const[t,n]=_.useState(!0),r=E.useTheme(),{watch:i,setValue:o,control:s}=Qn(),{ATHENA_MAIN_URL:a,onChange:l,suggestionsData:u,viewOnly:c=!1,isLoop:d,name:p,WORKFLOW_URLS:h}=e,A=i("properties")||{},[m,g]=_.useState(null),O=_.useRef(null),y=ht.useDispatch(),[T,v]=_.useState([]),[C,x]=_.useState({}),[b,w]=_.useState([]),[D,I]=_.useState([]),[P,k]=_.useState([]),L=_.useRef(null),N=_.useRef(null),M=_.useRef(null),[B,V]=_.useState({}),[W,K]=_.useState(!1),[F,H]=_.useState(""),[U,R]=_.useState(!1),[$,j]=_.useState(""),[Y,z]=_.useState(""),[G,Q]=_.useState(!1),[X,Z]=_.useState([]),[J,oe]=_.useState(""),[q,ie]=_.useState(""),[se,pe]=_.useState(""),[ee,ne]=_.useState(""),[ue,te]=_.useState(!1),[le,fe]=_.useState(""),[Oe,Ae]=_.useState(""),[ge,we]=_.useState(!1),[Ee,ye]=_.useState(!1),[Ve,Qe]=_.useState(!1),[Ue,nt]=_.useState(!1),[Ge,Xe]=_.useState([]),[Pe,Ke]=_.useState(uFe),[Je,ve]=_.useState(cFe),[_e,Ie]=_.useState(dFe),[re,me]=_.useState(fFe),[Ce,Le]=_.useState(pFe),[Me,qe]=_.useState(hFe),dt=E.debounce(Bt=>{Lt(Bt=Bt)},300),Tt=_.useRef([]);Tt.current=T;const{loopSuggestionsData:xe={}}=ht.useSelector(Bt=>Bt.loopActivity);_.useEffect(()=>{(async()=>{if(a)try{const Zt=Yt(a,"/query/editor-keywords"),Rn=(await qt.get(Zt)).data?.data||{};if(Rn.SQL_KEYWORDS&&Array.isArray(Rn.SQL_KEYWORDS)){const yn=Rn.SQL_KEYWORDS.map(Un=>({label:Un,type:"keyword"}));Xe(yn)}Rn.DEFAULT_SELECT_FUNCTION_OPTIONS&&Ke(Rn.DEFAULT_SELECT_FUNCTION_OPTIONS),Rn.SQL_POST_TABLE_KEYWORDS&&ve(Rn.SQL_POST_TABLE_KEYWORDS),Rn.SQL_AFTER_SELECT_STAR_OPTIONS&&Ie(Rn.SQL_AFTER_SELECT_STAR_OPTIONS),Rn.SQL_AFTER_JOIN_TABLE_OPTIONS&&me(Rn.SQL_AFTER_JOIN_TABLE_OPTIONS),Rn.SQL_AFTER_GROUP_ORDER_OPTIONS&&Le(Rn.SQL_AFTER_GROUP_ORDER_OPTIONS),Rn.SQL_FUNCTION_TEMPLATES&&qe(Rn.SQL_FUNCTION_TEMPLATES)}catch{}})()},[a]),_.useEffect(()=>{se&&(async()=>{try{const Zt=se||"",Zn=Zt?`${a}/query/suggestions?db_id=${Zt}`:`${a}/query/suggestions`,yn=(await qt.get(Zn)).data?.data||{},Un=Object.keys(yn);x(yn);const Jn=Un.map(Hn=>({label:`"${Hn}"`,type:"table"}));v(Jn)}catch{}})()},[se]);const ut=async()=>{if(!a){Qe(!1);return}Qe(!0);const Bt=Yt(a,"/connectors/list");qt.post(Bt,{data:{page:{page_no:1,page_size:999},filters:[],sort:[]}}).then(Zt=>{Qe(!1);const Zn=[{id:"boltic",name:"Boltic Cloud"},...Zt?.data?.data||[]];I(Zn);const yn=i("properties")?.connector;if(!yn&&Zn.length>0){const Un=Zn[0].id;o("properties.connector",Un),ie(Un),mt(Un)}else yn&&(ie(yn),mt(yn))}).catch(Zt=>{An(Zt,y),Qe(!1)})},mt=async Bt=>{if(!Bt)return[];nt(!0);try{const Zt={page:{page_no:1,page_size:1e3},filters:[{field:"status",operator:"=",values:["ACTIVE"]}],sort:[]},Zn=`${a}/databases/list?add_default_if_missing=true&connector_id=${Bt}`,yn=(await qt.post(Zn,{data:Zt}))?.data?.data||[];k(yn);const Jn=i("properties")?.database;if(!Jn&&yn.length>0){const Hn=yn[0].id;o("properties.database",Hn),pe(Hn),setTimeout(()=>{Lt()},100)}else Jn&&(pe(Jn),setTimeout(()=>{Lt()},100));return yn}catch(Zt){return An(Zt,y),[]}finally{nt(!1)}};_.useEffect(()=>{ut()},[]),_.useEffect(()=>{const Bt=A.connector||"",Zt=A.database||"";Bt!==q&&(ie(Bt),Bt&&!q&&mt(Bt)),Zt!==se&&pe(Zt)},[A.connector,A.database]);const bt=_.useCallback(Bt=>{const Zt=C,Zn=[...Je],{state:Rn,pos:yn}=Bt,Jn=Rn.doc.toString().slice(0,yn),Hn=AFe(Jn,Zt,ae=>Bt.matchBefore(ae)),Nr=/from\s+/i.test(Jn),Or=Nr?mFe(Jn,Zt):[],Lr=200,Jr=[];if(Nr&&Or.length>0)for(const ae of Or){const be=Zt[ae]||[];for(const We of be){if(Jr.length>=Lr)break;Jr.push({label:`"${ae}"."${We}"`,type:"field"},{label:`"${We}"`,type:"field"})}if(Jr.length>=Lr)break}const Wi=Bt.matchBefore(/[\w\.\-"]*/);if(!Wi&&!Bt.explicit)return null;let zn=[];switch(Hn.type){case"AFTER_INSERT_INTO":case"AFTER_UPDATE":case"AFTER_DELETE_FROM":zn=Object.keys(Zt).map(ur=>({label:`"${ur}"`,type:"table"}));break;case"AFTER_SET":zn=Or.flatMap(ur=>(Zt[ur]||[]).map(Kr=>({label:`"${Kr}"`,type:"field"})));break;case"AFTER_SELECT":if(zn=[{label:"*",type:"keyword"}],Nr&&Or.length>0)Or.forEach(ur=>{zn.push({label:`"${ur}".*`,type:"keyword"})}),zn.push(...Jr);else{zn.push(...Pe);const Kr=Object.keys(Zt).slice(0,100).map(Xr=>({label:`"${Xr}"`,type:"table"}));zn.push(...Kr)}zn.sort((ur,Kr)=>ur.label==="*"?-1:Kr.label==="*"?1:0);break;case"AFTER_SELECT_STAR":zn=[..._e];break;case"SELECT_COLUMN_LIST":const ae=/(?:BOLTIC_ENCRYPT|BOLTIC_DECRYPT)\s*\(/i.test(Jn);if(zn=[{label:",",type:"separator"},{label:"FROM",type:"keyword"}],ae){const Kr=Object.keys(Zt),Xr=[];for(const Ci of Kr){if(Xr.length>=100)break;const qs=Zt[Ci]||[];for(const Ys of qs){if(Xr.length>=100)break;Xr.push({label:`"${Ci}"."${Ys}"`,type:"field"},{label:`"${Ys}"`,type:"field"})}}zn.push(...Xr)}else zn.push(...Jr);const be=50;if(Nr&&Or.length>0&&Jr.length>0){const ur=Me.filter(Xr=>!["BOLTIC_ENCRYPT","BOLTIC_DECRYPT"].includes(Xr));let Kr=0;for(const Xr of Jr){if(Kr>=be)break;for(const Ci of ur){if(Kr>=be)break;zn.push({label:`${Ci}(${Xr.label})`,type:"function"}),Kr++}}zn.push({label:"BOLTIC_ENCRYPT(",type:"function"}),zn.push({label:"BOLTIC_DECRYPT(",type:"function"})}else ae||(zn.push({label:"BOLTIC_ENCRYPT(",type:"function"}),zn.push({label:"BOLTIC_DECRYPT(",type:"function"}));break;case"AFTER_FROM":case"AFTER_JOIN":zn=Object.keys(Zt).filter(ur=>!Or.includes(ur)||Hn.type==="AFTER_FROM").map(ur=>({label:`"${ur}"`,type:"table"}));break;case"AFTER_FROM_TABLE":case"AFTER_TABLE_ALIAS":zn=[...Zn,{label:"AS",type:"keyword"}];break;case"AFTER_JOIN_TABLE":zn=[...re];break;case"AFTER_WHERE":zn=[...Jr,{label:"EXISTS (",type:"keyword"},{label:"NOT EXISTS (",type:"keyword"}];break;case"JOIN_CONDITION":case"AFTER_ON":zn=[...gFe(Or,Zt),...Jr];break;case"AFTER_TABLE_DOT":{const ur=Hn.tableName,Kr=Object.keys(Zt).find(Xr=>Xr.toLowerCase()===ur.toLowerCase());Kr&&(zn=Zt[Kr].map(Xr=>({label:`"${Xr}"`,type:"field"})));break}case"AFTER_GROUP_BY":case"AFTER_ORDER_BY":zn=[...Jr,...Ce];break;case"PARTIAL_WORD":const ct=Hn.word,Dt=Ge.filter(ur=>ur.label.toLowerCase().startsWith(ct)),en=/(?:BOLTIC_ENCRYPT|BOLTIC_DECRYPT)\s*\(/i.test(Jn),er=Object.keys(Zt),rr=er.filter(ur=>ur.toLowerCase().startsWith(ct)).map(ur=>({label:`"${ur}"`,type:"table"})),li=100,Hr=[],ba=en||!Nr||Or.length===0?er:Or;for(const ur of ba){if(Hr.length>=li)break;const Kr=Zt[ur]||[];for(const Xr of Kr){if(Hr.length>=li)break;const Ci=`"${ur}"."${Xr}"`,qs=`"${Xr}"`;en&&(!ct||ct==='"')?(Hr.push({label:Ci,type:"field"}),Hr.push({label:qs,type:"field"})):Ci.toLowerCase().startsWith(ct)?Hr.push({label:Ci,type:"field"}):qs.toLowerCase().startsWith(ct)&&Hr.push({label:qs,type:"field"})}}const Rl=["BOLTIC_ENCRYPT","BOLTIC_DECRYPT"].filter(ur=>ur.toLowerCase().startsWith(ct.toLowerCase())).map(ur=>({label:`${ur}(`,type:"function"}));zn=[...Dt,...rr,...Hr,...Rl];break;default:const Es=Nr?Jr:[],os=Object.keys(Zt).slice(0,100).map(ur=>({label:`"${ur}"`,type:"table"}));zn=[...Ge,...os,...Es,{label:"BOLTIC_ENCRYPT(",type:"function"},{label:"BOLTIC_DECRYPT(",type:"function"}]}let io=Wi?Wi.from:yn;return Hn.type==="AFTER_TABLE_DOT"&&(io=yn),{from:io,options:zn,validFor:/[\w\.\-"]*$/}},[C,Ge,Pe,Je,_e,re,Ce,Me]),wt=async Bt=>{Q(!0);const Zt=N.current?.state.doc.toString()||"";H(Zt);const Zn={data:{prompt:Bt,current_query:Zt},headers:{"Content-Type":"application/json","x-request-source":"workflow"}};try{const Rn=await qt.post(a+"/query/text-to-sql?db_id="+se,Zn);ne(""),Ae("");const yn=Rn?.data?.data||"";if(U)if(typeof yn=="string"&&!yn.toLowerCase().startsWith("error")){let Un;try{Un=Lz(yn,{language:"postgresql"})}catch{Un=yn}ue?(we(!0),fe(Un)):(K(!0),N.current&&N.current.dispatch({changes:{from:0,to:N.current.state.doc.length,insert:Un}}))}else ue?(Ae(yn),we(!1)):(ne(yn),K(!1))}catch(Rn){const yn=Rn?.meta?.[0]?Rn?.meta?.[0]:"Something went wrong.";ue?Ae(yn):ne(yn)}finally{Q(!1)}},Xt=async Bt=>{const Zt=Yt(a,`/${Bt}/fields/list`);qt.post(Zt,{data:{page:{page_no:1,page_size:999},filters:[],sort:[{field:"name",direction:"desc"}]}}).then(Zn=>{const Rn=(Zn?.data?.data||[]).sort((yn,Un)=>{const Jn=yn.field_order===-1?Number.MAX_SAFE_INTEGER:yn.field_order,Hn=Un.field_order===-1?Number.MAX_SAFE_INTEGER:Un.field_order;return Jn-Hn});Z(Rn||[])}).catch(Zn=>{An(Zn,y)})};_.useEffect(()=>{N.current?.state.doc.toString()&&o("properties.query",N.current?.state.doc.toString())},[N.current?.state.doc.toString()]),_.useEffect(()=>{if(Lt(),!L.current)return;const Bt=Pt.updateListener.of(Un=>{if(Un.docChanged||Un.selectionSet){const Jn=Un.state.doc.toString();c||l?.(Jn);const Hn=Un.state.selection.main.head;if(Jn.slice(0,Hn).endsWith("")){const Or=L.current;if(!Or)return;const Lr=Or.querySelector(".cm-cursor");Lr&&g(Lr)}else g(null)}}),Zt=Pt.theme({"&":{fontFamily:"ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace",fontSize:"14px"},"&.cm-focused":{outline:"none",boxShadow:"none"},"&.cm-editor":{height:"100%"},".cm-content":{caretColor:r.palette.common.white},".cm-line":{lineHeight:"1.6"},".cm-scroller":{borderRadius:"4px"}}),Zn=i(p)||"",Rn=Rr.create({doc:Zn,extensions:[DD,dD(),Xy({override:[bt]}),Bt,Zt,Pt.lineWrapping,Pt.editable.of(!c),PI(`SELECT * FROM "table name" WHERE "table name"."User Name"='john doe' AND "table name"."age">28`)]}),yn=new Pt({state:Rn,parent:L.current});return N.current=yn,()=>yn.destroy()},[bt]);const Lt=async(Bt=null)=>{const Zt=se||"";let Zn=P.find(Jn=>Jn.id===Zt);if(!Zn&&Zt&&(Zn={id:Zt,resource_id:"boltic"}),!Zt||!Zn)return;ye(!0);const Rn=Yt(a,`list?db_id=${Zt}`),yn=[{field:"name",operator:"ILIKE",values:[""]},{field:"resource_id",operator:"=",values:[Zn.resource_id||"boltic"]},{field:"db_id",operator:"=",values:[Zt]}],Un={data:{page:{page_no:1,page_size:999},filters:yn,sort:[{field:"created_at",direction:"desc"}]}};if(Bt&&Array.isArray(Bt)){const Jn=Bt.find(Hn=>Hn.field==="name");if(Jn){Un.data.filters[0]=Jn;const Hn=Bt.filter(Nr=>!["name","resource_id","db_id"].includes(Nr.field));Un.data.filters.push(...Hn)}}qt.post(Rn,Un).then(Jn=>{ye(!1),w(Jn?.data?.data||[])}).catch(Jn=>{ye(!1),An(Jn,y)})},He=()=>{R(Bt=>!Bt),W&&K(!1),N.current&&N.current.dispatch({changes:{from:0,to:N.current.state.doc.length,insert:F}}),j(""),z("")},it=_.useRef(null),[Ye,lt]=_.useState(!1),{canvasWorkflow:Ot,activityExecutionData:yt}=ht.useSelector(Bt=>Bt.canvas),{getNodes:Ct,setNodes:Re,getEdges:ot}=Rt.useReactFlow(),Ze=Ct(),{ENTITY_ID:De="",analytics:at,openAddonModal:gt,currentSubscription:rn}=eo(),{VORTEX_MAIN_URL:pn="",GYRATE_MAIN_URL:Ln=""}=h||{},Er=To(),ar=Cr(Er),un=Cr(Nn.VERSION)||ar,Dn=async Bt=>{const Zt=[...Array.isArray(Ze)?Ze:[]],Zn={workflow_json:[gc({...Bt})],result:W0(Ot,Ze,yt,Bt?.id,ot())};lt(!0);const{success:Rn,isError:yn,data:Un}=await G0(Bt,y,pn,De,Zt,Ze,Zn,it,at,un,gt,rn);return Rn&&!yn?(lt(!1),Da(Re,Bt,{...Bt.data.blt_node_states,test:"completed",node:"completed"}),Rn):(yn&&(delete Un.singleRunFailure,Da(Re,Bt,{...Bt.data.blt_node_states,test:"error",node:"failed"}),Object.keys(Un).forEach(Hn=>{QO(Un[Hn]).forEach(Or=>{y({type:Kn,payload:{open:!0,title:typeof Or!="string"?JSON.stringify(Or):Or,type:"error",width:"30rem",duration:3e3}})})})),lt(!1),!1)},Br=async Bt=>{const Zt=Ze?.find(Zn=>Zn?.id===Bt);Zt&&await Dn(Zt)};return f.jsx(Mr,{children:f.jsxs(E.Stack,{style:{width:"100%"},ref:O,spacing:2,children:[" ",f.jsx(E.Grid,{container:!0,gap:1,children:f.jsx(E.Grid,{item:!0,xs:12,children:f.jsx(E.FormControl,{fullWidth:!0,children:f.jsx(Kt,{name:"properties.connector",control:s,meta:{options:(D||[]).map(Bt=>({value:Bt.id,title:Bt.name||Bt.id})),displayName:"Connector",searchFieldPlaceholder:"Search Connector",placeholder:"Select Connector",isLoading:Ve},validationRules:{required:"Connector is required"},viewOnly:c,fullWidth:!0,id:"connector",required:!0,handleChange:Bt=>{const{value:Zt}=Bt;ie(Zt),o("properties.connector",Zt),pe(""),o("properties.database",""),oe(""),k([]),w([]),Z([]),Zt&&mt(Zt)}})})})}),q&&f.jsx(E.Grid,{container:!0,gap:1,children:f.jsx(E.Grid,{item:!0,xs:12,children:f.jsx(E.FormControl,{fullWidth:!0,children:f.jsx(Kt,{name:"properties.database",control:s,meta:{options:(P||[]).map(Bt=>({value:Bt.id,title:Bt.db_name||Bt.id,...q&&q!=="boltic"&&Bt?.resource_name?{description:Bt.resource_name}:{}})),displayName:"Database",searchFieldPlaceholder:"Search Database",placeholder:"Select Database",isLoading:Ue},viewOnly:c,fullWidth:!0,id:"database",required:!0,handleChange:Bt=>{const{value:Zt}=Bt;pe(Zt),o("properties.database",Zt),o("properties.table",null),oe(""),w([]),Z([]),Zt&&Lt()}})})})}),q&&se&&f.jsxs(f.Fragment,{children:[!c&&f.jsx(So,{open:ue,handleClose:()=>{j(Y),te(!1),ne(""),fe(""),z(""),K(!1),we(!1)},title:"Generate using AI",content:ge?f.jsxs(E.Box,{sx:{width:"100%"},children:[f.jsx(lo,{height:"27vh",value:le,language:"sql",viewOnly:c}),f.jsxs(E.Box,{display:"flex",justifyContent:"center",gap:2,mt:2,children:[f.jsx(E.Button,{variant:"contained",onClick:()=>{N.current&&N.current.dispatch({changes:{from:0,to:N.current.state.doc.length,insert:le}}),K(!1),te(!1),fe(""),R(!1),we(!1),j(""),z(""),V({})},children:"Accept"}),f.jsx(E.Button,{variant:"outlined",onClick:()=>{N.current&&N.current.dispatch({changes:{from:0,to:N.current.state.doc.length,insert:F}}),j(Y),K(!1),fe(""),we(!1),V({})},children:"Reject"})]})]}):f.jsxs(E.Box,{sx:{display:"flex",flexDirection:"column",width:"100%"},children:[f.jsx(E.Typography,{sx:{mb:"8px"},children:"Use AI to generate a SQL query. Write a prompt below to get started."}),f.jsx(E.TextField,{name:"prompt",size:"medium",placeholder:"e.g., Show all users who signed up in the last 30 days",fullWidth:!0,multiline:!0,rows:6,value:Y,onChange:Bt=>z(Bt.target.value),onKeyDown:Bt=>{Bt.key==="Enter"&&!G&&Y.trim().length&&!Bt.shiftKey&&(Bt.preventDefault(),wt(Y))}}),Oe&&f.jsx(E.Typography,{sx:{color:r.palette.error.main,mt:1,fontWeight:500},children:Oe}),f.jsxs(E.Box,{display:"flex",justifyContent:"center",gap:2,mt:3,children:[f.jsx(E.Button,{disabled:G||!Y,variant:"contained",onClick:()=>{wt(Y),ne("")},endIcon:G?f.jsx(E.CircularProgress,{size:20}):null,children:"Generate"}),f.jsx(E.Button,{variant:"outlined",onClick:()=>{te(!1),z(""),ne(""),j(Y)},children:"Cancel"})]})]})}),f.jsxs(E.Stack,{ref:L,className:"rounded-lg overflow-hidden",style:{height:"400px",width:"100%",border:B?.sql_query?`2px solid ${r.palette.error.main}`:"2px solid rgba(0, 132, 255, 0.3)",borderRadius:3,position:"relative"},children:[f.jsx(xw,{anchorEl:m,suggestionsData:e.isLoop?xe:u,setAnchorEl:()=>g(null),ref:O,handleSuggestionClick:({label:Bt})=>{if(c)return;const Zt=N.current;if(!Zt)return;const Zn=Zt.state.selection.main.head;Zt.dispatch({changes:{from:Zn,to:Zn,insert:`'{{${Bt}}}'`}}),g(null)},runActivity:Br,isLoading:Ye}),!c&&W&&f.jsx(E.Box,{sx:{position:"absolute",bottom:"-5.0rem",right:"1rem",backgroundColor:r.palette.common.white,borderRadius:1,boxShadow:`0px 2px 10px ${r.palette.secondary.main}`,zIndex:15,minWidth:"160px",transition:"all 0.2s ease-in-out",transform:W?"scale(1)":"scale(0.95)",opacity:1},children:f.jsxs(E.Stack,{spacing:1,children:[f.jsx(E.Box,{display:"flex",alignItems:"center",justifyContent:"space-between",sx:{cursor:"pointer"},onClick:()=>{K(!1),R(!1),j(""),z(""),ne(""),Ae(""),V({})},children:f.jsxs(E.IconButton,{sx:{width:"100%",display:"flex",justifyContent:"flex-start"},children:[f.jsx(E.Box,{component:"span",sx:{fontSize:18,display:"inline-flex",alignItems:"center"},children:f.jsx(je,{src:"ic_done",width:20,height:20})}),f.jsx(E.Typography,{sx:{marginLeft:1},children:"Accept"})]})}),f.jsx(E.Box,{display:"flex",alignItems:"center",justifyContent:"space-between",sx:{cursor:"pointer"},onClick:()=>{N.current&&N.current.dispatch({changes:{from:0,to:N.current.state.doc.length,insert:F}}),ne(""),Ae(""),K(!1),V({}),setTimeout(()=>M.current?.focus(),0)},children:f.jsxs(E.IconButton,{sx:{width:"100%",display:"flex",justifyContent:"flex-start"},children:[f.jsx(E.Box,{component:"span",sx:{fontSize:18,display:"inline-flex",alignItems:"center"},children:f.jsx(je,{src:"ic_close",width:20,height:20})}),f.jsx(E.Typography,{sx:{marginLeft:1},children:"Reject"})]})})]})}),!c&&f.jsxs(E.Box,{sx:{position:"absolute",bottom:6,left:6,right:6,borderRadius:2,zIndex:10,display:"flex",alignItems:"center",flexDirection:"column",boxShadow:Bt=>Bt.shadows?.overlay||"0 4px 20px rgba(0,0,0,0.16)",background:r.palette.common.white,transform:U?"scale(1)":"scale(0.8)",opacity:U?1:0,transition:"transform 250ms ease, opacity 250ms ease",transformOrigin:"bottom right",visibility:U?"visible":"hidden",pointerEvents:U?"auto":"none"},children:[ee&&f.jsxs(E.Box,{sx:{position:"relative",backgroundColor:r.palette.error.soft.bg,color:r.palette.error.main,px:2,py:1,borderRadius:2,paddingRight:4,width:"100%",fontSize:13,fontWeight:500,maxWidth:"100%",boxShadow:`0 1px 3px ${r.palette.secondary.main}`,paddingBottom:3,marginBottom:-2},children:[f.jsx(E.IconButton,{onClick:()=>ne(""),size:"small",sx:{position:"absolute",top:4,right:4,padding:"2px",color:r.palette.error.main,"& svg":{fontSize:"14px"}},children:f.jsx(je,{src:"ic_close",width:20,height:20})}),ee]}),f.jsx(E.TextField,{inputRef:M,variant:"outlined",fullWidth:!0,multiline:!0,placeholder:"Ask AI something...",value:$,onChange:Bt=>j(Bt.target.value),disabled:G||W,onKeyDown:Bt=>{Bt.key==="Enter"&&!G&&$.trim().length&&!Bt.shiftKey&&(Bt.preventDefault(),wt($))},InputProps:{disableUnderline:!0,sx:{backgroundColor:r.palette.common.white,alignItems:"flex-end","&.MuiOutlinedInput-root:hover .MuiOutlinedInput-notchedOutline":{borderColor:r.palette.primary.main}},endAdornment:f.jsx(E.InputAdornment,{position:"end",sx:{pr:1,mt:"auto",display:"flex",alignItems:"flex-end",marginRight:1,marginBottom:.5},children:G?f.jsx(E.CircularProgress,{sx:{position:"absolute",right:10,bottom:10},size:20}):f.jsx(E.IconButton,{onClick:()=>{$.trim().length&&wt($)},disableRipple:!0,disabled:$?.trim().length==0||W,sx:{padding:.2,fontSize:.9,cursor:"pointer",...$.trim().length>0&&{color:r.palette.primary.main},"&:hover":{color:$.trim().length>0?r.palette.primary.main:"transparent"}},edge:"end",children:f.jsx(je,{src:"ic_east",width:20,height:20})})})},minRows:4,maxRows:4,inputProps:{style:{overflow:"auto",textOverflow:"unset",whiteSpace:"pre-wrap",wordBreak:"break-word"}}})]}),!c&&U==!0?f.jsxs(E.Stack,{style:{position:"absolute",bottom:76,right:11,display:"flex",flexDirection:"row",zIndex:12},children:[f.jsx(E.IconButton,{style:{marginRight:2,background:r.palette.common.white,padding:0,width:22,cursor:G||W?"not-allowed":"pointer"},disabled:G||W,onClick:()=>{te(!0),z($)},children:f.jsx(je,{src:"ic_maximize",fill:r.palette.neutral.solid.bg})}),f.jsx(E.IconButton,{style:{marginRight:1,background:r.palette.common.white,padding:0,cursor:G||W?"not-allowed":"pointer"},disabled:G||W,onClick:()=>{U&&W&&He(),R(!1),ne(""),j(""),z("")},children:f.jsx(je,{src:"ic_close",width:24,height:24})})]}):c?null:f.jsx(E.Tooltip,{title:"Ask AI",arrow:!0,children:f.jsx(E.IconButton,{style:{position:"absolute",bottom:13,right:10,cursor:"pointer",zIndex:12,background:r.palette.common.white,padding:0},onClick:()=>{U&&W&&He(),R(!0)},children:f.jsx("img",{src:"https://cdn.pixelbin.io/v2/fyndcloud/original/icons/genai_icon.svg",width:32,height:32})})})]}),f.jsx(E.FormHelperText,{sx:{marginTop:"4px !important"},error:!0,children:B?.sql_query}),f.jsxs(E.FormHelperText,{style:{color:r.palette.grey[700]},component:"div",children:["By default, a limit of ",f.jsx("strong",{children:"100 rows"})," will be applied to your query. To retrieve all results without any limit, add ",f.jsx("strong",{children:"NOLIMIT"})," at the end of your query. ",f.jsx(E.Link,{href:`${Ln}/docs/workflow-builder/activities/tables#sql-editor`,target:"_blank",rel:"noopener noreferrer",underline:"always",children:"Need help?"}),f.jsxs(E.Box,{mt:.5,children:[f.jsx("strong",{style:{color:r.palette.grey[700]},children:"Note:"})," Only",f.jsx("strong",{children:"PostgreSQL"})," supported queries can be executed here."]})," "]}),f.jsx(E.Stack,{children:f.jsx(E.Stack,{sx:{borderRadius:1,px:1,py:.5,border:`1px solid ${r.palette.grey[200]}`},children:f.jsxs(E.Accordion,{expanded:t,onChange:()=>n(!t),children:[f.jsx(E.AccordionSummary,{"aria-controls":"panel1-content",id:"panel1-header",expandIcon:null,sx:{pl:0,flexDirection:"row-reverse","& .MuiAccordionSummary-content":{margin:.5}},children:f.jsxs(E.Box,{display:"flex",alignItems:"center",gap:1,children:[t?f.jsx(je,{src:"ic_arrow_up",width:20,height:20}):f.jsx(je,{src:"ic_arrow_down",width:20,height:20}),f.jsx(E.Box,{display:"flex",alignItems:"center",gap:.5,children:f.jsx(E.Typography,{variant:"subtitle1",fontWeight:"600",children:"Schema"})})]})}),f.jsxs(E.AccordionDetails,{children:[f.jsx(E.Box,{sx:{marginBottom:1,px:"6px"},children:f.jsx(SP,{value:J||"",disableClearable:!0,handleChange:Bt=>{const{value:Zt}=Bt;oe(Zt),Xt(Zt)},viewOnly:c,type:"bolticTableActivity",name:"table",title:"Table",options:b,loadDataFromApi:async Bt=>{b?.length||await Lt(),Bt(!1)},required:!0,onTextInputChange:(Bt,Zt)=>{Bt(!0),dt([{field:"name",operator:"ILIKE",values:[Zt]}])},selectedValueTitle:J,loadingState:Ee,renderFieldValue:()=>J})}),X.length>0&&f.jsx(E.List,{sx:{paddingBottom:1},dense:!0,children:X.map(Bt=>f.jsx(E.ListItem,{children:f.jsxs(E.Box,{display:"flex",justifyContent:"space-between",width:"100%",children:[f.jsx(E.Typography,{sx:{fontWeight:"500",flexGrow:1,color:r.palette.text.primary},children:Bt.name}),f.jsxs(E.Typography,{textAlign:"right",minWidth:100,children:[Bt.type," (",Bt.sql_field_type,")"]})]})},Bt.name))})]})]})})}),!d&&f.jsx(E.Grid,{item:!0,xs:12,children:f.jsx(Bi,{viewOnly:c})})]})]})})}),OFe=e=>{const{watch:t,setValue:n,control:r}=Qn(),o=t("properties").tabIndex??0,[s,a]=_.useState(o),{viewOnly:l=!1}=e;_.useEffect(()=>{o!==s&&a(o)},[o,s]);const u=d=>{a(d),n("properties.tabIndex",d)},c=(d,p)=>{if(l)return;const h=p?1:0;h!==s&&u(h)};return f.jsx(E.Box,{children:f.jsxs(E.Stack,{sx:{paddingBottom:2,borderRadius:2},children:[!l&&f.jsxs(E.Stack,{sx:{width:"100%",justifyContent:"space-between",flexDirection:"row",pt:2,pb:2},children:[f.jsx("span",{children:s===0?"Switch to SQL editor":"Switch to GUI"}),f.jsx(E.Switch,{checked:s===1,onChange:c,disabled:l})]}),f.jsxs(E.Box,{children:[s===0&&f.jsx(lFe,{...e}),s===1&&f.jsx(E.Grid,{children:f.jsx(bn,{name:"properties.query",control:r,rules:{required:"SQL query is required",validate:{validSql:d=>d.trim()?!0:"SQL query cannot be empty."}},render:({field:d})=>f.jsx(EFe,{...d,onChange:p=>{d.onChange(p),n("properties.event","sql_query")},name:"properties.query",...e})})})]})]})})},yFe=_.forwardRef((e,t)=>{const n=ht.useDispatch(),{ENTITY_ID:r,TESSERACT_MAIN_URL:i,FRONTEND_URL:o,type:s,id:a,isLoop:l=!1,openIntegrationDrawer:u,suggestionsData:c,INTEGRATION_DATA:d,VORTEX_MAIN_URL:p,WORKFLOW_URLS:h,viewOnly:A=!1}=e,{GYRATE_MAIN_URL:m}=h,[g,O]=_.useState([]),[y,T]=_.useState(!1),{setValue:v,control:C,watch:x,formState:{errors:b}}=Qn(),w=x("properties"),D=()=>{T(!0);const P={page_size:999,current_page:1,type:"BOTH"},k=Yt(i,"/v1/integrations/entity/BROWSERBASE");qt.get(k,{params:P}).then(({data:L})=>{O(Ko(L.data))}).catch(L=>{An(L,n)}).finally(()=>{T(!1)})};_.useEffect(()=>{Et(w)||D()},[]),_.useEffect(()=>{d?._id&&d?.meta?.entity==="BROWSERBASE"&&(D(),v("properties.secret",d._id))},[d]);const I=P=>{try{return new URL(P),!0}catch{return!1}};return _.useEffect(()=>{w?.operation==="custom_action"?v("properties.script",`const context = await browser.contexts()[0];
|
|
440
440
|
const page = await context.pages()[0];
|
|
441
441
|
|
|
442
442
|
// Go to DuckDuckGo
|
package/package.json
CHANGED