diff --git a/ui/src/CheckSources.tsx b/ui/src/CheckSources.tsx index 1e56ec3713..6514eabf96 100644 --- a/ui/src/CheckSources.tsx +++ b/ui/src/CheckSources.tsx @@ -51,6 +51,8 @@ interface Props { errorThrown: () => void } +export const SourceContext = React.createContext() + // Acts as a 'router middleware'. The main `App` component is responsible for // getting the list of data sources, but not every page requires them to function. // Routes that do require data sources can be nested under this component. @@ -207,8 +209,10 @@ export class CheckSources extends Component { // TODO: guard against invalid resource access return ( - this.props.children && - React.cloneElement(this.props.children, {...this.props, source}) + + {this.props.children && + React.cloneElement(this.props.children, {...this.props, source})} + ) } } diff --git a/ui/src/dashboards/components/MeasurementDropdown.js b/ui/src/dashboards/components/MeasurementDropdown.js index 3df2f0a0f6..6cfb88d5ca 100644 --- a/ui/src/dashboards/components/MeasurementDropdown.js +++ b/ui/src/dashboards/components/MeasurementDropdown.js @@ -42,16 +42,14 @@ class MeasurementDropdown extends Component { } _getMeasurements = async () => { - const { - source: { - links: {proxy}, - }, - } = this.context const { measurement, database, onSelectMeasurement, onErrorThrown, + source: { + links: {proxy}, + }, } = this.props try { @@ -72,7 +70,12 @@ class MeasurementDropdown extends Component { const {func, shape, string} = PropTypes -MeasurementDropdown.contextTypes = { +MeasurementDropdown.propTypes = { + database: string.isRequired, + measurement: string, + onSelectMeasurement: func.isRequired, + onStartEdit: func.isRequired, + onErrorThrown: func.isRequired, source: shape({ links: shape({ proxy: string.isRequired, @@ -80,12 +83,4 @@ MeasurementDropdown.contextTypes = { }).isRequired, } -MeasurementDropdown.propTypes = { - database: string.isRequired, - measurement: string, - onSelectMeasurement: func.isRequired, - onStartEdit: func.isRequired, - onErrorThrown: func.isRequired, -} - export default MeasurementDropdown diff --git a/ui/src/dashboards/components/template_variables/Manager.js b/ui/src/dashboards/components/template_variables/Manager.js index 3432b9f758..56334c5bc1 100644 --- a/ui/src/dashboards/components/template_variables/Manager.js +++ b/ui/src/dashboards/components/template_variables/Manager.js @@ -3,12 +3,12 @@ import PropTypes from 'prop-types' import classnames from 'classnames' import uuid from 'uuid' +import {SourceContext} from 'src/CheckSources' import TemplateVariableTable from 'src/dashboards/components/template_variables/Table' import {TEMPLATE_VARIABLE_TYPES} from 'src/dashboards/constants' const TemplateVariableManager = ({ - source, onClose, onDelete, isEdited, @@ -46,14 +46,18 @@ const TemplateVariableManager = ({
- + + {source => ( + + )} +
) @@ -218,11 +222,6 @@ TemplateVariableManager.propTypes = { TemplateVariableManagerWrapper.propTypes = { onEditTemplateVariables: func.isRequired, - source: shape({ - links: shape({ - proxy: string, - }), - }).isRequired, templates: arrayOf( shape({ type: string.isRequired, diff --git a/ui/src/dashboards/components/template_variables/Row.js b/ui/src/dashboards/components/template_variables/Row.js index 4760990f46..8c5605f1d1 100644 --- a/ui/src/dashboards/components/template_variables/Row.js +++ b/ui/src/dashboards/components/template_variables/Row.js @@ -46,6 +46,7 @@ const TemplateVariableRow = ({ onSubmit, onErrorThrown, onDeleteTempVar, + source, }) => (
{ switch (selectedType) { case 'csv': @@ -25,6 +26,7 @@ const TemplateQueryBuilder = ({
SHOW MEASUREMENTS ON FROM {selectedDatabase ? ( SHOW TAG VALUES ON FROM {selectedDatabase ? ( (this.fileInput = el) render() { - const {onClose, errorThrown} = this.props + const {onClose, errorThrown, source} = this.props const {dragClass} = this.state return ( @@ -148,6 +148,7 @@ class WriteDataForm extends Component {
(

Write Data To

) -const {func, string, bool} = PropTypes +const {func, shape, string, bool} = PropTypes WriteDataHeader.propTypes = { handleSelectDatabase: func.isRequired, @@ -49,6 +51,11 @@ WriteDataHeader.propTypes = { errorThrown: func.isRequired, onClose: func.isRequired, isManual: bool, + source: shape({ + links: shape({ + proxy: string.isRequired, + }).isRequired, + }).isRequired, } export default WriteDataHeader diff --git a/ui/src/shared/components/DatabaseDropdown.js b/ui/src/shared/components/DatabaseDropdown.js index bd27c26015..725b339f03 100644 --- a/ui/src/shared/components/DatabaseDropdown.js +++ b/ui/src/shared/components/DatabaseDropdown.js @@ -39,8 +39,7 @@ class DatabaseDropdown extends Component { } _getDatabases = async () => { - const {source} = this.context - const {database, onSelectDatabase, onErrorThrown} = this.props + const {source, database, onSelectDatabase, onErrorThrown} = this.props const proxy = source.links.proxy try { const {data} = await showDatabases(proxy) @@ -65,7 +64,11 @@ class DatabaseDropdown extends Component { const {func, shape, string} = PropTypes -DatabaseDropdown.contextTypes = { +DatabaseDropdown.propTypes = { + database: string, + onSelectDatabase: func.isRequired, + onStartEdit: func, + onErrorThrown: func.isRequired, source: shape({ links: shape({ proxy: string.isRequired, @@ -73,11 +76,4 @@ DatabaseDropdown.contextTypes = { }).isRequired, } -DatabaseDropdown.propTypes = { - database: string, - onSelectDatabase: func.isRequired, - onStartEdit: func, - onErrorThrown: func.isRequired, -} - export default DatabaseDropdown