"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[2550],{23390:(Oe,J,t)=>{t.r(J),t.d(J,{default:()=>xe});var u=t(32196),e=t(96540),C=t(63329),H=t(26272),D=t(39070),y=t(13544),I=t(14110),W=t(32264),K=t(72109),O=t(37270),c=t(88575),Y=t(60029),p=t(10354),h=t(55852),Q=t(21744),S=t(67061),X=t(62930),R=t(40845),Z=t(3911),w=t(28138),F=t(72235),G=t(17205),i=t(44836),k=t(97007),q=t(72724),_=t(12131),ee=t(90613),$=t(17408),N=t(11230),b=t(88264),A=t(49785),ae=t(26657),te=t(85242),re=t(51612),x=t(72635),ne=t(17172),oe=t(71500);const se=r=>{let a;try{a=JSON.parse(r)}catch{return(0,x.t)("dashboard.validation.invalid-json","Not valid JSON")}if(a&&a.hasOwnProperty("tags"))if(Array.isArray(a.tags)){if(a.tags.some(o=>typeof o!="string"))return(0,x.t)("dashboard.validation.tags-expected-strings","tags expected array of strings")}else return(0,x.t)("dashboard.validation.tags-expected-array","tags expected array");return!0},de=r=>{const a=/(^\d+$)|dashboards\/(\d+)/.exec(r);return a&&(a[1]||a[2])?!0:(0,x.t)("dashboard.validation.invalid-dashboard-id","Could not find a valid Grafana.com ID")},le=(r,a)=>oe.P.validateNewDashboardName(a,r).then(()=>!0).catch(l=>{if(l.type==="EXISTING")return l.message}),j=r=>(0,ne.AI)().get(`/api/dashboards/uid/${r}`).then(a=>`Dashboard named '${a?.dashboard.title}' in folder '${a?.meta.folderTitle}' has the same UID`).catch(a=>(a.isHandled=!0,!0));var ie=t(86474);function B({inputs:r,label:a,description:l,folderName:o}){const n=(0,R.of)(me);return r?.length?e.createElement("div",{className:n.spacer},e.createElement(c.D,{label:a,description:l},e.createElement(e.Fragment,null,r.map((s,f)=>{const v=`elements[${f}]`,E=s.state===b.J7.New?{...s.model,meta:{...s.model.meta,folderName:o??"General"}}:{...s.model};return e.createElement("div",{className:n.item,key:v},e.createElement(ie.E,{libraryPanel:E,onClick:()=>{}}))})))):null}function me(r){return{spacer:(0,u.css)`
      margin-bottom: ${r.spacing(2)};
    `,item:(0,u.css)`
      margin-bottom: ${r.spacing(1)};
    `}}const ce=({register:r,errors:a,control:l,getValues:o,uidReset:n,inputs:s,initialFolderUid:f,onUidReset:v,onCancel:E,onSubmit:P,watch:L})=>{const[T,Le]=(0,e.useState)(!1),Te=L("dataSources"),M=L("folder");(0,e.useEffect)(()=>{T&&(a.title||a.uid)&&P(o())},[a,o,T,P]);const Fe=s?.libraryPanels?.filter(d=>d.state===b.J7.New)??[],Ue=s?.libraryPanels?.filter(d=>d.state===b.J7.Exists)??[];return e.createElement(e.Fragment,null,e.createElement($.s,null,"Options"),e.createElement(c.D,{label:"Name",invalid:!!a.title,error:a.title&&a.title.message},e.createElement(p.p,{...r("title",{required:"Name is required",validate:async d=>await le(d,o().folder.uid)}),type:"text","data-testid":y.Tp.components.ImportDashboardForm.name})),e.createElement(c.D,{label:"Folder"},e.createElement(A.xI,{render:({field:{ref:d,...m}})=>e.createElement(te.sR,{...m,enableCreateNew:!0,initialFolderUid:f}),name:"folder",control:l})),e.createElement(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:!!a.uid,error:a.uid&&a.uid.message},e.createElement(e.Fragment,null,n?e.createElement(p.p,{...r("uid",{required:!0,validate:async d=>await j(d)})}):e.createElement(p.p,{disabled:!0,...r("uid",{validate:async d=>await j(d)}),addonAfter:!n&&e.createElement(h.$n,{onClick:v},"Change uid")}))),s.dataSources&&s.dataSources.map((d,m)=>{if(d.pluginId===ae.dR.type)return null;const g=`dataSources.${m}`,Je=Te??[];return e.createElement(c.D,{label:d.label,description:d.description,key:g,invalid:a.dataSources&&!!a.dataSources[m],error:a.dataSources&&a.dataSources[m]&&"A data source is required"},e.createElement(A.xI,{name:g,render:({field:{ref:Re,...Ce}})=>e.createElement(re.s,{...Ce,noDefault:!0,placeholder:d.info,pluginId:d.pluginId,current:Je[m]?.uid}),control:l,rules:{required:!0}}))}),s.constants&&s.constants.map((d,m)=>{const g=`constants.${m}`;return e.createElement(c.D,{label:d.label,error:a.constants&&a.constants[m]&&`${d.label} needs a value`,invalid:a.constants&&!!a.constants[m],key:g},e.createElement(p.p,{...r(g,{required:!0}),defaultValue:d.value}))}),e.createElement(B,{inputs:Fe,label:"New library panels",description:"List of new library panels that will get imported.",folderName:M.title}),e.createElement(B,{inputs:Ue,label:"Existing library panels",description:"List of existing library panels. These panels are not affected by the import.",folderName:M.title}),e.createElement(S.B,null,e.createElement(h.$n,{type:"submit","data-testid":y.Tp.components.ImportDashboardForm.submit,variant:he(a),onClick:()=>{Le(!0)}},ue(a)),e.createElement(h.$n,{type:"reset",variant:"secondary",onClick:E},"Cancel")))};function he(r){return r&&(r.title||r.uid)?"destructive":"primary"}function ue(r){return r&&(r.title||r.uid)?"Import (Overwrite)":"Import"}const pe="dashboard_import_imported",be=r=>{const a=_.Ny.getSearchObject();return{dashboard:r.importDashboard.dashboard,meta:r.importDashboard.meta,source:r.importDashboard.source,inputs:r.importDashboard.inputs,folder:a.folderUid?{uid:String(a.folderUid)}:{uid:""}}},fe={clearLoadedDashboard:N.FG,importDashboard:N.Q9},ve=(0,C.connect)(be,fe);class Ee extends e.PureComponent{constructor(){super(...arguments),this.state={uidReset:!1},this.onSubmit=a=>{(0,I.rR)(pe),this.props.importDashboard(a)},this.onCancel=()=>{this.props.clearLoadedDashboard()},this.onUidReset=()=>{this.setState({uidReset:!0})}}render(){const{dashboard:a,inputs:l,meta:o,source:n,folder:s}=this.props,{uidReset:f}=this.state;return e.createElement(e.Fragment,null,n===b.qx.Gcom&&e.createElement(ee.a,{marginBottom:3},e.createElement("div",null,e.createElement($.s,null,"Importing dashboard from"," ",e.createElement("a",{href:`https://grafana.com/dashboards/${a.gnetId}`,className:"external-link",target:"_blank",rel:"noreferrer"},"Grafana.com"))),e.createElement("table",{className:"filter-table form-inline"},e.createElement("tbody",null,e.createElement("tr",null,e.createElement("td",null,"Published by"),e.createElement("td",null,o.orgName)),e.createElement("tr",null,e.createElement("td",null,"Updated on"),e.createElement("td",null,(0,q.LE)(o.updatedAt)))))),e.createElement(F.l,{onSubmit:this.onSubmit,defaultValues:{...a,constants:[],dataSources:[],elements:[],folder:s},validateOnMount:!0,validateFieldsOnMount:["title","uid"],validateOn:"onChange"},({register:v,errors:E,control:P,watch:L,getValues:T})=>e.createElement(ce,{register:v,errors:E,control:P,getValues:T,uidReset:f,inputs:l,onCancel:this.onCancel,onUidReset:this.onUidReset,onSubmit:this.onSubmit,watch:L,initialFolderUid:s.uid})))}}const z=ve(Ee);z.displayName="ImportDashboardOverview";const U="dashboard_import_loaded",ge=`{
    "title": "Example - Repeating Dictionary variables",
    "uid": "_0HnEoN4z",
    "panels": [...]
    ...
}
`,De=r=>({loadingState:r.importDashboard.state}),ye={fetchGcomDashboard:N.rw,importDashboardJson:N.iP,cleanUpAction:k.N},Ie=(0,C.connect)(De,ye);class Se extends e.PureComponent{constructor(a){super(a),this.fileListRenderer=(o,n)=>null,this.onFileUpload=o=>{(0,I.rR)(U,{import_source:"json_uploaded"});try{this.props.importDashboardJson(JSON.parse(String(o)))}catch(n){n instanceof Error&&w.A.emit(H.r1.alertError,["Import failed","JSON -> JS Serialization failed: "+n.message]);return}},this.getDashboardFromJson=o=>{(0,I.rR)(U,{import_source:"json_pasted"}),this.props.importDashboardJson(JSON.parse(o.dashboardJson))},this.getGcomDashboard=o=>{(0,I.rR)(U,{import_source:"gcom"});let n;const s=/(^\d+$)|dashboards\/(\d+)/.exec(o.gcomDashboard);s&&s[1]?n=s[1]:s&&s[2]&&(n=s[2]),n&&this.props.fetchGcomDashboard(n)},this.pageNav={text:"Import dashboard",subTitle:"Import dashboard from file or Grafana.com"};const{gcomDashboardId:l}=this.props.queryParams;if(l){this.getGcomDashboard({gcomDashboard:l});return}}componentWillUnmount(){this.props.cleanUpAction({cleanupAction:a=>a.importDashboard=b.V9})}renderImportForm(){const a=Pe(this.props.theme),l=()=>e.createElement(K.Y,{variant:"bodySmall",href:"https://grafana.com/grafana/dashboards/",external:!0},"grafana.com/dashboards");return e.createElement(e.Fragment,null,e.createElement("div",{className:a.option},e.createElement(O.gH,{options:{multiple:!1,accept:[".json",".txt"]},readAs:"readAsText",fileListRenderer:this.fileListRenderer,onLoad:this.onFileUpload},e.createElement(O.wI,{primaryText:(0,i.t)("dashboard-import.file-dropzone.primary-text","Upload dashboard JSON file"),secondaryText:(0,i.t)("dashboard-import.file-dropzone.secondary-text","Drag and drop here or click to browse")}))),e.createElement("div",{className:a.option},e.createElement(F.l,{onSubmit:this.getGcomDashboard,defaultValues:{gcomDashboard:""}},({register:o,errors:n})=>e.createElement(c.D,{label:e.createElement(Y.J,{className:a.labelWithLink,htmlFor:"url-input"},e.createElement("span",null,e.createElement(i.x6,{i18nKey:"dashboard-import.gcom-field.label"},"Find and import dashboards for common applications at ",e.createElement(l,null)))),invalid:!!n.gcomDashboard,error:n.gcomDashboard&&n.gcomDashboard.message},e.createElement(p.p,{id:"url-input",placeholder:(0,i.t)("dashboard-import.gcom-field.placeholder","Grafana.com dashboard URL or ID"),type:"text",...o("gcomDashboard",{required:(0,i.t)("dashboard-import.gcom-field.validation-required","A Grafana dashboard URL or ID is required"),validate:de}),addonAfter:e.createElement(h.$n,{type:"submit"},e.createElement(i.x6,{i18nKey:"dashboard-import.gcom-field.load-button"},"Load"))})))),e.createElement("div",{className:a.option},e.createElement(F.l,{onSubmit:this.getDashboardFromJson,defaultValues:{dashboardJson:""}},({register:o,errors:n})=>e.createElement(e.Fragment,null,e.createElement(c.D,{label:(0,i.t)("dashboard-import.json-field.label","Import via dashboard JSON model"),invalid:!!n.dashboardJson,error:n.dashboardJson&&n.dashboardJson.message},e.createElement(Q.f,{...o("dashboardJson",{required:(0,i.t)("dashboard-import.json-field.validation-required","Need a dashboard JSON model"),validate:se}),"data-testid":y.Tp.components.DashboardImportPage.textarea,id:"dashboard-json-textarea",rows:10,placeholder:ge})),e.createElement(S.B,null,e.createElement(h.$n,{type:"submit","data-testid":y.Tp.components.DashboardImportPage.submit},e.createElement(i.x6,{i18nKey:"dashboard-import.form-actions.load"},"Load")),e.createElement(h.z9,{variant:"secondary",href:`${W.$.appSubUrl}/dashboards`},e.createElement(i.x6,{i18nKey:"dashboard-import.form-actions.cancel"},"Cancel")))))))}render(){const{loadingState:a}=this.props;return e.createElement(G.Y,{navId:"dashboards/browse",pageNav:this.pageNav},e.createElement(G.Y.Contents,null,a===D.Gu.Loading&&e.createElement(S.B,{direction:"column",justifyContent:"center"},e.createElement(S.B,{justifyContent:"center"},e.createElement(X.y,{size:"xxl"}))),[D.Gu.Error,D.Gu.NotStarted].includes(a)&&this.renderImportForm(),a===D.Gu.Done&&e.createElement(z,null)))}}const Ne=(0,R.cV)(Se),V=Ie(Ne);V.displayName="DashboardImport";const xe=V,Pe=(0,Z.N)(r=>({option:(0,u.css)`
      margin-bottom: ${r.spacing(4)};
      max-width: 600px;
    `,labelWithLink:(0,u.css)`
      max-width: 100%;
    `,linkWithinLabel:(0,u.css)`
      font-size: inherit;
    `}))}}]);

//# sourceMappingURL=DashboardImport.0b85651e842c6bd494ac.js.map