From 20799a3ac1d51e78188ea3976ec820d426dde753 Mon Sep 17 00:00:00 2001 From: Hunter Trujillo Date: Tue, 25 Apr 2017 16:09:22 -0600 Subject: [PATCH] TVM now persists its state to the server. --- ui/src/dashboards/actions/index.js | 20 ------------------- ui/src/dashboards/apis/index.js | 9 +++------ .../components/TemplateVariableManager.js | 6 ++++-- ui/src/dashboards/constants/index.js | 9 +++++++++ ui/src/dashboards/containers/DashboardPage.js | 17 +++++++++------- ui/src/dashboards/reducers/ui.js | 2 +- 6 files changed, 27 insertions(+), 36 deletions(-) diff --git a/ui/src/dashboards/actions/index.js b/ui/src/dashboards/actions/index.js index de738f6ce..354e45583 100644 --- a/ui/src/dashboards/actions/index.js +++ b/ui/src/dashboards/actions/index.js @@ -5,7 +5,6 @@ import { updateDashboardCell as updateDashboardCellAJAX, addDashboardCell as addDashboardCellAJAX, deleteDashboardCell as deleteDashboardCellAJAX, - editTemplateVariable as editTemplateVariableAJAX, } from 'src/dashboards/apis' import {publishNotification} from 'shared/actions/notifications' @@ -199,22 +198,3 @@ export const deleteDashboardCellAsync = cell => async dispatch => { throw error } } - -export const editTemplateVariableAsync = ( - dashboardID, - staleTemplateVariable, - editedTemplateVariable -) => async dispatch => { - // dispatch(editTemplateVariableRequested()) - try { - const {data} = await editTemplateVariableAJAX( - staleTemplateVariable, - editedTemplateVariable - ) - dispatch(editTemplateVariableSuccess(+dashboardID, data)) - } catch (error) { - console.error(error) - // dispatch(errorThrown(error)) - // dispatch(editTemplateVariableFailed()) - } -} diff --git a/ui/src/dashboards/apis/index.js b/ui/src/dashboards/apis/index.js index 80f23d934..90db53818 100644 --- a/ui/src/dashboards/apis/index.js +++ b/ui/src/dashboards/apis/index.js @@ -74,15 +74,12 @@ export const deleteDashboardCell = async cell => { } } -export const editTemplateVariable = async ( - staleTemplateVariable, - editedTemplateVariable -) => { +export const editTemplateVariables = async templateVariable => { try { return await AJAX({ method: 'PUT', - url: staleTemplateVariable.links.self, - data: editedTemplateVariable, + url: templateVariable.links.self, + data: templateVariable, }) } catch (error) { console.error(error) diff --git a/ui/src/dashboards/components/TemplateVariableManager.js b/ui/src/dashboards/components/TemplateVariableManager.js index d2fd9e62a..192d4e4b7 100644 --- a/ui/src/dashboards/components/TemplateVariableManager.js +++ b/ui/src/dashboards/components/TemplateVariableManager.js @@ -3,6 +3,8 @@ import OnClickOutside from 'react-onclickoutside' import TemplateVariableTable from 'src/dashboards/components/TemplateVariableTable' +import {TEMPLATE_VARIABLE_TYPES} from 'src/dashboards/constants' + const TemplateVariableManager = ({ onClose, onEditTemplateVariables, @@ -20,7 +22,7 @@ const TemplateVariableManager = ({ @@ -86,7 +88,7 @@ class TemplateVariableManagerWrapper extends Component { const values = parsedData.map(value => ({ value, - type, + type: TEMPLATE_VARIABLE_TYPES[type], selected: selectedValue === value, })) diff --git a/ui/src/dashboards/constants/index.js b/ui/src/dashboards/constants/index.js index fc1556308..51c187e17 100644 --- a/ui/src/dashboards/constants/index.js +++ b/ui/src/dashboards/constants/index.js @@ -54,6 +54,15 @@ export const TEMPLATE_TYPES = [ }, ] +export const TEMPLATE_VARIABLE_TYPES = { + csv: 'csv', + databases: 'database', + measurements: 'measurement', + fieldKeys: 'fieldKey', + tagKeys: 'tagKey', + tagValues: 'tagValue', +} + export const TEMPLATE_VARIABLE_QUERIES = { databases: 'SHOW DATABASES', measurements: 'SHOW MEASUREMENTS ON $database', diff --git a/ui/src/dashboards/containers/DashboardPage.js b/ui/src/dashboards/containers/DashboardPage.js index 7c17f2901..1e3b22eee 100644 --- a/ui/src/dashboards/containers/DashboardPage.js +++ b/ui/src/dashboards/containers/DashboardPage.js @@ -177,13 +177,16 @@ class DashboardPage extends Component { } // TODO: make this work over array of template variables onSave in TVM - handleEditTemplateVariables(staleTemplateVariable, editedTemplateVariable) { - // // this.props.dashboardActions.editTemplateVariableAsync( - // // this.props.params.dashboardID, - // // staleTemplateVariable, - // // editedTemplateVariable - // // ) - // console.log('hello') + handleEditTemplateVariables(templates) { + return e => { + const {params: {dashboardID}, dashboards} = this.props + const currentDashboard = dashboards.find(({id}) => id === +dashboardID) + + this.props.dashboardActions.putDashboard({ + ...currentDashboard, + templates, + }) + } } handleRunQueryFailure(error) { diff --git a/ui/src/dashboards/reducers/ui.js b/ui/src/dashboards/reducers/ui.js index 801bd7aea..9efe34db1 100644 --- a/ui/src/dashboards/reducers/ui.js +++ b/ui/src/dashboards/reducers/ui.js @@ -219,7 +219,7 @@ export default function ui(state = initialState, action) { (d.id === dashboardID ? { ...d, - templates: d.templates.map(t => (t.id === data.id ? data : t)), + templates: data, } : d) )