DataSourceSettings.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import React, { PureComponent } from 'react';
  2. import { connect } from 'react-redux';
  3. import { DataSource, Plugin } from 'app/types';
  4. export interface Props {
  5. dataSource: DataSource;
  6. dataSourceMeta: Plugin;
  7. }
  8. interface State {
  9. name: string;
  10. }
  11. enum DataSourceStates {
  12. Alpha = 'alpha',
  13. Beta = 'beta',
  14. }
  15. export class DataSourceSettings extends PureComponent<Props, State> {
  16. constructor(props) {
  17. super(props);
  18. this.state = {
  19. name: props.dataSource.name,
  20. };
  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. isReadyOnly() {
  35. return this.props.dataSource.readOnly === true;
  36. }
  37. shouldRenderInfoBox() {
  38. const { state } = this.props.dataSourceMeta;
  39. return state === DataSourceStates.Alpha || state === DataSourceStates.Beta;
  40. }
  41. getInfoText() {
  42. const { dataSourceMeta } = this.props;
  43. switch (dataSourceMeta.state) {
  44. case DataSourceStates.Alpha:
  45. return (
  46. 'This plugin is marked as being in alpha state, which means it is in early development phase and updates' +
  47. ' will include breaking changes.'
  48. );
  49. case DataSourceStates.Beta:
  50. return (
  51. 'This plugin is marked as being in a beta development state. This means it is in currently in active' +
  52. ' development and could be missing important features.'
  53. );
  54. }
  55. return null;
  56. }
  57. render() {
  58. const { name } = this.state;
  59. return (
  60. <div>
  61. <h3 className="page-sub-heading">Settings</h3>
  62. <form onSubmit={this.onSubmit}>
  63. <div className="gf-form-group">
  64. <div className="gf-form-inline">
  65. <div className="gf-form max-width-30">
  66. <span className="gf-form-label width-10">Name</span>
  67. <input
  68. className="gf-form-input max-width-23"
  69. type="text"
  70. value={name}
  71. placeholder="name"
  72. onChange={this.onNameChange}
  73. required
  74. />
  75. </div>
  76. </div>
  77. </div>
  78. {this.shouldRenderInfoBox() && <div className="grafana-info-box">{this.getInfoText()}</div>}
  79. {this.isReadyOnly() && (
  80. <div className="grafana-info-box span8">
  81. This datasource was added by config and cannot be modified using the UI. Please contact your server admin
  82. to update this datasource.
  83. </div>
  84. )}
  85. <div className="gf-form-button-row">
  86. <button type="submit" className="btn btn-success" disabled={this.isReadyOnly()} onClick={this.onSubmit}>
  87. Save &amp; Test
  88. </button>
  89. <button type="submit" className="btn btn-danger" disabled={this.isReadyOnly()} onClick={this.onDelete}>
  90. Delete
  91. </button>
  92. <a className="btn btn-inverse" href="datasources">
  93. Back
  94. </a>
  95. </div>
  96. </form>
  97. </div>
  98. );
  99. }
  100. }
  101. function mapStateToProps(state) {
  102. return {
  103. dataSource: state.dataSources.dataSource,
  104. dataSourceMeta: state.dataSources.dataSourceMeta,
  105. };
  106. }
  107. export default connect(mapStateToProps)(DataSourceSettings);