"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[7454],{5460:(H,u,t)=>{t.r(u),t.d(u,{default:()=>j});var D=t(42844),e=t(27702),b=t(38192),E=t(73289),N=t(66310),y=t(58456),T=t(60729),f=t(66670),O=t(44644),x=t(26473),m=t(18771),M=t(83341),P=t(57082),J=t(64611),F=t(65036),U=t(34667),V=t(14574),$=t(15372),S=t(54281),z=t(60042),B=t(43590),G=t(3323),C=t(23852),Z=t(23839),A=t(73807);const K=({dashboard:a,onCancel:s,onSubmit:c,onSuccess:v,saveModel:n})=>{const[l,i]=(0,e.useState)(!1),o=(0,A.iG)(),r=(0,e.useMemo)(()=>a.hasTimeChanged()||n.hasChanges,[a,n]),d=async()=>{c&&(i(!0),c(n.clone).then(()=>{o.success("Dashboard saved locally"),v()}).catch(h=>{o.error(h.message||"Error saving dashboard")}).finally(()=>i(!1)))};return e.createElement(Z.l,{onSubmit:d},()=>e.createElement(C.K,{gap:2},e.createElement(C.K,{alignItems:"center"},e.createElement(f.zx,{variant:"secondary",onClick:s,fill:"outline"},"Cancel"),e.createElement(f.zx,{type:"submit",disabled:!r,icon:l?"fa fa-spinner":void 0},"Save"),!r&&e.createElement("div",null,"No changes to save"))))},L=({dashboard:a,onDismiss:s,dashboardJson:c,onSave:v})=>{const n=(0,e.useMemo)(()=>{const o=a.getSaveModelClone(),r=JSON.stringify(o,null,2),d=JSON.parse(r),h=(0,G.Q$)(JSON.parse(JSON.stringify(c,null,2)),d);let g=0;for(const X of Object.values(h))g+=X.length;return{clone:o,diff:h,diffCount:g,hasChanges:g>0}},[a,c]),[l,i]=(0,e.useState)(!1);return e.createElement(V.d,{title:"Save dashboard",onClose:s,subtitle:a.title,tabs:e.createElement($.J,null,e.createElement(S.O,{label:"Details",active:!l,onChangeTab:()=>i(!1)}),n.hasChanges&&e.createElement(S.O,{label:"Changes",active:l,onChangeTab:()=>i(!0),counter:n.diffCount})),scrollableContent:!0},l?e.createElement(B._,{diff:n.diff,oldValue:c,newValue:n.clone}):e.createElement(K,{dashboard:a,saveModel:n,onCancel:s,onSuccess:s,onSubmit:v}),U.config.featureToggles.showDashboardValidationWarnings&&e.createElement(z.Z,{dashboard:a}))};var Q=t(83350),W=t(73170),Y=t(54195);function j({route:a,queryParams:s}){const c=(0,m.useDispatch)(),v=(0,x.p)(),n=(0,m.useSelector)(r=>r.dashboard),l=n.getModel(),[i,o]=(0,e.useState)("");return(0,e.useEffect)(()=>{const r=s.callbackUrl;if(!r)throw new Error("No callback URL provided");(0,E.i)().get(`${r}/load-dashboard`).then(d=>{o(d),delete d.uid;const h=new W.f(d);c((0,Y.mV)({routeName:a.routeName,fixUrl:!1,keybindingSrv:v.keybindings,dashboardDto:{dashboard:h,meta:{canEdit:!0}}}))}).catch(d=>{console.log("Error getting dashboard JSON: ",d)})},[]),l?l.meta.dashboardNotFound?e.createElement("p",null,"Not available"):e.createElement(O.T,{pageNav:{text:l.title},layout:b.Q.Custom},e.createElement(I,{dashboard:l,callbackUrl:s.callbackUrl,dashboardJson:i}),n.initError&&e.createElement(J.u,{initError:n.initError}),e.createElement("div",null,e.createElement(Q.Z,{dashboard:l,isEditable:!0,viewPanel:null,editPanel:null,hidePanelMenus:!0}))):e.createElement(F.B,{initPhase:n.initPhase})}const I=({dashboard:a,callbackUrl:s,dashboardJson:c})=>{const v=(0,m.useDispatch)(),n=(0,N.wW)(R),l=o=>{v((0,M.YT)(o))},i=async o=>{if(!(!o||!s))return(0,E.i)().post(`${s}/save-dashboard`,{dashboard:o})};return e.createElement(y.X,{title:a.title,buttonOverflowAlignment:"right",className:n.toolbar},!a.timepicker.hidden&&e.createElement(P.C,{dashboard:a,onChangeTimeZone:l}),e.createElement(T.JY,{key:"button-save"},({showModal:o,hideModal:r})=>e.createElement(f.zx,{onClick:()=>{o(L,{dashboard:a,dashboardJson:c,onDismiss:r,onSave:i})}},"Save")))},R=a=>({toolbar:(0,D.css)`
      padding: ${a.spacing(3,2)};
    `})}}]);

//# sourceMappingURL=EmbeddedDashboardPage.dae378ecbb53288ec835.js.map