UNPKG

@techdocs/cli

Version:

Utility CLI for managing TechDocs sites in Backstage.

3 lines (2 loc) • 10.2 kB
"use strict";(()=>{(self.webpackChunktechdocs_cli_embedded_app=self.webpackChunktechdocs_cli_embedded_app||[]).push([[5470,5788],{52235:(k,x,t)=>{var a,u=t(4293),C=t(78920);a={value:!0},x.A=void 0;var p=C(t(14041)),B=u(t(74044)),j=(0,B.default)(p.createElement("path",{d:"M12 4l-1.41 1.41L16.17 11H4v2h12.17l-5.58 5.59L12 20l8-8z"}),"ArrowForward");x.A=j},48045:(k,x,t)=>{t.d(x,{n:()=>st});var a=t(31085),u=t(40703),C=t(59469),p=t(48653),B=t(45685),j=t(37197),T=t(58837),w=t(87051),q=t(53373),M=t.n(q),W=t(10394),N=t(72501),_=t(52235),tt=t(72072);const U=(0,T.A)(i=>({root:{maxWidth:"fit-content",padding:i.spacing(2,2,2,2.5)},boxTitle:{margin:0,color:i.palette.textSubtle},arrow:{color:i.palette.textSubtle}}),{name:"BackstageBottomLink"});function P(i){const{link:o,title:c,onClick:S}=i,I=U();return(0,a.jsxs)(W.A,{children:[(0,a.jsx)(j.A,{}),(0,a.jsx)(tt.N_,{to:o,onClick:S,underline:"none",children:(0,a.jsxs)(W.A,{display:"flex",alignItems:"center",className:I.root,children:[(0,a.jsx)(W.A,{className:I.boxTitle,fontWeight:"fontWeightBold",m:1,children:(0,a.jsx)(N.A,{children:(0,a.jsx)("strong",{children:c})})}),(0,a.jsx)(_.A,{className:I.arrow})]})})]})}var G=t(14041),V=t(73896),L=t(22020),z=t(10315),at=t(87849);const et=i=>{const{slackChannel:o}=i,{t:c}=(0,at.i)(z.O);if(o){if(typeof o=="string")return(0,a.jsx)(N.A,{children:c("errorBoundary.title",{slackChannel:o})});if(!o.href)return(0,a.jsx)(N.A,{children:c("errorBoundary.title",{slackChannel:o.name})})}else return null;return(0,a.jsx)(V.z,{to:o.href,variant:"contained",children:o.name})},F=class extends G.Component{constructor(o){super(o),this.state={error:void 0,errorInfo:void 0}}componentDidCatch(o,c){console.error(`ErrorBoundary, error: ${o}`,{error:o,errorInfo:c}),this.setState({error:o,errorInfo:c})}render(){const{slackChannel:o,children:c}=this.props,{error:S}=this.state;return S?(0,a.jsx)(L.b,{title:"Something Went Wrong",error:S,children:(0,a.jsx)(et,{slackChannel:o})}):c}},K=(0,T.A)(i=>({noPadding:{padding:0,"&:last-child":{paddingBottom:0}},contentAlignBottom:{display:"flex",alignItems:"self-end"},header:{padding:i.spacing(2,2,2,2.5)},headerTitle:{fontWeight:i.typography.fontWeightBold},headerSubheader:{paddingTop:i.spacing(1)},headerAvatar:{},headerAction:{},headerContent:{},subheader:{display:"flex"}}),{name:"BackstageInfoCard"}),nt=(0,w.A)(i=>({root:{display:"inline-block",padding:i.spacing(8,8,0,0),float:"right"}}),{name:"BackstageInfoCardCardActionsTopRight"})(C.A),$={card:{flex:{display:"flex",flexDirection:"column"},fullHeight:{display:"flex",flexDirection:"column",height:"100%"},gridItem:{display:"flex",flexDirection:"column",height:"calc(100% - 10px)",marginBottom:"10px",breakInside:"avoid-page","@media print":{height:"auto"}}},cardContent:{fullHeight:{flex:1},gridItem:{flex:1}}};function st(i){const{title:o,subheader:c,divider:S=!0,deepLink:I,slackChannel:Y,errorBoundaryProps:J,variant:Q,alignContent:ot="normal",children:rt,headerStyle:dt,headerProps:lt,icon:D,action:it,actionsClassName:ct,actions:X,cardClassName:H,actionsTopRight:Z,className:ht,noPadding:gt,titleTypographyProps:mt,subheaderTypographyProps:ut}=i,f=K();let R={},O={};Q&&Q.split(/[\s]+/g).forEach(n=>{R={...R,...$.card[n]},O={...O,...$.cardContent[n]}});const b=()=>!c&&!D?null:(0,a.jsxs)("div",{"data-testid":"info-card-subheader",children:[c&&(0,a.jsx)("div",{className:f.subheader,children:c}),D]}),pt=J||(Y?{slackChannel:Y}:{});return(0,a.jsx)(u.A,{style:R,className:ht,children:(0,a.jsxs)(F,{...pt,children:[o&&(0,a.jsx)(B.A,{classes:{root:M()(f.header),title:f.headerTitle,subheader:f.headerSubheader,avatar:f.headerAvatar,action:f.headerAction,content:f.headerContent},title:o,subheader:b(),action:it,style:{...dt},titleTypographyProps:mt,subheaderTypographyProps:ut,...lt}),Z&&(0,a.jsx)(nt,{children:Z}),S&&(0,a.jsx)(j.A,{}),(0,a.jsx)(p.A,{className:M()(H,{[f.noPadding]:gt,[f.contentAlignBottom]:ot==="bottom"}),style:O,children:rt}),X&&(0,a.jsx)(C.A,{className:ct,children:X}),I&&(0,a.jsx)(P,{...I})]})})}},25470:(k,x,t)=>{t.r(x),t.d(x,{CustomDocsPanel:()=>b,TechDocsCustomHome:()=>pt});var a=t(31085),u=t(14041),C=t(73466),p=t(58837),B=t(51372),j=t(6820),T=t(72427),w=t(16009),q=t(67871);function M(){const e=(0,T.gf)(w.K),{loading:n,value:d}=(0,C.A)(async()=>{const{ownershipEntityRefs:r}=await e.getBackstageIdentity();return r},[]),s=(0,u.useMemo)(()=>{const r=new Set(d??[]);return g=>{const h=(0,q.t)(g,B.vv).map(j.U2);for(const y of h)if(r.has(y))return!0;return!1}},[d]);return{loading:n,isOwnedEntity:s}}var W=t(21405),N=t(7341),_=t(86519),tt=t(27125),U=t(82779),P=t(95768),G=t(9222),V=t(65461),L=t(10394),z=t(12398);const at=e=>(0,z.A)({root:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(22em, 1fr))",gridAutoRows:"1fr",gridGap:e.spacing(2)}}),et=(0,p.A)(at,{name:"BackstageItemCardGrid"});function F(e){const{children:n,...d}=e,s=et(d);return(0,a.jsx)(L.A,{className:s.root,...d,children:n})}var K=t(72501);const nt=e=>(0,z.A)({root:{color:e.palette.common.white,padding:e.spacing(2,2,3),backgroundImage:e.getPageTheme({themeId:"card"}).backgroundImage,backgroundPosition:0,backgroundSize:"inherit"}}),$=(0,p.A)(nt,{name:"BackstageItemCardHeader"});function st(e){const{title:n,subtitle:d,children:s}=e,r=$(e);return(0,a.jsxs)(L.A,{className:r.root,children:[d&&(0,a.jsx)(K.A,{variant:"subtitle2",component:"h3",children:d}),n&&(0,a.jsx)(K.A,{variant:"h6",component:"h4",children:n}),s]})}var i=t(73896),o=t(40703),c=t(59469),S=t(48653),I=t(57369);const Y=e=>{const{entities:n}=e,d=(0,G.S)(U.Oc),s=(0,T.gf)(V.U);return n?(0,a.jsx)(F,{"data-testid":"docs-explore",children:n?.length?n.map((r,g)=>(0,a.jsxs)(o.A,{children:[(0,a.jsx)(I.A,{children:(0,a.jsx)(st,{title:r.metadata.title??r.metadata.name})}),(0,a.jsx)(S.A,{children:r.metadata.description}),(0,a.jsx)(c.A,{children:(0,a.jsx)(i.z,{to:d({namespace:(0,P.V)(r.metadata.namespace??"default",s),kind:(0,P.V)(r.kind,s),name:(0,P.V)(r.metadata.name,s)}),color:"primary","data-testid":"read_docs",children:"Read Docs"})})]},g)):null}):null};var J=t(68146),Q=t(48045),ot=t(72072),rt=t(82292);const dt=(0,p.A)(e=>({linkSpacer:{paddingTop:e.spacing(.2)},readMoreLink:{paddingTop:e.spacing(.2)}}),{name:"BackstageInfoCardGrid"}),lt=e=>{const{entities:n,linkContent:d,linkDestination:s}=e,r=dt(),g=(0,G.S)(U.Oc),h=(0,T.gf)(V.U),y=l=>{if(s){const v=s(l);if(v)return v}return g({namespace:(0,P.V)(l.metadata.namespace??"default",h),kind:(0,P.V)(l.kind,h),name:(0,P.V)(l.metadata.name,h)})},A=(0,T.gf)(rt.n),{value:m,loading:E}=(0,C.A)(async()=>new Map(await Promise.all(n?.map(async l=>{const v=await A.forEntity(l).promise;return[(0,j.U2)(l),v]})||[])));return E?(0,a.jsx)(J.k,{}):!n||!n?.length?null:(0,a.jsx)(F,{"data-testid":"info-card-container",children:n.map(l=>(0,a.jsxs)(Q.n,{"data-testid":l?.metadata?.title,title:m?.get((0,j.U2)(l))?.primaryTitle,children:[(0,a.jsx)("div",{children:l?.metadata?.description}),(0,a.jsx)("div",{className:r.linkSpacer}),(0,a.jsx)(ot.N_,{to:y(l),className:r.readMoreLink,"data-testid":"read-docs-link",children:d||"Read Docs"})]},l.metadata.name))})};var D=t(81859),it=t(85788),ct=t(59428),X=t(27586),H=t(26280),Z=t(88640),ht=t(77310),gt=t(38605),mt=t(31653);const ut=(0,p.A)(e=>({tabsWrapper:{gridArea:"pageSubheader",backgroundColor:e.palette.background.paper,paddingLeft:e.spacing(3),minWidth:0},defaultTab:{...e.typography.caption,padding:e.spacing(3,3),textTransform:"uppercase",fontWeight:e.typography.fontWeightBold,color:e.palette.text.secondary},selected:{color:e.palette.text.primary},tabRoot:{"&:hover":{backgroundColor:e.palette.background.default,color:e.palette.text.primary}}}),{name:"BackstageHeaderTabs"});function f(e){const{tabs:n,onChange:d,selectedIndex:s}=e,[r,g]=(0,u.useState)(s??0),h=ut(),y=(0,u.useCallback)((A,m)=>{s===void 0&&g(m),d&&d(m)},[s,d]);return(0,u.useEffect)(()=>{s!==void 0&&g(s)},[s]),(0,a.jsx)(L.A,{className:h.tabsWrapper,children:(0,a.jsx)(mt.A,{indicatorColor:"primary",textColor:"inherit",variant:"scrollable",scrollButtons:"auto","aria-label":"tabs",onChange:y,value:r,children:n.map((A,m)=>(0,a.jsx)(gt.A,{"data-testid":`header-tab-${m}`,label:A.label,value:m,className:h.defaultTab,classes:{selected:h.selected,root:h.tabRoot},...A.tabProps},A.id))})})}var R=t(86202);const O={DocsTable:tt.o,DocsCardGrid:Y,TechDocsIndexPage:it.TechDocsIndexPage,InfoCardGrid:lt},b=({config:e,entities:n,index:d})=>{const r=(0,p.A)({panelContainer:{marginBottom:"2rem",...e.panelCSS?e.panelCSS:{}}})(),{loading:g,isOwnedEntity:h}=M(),y=O[e.panelType],A=n.filter(E=>e.filterPredicate==="ownedByUser"?g?!1:h(E):typeof e.filterPredicate=="function"&&e.filterPredicate(E)),m=e.panelProps?.CustomHeader||(()=>(0,a.jsx)(ct.d,{title:e.title,description:e.description,children:d===0?(0,a.jsx)(X.Y,{children:"Discover documentation in your ecosystem."}):null}));return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(m,{}),(0,a.jsx)("div",{className:r.panelContainer,children:(0,a.jsx)(W.B9,{children:(0,a.jsx)(y,{"data-testid":"techdocs-custom-panel",entities:A,...e.panelProps})})})]})},pt=e=>{const{tabsConfig:n,filter:d,CustomPageWrapper:s}=e,[r,g]=(0,u.useState)(0),h=(0,T.gf)(N.v),{value:y,loading:A,error:m}=(0,C.A)(async()=>(await h.getEntities({filter:{...d,[`metadata.annotations.${R.As}`]:_.c},fields:["apiVersion","kind","metadata","relations","spec.owner","spec.type"]})).items.filter(v=>!!v.metadata.annotations?.[R.As])),E=n[r];return A?(0,a.jsx)(D.S,{CustomPageWrapper:s,children:(0,a.jsx)(H.U,{children:(0,a.jsx)(J.k,{})})}):m?(0,a.jsx)(D.S,{CustomPageWrapper:s,children:(0,a.jsx)(H.U,{children:(0,a.jsx)(Z.B,{severity:"error",title:"Could not load available documentation.",children:(0,a.jsx)(ht.z,{language:"text",text:m.toString()})})})}):(0,a.jsxs)(D.S,{CustomPageWrapper:s,children:[(0,a.jsx)(f,{selectedIndex:r,onChange:l=>g(l),tabs:n.map(({label:l},v)=>({id:v.toString(),label:l}))}),(0,a.jsx)(H.U,{"data-testid":"techdocs-content",children:E.panels.map((l,v)=>(0,a.jsx)(b,{config:l,entities:y||[],index:v},v))})]})}},85788:(k,x,t)=>{t.r(x),t.d(x,{TechDocsIndexPage:()=>p});var a=t(31085),u=t(18690),C=t(8915);const p=B=>(0,u.P1)()||(0,a.jsx)(C.K,{...B})}}]);})(); //# sourceMappingURL=5470.cbffc774.chunk.js.map