@baseplate-dev/project-builder-web
Version:
Web interface for constructing project builder JSON
3 lines (2 loc) • 4.83 kB
JavaScript
import{i as c}from"./_virtual___federation_fn_import-C4el_tlG.js";import{j as e}from"./jsx-runtime-D_zvdyIk.js";import{u as E,l as I,I as $,t as M}from"./index-BsqYBobW.js";import{C as W}from"./index--XHV4ygU.js";function A(f,a,t){return`/api/plugins/${f}/${a}/static/${t}`}const{createPluginImplementationStoreWithNewPlugins:B,PluginUtils:N,webConfigSpec:w}=await c("@baseplate-dev/project-builder-lib"),{useProjectDefinition:F}=await c("@baseplate-dev/project-builder-lib/web"),{Button:h,Card:z,CardContent:T,CardDescription:H,CardHeader:L,CardTitle:R}=await c("@baseplate-dev/ui-components"),{Link:S,useNavigate:U}=await c("@tanstack/react-router");function C({className:f,plugin:a,isActive:t,managerPlugin:i}){const{currentProjectId:x}=E(),{saveDefinitionWithFeedbackSync:j,schemaParserContext:b,definitionContainer:u,pluginContainer:y,isSavingDefinition:P}=F(),g=U();function p(){const d=B(b.pluginStore,[a],u.definition);if(d.getPluginSpec(w).getWebConfigComponent(a.key)){g({to:`/plugins/edit/${a.key}`}).catch(I);return}j(m=>{m.plugins=(m.plugins??[]).filter(v=>v.packageName!==a.packageName||v.name!==a.name),N.setPluginConfig(m,a,{},d)},{successMessage:`Enabled ${a.displayName}!`})}function r(){j(d=>{N.disablePlugin(d,a.key,b)},{successMessage:`Disabled ${a.displayName}!`})}const n=y.getPluginSpec(w),s=n.getWebConfigComponent(a.key),o=i?n.getWebConfigComponent(i.key):null;return e.jsxs(z,{className:f,children:[e.jsx(L,{children:e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx("div",{className:"rounded-xl border",children:a.icon&&x?e.jsx("img",{src:A(x,a.key,a.icon),className:"size-12 rounded-xl bg-muted",alt:`${a.displayName} logo`}):e.jsx(W,{className:"size-12 bg-muted p-2"})}),e.jsxs("div",{children:[e.jsx(R,{children:a.displayName}),e.jsx(H,{children:a.packageName})]})]}),e.jsx("div",{children:i?o&&t?e.jsx(S,{to:"/plugins/edit/$key",params:{key:i.key},children:e.jsx(h,{variant:"secondary",children:"Configure"})}):e.jsx(h,{variant:"secondary",disabled:!0,children:t?"Managed":"Disabled"}):t?s?e.jsx(S,{to:"/plugins/edit/$key",params:{key:a.key},children:e.jsx(h,{variant:"secondary",children:"Configure"})}):e.jsx(h,{variant:"secondary",onClick:r,disabled:P,children:"Disable"}):e.jsx(h,{variant:"secondary",onClick:p,disabled:P,children:"Enable"})})]})}),e.jsx(T,{children:e.jsx("div",{className:"text-sm",children:e.jsx("p",{children:a.description})})})]})}const{useProjectDefinition:Q}=await c("@baseplate-dev/project-builder-lib/web"),{EmptyDisplay:V,ErrorableLoader:Y}=await c("@baseplate-dev/ui-components"),{useEffect:_,useState:D}=await c("react"),O=function(){const{currentProjectId:a}=E(),[t,i]=D(null),{definition:x}=Q(),[j,b]=D(null);if(_(()=>{if(i(null),!!a){if($){i([]);return}M.plugins.getAvailablePlugins.mutate({projectId:a}).then(i).catch(b)}},[a]),!t)return e.jsx(Y,{error:j});if(t.length===0)return e.jsx(V,{header:"No plugins available.",subtitle:"Please install plugins via package.json."});const u=x.plugins??[],y=t.filter(n=>!n.managedBy),P=t.filter(n=>n.managedBy),g=y.filter(n=>u.some(s=>s.packageName===n.packageName&&s.name===n.name)),p=y.filter(n=>!n.hidden&&!u.some(s=>s.packageName===n.packageName&&s.name===n.name)),r=new Map;for(const n of P){const s=n.managedBy;if(!s)continue;r.has(s)||r.set(s,[]);const o=r.get(s);o&&o.push(n)}return e.jsxs("div",{className:"max-w-2xl space-y-4 p-4",children:[e.jsx("h1",{children:"Manage Plugins"}),e.jsx("p",{children:"Plugins are a way to extend the functionality of your project, such as adding authentication. You can enable, disable, and manage plugins from this page."}),e.jsxs("p",{children:["To add additional plugins, you can install them to your root package with ",e.jsx("strong",{children:"pnpm"}),"."]}),g.length===0?null:e.jsxs(e.Fragment,{children:[e.jsxs("h3",{children:["Active Plugins (",g.length,")"]}),g.map(n=>e.jsx(C,{plugin:n,isActive:!0},n.key))]}),p.length===0?null:e.jsxs(e.Fragment,{children:[e.jsxs("h3",{children:["Available Plugins (",p.length,")"]}),p.map(n=>e.jsx(C,{plugin:n,isActive:!1},n.key))]}),r.size===0?null:e.jsxs(e.Fragment,{children:[e.jsx("h3",{children:"Managed Plugins"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"These plugins are managed by their parent plugins and cannot be configured directly."}),[...r.entries()].map(([n,s])=>{const o=t.find(l=>l.fullyQualifiedName===n),d=o?.displayName??n;return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h4",{className:"text-sm font-medium text-muted-foreground",children:["Managed by ",d]}),s.map(l=>{const k=u.some(m=>m.packageName===l.packageName&&m.name===l.name);return e.jsx(C,{plugin:l,isActive:k,managerPlugin:o},l.key)})]},n)})]})]})};export{O as component};
//# sourceMappingURL=index-Dm2uG0g1.js.map