DataSourceSettings.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. import React, { PureComponent } from 'react';
  2. import { connect } from 'react-redux';
  3. import { DataSource, Plugin } from 'app/types';
  4. import DataSourceHttpSettings from './DataSourceHttpSettings';
  5. export interface Props {
  6. dataSource: DataSource;
  7. dataSourceMeta: Plugin;
  8. }
  9. interface State {
  10. name: string;
  11. showNamePopover: boolean;
  12. }
  13. enum DataSourceStates {
  14. Alpha = 'alpha',
  15. Beta = 'beta',
  16. }
  17. export class DataSourceSettings extends PureComponent<Props, State> {
  18. state = {
  19. name: this.props.dataSource.name,
  20. showNamePopover: false,
  21. };
  22. onNameChange = event => {
  23. this.setState({
  24. name: event.target.value,
  25. });
  26. };
  27. onSubmit = event => {
  28. event.preventDefault();
  29. console.log(event);
  30. };
  31. onDelete = event => {
  32. console.log(event);
  33. };
  34. onTogglePopover = () => {
  35. this.setState(prevState => ({
  36. showNamePopover: !prevState.showNamePopover,
  37. }));
  38. };
  39. isReadyOnly() {
  40. return this.props.dataSource.readOnly === true;
  41. }
  42. shouldRenderInfoBox() {
  43. const { state } = this.props.dataSourceMeta;
  44. return state === DataSourceStates.Alpha || state === DataSourceStates.Beta;
  45. }
  46. getInfoText() {
  47. const { dataSourceMeta } = this.props;
  48. switch (dataSourceMeta.state) {
  49. case DataSourceStates.Alpha:
  50. return (
  51. 'This plugin is marked as being in alpha state, which means it is in early development phase and updates' +
  52. ' will include breaking changes.'
  53. );
  54. case DataSourceStates.Beta:
  55. return (
  56. 'This plugin is marked as being in a beta development state. This means it is in currently in active' +
  57. ' development and could be missing important features.'
  58. );
  59. }
  60. return null;
  61. }
  62. render() {
  63. const { name, showNamePopover } = this.state;
  64. const props = {
  65. access: {},
  66. basicAuth: {},
  67. showAccessOption: {},
  68. tlsAuth: {},
  69. tlsAuthWithCACert: {},
  70. tlsCACert: {},
  71. tlsClientCert: {},
  72. tlsClientKey: {},
  73. };
  74. return (
  75. <div>
  76. <form onSubmit={this.onSubmit}>
  77. <div className="gf-form-group">
  78. <div className="gf-form-inline">
  79. <div className="gf-form max-width-30">
  80. <span className="gf-form-label width-10">Name</span>
  81. <input
  82. className="gf-form-input max-width-23"
  83. type="text"
  84. value={name}
  85. placeholder="Name"
  86. onChange={this.onNameChange}
  87. required
  88. />
  89. <div onClick={this.onTogglePopover}>
  90. <i className="fa fa-info-circle" />
  91. </div>
  92. {showNamePopover && (
  93. <div
  94. style={{
  95. position: 'absolute',
  96. left: '450px',
  97. top: '-20px',
  98. padding: '10px',
  99. backgroundColor: 'black',
  100. zIndex: 2,
  101. width: '300px',
  102. border: '1px solid gray',
  103. borderRadius: '3px',
  104. }}
  105. >
  106. The name is used when you select the data source in panels. The <em>Default</em> data source is
  107. preselected in new panels.
  108. </div>
  109. )}
  110. </div>
  111. </div>
  112. </div>
  113. {this.shouldRenderInfoBox() && <div className="grafana-info-box">{this.getInfoText()}</div>}
  114. {this.isReadyOnly() && (
  115. <div className="grafana-info-box span8">
  116. This datasource was added by config and cannot be modified using the UI. Please contact your server admin
  117. to update this datasource.
  118. </div>
  119. )}
  120. <DataSourceHttpSettings {...props} />
  121. <div className="gf-form-button-row">
  122. <button type="submit" className="btn btn-success" disabled={this.isReadyOnly()} onClick={this.onSubmit}>
  123. Save &amp; Test
  124. </button>
  125. <button type="submit" className="btn btn-danger" disabled={this.isReadyOnly()} onClick={this.onDelete}>
  126. Delete
  127. </button>
  128. <a className="btn btn-inverse" href="datasources">
  129. Back
  130. </a>
  131. </div>
  132. </form>
  133. </div>
  134. );
  135. }
  136. }
  137. function mapStateToProps(state) {
  138. return {
  139. dataSource: state.dataSources.dataSource,
  140. dataSourceMeta: state.dataSources.dataSourceMeta,
  141. };
  142. }
  143. export default connect(mapStateToProps)(DataSourceSettings);