DataSourceSettings.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. url: {},
  74. };
  75. return (
  76. <div>
  77. <form onSubmit={this.onSubmit}>
  78. <div className="gf-form-group">
  79. <div className="gf-form-inline">
  80. <div className="gf-form max-width-30">
  81. <span className="gf-form-label width-10">Name</span>
  82. <input
  83. className="gf-form-input max-width-23"
  84. type="text"
  85. value={name}
  86. placeholder="Name"
  87. onChange={this.onNameChange}
  88. required
  89. />
  90. <div onClick={this.onTogglePopover}>
  91. <i className="fa fa-info-circle" />
  92. </div>
  93. {showNamePopover && (
  94. <div
  95. style={{
  96. position: 'absolute',
  97. left: '450px',
  98. top: '-20px',
  99. padding: '10px',
  100. backgroundColor: 'black',
  101. zIndex: 2,
  102. width: '300px',
  103. border: '1px solid gray',
  104. borderRadius: '3px',
  105. }}
  106. >
  107. The name is used when you select the data source in panels. The <em>Default</em> data source is
  108. preselected in new panels.
  109. </div>
  110. )}
  111. </div>
  112. </div>
  113. </div>
  114. {this.shouldRenderInfoBox() && <div className="grafana-info-box">{this.getInfoText()}</div>}
  115. {this.isReadyOnly() && (
  116. <div className="grafana-info-box span8">
  117. This datasource was added by config and cannot be modified using the UI. Please contact your server admin
  118. to update this datasource.
  119. </div>
  120. )}
  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. <DataSourceHttpSettings {...props} />
  134. </div>
  135. );
  136. }
  137. }
  138. function mapStateToProps(state) {
  139. return {
  140. dataSource: state.dataSources.dataSource,
  141. dataSourceMeta: state.dataSources.dataSourceMeta,
  142. };
  143. }
  144. export default connect(mapStateToProps)(DataSourceSettings);