"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[2793],{42278(z,f,t){t.r(f),t.d(f,{NotebookScenePage:()=>S,default:()=>U});var s=t(74848),v=t(96540),m=t(54148),l=t(64342),N=t(5989),y=t(17189),h=t(5195),c=t(5246),b=t(25021),j=t(50709),k=t(22803),i=t(52358),C=t(49439),P=t(43304),E=t(27181);function L({uid:o}){const e=(0,C.of)(p);return(0,s.jsx)("div",{className:e.toolbar,children:(0,s.jsx)(P.b,{variant:"secondary",size:"sm",icon:"link",getText:()=>(0,E.Y7)(o),children:(0,i.t)("notebooks.view.copy-link","Copy link")})})}const p=o=>({toolbar:(0,k.css)({display:"flex",alignItems:"center",justifyContent:"flex-end",gap:o.spacing(1),padding:o.spacing(1,2),borderBottom:`1px solid ${o.colors.border.weak}`})});var I=t(33100),M=t(51389);function F({error:o}){const e=o.status===404;return(0,s.jsx)(c.Y,{navId:"notebooks",layout:l.k.Canvas,pageNav:{text:e?(0,i.t)("notebook.errors.not-found-title","Not found"):(0,i.t)("notebook.errors.failed-to-load","Failed to load notebook")},children:(0,s.jsx)(h.a,{paddingY:4,display:"flex",direction:"column",alignItems:"center",children:e?(0,s.jsx)(M.L,{entity:(0,i.t)("notebook.errors.entity","Notebook")}):(0,s.jsx)(I.F,{title:(0,i.t)("notebook.errors.failed-to-load","Failed to load notebook"),severity:"error","data-testid":"notebook-page-error",children:o.message})})})}var Y=t(89344),B=t(23829),g=t(25948),T=t(11534),A=t(52934);class $ extends B.Q{constructor(){super(...arguments),this.cache=new Map,this.requestSeq=0}async loadNotebook(e){const n=++this.requestSeq;this.setState({isLoading:!0,loadError:void 0});try{const a=await(0,T.JD)(Y.cA.endpoints.getNotebook.initiate({name:e},{subscribe:!1}));if(a&&"error"in a)throw a.error;if(!a.data)throw new Error("Notebook not found");const d=a.data,r=this.cache.get(e);if(r&&r.generation===d.metadata.generation){if(this.isSuperseded(n))return;this.setState({scene:r.scene,isLoading:!1});return}const x=(0,A.P)(structuredClone(d));if(this.cache.set(e,{generation:d.metadata.generation,scene:x}),this.isSuperseded(n))return;this.setState({scene:x,isLoading:!1})}catch(a){if(this.isSuperseded(n))return;this.setState({isLoading:!1,loadError:{status:(0,g.do)(a),message:(0,g.q6)(a),messageId:(0,g.rE)(a)}})}}isSuperseded(e){return e!==this.requestSeq}clearState(){this.requestSeq++,this.setState({scene:void 0,isLoading:!1,loadError:void 0})}removeSceneCache(e){this.cache.delete(e)}clearSceneCache(){this.cache.clear()}}let u;function D(){return u||(u=new $({isLoading:!1})),u}function S(){const o=(0,N.s$)(),{uid:e}=(0,m.g)(),n=D(),{scene:a,isLoading:d,loadError:r}=n.useState();return(0,v.useEffect)(()=>(o&&e&&n.loadNotebook(e),()=>{n.clearState()}),[n,e,o]),o?a?(0,s.jsx)(y.$,{scene:a,updateUrlOnInit:!0,createBrowserHistorySteps:!0,children:(0,s.jsx)(H,{scene:a})}):r?(0,s.jsx)(F,{error:r}):(0,s.jsx)(c.Y,{navId:"notebooks",layout:l.k.Canvas,"data-testid":"notebook-scene-page",children:(0,s.jsx)(h.a,{paddingY:4,display:"flex",direction:"column",alignItems:"center",children:d&&(0,s.jsx)(b.A,{})})}):(0,s.jsx)(j.H,{})}function H({scene:o}){const{title:e,uid:n}=o.useState();(0,v.useEffect)(()=>o.activate(),[o]);const a={text:e};return(0,s.jsxs)(c.Y,{navId:"notebooks",pageNav:a,layout:l.k.Custom,children:[n&&(0,s.jsx)(L,{uid:n}),(0,s.jsx)(o.Component,{model:o})]})}const U=S}}]);

//# sourceMappingURL=NotebookScenePage.99f09080d066d4c03493.js.map