"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[2550],{72235:(Z,N,s)=>{s.d(N,{l:()=>R});var a=s(74848),p=s(32196),f=s(96540),P=s(49785);function R({defaultValues:x,onSubmit:v,validateOnMount:u=!1,validateFieldsOnMount:E,children:A,validateOn:L="onSubmit",maxWidth:l=600,...G}){const{handleSubmit:b,trigger:c,formState:T,...g}=(0,P.mN)({mode:L,defaultValues:x});return(0,f.useEffect)(()=>{u&&c(E)},[c,E,u]),(0,a.jsx)("form",{className:(0,p.css)({maxWidth:l!=="none"?l+"px":l,width:"100%"}),onSubmit:b(v),...G,children:A({errors:T.errors,formState:T,trigger:c,...g})})}},23390:(Z,N,s)=>{s.r(N),s.d(N,{default:()=>Ea});var a=s(74848),p=s(32196),f=s(96540),P=s(71468),R=s(26272),x=s(39070),v=s(13544),u=s(14110),E=s(32264),A=s(72109),L=s(37270),l=s(88575),G=s(60029),b=s(10354),c=s(55852),T=s(21744),g=s(67061),w=s(62930),M=s(40845),k=s(3911),q=s(28138),$=s(72235),W=s(21780),h=s(8484),_=s(97007),aa=s(72724),ta=s(39601),sa=s(90613),z=s(17408),O=s(11230),j=s(88264),K=s(49785),ea=s(26657),oa=s(85242),ra=s(51612),U=s(72635),na=s(17172),da=s(71500);const ia=e=>{let t;try{t=JSON.parse(e)}catch{return(0,U.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,U.t)("dashboard.validation.tags-expected-strings","tags expected array of strings")}else return(0,U.t)("dashboard.validation.tags-expected-array","tags expected array");return!0},la=e=>{const t=/(^\d+$)|dashboards\/(\d+)/.exec(e);return t&&(t[1]||t[2])?!0:(0,U.t)("dashboard.validation.invalid-dashboard-id","Could not find a valid Grafana.com ID")},ca=(e,t)=>da.P.validateNewDashboardName(t,e).then(()=>!0).catch(i=>{if(i.type==="EXISTING")return i.message}),V=e=>(0,na.AI)().get(`/api/dashboards/uid/${e}`).then(t=>`Dashboard named '${t?.dashboard.title}' in folder '${t?.meta.folderTitle}' has the same UID`).catch(t=>(t.isHandled=!0,!0));var ha=s(86474);function H({inputs:e,label:t,description:i,folderName:r}){const o=(0,M.of)(ma);return e?.length?(0,a.jsx)("div",{className:o.spacer,children:(0,a.jsx)(l.D,{label:t,description:i,children:(0,a.jsx)(a.Fragment,{children:e.map((n,D)=>{const y=`elements[${D}]`,I=n.state===j.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)(ha.E,{libraryPanel:I,onClick:()=>{}})},y)})})})}):null}function ma(e){return{spacer:(0,p.css)`
      margin-bottom: ${e.spacing(2)};
    `,item:(0,p.css)`
      margin-bottom: ${e.spacing(1)};
    `}}const pa=({register:e,errors:t,control:i,getValues:r,uidReset:o,inputs:n,initialFolderUid:D,onUidReset:y,onCancel:I,onSubmit:C,watch:F})=>{const[J,Ta]=(0,f.useState)(!1),Oa=F("dataSources"),X=F("folder");(0,f.useEffect)(()=>{J&&(t.title||t.uid)&&C(r())},[t,r,J,C]);const Ua=n?.libraryPanels?.filter(d=>d.state===j.J7.New)??[],Ca=n?.libraryPanels?.filter(d=>d.state===j.J7.Exists)??[];return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(z.s,{children:"Options"}),(0,a.jsx)(l.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 ca(d,r().folder.uid)}),type:"text","data-testid":v.Tp.components.ImportDashboardForm.name})}),(0,a.jsx)(l.D,{label:"Folder",children:(0,a.jsx)(K.xI,{render:({field:{ref:d,...m}})=>(0,a.jsx)(oa.sR,{...m,enableCreateNew:!0,initialFolderUid:D}),name:"folder",control:i})}),(0,a.jsx)(l.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 V(d)})}):(0,a.jsx)(b.p,{disabled:!0,...e("uid",{validate:async d=>await V(d)}),addonAfter:!o&&(0,a.jsx)(c.$n,{onClick:y,children:"Change uid"})})})}),n.dataSources&&n.dataSources.map((d,m)=>{if(d.pluginId===ea.dR.type)return null;const S=`dataSources.${m}`,Fa=Oa??[];return(0,a.jsx)(l.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)(K.xI,{name:S,render:({field:{ref:Ra,...Ja}})=>(0,a.jsx)(ra.s,{...Ja,noDefault:!0,placeholder:d.info,pluginId:d.pluginId,current:Fa[m]?.uid}),control:i,rules:{required:!0}})},S)}),n.constants&&n.constants.map((d,m)=>{const S=`constants.${m}`;return(0,a.jsx)(l.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(S,{required:!0}),defaultValue:d.value})},S)}),(0,a.jsx)(H,{inputs:Ua,label:"New library panels",description:"List of new library panels that will get imported.",folderName:X.title}),(0,a.jsx)(H,{inputs:Ca,label:"Existing library panels",description:"List of existing library panels. These panels are not affected by the import.",folderName:X.title}),(0,a.jsxs)(g.B,{children:[(0,a.jsx)(c.$n,{type:"submit","data-testid":v.Tp.components.ImportDashboardForm.submit,variant:ua(t),onClick:()=>{Ta(!0)},children:ba(t)}),(0,a.jsx)(c.$n,{type:"reset",variant:"secondary",onClick:I,children:"Cancel"})]})]})};function ua(e){return e&&(e.title||e.uid)?"destructive":"primary"}function ba(e){return e&&(e.title||e.uid)?"Import (Overwrite)":"Import"}const fa="dashboard_import_imported",xa=e=>{const t=ta.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:""}}},va={clearLoadedDashboard:O.FG,importDashboard:O.Q9},ga=(0,P.connect)(xa,va);class ja extends f.PureComponent{constructor(){super(...arguments),this.state={uidReset:!1},this.onSubmit=t=>{(0,u.rR)(fa),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:D}=this.state;return(0,a.jsxs)(a.Fragment,{children:[o===j.qx.Gcom&&(0,a.jsxs)(sa.a,{marginBottom:3,children:[(0,a.jsx)("div",{children:(0,a.jsxs)(z.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,aa.LE)(r.updatedAt)})]})]})})]}),(0,a.jsx)($.l,{onSubmit:this.onSubmit,defaultValues:{...t,constants:[],dataSources:[],elements:[],folder:n},validateOnMount:!0,validateFieldsOnMount:["title","uid"],validateOn:"onChange",children:({register:y,errors:I,control:C,watch:F,getValues:J})=>(0,a.jsx)(pa,{register:y,errors:I,control:C,getValues:J,uidReset:D,inputs:i,onCancel:this.onCancel,onUidReset:this.onUidReset,onSubmit:this.onSubmit,watch:F,initialFolderUid:n.uid})})]})}}const Y=ga(ja);Y.displayName="ImportDashboardOverview";const B="dashboard_import_loaded",Da=`{
    "title": "Example - Repeating Dictionary variables",
    "uid": "_0HnEoN4z",
    "panels": [...]
    ...
}
`,ya=e=>({loadingState:e.importDashboard.state}),Ia={fetchGcomDashboard:O.rw,importDashboardJson:O.iP,cleanUpAction:_.N},Sa=(0,P.connect)(ya,Ia);class Na extends f.PureComponent{constructor(t){super(t),this.fileListRenderer=(r,o)=>null,this.onFileUpload=r=>{(0,u.rR)(B,{import_source:"json_uploaded"});try{this.props.importDashboardJson(JSON.parse(String(r)))}catch(o){o instanceof Error&&q.A.emit(R.r1.alertError,["Import failed","JSON -> JS Serialization failed: "+o.message]);return}},this.getDashboardFromJson=r=>{(0,u.rR)(B,{import_source:"json_pasted"}),this.props.importDashboardJson(JSON.parse(r.dashboardJson))},this.getGcomDashboard=r=>{(0,u.rR)(B,{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=j.V9})}renderImportForm(){const t=La(this.props.theme),i=()=>(0,a.jsx)(A.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)(L.gH,{options:{multiple:!1,accept:[".json",".txt"]},readAs:"readAsText",fileListRenderer:this.fileListRenderer,onLoad:this.onFileUpload,children:(0,a.jsx)(L.wI,{primaryText:(0,h.t)("dashboard-import.file-dropzone.primary-text","Upload dashboard JSON file"),secondaryText:(0,h.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)($.l,{onSubmit:this.getGcomDashboard,defaultValues:{gcomDashboard:""},children:({register:r,errors:o})=>(0,a.jsx)(l.D,{label:(0,a.jsx)(G.J,{className:t.labelWithLink,htmlFor:"url-input",children:(0,a.jsx)("span",{children:(0,a.jsxs)(h.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,h.t)("dashboard-import.gcom-field.placeholder","Grafana.com dashboard URL or ID"),type:"text",...r("gcomDashboard",{required:(0,h.t)("dashboard-import.gcom-field.validation-required","A Grafana dashboard URL or ID is required"),validate:la}),addonAfter:(0,a.jsx)(c.$n,{type:"submit",children:(0,a.jsx)(h.x6,{i18nKey:"dashboard-import.gcom-field.load-button",children:"Load"})})})})})}),(0,a.jsx)("div",{className:t.option,children:(0,a.jsx)($.l,{onSubmit:this.getDashboardFromJson,defaultValues:{dashboardJson:""},children:({register:r,errors:o})=>(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(l.D,{label:(0,h.t)("dashboard-import.json-field.label","Import via dashboard JSON model"),invalid:!!o.dashboardJson,error:o.dashboardJson&&o.dashboardJson.message,children:(0,a.jsx)(T.f,{...r("dashboardJson",{required:(0,h.t)("dashboard-import.json-field.validation-required","Need a dashboard JSON model"),validate:ia}),"data-testid":v.Tp.components.DashboardImportPage.textarea,id:"dashboard-json-textarea",rows:10,placeholder:Da})}),(0,a.jsxs)(g.B,{children:[(0,a.jsx)(c.$n,{type:"submit","data-testid":v.Tp.components.DashboardImportPage.submit,children:(0,a.jsx)(h.x6,{i18nKey:"dashboard-import.form-actions.load",children:"Load"})}),(0,a.jsx)(c.z9,{variant:"secondary",href:`${E.$.appSubUrl}/dashboards`,children:(0,a.jsx)(h.x6,{i18nKey:"dashboard-import.form-actions.cancel",children:"Cancel"})})]})]})})})]})}render(){const{loadingState:t}=this.props;return(0,a.jsx)(W.YW,{navId:"dashboards/browse",pageNav:this.pageNav,children:(0,a.jsxs)(W.YW.Contents,{children:[t===x.Gu.Loading&&(0,a.jsx)(g.B,{direction:"column",justifyContent:"center",children:(0,a.jsx)(g.B,{justifyContent:"center",children:(0,a.jsx)(w.y,{size:"xxl"})})}),[x.Gu.Error,x.Gu.NotStarted].includes(t)&&this.renderImportForm(),t===x.Gu.Done&&(0,a.jsx)(Y,{})]})})}}const Pa=(0,M.cV)(Na),Q=Sa(Pa);Q.displayName="DashboardImport";const Ea=Q,La=(0,k.N)(e=>({option:(0,p.css)`
      margin-bottom: ${e.spacing(4)};
      max-width: 600px;
    `,labelWithLink:(0,p.css)`
      max-width: 100%;
    `,linkWithinLabel:(0,p.css)`
      font-size: inherit;
    `}))}}]);

//# sourceMappingURL=DashboardImport.bba95b5237b4d8acf313.js.map