From 112fc10e61c98c30dd3d15926c184559bb8eeb31 Mon Sep 17 00:00:00 2001 From: Jared Scheib Date: Wed, 26 Apr 2017 15:58:23 -0700 Subject: [PATCH] Add user ability to enter a CSV via text input to TVM; fix row find for state update --- .../components/TemplateVariableManager.js | 2 +- .../components/TemplateVariableRow.js | 67 +++++++++++++------ 2 files changed, 47 insertions(+), 22 deletions(-) diff --git a/ui/src/dashboards/components/TemplateVariableManager.js b/ui/src/dashboards/components/TemplateVariableManager.js index 17262a468..7c250c390 100644 --- a/ui/src/dashboards/components/TemplateVariableManager.js +++ b/ui/src/dashboards/components/TemplateVariableManager.js @@ -105,7 +105,7 @@ class TemplateVariableManagerWrapper extends Component { } = queryConfig // Determine which is the selectedValue, if any - const currentRow = rows.find(row => row.tempVar === tempVar) + const currentRow = rows.find(row => row.id === id) let selectedValue if (currentRow && currentRow.values && currentRow.values.length) { diff --git a/ui/src/dashboards/components/TemplateVariableRow.js b/ui/src/dashboards/components/TemplateVariableRow.js index 4e099c35b..5b60c5865 100644 --- a/ui/src/dashboards/components/TemplateVariableRow.js +++ b/ui/src/dashboards/components/TemplateVariableRow.js @@ -41,6 +41,26 @@ const RowValues = ({ : (No values to display) } +const RowButtons = ({isEditing, onCancelEdit, onDelete, id, selectedType}) => { + if (isEditing) { + return ( +
+ + +
+ ) + } + return onDelete(id)} /> +} + const TemplateVariableRow = ({ template: {id, label, tempVar, values}, isEditing, @@ -112,20 +132,13 @@ const TemplateVariableRow = ({ />
- {isEditing - ?
- - -
- : onDelete(id)} />} +
) @@ -165,7 +178,7 @@ class RowWrapper extends Component { autoFocusTarget: null, } - this.handleRunQueryRequested = ::this.handleRunQueryRequested + this.handleSubmit = ::this.handleSubmit this.handleSelectType = ::this.handleSelectType this.handleSelectDatabase = ::this.handleSelectDatabase this.handleSelectMeasurement = ::this.handleSelectMeasurement @@ -175,7 +188,7 @@ class RowWrapper extends Component { this.runTemplateVariableQuery = ::this.runTemplateVariableQuery } - handleRunQueryRequested({ + handleSubmit({ selectedDatabase: database, selectedMeasurement: measurement, selectedTagKey: tagKey, @@ -219,10 +232,14 @@ class RowWrapper extends Component { } try { - const parsedData = await this.runTemplateVariableQuery( - source, - queryConfig - ) + let parsedData + if (type === 'csv') { + parsedData = e.target.values.value + .split(',') + .map(value => value.trim()) + } else { + parsedData = await this.runTemplateVariableQuery(source, queryConfig) + } onRunQuerySuccess(template, queryConfig, parsedData, {tempVar, label}) } catch (error) { onRunQueryFailure(error) @@ -318,7 +335,7 @@ class RowWrapper extends Component { onStartEdit={this.handleStartEdit} onCancelEdit={this.handleCancelEdit} autoFocusTarget={autoFocusTarget} - onSubmit={this.handleRunQueryRequested} + onSubmit={this.handleSubmit} /> ) } @@ -387,4 +404,12 @@ RowValues.propTypes = { autoFocusTarget: string, } +RowButtons.propTypes = { + isEditing: bool.isRequired, + onCancelEdit: func.isRequired, + onDelete: func.isRequired, + id: string.isRequired, + selectedType: string.isRequired, +} + export default OnClickOutside(RowWrapper)