PageSourceSearch

https://cloud.agenty.com/assets/page-DNNEKazn.js

js agenty.com collected 2026-10-01 15:34:43 UTC 5,571 bytes, 1 lines download raw bytes

1import{R as W,j as e,y as G,z as J,B as Q,am as U,F as X,a$ as Y,a4 as Z,b0 as ee,b1 as se,b2 as ae,b3 as te,V as ie,b4 as le,at as ne,H as y,W as u,a5 as re,a6 as oe,a7 as T,a8 as A,a9 as ce,aa as F,D as de,q as ue,s as me,u as P}from"./ui-CfRm5DTA.js";import{L as he,r as l,a4 as pe,F as fe,aE as xe,s as ge}from"./icons-CoWim_VM.js";import{u as je,b as we}from"./index-CO7lCi65.js";import{P as be}from"./page-header-C_yrDXSw.js";import{r as ye,s as _,a as Ce}from"./schemas-Z-bF3x6t.js";import{C as De}from"./confirm-dialog-vrDTVcTM.js";import{u as ve,P as Ne}from"./pagination-controls-BIvW4wzY.js";import{E as Se}from"./empty-state-KFFUCOK_.js";import{a as f,A as x}from"./api-TVx_5Nik.js";import{s as Le}from"./utility-D9ML9P8b.js";import"./index-BiJdn4L4.js";const Ee=ye(_(),_().optional()).refine(a=>Object.keys(a).length>0,{message:"At least one field is required"});function $e({open:a,onOpenChange:g,onSubmit:v,defaultValues:j={},mode:m,isSubmitting:w}){const n=m==="edit"?Object.fromEntries(Object.entries(j).filter(([r])=>r!=="_id")):j,h=W({resolver:Ce(Ee),defaultValues:n}),d=async r=>{v(r)},p=Object.keys(n).length?Object.keys(n):[""];return e.jsx(G,{open:a,onOpenChange:g,children:e.jsxs(J,{className:"max-h-[80vh] p-0",children:[e.jsxs(Q,{className:"p-6 pb-0",children:[e.jsx(U,{children:m==="create"?"Add Row":"Edit Row"}),e.jsx(X,{children:m==="create"?"Add a new record with one or more fields.":"Edit the existing record."})]}),e.jsx(Y,{...h,children:e.jsxs("form",{onSubmit:h.handleSubmit(d),className:"space-y-4",children:[e.jsx(Z,{className:"h-full max-h-[60vh]",children:e.jsx("div",{className:"space-y-4 p-6 pt-0",children:p.map((r,o)=>e.jsx(ee,{control:h.control,name:r,render:({field:N})=>e.jsxs(se,{children:[e.jsx(ae,{children:r||`Field ${o+1}`}),e.jsx(te,{children:e.jsx(ie,{placeholder:"Enter value",...N,onChange:b=>h.setValue(r||`field_${o}`,b.target.value)})}),e.jsx(le,{})]})},o))})}),e.jsxs(ne,{className:"p-6 pt-0",children:[e.jsx(y,{type:"button",variant:"outline",onClick:()=>g(!1),children:"Cancel"}),e.jsxs(y,{type:"submit",disabled:w,children:[w&&e.jsx(he,{className:"mr-2 h-4 w-4 animate-spin"}),m==="create"?"Add Row":"Save Changes"]})]})]})})]})})}function Be(){const{id:a}=je(),g=we(),[v,j]=l.useState(!0),[m,w]=l.useState(!1),[n,h]=l.useState(null),[d,p]=l.useState([]),[r,o]=l.useState(!1),[N,b]=l.useState(!1),[t,S]=l.useState(null),[C,k]=l.useState([]),{page:I,limit:L,offset:E,paged:M,setPage:H,setLimit:q,setPaged:$}=ve({defaultLimit:20}),O=l.useCallback(async()=>{j(!0);try{const s=await f.list(`${x.lists}/${a}/rows`,{offset:E,limit:L});if(s!=null&&s.result){const{result:i,...c}=s;if(p(i),$({total:c.total,returned:c.returned}),s.result.length>0){const D=Object.keys(s.result[0]);k(K=>[...new Set([...K,...D])])}}}catch{}finally{j(!1)}},[L,E,$,a]),R=l.useCallback(async()=>{try{const s=await f.get(x.lists,a);s&&h(s)}catch{u.error("No list found"),g("/lists")}},[a,g]);l.useEffect(()=>{R(),O()},[R,O]);const B=async s=>{w(!0);try{if(t)await f.put(`${x.lists}/${a}/rows`,t._id,s),p(d.map(i=>i._id===t._id?{...i,...s}:i)),u.success("The row has been updated successfully.");else{const i=await f.post(`${x.lists}/${a}/rows`,[s]);p([...d,...i]),u.success("The row has been added successfully.")}o(!1)}catch(i){u.error(i.message)}finally{w(!1)}},V=async()=>{try{await f.download(`${x.lists}/${a}/rows/download`,{},n?`agenty-list-${Le(n.name)}`:`list-${a}`)}catch(s){u.error(s.message)}},z=async()=>{if(t)try{await f.deleteMany(`${x.lists}/${a}/rows`,{id:t._id}),p(d.filter(s=>s._id!==t._id)),b(!1),u.success("The row has been deleted successfully.")}catch(s){u.error(s.message)}};return e.jsxs("div",{className:"space-y-6",children:[e.jsx(be,{title:n?n.name:"Loading...",description:n?n.description:"Loading...",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(y,{onClick:()=>o(!0),children:[e.jsx(pe,{className:"mr-2 h-4 w-4"}),"Add"]}),e.jsxs(y,{variant:"outline",onClick:V,children:[e.jsx(fe,{className:"mr-2 h-4 w-4"}),"Download"]})]})}),e.jsx("div",{className:"rounded-md border",children:e.jsx("div",{className:"relative w-full overflow-auto grid grid-cols-1",children:e.jsxs(re,{children:[e.jsx(oe,{children:e.jsxs(T,{children:[C.map(s=>e.jsx(A,{className:"max-w-[200px] truncate",children:s},s)),e.jsx(A,{className:"w-[50px]"})]})}),e.jsx(ce,{children:d.map((s,i)=>e.jsxs(T,{children:[C.map(c=>{var D;return e.jsx(F,{className:"max-w-[200px] truncate",title:(D=s[c])==null?void 0:D.toString(),children:s[c]!==null&&s[c]!==void 0?s[c].toString():"-"},c)}),e.jsx(F,{children:e.jsxs(de,{modal:!1,children:[e.jsx(ue,{asChild:!0,children:e.jsx(y,{variant:"ghost",className:"h-8 w-8 p-0",children:e.jsx(xe,{className:"h-4 w-4"})})}),e.jsxs(me,{align:"end",children:[e.jsx(P,{onClick:()=>{S(s),o(!0)},children:"Edit row"}),e.jsx(P,{className:"text-destructive",onClick:()=>{S(s),b(!0)},children:"Delete row"})]})]})})]},i))})]})})}),d.length===0&&!v&&e.jsx(Se,{icon:e.jsx(ge,{className:"w-full h-full"}),title:"No data found",description:"This list is empty, upload a file to add rows"}),e.jsx(Ne,{paged:M,onPageChange:H,onLimitChange:q,currentPage:I}),e.jsx($e,{open:r,onOpenChange:o,onSubmit:B,defaultValues:Object.fromEntries(t?C.filter(s=>s!=="_id").map(s=>[s,(t==null?void 0:t[s])??""]):C.filter(s=>s!=="_id").map(s=>[s,""])),mode:t?"edit":"create",isSubmitting:m}),e.jsx(De,{open:N,onOpenChange:b,title:"Delete Row",description:"Are you sure you want to delete this row? This action cannot be undone.",onConfirm:z,confirmLabel:"Delete",variant:"destructive"})]})}
1export{Be as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.