"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[2550],{47761:(k,N,s)=>{s.d(N,{l:()=>F});var a=s(74848),p=s(22803),x=s(96540),P=s(49785);function F({defaultValues:v,onSubmit:g,validateOnMount:u=!1,validateFieldsOnMount:E,children:J,validateOn:T="onSubmit",maxWidth:c=600,...R}){const{handleSubmit:b,trigger:h,formState:L,...D}=(0,P.mN)({mode:T,defaultValues:v});return(0,x.useEffect)(()=>{u&&h(E)},[h,E,u]),(0,a.jsx)("form",{className:(0,p.css)({maxWidth:c!=="none"?c+"px":c,width:"100%"}),onSubmit:b(g),...R,children:J({errors:L.errors,formState:L,trigger:h,...D})})}},83029:(k,N,s)=>{s.r(N),s.d(N,{default:()=>La});var a=s(74848),p=s(22803),x=s(96540),P=s(71468),F=s(52718),v=s(8392),g=s(58779),u=s(56276),E=s(32370),J=s(54731),T=s(50876),c=s(86489),R=s(40271),b=s(34128),h=s(54594),L=s(50926),D=s(48583),q=s(20968),W=s(29675),_=s(90617),aa=s(22492),A=s(47761),z=s(54122),l=s(11817),ta=s(40449),sa=s(88090),ea=s(53027),oa=s(90231),K=s(99178),O=s(4956),y=s(33914),V=s(49785),ra=s(65502),na=s(62851),da=s(15773),ia=s(15543),la=s(3142);const ca=e=>{let t;try{t=JSON.parse(e)}catch{return(0,l.t)("dashboard.validation.invalid-json","Not valid JSON")}if(t&&t.hasOwnProperty("tags"))if(Array.isArray(t.tags)){if(t.tags.some(r=>typeof r!="string"))return(0,l.t)("dashboard.validation.tags-expected-strings","tags expected array of strings")}else return(0,l.t)("dashboard.validation.tags-expected-array","tags expected array");return!0},ha=e=>{const t=/(^\d+$)|dashboards\/(\d+)/.exec(e);return t&&(t[1]||t[2])?!0:(0,l.t)("dashboard.validation.invalid-dashboard-id","Could not find a valid Grafana.com ID")},ma=(e,t)=>la.P.validateNewDashboardName(t,e).then(()=>!0).catch(i=>{if(i.type==="EXISTING")return i.message}),H=e=>(0,ia.n)().getDashboardDTO(e).then(t=>`Dashboard named '${t?.dashboard.title}' in folder '${t?.meta.folderTitle}' has the same UID`).catch(t=>(t.isHandled=!0,t.status===403?"Dashboard with the same UID already exists":!0));var pa=s(78935);function Y({inputs:e,label:t,description:i,folderName:r}){const o=(0,W.of)(ua);return e?.length?(0,a.jsx)("div",{className:o.spacer,children:(0,a.jsx)(c.D,{label:t,description:i,children:(0,a.jsx)(a.Fragment,{children:e.map((n,I)=>{const S=`elements[${I}]`,j=n.state===y.J7.New?{...n.model,meta:{...n.model.meta,folderName:r??"Dashboards"}}:{...n.model};return(0,a.jsx)("div",{className:o.item,children:(0,a.jsx)(pa.E,{libraryPanel:j,onClick:()=>{}})},S)})})})}):null}function ua(e){return{spacer:(0,p.css)({marginBottom:e.spacing(2)}),item:(0,p.css)({marginBottom:e.spacing(1)})}}const ba=({register:e,errors:t,control:i,getValues:r,uidReset:o,inputs:n,onUidReset:I,onCancel:S,onSubmit:j,watch:U})=>{const[C,B]=(0,x.useState)(!1),Ua=U("dataSources"),Z=U("folder");(0,x.useEffect)(()=>{C&&(t.title||t.uid)&&j(r())},[t,r,C,j]);const Ca=n?.libraryPanels?.filter(d=>d.state===y.J7.New)??[],Fa=n?.libraryPanels?.filter(d=>d.state===y.J7.Exists)??[];return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(K.s,{children:"Options"}),(0,a.jsx)(c.D,{label:"Name",invalid:!!t.title,error:t.title&&t.title.message,children:(0,a.jsx)(b.p,{...e("title",{required:"Name is required",validate:async d=>await ma(d,r().folder.uid)}),type:"text","data-testid":g.Tp.components.ImportDashboardForm.name})}),(0,a.jsx)(c.D,{label:"Folder",children:(0,a.jsx)(V.xI,{render:({field:{ref:d,value:m,onChange:f,...$}})=>(0,a.jsx)(na.d,{...$,onChange:(w,M)=>f({uid:w,title:M}),value:m.uid}),name:"folder",control:i})}),(0,a.jsx)(c.D,{label:"Unique identifier (UID)",description:`The unique identifier (UID) of a dashboard can be used for uniquely identify a dashboard between multiple Grafana installs.
                The UID allows having consistent URLs for accessing dashboards so changing the title of a dashboard will not break any
                bookmarked links to that dashboard.`,invalid:!!t.uid,error:t.uid&&t.uid.message,children:(0,a.jsx)(a.Fragment,{children:o?(0,a.jsx)(b.p,{...e("uid",{required:!0,validate:async d=>await H(d)})}):(0,a.jsx)(b.p,{disabled:!0,...e("uid",{validate:async d=>await H(d)}),addonAfter:!o&&(0,a.jsx)(h.$n,{onClick:I,children:"Change uid"})})})}),n.dataSources&&n.dataSources.map((d,m)=>{if(d.pluginId===ra.dR.type)return null;const f=`dataSources.${m}`,$=Ua??[];return(0,a.jsx)(c.D,{label:d.label,description:d.description,invalid:t.dataSources&&!!t.dataSources[m],error:t.dataSources&&t.dataSources[m]&&"A data source is required",children:(0,a.jsx)(V.xI,{name:f,render:({field:{ref:w,...M}})=>(0,a.jsx)(da.s,{...M,noDefault:!0,placeholder:d.info,pluginId:d.pluginId,current:$[m]?.uid}),control:i,rules:{required:!0}})},f)}),n.constants&&n.constants.map((d,m)=>{const f=`constants.${m}`;return(0,a.jsx)(c.D,{label:d.label,error:t.constants&&t.constants[m]&&`${d.label} needs a value`,invalid:t.constants&&!!t.constants[m],children:(0,a.jsx)(b.p,{...e(f,{required:!0}),defaultValue:d.value})},f)}),(0,a.jsx)(Y,{inputs:Ca,label:"New library panels",description:"List of new library panels that will get imported.",folderName:Z.title}),(0,a.jsx)(Y,{inputs:Fa,label:"Existing library panels",description:"List of existing library panels. These panels are not affected by the import.",folderName:Z.title}),(0,a.jsxs)(D.B,{children:[(0,a.jsx)(h.$n,{type:"submit","data-testid":g.Tp.components.ImportDashboardForm.submit,variant:fa(t),onClick:()=>{B(!0)},children:xa(t)}),(0,a.jsx)(h.$n,{type:"reset",variant:"secondary",onClick:S,children:"Cancel"})]})]})};function fa(e){return e&&(e.title||e.uid)?"destructive":"primary"}function xa(e){return e&&(e.title||e.uid)?"Import (Overwrite)":"Import"}const va="dashboard_import_imported",ga=e=>{const t=ea.Ny.getSearchObject();return{dashboard:e.importDashboard.dashboard,meta:e.importDashboard.meta,source:e.importDashboard.source,inputs:e.importDashboard.inputs,folder:t.folderUid?{uid:String(t.folderUid)}:{uid:""}}},Da={clearLoadedDashboard:O.FG,importDashboard:O.Q9},ja=(0,P.connect)(ga,Da);class ya extends x.PureComponent{constructor(){super(...arguments),this.state={uidReset:!1},this.onSubmit=t=>{(0,u.rR)(va),this.props.importDashboard(t)},this.onCancel=()=>{this.props.clearLoadedDashboard()},this.onUidReset=()=>{this.setState({uidReset:!0})}}render(){const{dashboard:t,inputs:i,meta:r,source:o,folder:n}=this.props,{uidReset:I}=this.state;return(0,a.jsxs)(a.Fragment,{children:[o===y.qx.Gcom&&(0,a.jsxs)(oa.a,{marginBottom:3,children:[(0,a.jsx)("div",{children:(0,a.jsxs)(K.s,{children:["Importing dashboard from"," ",(0,a.jsx)("a",{href:`https://grafana.com/dashboards/${t.gnetId}`,className:"external-link",target:"_blank",rel:"noreferrer",children:"Grafana.com"})]})}),(0,a.jsx)("table",{className:"filter-table form-inline",children:(0,a.jsxs)("tbody",{children:[(0,a.jsxs)("tr",{children:[(0,a.jsx)("td",{children:"Published by"}),(0,a.jsx)("td",{children:r.orgName})]}),(0,a.jsxs)("tr",{children:[(0,a.jsx)("td",{children:"Updated on"}),(0,a.jsx)("td",{children:(0,sa.LE)(r.updatedAt)})]})]})})]}),(0,a.jsx)(A.l,{onSubmit:this.onSubmit,defaultValues:{...t,constants:[],dataSources:[],elements:[],folder:n},validateOnMount:!0,validateFieldsOnMount:["title","uid"],validateOn:"onChange",children:({register:S,errors:j,control:U,watch:C,getValues:B})=>(0,a.jsx)(ba,{register:S,errors:j,control:U,getValues:B,uidReset:I,inputs:i,onCancel:this.onCancel,onUidReset:this.onUidReset,onSubmit:this.onSubmit,watch:C})})]})}}const Q=ja(ya);Q.displayName="ImportDashboardOverview";const G="dashboard_import_loaded",Ia=`{
    "title": "Example - Repeating Dictionary variables",
    "uid": "_0HnEoN4z",
    "panels": [...]
    ...
}
`,Sa=e=>({loadingState:e.importDashboard.state}),Na={fetchGcomDashboard:O.rw,importDashboardJson:O.iP,cleanUpAction:ta.N},Pa=(0,P.connect)(Sa,Na);class Ea extends x.PureComponent{constructor(t){super(t),this.fileListRenderer=(r,o)=>null,this.onFileUpload=r=>{(0,u.rR)(G,{import_source:"json_uploaded"});try{this.props.importDashboardJson(JSON.parse(String(r)))}catch(o){o instanceof Error&&aa.A.emit(F.r1.alertError,["Import failed","JSON -> JS Serialization failed: "+o.message]);return}},this.getDashboardFromJson=r=>{(0,u.rR)(G,{import_source:"json_pasted"}),this.props.importDashboardJson(JSON.parse(r.dashboardJson))},this.getGcomDashboard=r=>{(0,u.rR)(G,{import_source:"gcom"});let o;const n=/(^\d+$)|dashboards\/(\d+)/.exec(r.gcomDashboard);n&&n[1]?o=n[1]:n&&n[2]&&(o=n[2]),o&&this.props.fetchGcomDashboard(o)},this.pageNav={text:"Import dashboard",subTitle:"Import dashboard from file or Grafana.com"};const{gcomDashboardId:i}=this.props.queryParams;if(i){this.getGcomDashboard({gcomDashboard:i});return}}componentWillUnmount(){this.props.cleanUpAction({cleanupAction:t=>t.importDashboard=y.V9})}renderImportForm(){const t=Oa(this.props.theme),i=()=>(0,a.jsx)(J.Y,{variant:"bodySmall",href:"https://grafana.com/grafana/dashboards/",external:!0,children:"grafana.com/dashboards"});return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:t.option,children:(0,a.jsx)(T.gH,{options:{multiple:!1,accept:[".json",".txt"]},readAs:"readAsText",fileListRenderer:this.fileListRenderer,onLoad:this.onFileUpload,children:(0,a.jsx)(T.wI,{primaryText:(0,l.t)("dashboard-import.file-dropzone.primary-text","Upload dashboard JSON file"),secondaryText:(0,l.t)("dashboard-import.file-dropzone.secondary-text","Drag and drop here or click to browse")})})}),(0,a.jsx)("div",{className:t.option,children:(0,a.jsx)(A.l,{onSubmit:this.getGcomDashboard,defaultValues:{gcomDashboard:""},children:({register:r,errors:o})=>(0,a.jsx)(c.D,{label:(0,a.jsx)(R.J,{className:t.labelWithLink,htmlFor:"url-input",children:(0,a.jsx)("span",{children:(0,a.jsxs)(l.x6,{i18nKey:"dashboard-import.gcom-field.label",children:["Find and import dashboards for common applications at ",(0,a.jsx)(i,{})]})})}),invalid:!!o.gcomDashboard,error:o.gcomDashboard&&o.gcomDashboard.message,children:(0,a.jsx)(b.p,{id:"url-input",placeholder:(0,l.t)("dashboard-import.gcom-field.placeholder","Grafana.com dashboard URL or ID"),type:"text",...r("gcomDashboard",{required:(0,l.t)("dashboard-import.gcom-field.validation-required","A Grafana dashboard URL or ID is required"),validate:ha}),addonAfter:(0,a.jsx)(h.$n,{type:"submit",children:(0,a.jsx)(l.x6,{i18nKey:"dashboard-import.gcom-field.load-button",children:"Load"})})})})})}),(0,a.jsx)("div",{className:t.option,children:(0,a.jsx)(A.l,{onSubmit:this.getDashboardFromJson,defaultValues:{dashboardJson:""},children:({register:r,errors:o})=>(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(c.D,{label:(0,l.t)("dashboard-import.json-field.label","Import via dashboard JSON model"),invalid:!!o.dashboardJson,error:o.dashboardJson&&o.dashboardJson.message,children:(0,a.jsx)(L.f,{...r("dashboardJson",{required:(0,l.t)("dashboard-import.json-field.validation-required","Need a dashboard JSON model"),validate:ca}),"data-testid":g.Tp.components.DashboardImportPage.textarea,id:"dashboard-json-textarea",rows:10,placeholder:Ia})}),(0,a.jsxs)(D.B,{children:[(0,a.jsx)(h.$n,{type:"submit","data-testid":g.Tp.components.DashboardImportPage.submit,children:(0,a.jsx)(l.x6,{i18nKey:"dashboard-import.form-actions.load",children:"Load"})}),(0,a.jsx)(h.z9,{variant:"secondary",href:`${E.$.appSubUrl}/dashboards`,children:(0,a.jsx)(l.x6,{i18nKey:"dashboard-import.form-actions.cancel",children:"Cancel"})})]})]})})})]})}render(){const{loadingState:t}=this.props;return(0,a.jsx)(z.Y,{navId:"dashboards/browse",pageNav:this.pageNav,children:(0,a.jsxs)(z.Y.Contents,{children:[t===v.Gu.Loading&&(0,a.jsx)(D.B,{direction:"column",justifyContent:"center",children:(0,a.jsx)(D.B,{justifyContent:"center",children:(0,a.jsx)(q.y,{size:"xxl"})})}),[v.Gu.Error,v.Gu.NotStarted].includes(t)&&this.renderImportForm(),t===v.Gu.Done&&(0,a.jsx)(Q,{})]})})}}const Ta=(0,W.cV)(Ea),X=Pa(Ta);X.displayName="DashboardImport";const La=X,Oa=(0,_.N)(e=>({option:(0,p.css)({marginBottom:e.spacing(4),maxWidth:"600px"}),labelWithLink:(0,p.css)({maxWidth:"100%"}),linkWithinLabel:(0,p.css)({fontSize:"inherit"})}))}}]);

//# sourceMappingURL=DashboardImport.8936b02afc3e8fba5f01.js.map