12 |
- "use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[3959],{26120:(e,t,a)=>{a.r(t),a.d(t,{DataSourceSettingsPage:()=>A,default:()=>L});var s=a(68404),n=a(18745),r=a(43215),o=a(16695),i=a(69783),l=a(45193),c=a(5831),d=a(33801),u=a(98163),h=a(8674),p=a(30978),g=a(58170),m=a(21169),f=a(87993),S=a(78487),b=a(75375),v=a(77197),x=a(45916);const D=e=>{let{dataSourceName:t,isDefault:a,onDefaultChange:s,onNameChange:n}=e;return(0,x.jsx)("div",{className:"gf-form-group","aria-label":"Datasource settings page basic settings",children:(0,x.jsxs)("div",{className:"gf-form-inline",children:[(0,x.jsx)("div",{className:"gf-form max-width-30",children:(0,x.jsx)(i.InlineField,{label:"Name",tooltip:"The name is used when you select the data source in panels. The default data source is 'preselected in new panels.",grow:!0,children:(0,x.jsx)(i.Input,{id:"basic-settings-name",type:"text",value:t,placeholder:"Name",onChange:e=>n(e.currentTarget.value),required:!0,"aria-label":o.wl.pages.DataSource.name})})}),(0,x.jsx)(i.InlineField,{label:"Default",labelWidth:8,children:(0,x.jsx)(i.InlineSwitch,{id:"basic-settings-default",value:a,onChange:e=>{s(e.currentTarget.checked)}})})]})})},y=e=>{let{canSave:t,canDelete:a,onDelete:s,onSubmit:n,onTest:r,exploreUrl:l}=e;const c=u.Vt.hasPermission(g.bW.DataSourcesExplore);return(0,x.jsxs)("div",{className:"gf-form-button-row",children:[(0,x.jsx)(i.Button,{variant:"secondary",fill:"solid",type:"button",onClick:()=>history.back(),children:"Back"}),(0,x.jsx)(i.LinkButton,{variant:"secondary",fill:"solid",href:l,disabled:!c,children:"Explore"}),(0,x.jsx)(i.Button,{type:"button",variant:"destructive",disabled:!a,onClick:s,"aria-label":o.wl.pages.DataSource.delete,children:"Delete"}),t&&(0,x.jsx)(i.Button,{type:"submit",variant:"primary",disabled:!t,onClick:e=>n(e),"aria-label":o.wl.pages.DataSource.saveAndTest,children:"Save & test"}),!t&&(0,x.jsx)(i.Button,{type:"submit",variant:"primary",onClick:r,children:"Test"})]})};var j=a(12011),C=a(56082),M=a(78837);const w=e=>{var t;let{dataSource:a}=e,s="",n="";if(a.readOnly||(null!==(t=a.version)&&void 0!==t?t:0)>2)return null;if(M.vc.buildInfo.edition!==j.e.OpenSource)return null;switch(a.type){case"prometheus":s="Prometheus",n="Loki";break;case"loki":s="Loki",n="Prometheus";break;default:return null}return(0,x.jsx)(C.G,{storageKey:"datasources.settings.cloudInfoBox.isDismissed",defaultValue:!1,children:(e,t)=>e?null:(0,x.jsxs)(i.Alert,{title:`Configure your ${s} data source below`,severity:"info",bottomSpacing:4,onRemove:()=>{t(!0)},children:["Or skip the effort and get ",s," (and ",n,") as fully-managed, scalable, and hosted data sources from Grafana Labs with the"," ",(0,x.jsx)("a",{className:"external-link",href:`https://grafana.com/signup/cloud/connect-account?src=grafana-oss&cnt=${a.type}-settings`,target:"_blank",rel:"noreferrer",title:"The free plan includes 10k active metrics and 50gb storage.",children:"free-forever Grafana Cloud plan"}),"."]})})};var P=a(82897),k=a(90923);function N(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}class I extends s.PureComponent{constructor(e){super(e),N(this,"element",null),N(this,"component",void 0),N(this,"scopeProps",void 0),N(this,"onModelChanged",(e=>{this.props.onModelChange(e)})),this.scopeProps={ctrl:{datasourceMeta:e.dataSourceMeta,current:(0,P.cloneDeep)(e.dataSource)},onModelChanged:this.onModelChanged},this.onModelChanged=this.onModelChanged.bind(this)}componentDidMount(){const{plugin:e}=this.props;if(this.element&&!e.components.ConfigEditor){const e=(0,k.getAngularLoader)(),t='<plugin-component type="datasource-config-ctrl" />';this.component=e.load(this.element,this.scopeProps,t)}}componentDidUpdate(e){const{plugin:t}=this.props;var a;t.components.ConfigEditor||this.props.dataSource===e.dataSource||(this.scopeProps.ctrl.current=(0,P.cloneDeep)(this.props.dataSource),null===(a=this.component)||void 0===a||a.digest())}componentWillUnmount(){this.component&&this.component.destroy()}render(){const{plugin:e,dataSource:t}=this.props;return e?(0,x.jsx)("div",{ref:e=>this.element=e,children:e.components.ConfigEditor&&s.createElement(e.components.ConfigEditor,{options:t,onOptionsChange:this.onModelChanged})}):null}}var O,T;function E(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}const B={deleteDataSource:f.xU,loadDataSource:f.gv,setDataSourceName:b.BX,updateDataSource:f.oe,setIsDefault:b.yr,dataSourceLoaded:b.rl,initDataSourceSettings:f.M9,testDataSource:f.kY,cleanUpAction:l.e},R=(0,n.connect)((function(e,t){const a=t.match.params.uid,s=new URLSearchParams(t.location.search),n=(0,v.f6)(e.dataSources,a),{plugin:r,loadError:o,loading:i,testingStatus:l}=e.dataSourceSettings,c=s.get("page"),d=r?(0,S.nI)((0,S.B1)(n,r),c||"settings"):(0,S.xG)("settings"),u=(0,h.h)(e.navIndex,c?`datasource-page-${c}`:`datasource-settings-${a}`,d);return{dataSource:(0,v.f6)(e.dataSources,a),dataSourceMeta:(0,v.G4)(e.dataSources,n.type),dataSourceId:a,page:c,plugin:r,loadError:o,loading:i,testingStatus:l,navModel:u}}),B);class A extends s.PureComponent{constructor(){super(...arguments),E(this,"onSubmit",(async e=>{e.preventDefault(),await this.props.updateDataSource(Object.assign({},this.props.dataSource)),this.testDataSource()})),E(this,"onTest",(async e=>{e.preventDefault(),this.testDataSource()})),E(this,"onDelete",(()=>{c.Z.publish(new m.VJ({title:"Delete",text:`Are you sure you want to delete the "${this.props.dataSource.name}" data source?`,yesText:"Delete",icon:"trash-alt",onConfirm:()=>{this.confirmDelete()}}))})),E(this,"confirmDelete",(()=>{this.props.deleteDataSource()})),E(this,"onModelChange",(e=>{this.props.dataSourceLoaded(e)}))}componentDidMount(){const{initDataSourceSettings:e,dataSourceId:t}=this.props;e(t)}componentWillUnmount(){this.props.cleanUpAction({stateSelector:e=>e.dataSourceSettings})}isReadOnly(){return!0===this.props.dataSource.readOnly}renderIsReadOnlyMessage(){return(0,x.jsx)(i.Alert,{"aria-label":o.wl.pages.DataSource.readOnly,severity:"info",title:"Provisioned data source",children:"This data source was added by config and cannot be modified using the UI. Please contact your server admin to update this data source."})}renderMissingEditRightsMessage(){return O||(O=(0,x.jsx)(i.Alert,{severity:"info",title:"Missing rights",children:"You are not allowed to modify this data source. Please contact your server admin to update this data source."}))}testDataSource(){const{dataSource:e,testDataSource:t}=this.props;t(e.name)}get hasDataSource(){return this.props.dataSource.id>0}onNavigateToExplore(){const{dataSource:e}=this.props,t=JSON.stringify({datasource:e.name,context:"explore"});return r.urlUtil.renderUrl("/explore",{left:t})}renderLoadError(){const{loadError:e,dataSource:t}=this.props,a=!this.isReadOnly()&&u.Vt.hasPermissionInMetadata(g.bW.DataSourcesDelete,t),s={text:e,subTitle:"Data Source Error",icon:"exclamation-triangle"},n={node:s,main:s};return(0,x.jsx)(d.Z,{navModel:n,children:(0,x.jsxs)(d.Z.Contents,{isLoading:this.props.loading,children:[this.isReadOnly()&&this.renderIsReadOnlyMessage(),(0,x.jsxs)("div",{className:"gf-form-button-row",children:[a&&(0,x.jsx)(i.Button,{type:"submit",variant:"destructive",onClick:this.onDelete,children:"Delete"}),(0,x.jsx)(i.Button,{variant:"secondary",fill:"outline",type:"button",onClick:()=>history.back(),children:"Back"})]})]})})}renderConfigPageBody(e){const{plugin:t}=this.props;if(!t||!t.configPages)return null;for(const a of t.configPages)if(a.id===e)return(0,x.jsx)(a.body,{plugin:t,query:{}});return(0,x.jsxs)("div",{children:["Page not found: ",e]})}renderAlertDetails(){var e,t,a;const{testingStatus:s}=this.props;return(0,x.jsxs)(x.Fragment,{children:[null==s||null===(e=s.details)||void 0===e?void 0:e.message,null!=s&&null!==(t=s.details)&&void 0!==t&&t.verboseMessage?(0,x.jsx)("details",{style:{whiteSpace:"pre-wrap"},children:null==s||null===(a=s.details)||void 0===a?void 0:a.verboseMessage}):null]})}renderSettings(){const{dataSourceMeta:e,setDataSourceName:t,setIsDefault:a,dataSource:s,plugin:n,testingStatus:r}=this.props,l=u.Vt.hasPermissionInMetadata(g.bW.DataSourcesWrite,s),c=u.Vt.hasPermissionInMetadata(g.bW.DataSourcesDelete,s);return(0,x.jsxs)("form",{onSubmit:this.onSubmit,children:[!l&&this.renderMissingEditRightsMessage(),this.isReadOnly()&&this.renderIsReadOnlyMessage(),e.state&&(0,x.jsxs)("div",{className:"gf-form",children:[T||(T=(0,x.jsx)("label",{className:"gf-form-label width-10",children:"Plugin state"})),(0,x.jsx)("label",{className:"gf-form-label gf-form-label--transparent",children:(0,x.jsx)(p.u,{state:e.state})})]}),(0,x.jsx)(w,{dataSource:s}),(0,x.jsx)(D,{dataSourceName:s.name,isDefault:s.isDefault,onDefaultChange:e=>a(e),onNameChange:e=>t(e)}),n&&(0,x.jsx)(I,{plugin:n,dataSource:s,dataSourceMeta:e,onModelChange:this.onModelChange}),(null==r?void 0:r.message)&&(0,x.jsx)("div",{className:"gf-form-group p-t-2",children:(0,x.jsx)(i.Alert,{severity:"error"===r.status?"error":"success",title:r.message,"aria-label":o.wl.pages.DataSource.alert,children:r.details&&this.renderAlertDetails()})}),(0,x.jsx)(y,{onSubmit:e=>this.onSubmit(e),canSave:!this.isReadOnly()&&l,canDelete:!this.isReadOnly()&&c,onDelete:this.onDelete,onTest:e=>this.onTest(e),exploreUrl:this.onNavigateToExplore()})]})}render(){const{navModel:e,page:t,loadError:a,loading:s}=this.props;return a?this.renderLoadError():(0,x.jsx)(d.Z,{navModel:e,children:(0,x.jsx)(d.Z.Contents,{isLoading:s,children:this.hasDataSource?(0,x.jsx)("div",{children:t?this.renderConfigPageBody(t):this.renderSettings()}):null})})}}const L=R(A)},30978:(e,t,a)=>{a.d(t,{u:()=>o});a(68404);var s=a(43215),n=a(69783),r=a(45916);const o=e=>{const t=function(e){switch(e){case s.PluginState.deprecated:return{text:"Deprecated",color:"red",tooltip:"This feature is deprecated and will be removed in a future release"};case s.PluginState.alpha:return{text:"Alpha",color:"blue",tooltip:"This feature is experimental and future updates might not be backward compatible"};case s.PluginState.beta:return{text:"Beta",color:"blue",tooltip:"This feature is close to complete but not fully tested"};default:return null}}(e.state);return t?(0,r.jsx)(n.Badge,{color:t.color,title:t.tooltip,text:t.text,icon:t.icon}):null}}}]);
- //# sourceMappingURL=DataSourceSettingsPage.c968388d22c7258c1511.js.map
|