@baseplate-dev/project-builder-web
Version:
Web interface for constructing project builder JSON
3 lines (2 loc) • 3.25 kB
JavaScript
import{i as n}from"./_virtual___federation_fn_import-C4el_tlG.js";import{j as o}from"./jsx-runtime-D_zvdyIk.js";import{s as M}from"./index-BsqYBobW.js";import{e as k}from"./index.esm-C5MSuOl4.js";import{u as K}from"./use-definition-schema-Dyj6xH4G.js";const{adminSectionEntityType:b,createWebAdminSectionSchema:U}=await n("@baseplate-dev/project-builder-lib"),{useProjectDefinition:W,useResettableForm:$}=await n("@baseplate-dev/project-builder-lib/web"),{Button:h,ComboboxFieldController:l,Dialog:E,DialogContent:B,DialogDescription:H,DialogFooter:V,DialogHeader:q,DialogTitle:z,DialogTrigger:G,InputFieldController:g,SelectFieldController:J,useControlledState:L}=await n("@baseplate-dev/ui-components"),{useNavigate:Q}=await n("@tanstack/react-router"),{useMemo:X}=await n("react");function te({children:x,appId:j,appKey:C,open:S,onOpenChange:y}){const[D,r]=L(S,y,!1),v=Q(),{definition:i,saveDefinitionWithFeedback:w,isSavingDefinition:c}=W(),R=K(U),d=i.features.map(e=>({label:e.name,value:e.id})),F=i.models.map(e=>({label:e.name,value:e.id})),N=$({resolver:M(R),defaultValues:{name:"",type:"crud",featureRef:d[0]?.value??"",icon:"",modelRef:"",nameFieldRef:"",form:{fields:[]},table:{columns:[]}}}),{control:t,handleSubmit:T,reset:m}=N,p=k({control:t,name:"modelRef"}),A=X(()=>i.models.find(e=>e.id===p)?.model.fields.map(e=>({label:e.name,value:e.id}))??[],[i.models,p]),I=T(e=>{const f=b.generateNewId();return w(O=>{const a=O.apps.find(s=>s.id===j);a?.type==="web"&&(a.adminApp??={enabled:!0,pathPrefix:"/admin",sections:[]},a.adminApp.sections=[...a.adminApp.sections??[],{...e,id:f}].sort((s,P)=>s.name.localeCompare(P.name)))},{successMessage:`Successfully created section "${e.name}"!`,onSuccess:()=>{r(!1),m(),v({to:"/admin-sections/$appKey/edit/$sectionKey",params:{appKey:C,sectionKey:b.keyFromId(f)}})}})}),u=e=>{r(e),e||m()};return o.jsxs(E,{open:D,onOpenChange:u,children:[o.jsx(G,{asChild:!0,children:x}),o.jsxs(B,{className:"sm:max-w-md",children:[o.jsxs(q,{children:[o.jsx(z,{children:"Create New Admin Section"}),o.jsx(H,{children:"Create a new CRUD interface for managing your data models."})]}),o.jsxs("form",{onSubmit:e=>(e.stopPropagation(),I(e)),className:"space-y-4",children:[o.jsx(g,{label:"Name",control:t,name:"name",placeholder:"e.g. Users, Posts, Categories",description:"The display name for this admin section",autoComplete:"off"}),o.jsx(l,{label:"Feature",control:t,options:d,name:"featureRef",description:"The feature this section belongs to"}),o.jsx(g,{label:"Icon",control:t,name:"icon",placeholder:"e.g. MdPeople, MdArticle",description:"React icon component name (optional)"}),o.jsx(J,{label:"Type",control:t,name:"type",options:[{label:"CRUD",value:"crud"}],description:"The type of admin interface"}),o.jsx(l,{label:"Model",control:t,options:F,name:"modelRef",description:"The model to use for this section"}),o.jsx(l,{label:"Name Field",control:t,options:A,name:"nameFieldRef",description:"The field to use for the name of the section"}),o.jsxs(V,{children:[o.jsx(h,{type:"button",variant:"outline",onClick:()=>{u(!1)},children:"Cancel"}),o.jsx(h,{type:"submit",disabled:c,children:c?"Creating...":"Create Section"})]})]})]})]})}export{te as N};
//# sourceMappingURL=new-admin-section-dialog-Cbu0HBZt.js.map